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

Include examples in readthedocs #2382

Closed
wants to merge 77 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
d90b0f7
further updates
quaquel Jan 21, 2024
9586490
Update benchmarks/WolfSheep/__init__.py
quaquel Jan 21, 2024
4aaa35d
Merge remote-tracking branch 'upstream/main'
quaquel Feb 21, 2024
d31478c
Merge remote-tracking branch 'upstream/main'
quaquel Apr 22, 2024
6e4c72e
Merge remote-tracking branch 'upstream/main'
quaquel Aug 14, 2024
70fbaf5
Merge remote-tracking branch 'upstream/main'
quaquel Aug 18, 2024
724c8db
Merge remote-tracking branch 'upstream/main'
quaquel Aug 21, 2024
45184a4
Merge remote-tracking branch 'upstream/main'
quaquel Aug 22, 2024
3d75d30
Merge remote-tracking branch 'upstream/main'
quaquel Aug 27, 2024
2759244
Update __init__.py
quaquel Aug 27, 2024
fc8aaea
Merge remote-tracking branch 'upstream/main'
quaquel Aug 28, 2024
1ba465d
Merge remote-tracking branch 'upstream/main'
quaquel Aug 30, 2024
2b5e822
Merge remote-tracking branch 'upstream/main'
quaquel Sep 2, 2024
3847799
Merge remote-tracking branch 'upstream/main'
quaquel Sep 4, 2024
301d80e
Merge remote-tracking branch 'upstream/main'
quaquel Sep 4, 2024
fe3d655
Merge remote-tracking branch 'upstream/main'
quaquel Sep 4, 2024
7d18880
Merge remote-tracking branch 'upstream/main'
quaquel Sep 5, 2024
6b49a3b
Merge remote-tracking branch 'upstream/main'
quaquel Sep 5, 2024
b9909e6
Merge remote-tracking branch 'upstream/main'
quaquel Sep 9, 2024
8ce3d83
Merge remote-tracking branch 'upstream/main'
quaquel Sep 10, 2024
88fbf74
Merge remote-tracking branch 'upstream/main'
quaquel Sep 13, 2024
077aca5
Merge remote-tracking branch 'upstream/main'
quaquel Sep 16, 2024
c771e3b
Merge remote-tracking branch 'upstream/main'
quaquel Sep 18, 2024
3fa0c27
Merge remote-tracking branch 'upstream/main'
quaquel Sep 18, 2024
8fdcf5c
Merge remote-tracking branch 'upstream/main'
quaquel Sep 21, 2024
475b060
Merge remote-tracking branch 'upstream/main'
quaquel Sep 21, 2024
fb93261
Merge remote-tracking branch 'upstream/main'
quaquel Sep 25, 2024
86f2f0c
Merge remote-tracking branch 'upstream/main'
quaquel Sep 25, 2024
dc1d843
Merge remote-tracking branch 'upstream/main'
quaquel Sep 25, 2024
9857ef1
Merge remote-tracking branch 'upstream/main'
quaquel Sep 25, 2024
afdd836
Merge remote-tracking branch 'upstream/main'
quaquel Sep 29, 2024
46c3d13
Merge remote-tracking branch 'upstream/main'
quaquel Sep 30, 2024
a5205eb
Merge remote-tracking branch 'upstream/main'
quaquel Oct 7, 2024
59a0413
Merge remote-tracking branch 'upstream/main'
quaquel Oct 12, 2024
56f00af
Merge remote-tracking branch 'upstream/main'
quaquel Oct 12, 2024
135c978
Merge remote-tracking branch 'upstream/main'
quaquel Oct 14, 2024
bd4ca35
Merge remote-tracking branch 'upstream/main'
quaquel Oct 15, 2024
5a69aee
Merge remote-tracking branch 'upstream/main'
quaquel Oct 15, 2024
98c4616
Merge remote-tracking branch 'upstream/main'
quaquel Oct 16, 2024
2aa5326
Merge remote-tracking branch 'upstream/main'
quaquel Oct 16, 2024
91e6c0f
Merge remote-tracking branch 'upstream/main'
quaquel Oct 16, 2024
5976962
Merge remote-tracking branch 'upstream/main'
quaquel Oct 17, 2024
95da9b7
Merge remote-tracking branch 'upstream/main'
quaquel Oct 17, 2024
66b70eb
Merge remote-tracking branch 'upstream/main'
quaquel Oct 18, 2024
2d1d391
first test of examples in docs
quaquel Oct 17, 2024
dc84b97
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 17, 2024
25837e2
Update conf.py
quaquel Oct 17, 2024
6c132d1
Update pyproject.toml
quaquel Oct 17, 2024
1251297
Update conf.py
quaquel Oct 17, 2024
6cb510d
filename updates
quaquel Oct 17, 2024
8f41c33
Update conf.py
quaquel Oct 17, 2024
8bbdb1d
fixes
quaquel Oct 17, 2024
962e794
further updates
quaquel Oct 17, 2024
ee662b1
Update examples_overview_template.txt
quaquel Oct 17, 2024
fd4bfaa
Update example_template.txt
quaquel Oct 18, 2024
3f0c3e6
add app.py into docs
quaquel Oct 18, 2024
1515f29
Update app.py
quaquel Oct 18, 2024
5759cb3
remove inits from api docs
quaquel Oct 18, 2024
f5070b7
updates
quaquel Oct 18, 2024
b65fa0a
hacky fix
quaquel Oct 18, 2024
6ec9687
Update visualization_tutorial.ipynb
quaquel Oct 18, 2024
4bbf000
cleanup
quaquel Oct 18, 2024
962c0cc
updated files
quaquel Oct 18, 2024
6ce1e0a
updates
quaquel Oct 18, 2024
14f7104
automated detection of updates to example files
quaquel Oct 18, 2024
2ef80f8
Update conf.py
quaquel Oct 18, 2024
ed764f8
Improve Mesa 3.0 beta 1 release notes (#2384)
EwoutH Oct 18, 2024
ed43d5c
refactor: Simplify Schelling code (#2353)
rht Oct 18, 2024
962adce
trying to merge
quaquel Oct 18, 2024
824459f
trying to merge
quaquel Oct 18, 2024
e0ac4ba
Update index.md
quaquel Oct 19, 2024
8fa9f53
some typo fixes
quaquel Oct 19, 2024
4be7dd2
allways create md files
quaquel Oct 20, 2024
f92b37c
Update conf.py
quaquel Oct 20, 2024
5163352
Update conf.py
quaquel Oct 20, 2024
6a34561
Merge branch 'main' into docs
quaquel Oct 20, 2024
04e8763
Update conf.py
quaquel Oct 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Benchmarking
benchmarks/**/*.pickle

# exampledocs
docs/examples/*.md

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down
9 changes: 4 additions & 5 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
Docs for Mesa
=============
# Docs for Mesa

The readable version of the docs is hosted at [mesa.readthedocs.org](http://mesa.readthedocs.org/).

This folder contains the docs that build the docs for the core mesa code on readthdocs.

### How to publish updates to the docs
## How to publish updates to the docs

Updating docs can be confusing. Here are the basic setups.

##### Submit a pull request with updates
#### Submit a pull request with updates
1. Create branch (either via branching or fork of repo) -- try to use a descriptive name.
* `git checkout -b doc-updates`
1. Update the docs. Save.
Expand All @@ -23,7 +22,7 @@ Updating docs can be confusing. Here are the basic setups.
* `git push origin doc-updates`
1. From here you will want to submit a pull request to main.

##### Update read the docs
#### Update read the docs

From this point, you will need to find someone that has access to readthedocs. Currently, that is [@jackiekazil](https://github.com/jackiekazil), [@rht](https://github.com/rht), and [@tpike3](https://github.com/dmasad).

Expand Down
10 changes: 0 additions & 10 deletions docs/apis/experimental.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@ This namespace contains experimental features. These are under development, and

## Cell Space

```{eval-rst}
.. automodule:: experimental.cell_space.__init__
:members:
```

```{eval-rst}
.. automodule:: experimental.cell_space.cell
:members:
Expand Down Expand Up @@ -40,11 +35,6 @@ This namespace contains experimental features. These are under development, and

## Devs

```{eval-rst}
.. automodule:: experimental.devs.__init__
:members:
```

```{eval-rst}
.. automodule:: experimental.devs.eventlist
:members:
Expand Down
70 changes: 70 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,16 @@
# serve to show the default.

import os
import os.path as osp
import pathlib
import sys
import string
from datetime import date

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
HERE = osp.abspath(osp.dirname(__file__))
sys.path.insert(0, os.path.abspath("."))
sys.path.insert(0, "../examples")
sys.path.insert(0, "../mesa")
Expand Down Expand Up @@ -289,3 +293,69 @@

# Example configuration for intersphinx: refer to the Python standard library.
intersphinx_mapping = {"python": ("https://docs.python.org/3", None)}



def write_example_md_file(agent_filename, model_filename, readme_filename, app_filename, md_filepath, template):
with open(agent_filename) as content_file:
agent_file = content_file.read()
with open(model_filename) as content_file:
model_file = content_file.read()
with open(readme_filename) as content_file:
readme_file = content_file.read()
with open(app_filename) as content_file:
app_file = content_file.read()

with open(md_filepath, "w") as fh:
content = template.substitute(
dict(agent_file=agent_file, model_file=model_file,
readme_file=readme_file, app_file=app_file)
)
fh.write(content)

def setup_examples_pages():
# create md files for all examples
# check what examples exist
examples_folder = osp.abspath(osp.join(HERE, "..", "mesa", "examples"))
basic_examples = [f.path for f in os.scandir(osp.join(examples_folder, "basic")) if f.is_dir() and not f.name.startswith("__") ]
advanced_examples = [] # fixme [f.path for f in os.scandir(osp.join(examples_folder, "advanced")) if f.is_dir()]
examples = basic_examples + advanced_examples

with open(os.path.join(HERE, "example_template.txt")) as fh:
template = string.Template(fh.read())

pathlib.Path(os.path.join(HERE, "examples")).mkdir(parents=True, exist_ok=True)

examples_md = []
for example in examples:
base_name = os.path.basename(os.path.normpath(example))

agent_filename = os.path.join(example, "agents.py")
model_filename = os.path.join(example, "model.py")
readme_filename = os.path.join(example, "Readme.md")
app_filename = os.path.join(example, "app.py")

md_filename = f"{base_name}.md"
examples_md.append(base_name)

md_filepath = os.path.join(HERE, "examples", md_filename)
write_example_md_file(agent_filename, model_filename, readme_filename, app_filename, md_filepath, template)

# create overview of examples.md
with open(os.path.join(HERE, "examples_overview_template.txt")) as fh:
template = string.Template(fh.read())

with open(os.path.join(HERE, "examples.md"), "w") as fh:
content = template.substitute(
dict(
examples="\n".join([f"{' '.join(base_name.split('_'))} </examples/{base_name}>" for base_name in examples_md]),
)
)
fh.write(content)

def setup(app):
setup_examples_pages()

#
if __name__ == "__main__":
setup_examples_pages()
22 changes: 22 additions & 0 deletions docs/example_template.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

$readme_file

## Agents

```python
$agent_file
```


## Model

```python
$model_file
```


## App

```python
$app_file
```
14 changes: 14 additions & 0 deletions docs/examples.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

# Examples


```{toctree}
:maxdepth: 1

boid flockers </examples/boid_flockers>
virus on network </examples/virus_on_network>
conways game of life </examples/conways_game_of_life>
schelling </examples/schelling>
boltzmann wealth model </examples/boltzmann_wealth_model>

```
10 changes: 10 additions & 0 deletions docs/examples_overview_template.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

# Examples


```{toctree}
:maxdepth: 1

$examples

```
1 change: 1 addition & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ ABM features users have shared that you may want to use in your model
Mesa Overview <overview>
tutorials/intro_tutorial
tutorials/visualization_tutorial
Examples <examples>
quaquel marked this conversation as resolved.
Show resolved Hide resolved
Migration guide <migration_guide>
Best Practices <best-practices>
How-to Guide <howto>
Expand Down
3 changes: 2 additions & 1 deletion docs/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ Mesa is modular, meaning that its modeling, analysis and visualization component

Most models consist of one class to represent the model itself and one or more classes for agents. Mesa provides built-in functionality for managing agents and their interactions. These are implemented in Mesa's modeling modules:

- `mesa.Model`, `mesa.Agent`
- [mesa.model](apis/model)
- [mesa.agent](apis/agent)
- [mesa.space](apis/space)

The skeleton of a model might look like this:
Expand Down
4 changes: 2 additions & 2 deletions docs/packages.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ The commands above should also work with Anaconda, just replace the `pip` with `

## Package Development: A "How-to Guide"

The purpose of this section is help you understand, setup, and distribute your Mesa package as quickly as possible. A Mesa package is just a Python package or repo. We just call it a Mesa package, because we are talking about a Python package in the context of Mesa. These instructions assume that you are a little familiar with development, but that you have little knowledge of the packaging process.
The purpose of this section is to help you understand, setup, and distribute your Mesa package as quickly as possible. A Mesa package is just a Python package or repo. We just call it a Mesa package, because we are talking about a Python package in the context of Mesa. These instructions assume that you are a little familiar with development, but that you have little knowledge of the packaging process.

There are two ways to share a package:

Expand All @@ -85,7 +85,7 @@ Most likely you created an ABM that has the code that you want to share in it, w
>
> 4. [Clone the repo to your computer](https://help.github.com/articles/cloning-a-repository/#platform-linux).
>
> 5. Copy your code directory into the repo that you cloned one your computer.
> 5. Copy your code directory into the repo that you cloned on your computer.
>
> 6. Add a requirements.txt file, which lets people know which external Python packages are needed to run the code in your repo. To create a file, run: `pip freeze > requirements.txt`. Note, if you are running Anaconda, you will need to install pip first: `conda install pip`.
>
Expand Down
16 changes: 8 additions & 8 deletions mesa/examples/basic/conways_game_of_life/agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ def __init__(self, pos, model, init_state=DEAD):
super().__init__(model)
self.x, self.y = pos
self.state = init_state
self._nextState = None
self._next_state = None

@property
def isAlive(self):
def is_alive(self):
return self.state == self.ALIVE

@property
Expand All @@ -31,17 +31,17 @@ def determine_state(self):
"""
# Get the neighbors and apply the rules on whether to be alive or dead
# at the next tick.
live_neighbors = sum(neighbor.isAlive for neighbor in self.neighbors)
live_neighbors = sum(neighbor.is_alive for neighbor in self.neighbors)

# Assume nextState is unchanged, unless changed below.
self._nextState = self.state
if self.isAlive:
self._next_state = self.state
if self.is_alive:
if live_neighbors < 2 or live_neighbors > 3:
self._nextState = self.DEAD
self._next_state = self.DEAD
else:
if live_neighbors == 3:
self._nextState = self.ALIVE
self._next_state = self.ALIVE

def assume_state(self):
"""Set the state to the new computed state -- computed in step()."""
self.state = self._nextState
self.state = self._next_state
71 changes: 71 additions & 0 deletions mesa/examples/basic/conways_game_of_life/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import time

Check warning on line 1 in mesa/examples/basic/conways_game_of_life/app.py

View check run for this annotation

Codecov / codecov/patch

mesa/examples/basic/conways_game_of_life/app.py#L1

Added line #L1 was not covered by tests

import altair as alt
import numpy as np
import pandas as pd
import streamlit as st
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still want to use streamlit or update to Solara?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in my view, we standardize all examples on solara

from model import ConwaysGameOfLife

Check warning on line 7 in mesa/examples/basic/conways_game_of_life/app.py

View check run for this annotation

Codecov / codecov/patch

mesa/examples/basic/conways_game_of_life/app.py#L3-L7

Added lines #L3 - L7 were not covered by tests

model = st.title("Conway's Game of Life")
num_ticks = st.slider("Select number of Steps", min_value=1, max_value=100, value=50)
height = st.slider("Select Grid Height", min_value=10, max_value=100, step=10, value=15)
width = st.slider("Select Grid Width", min_value=10, max_value=100, step=10, value=20)
model = ConwaysGameOfLife(height, width)

Check warning on line 13 in mesa/examples/basic/conways_game_of_life/app.py

View check run for this annotation

Codecov / codecov/patch

mesa/examples/basic/conways_game_of_life/app.py#L9-L13

Added lines #L9 - L13 were not covered by tests

col1, col2, col3 = st.columns(3)
status_text = st.empty()

Check warning on line 16 in mesa/examples/basic/conways_game_of_life/app.py

View check run for this annotation

Codecov / codecov/patch

mesa/examples/basic/conways_game_of_life/app.py#L15-L16

Added lines #L15 - L16 were not covered by tests
# step_mode = st.checkbox('Run Step-by-Step')
run = st.button("Run Simulation")

Check warning on line 18 in mesa/examples/basic/conways_game_of_life/app.py

View check run for this annotation

Codecov / codecov/patch

mesa/examples/basic/conways_game_of_life/app.py#L18

Added line #L18 was not covered by tests


if run:
tick = time.time()
step = 0

Check warning on line 23 in mesa/examples/basic/conways_game_of_life/app.py

View check run for this annotation

Codecov / codecov/patch

mesa/examples/basic/conways_game_of_life/app.py#L22-L23

Added lines #L22 - L23 were not covered by tests
# init grid
df_grid = pd.DataFrame()
agent_counts = np.zeros((model.grid.width, model.grid.height))

Check warning on line 26 in mesa/examples/basic/conways_game_of_life/app.py

View check run for this annotation

Codecov / codecov/patch

mesa/examples/basic/conways_game_of_life/app.py#L25-L26

Added lines #L25 - L26 were not covered by tests
for x in range(width):
for y in range(height):
df_grid = pd.concat(

Check warning on line 29 in mesa/examples/basic/conways_game_of_life/app.py

View check run for this annotation

Codecov / codecov/patch

mesa/examples/basic/conways_game_of_life/app.py#L29

Added line #L29 was not covered by tests
[df_grid, pd.DataFrame({"x": [x], "y": [y], "state": [0]})],
ignore_index=True,
)

heatmap = (

Check warning on line 34 in mesa/examples/basic/conways_game_of_life/app.py

View check run for this annotation

Codecov / codecov/patch

mesa/examples/basic/conways_game_of_life/app.py#L34

Added line #L34 was not covered by tests
alt.Chart(df_grid)
.mark_point(size=100)
.encode(x="x", y="y", color=alt.Color("state"))
.interactive()
.properties(width=800, height=600)
)

# init progress bar
my_bar = st.progress(0, text="Simulation Progress") # progress
placeholder = st.empty()
st.subheader("Agent Grid")
chart = st.altair_chart(heatmap, use_container_width=True)
color_scale = alt.Scale(domain=[0, 1], range=["red", "yellow"])

Check warning on line 47 in mesa/examples/basic/conways_game_of_life/app.py

View check run for this annotation

Codecov / codecov/patch

mesa/examples/basic/conways_game_of_life/app.py#L43-L47

Added lines #L43 - L47 were not covered by tests
for i in range(num_ticks):
model.step()
my_bar.progress((i / num_ticks), text="Simulation progress")
placeholder.text("Step = %d" % i)

Check warning on line 51 in mesa/examples/basic/conways_game_of_life/app.py

View check run for this annotation

Codecov / codecov/patch

mesa/examples/basic/conways_game_of_life/app.py#L49-L51

Added lines #L49 - L51 were not covered by tests
for contents, (x, y) in model.grid.coord_iter():
# print('x:',x,'y:',y, 'state:',contents)
selected_row = df_grid[(df_grid["x"] == x) & (df_grid["y"] == y)]
df_grid.loc[selected_row.index, "state"] = (

Check warning on line 55 in mesa/examples/basic/conways_game_of_life/app.py

View check run for this annotation

Codecov / codecov/patch

mesa/examples/basic/conways_game_of_life/app.py#L54-L55

Added lines #L54 - L55 were not covered by tests
contents.state
) # random.choice([1,2])

heatmap = (

Check warning on line 59 in mesa/examples/basic/conways_game_of_life/app.py

View check run for this annotation

Codecov / codecov/patch

mesa/examples/basic/conways_game_of_life/app.py#L59

Added line #L59 was not covered by tests
alt.Chart(df_grid)
.mark_circle(size=100)
.encode(x="x", y="y", color=alt.Color("state", scale=color_scale))
.interactive()
.properties(width=800, height=600)
)
chart.altair_chart(heatmap)

Check warning on line 66 in mesa/examples/basic/conways_game_of_life/app.py

View check run for this annotation

Codecov / codecov/patch

mesa/examples/basic/conways_game_of_life/app.py#L66

Added line #L66 was not covered by tests

time.sleep(0.1)

Check warning on line 68 in mesa/examples/basic/conways_game_of_life/app.py

View check run for this annotation

Codecov / codecov/patch

mesa/examples/basic/conways_game_of_life/app.py#L68

Added line #L68 was not covered by tests

tock = time.time()
st.success(f"Simulation completed in {tock - tick:.2f} secs")

Check warning on line 71 in mesa/examples/basic/conways_game_of_life/app.py

View check run for this annotation

Codecov / codecov/patch

mesa/examples/basic/conways_game_of_life/app.py#L70-L71

Added lines #L70 - L71 were not covered by tests
47 changes: 47 additions & 0 deletions mesa/examples/basic/schelling/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Schelling Segregation Model

## Summary

The Schelling segregation model is a classic agent-based model, demonstrating how even a mild preference for similar neighbors can lead to a much higher degree of segregation than we would intuitively expect. The model consists of agents on a square grid, where each grid cell can contain at most one agent. Agents come in two colors: red and blue. They are happy if a certain number of their eight possible neighbors are of the same color, and unhappy otherwise. Unhappy agents will pick a random empty cell to move to each step, until they are happy. The model keeps running until there are no unhappy agents.

By default, the number of similar neighbors the agents need to be happy is set to 3. That means the agents would be perfectly happy with a majority of their neighbors being of a different color (e.g. a Blue agent would be happy with five Red neighbors and three Blue ones). Despite this, the model consistently leads to a high degree of segregation, with most agents ending up with no neighbors of a different color.

## Installation

To install the dependencies use pip and the requirements.txt in this directory. e.g.

```
$ pip install -r requirements.txt
```

## How to Run

To run the model interactively, in this directory, run the following command

```
$ solara run app.py
```

Then open your browser to [http://127.0.0.1:8765/](http://127.0.0.1:8765/) and click the Play button.

To view and run some example model analyses, launch the IPython Notebook and open ``analysis.ipynb``. Visualizing the analysis also requires [matplotlib](http://matplotlib.org/).

## How to Run without the GUI

To run the model with the grid displayed as an ASCII text, run `python run_ascii.py` in this directory.

## Files

* ``app.py``: Code for the interactive visualization.
* ``schelling.py``: Contains the agent class, and the overall model class.
* ``analysis.ipynb``: Notebook demonstrating how to run experiments and parameter sweeps on the model.

## Further Reading

Schelling's original paper describing the model:

[Schelling, Thomas C. Dynamic Models of Segregation. Journal of Mathematical Sociology. 1971, Vol. 1, pp 143-186.](https://www.stat.berkeley.edu/~aldous/157/Papers/Schelling_Seg_Models.pdf)

An interactive, browser-based explanation and implementation:

[Parable of the Polygons](http://ncase.me/polygons/), by Vi Hart and Nicky Case.
Loading
Loading