Skip to content
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

Merged
merged 3 commits into from
Aug 20, 2019

Conversation

def-mycroft
Copy link
Contributor

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.

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.
@kavir1698
Copy link
Collaborator

kavir1698 commented Aug 19, 2019

This is very good. Thanks for your contribution.
There is a to-do for the agent_step! function where you want the agents to exchange money only with other nearby agents. The original function already has implemented it. Specifically, the lines below:

    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?

@def-mycroft
Copy link
Contributor Author

@kavir1698 thanks for sharing the updated agent_step! code for the second part of the Boltzmann example, I'll update this and remove the TODO (will try to do it tonight, about 8 hours from now). I don't see that code in the docs on the master branch, but no matter I'll just update it now. This will close issue #27.

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.
@def-mycroft
Copy link
Contributor Author

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

@def-mycroft
Copy link
Contributor Author

@kavir1698 should the below lines be included in the agent_step! function?

   # 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 agent_step! and would like to explain it in the example.

@kavir1698
Copy link
Collaborator

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.
@def-mycroft
Copy link
Contributor Author

@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.

@kavir1698 kavir1698 merged commit d611eb7 into JuliaDynamics:master Aug 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants