-
Notifications
You must be signed in to change notification settings - Fork 116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactored Boltzmann example docs and scripts. #26
Conversation
Made substantial edits to the Boltzmann wealth distribution example. The general train of thought wasn't changed in the .md file, but many paragraph were restructured significantly and a few paragraphs were added. Also, the corresponding files in `examples/` were edited as well. Since the docs page gives two examples of the Boltzmann model (with a grid and without), two separate `.jl` files where created so that either variation can be easily executed by the user. The code referenced in docs page is exactly the same code in the two `.jl` files.
This is very good. Thanks for your contribution. available_agents = get_node_contents(agent, model)
agent2id = rand(available_agents)
agent.wealth -= 1
agent2 = [i for i in model.agents if i.id == agent2id][1]
agent2.wealth += 1
# now move
neighboring_nodes = node_neighbors(agent, model)
move_agent!(agent, rand(neighboring_nodes), model) Could you add them to the function and remove the to-do before I merge this PR? |
@kavir1698 thanks for sharing the updated |
This is for issue JuliaDynamics#27. Added new agent_step! code provided by kavir1698, function forces agents to only give wealth to someone on their own node.
Below is what I added to the Boltzmann example. function agent_step!(agent::AbstractAgent, model::AbstractModel)
# If the agent's wealth is zero, then do nothing.
if agent.wealth == 0
return
# Otherwise..
else
#...create a list of all agents on the same node and select a random agent.
available_agents = get_node_contents(agent, model)
random_neighbor_agent_id = rand(available_agents)
random_neighbor_agent = [i for i in model.agents
if i.id == random_neighbor_agent_id][1]
# Then decrement the current agent's wealth and increment the neighbor's wealth.
agent.wealth -= 1
random_neighbor_agent.wealth += 1
end
end |
@kavir1698 should the below lines be included in the # now move
neighboring_nodes = node_neighbors(agent, model)
move_agent!(agent, rand(neighboring_nodes), model) I didn't include them in my latest commit, I just didn't see where that was explained in the Boltzmann example. I can add the "move agent" lines back in if needed, I just wasn't quite sure why the agents where being moved in |
Yes, agents should actually move for the model to work. Otherwise, same agents would give and receive among themselves. See this article. |
Agents who trade wealth with only agents on their own node must be moved at every step, otherwise they will just trade wealth amongst themselves.
@kavir1698 , ah, I see, that is intuitive in hindsight. I added those lines to the example and wrote a comment and paragraph in the docs page mentioning this. |
Made substantial edits to the Boltzmann wealth distribution example. The
general train of thought wasn't changed in the .md file, but many
paragraph were restructured significantly and a few paragraphs were
added.
Also, the corresponding files in
examples/
were edited as well. Sincethe docs page gives two examples of the Boltzmann model (with a grid and
without), two separate
.jl
files where created so that eithervariation can be easily executed by the user. The code referenced in
docs page is exactly the same code in the two
.jl
files.