Skip to content

Commit

Permalink
Resolved merge conflict adopting upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
tpike3 committed Jun 9, 2020
2 parents 577b933 + a06a9b2 commit 64e7efe
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 29 deletions.
3 changes: 1 addition & 2 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ No contribution is too small. Although, contributions can be too big, so let's d
- Git commit your changes with a meaningful message: ``git commit -m "Fixes X issue."``
- If implementing a new feature, include some documentation in docs folder.
- Make sure that your submission passes the `Travis build`_. See "Testing and Standards below" to be able to run these locally.
- Make sure that your code is formatted according to `the black`_ standard (you can do it via
`pre-commit`_).
- Make sure that your code is formatted according to `the black`_ standard (you can do it via `pre-commit`_).
- Push your changes to your fork on Github: ``git push origin NAME_OF_BRANCH``.
- `Create a pull request`_.
- Describe the change w/ ticket number(s) that the code fixes.
Expand Down
71 changes: 45 additions & 26 deletions docs/tutorials/intro_tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ file, which can be installed directly from the github repository by running:

.. code:: bash
$ pip install -r https://raw.githubusercontent.com/projectmesa/mesa/master/examples/boltzmann_wealth_model/requirements.txt
$ pip install -r https://raw.githubusercontent.com/projectmesa/mesa/master/examples/boltzmann_wealth_model/requirements.txt
or if you have the requirements file locally with

Expand Down Expand Up @@ -184,7 +184,7 @@ this:
# The agent's step will go here.
# For demonstration purposes we will print the agent's unique_id
print ("Hi, I am agent " + str(self.unique_id) +".")
class MoneyModel(Model):
"""A model with some number of agents."""
def __init__(self, N):
Expand All @@ -208,7 +208,7 @@ code is in ``money_model.py``:

.. code:: python
from money_model import MoneyModel
from money_model import MoneyModel
Then create the model object, and run it for one step:

Expand All @@ -217,7 +217,6 @@ Then create the model object, and run it for one step:
empty_model = MoneyModel(10)
empty_model.step()
.. parsed-literal::
Hi, I am agent 8.
Expand All @@ -230,7 +229,6 @@ Then create the model object, and run it for one step:
Hi, I am agent 1.
Hi, I am agent 6.
Hi, I am agent 7.
Exercise
^^^^^^^^
Expand Down Expand Up @@ -280,14 +278,13 @@ the model.

If you've written the code in its own file (``money_model.py`` or a
different name), launch an interpreter in the same directory as the file
(either the plain Python command-line interpreter, or the make htm
interpreter), or launch a Jupyter Notebook there. Then import the
(either the plain Python command-line interpreter, or the IPython interpreter), or launch a Jupyter Notebook there. Then import the
classes you created. (If you wrote the code in a Notebook, obviously
this step isn't necessary).

.. code:: python
from money_model import *
from money_model import *
Now let's create a model with 10 agents, and run it for 10 steps.

Expand Down Expand Up @@ -315,11 +312,11 @@ graphics library) to visualize the data in a histogram.
#For a script add the following line
plt.show()
You'll should see something like the distribution below. Yours will
You should see something like the distribution below. Yours will
almost certainly look at least slightly different, since each run of the
model is random.

.. image:: intro_tutorial_files/intro_tutorial_19_1.png
.. image:: files/output_19_1.png

To get a better idea of how a model behaves, we can create multiple
model runs and see the distribution that emerges from all of them. We
Expand All @@ -328,7 +325,8 @@ can do this with a nested for loop:
.. code:: python
all_wealth = []
#This runs the model 100 times, each model executing 10 steps.
#This runs the model 100 times, each model executing 10 steps.
for j in range(100):
# Run the model
model = MoneyModel(10)
Expand Down Expand Up @@ -447,15 +445,15 @@ With that in mind, the agent's ``move`` method looks like this:

.. code:: python
class MoneyAgent(Agent):
#...
def move(self):
possible_steps = self.model.grid.get_neighborhood(
self.pos,
moore=True,
include_center=False)
new_position = self.random.choice(possible_steps)
self.model.grid.move_agent(self, new_position)
class MoneyAgent(Agent):
#...
def move(self):
possible_steps = self.model.grid.get_neighborhood(
self.pos,
moore=True,
include_center=False)
new_position = self.random.choice(possible_steps)
self.model.grid.move_agent(self, new_position)
Next, we need to get all the other agents present in a cell, and give
one of them some money. We can get the contents of one or more cells
Expand Down Expand Up @@ -536,6 +534,27 @@ Now, putting that all together should look like this:
class MoneyModel(Model):
"""A model with some number of agents."""
def __init__(self, N, width, height):
self.num_agents = N
self.grid = MultiGrid(width, height, True)
self.schedule = RandomActivation(self)
# Create agents
for i in range(self.num_agents):
a = MoneyAgent(i, self)
self.schedule.add(a)
# Add the agent to a random grid cell
x = self.random.randrange(self.grid.width)
y = self.random.randrange(self.grid.height)
self.grid.place_agent(a, (x, y))
def step(self):
self.schedule.step()
Let's create a model with 50 agents on a 10x10 grid, and run it for 20
steps.

Expand Down Expand Up @@ -803,7 +822,7 @@ True indefinitely.
N = model.num_agents
B = sum( xi * (N-i) for i,xi in enumerate(x) ) / (N*sum(x))
return (1 + (1/N) - 2*B)
class MoneyModel(Model):
"""A model with some number of agents."""
def __init__(self, N, width, height):
Expand All @@ -824,7 +843,7 @@ True indefinitely.
self.datacollector = DataCollector(
model_reporters={"Gini": compute_gini},
agent_reporters={"Wealth": "wealth"})
def step(self):
self.datacollector.collect(self)
self.schedule.step()
Expand Down Expand Up @@ -858,14 +877,14 @@ times (49* 5) for 245 iterations
.. code:: python
fixed_params = {"width": 10,
fixed_params = {"width": 10,
"height": 10}
variable_params = {"N": range(10, 500, 10)}
batch_run = BatchRunner(MoneyModel,

batch_run = BatchRunner(MoneyModel,
variable_params,
fixed_params,
iterations=5,
iterations=5,
max_steps=100,
model_reporters={"Gini": compute_gini})
batch_run.run_all()
Expand Down
3 changes: 2 additions & 1 deletion tests/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,5 @@ def test_examples(self):
server.server.render_model()
Model = getattr(mod, classcase(example))
model = Model()
(model.step() for _ in range(100))
for _ in range(10):
model.step()

0 comments on commit 64e7efe

Please sign in to comment.