Skip to content
This repository was archived by the owner on Apr 3, 2023. It is now read-only.

Commit 471d5a4

Browse files
committed
Cleaned code for Mesa stand alone example
1 parent d962b49 commit 471d5a4

File tree

1 file changed

+44
-2
lines changed

1 file changed

+44
-2
lines changed

README.md

+44-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,44 @@
1-
# mesa-schelling
2-
This is an example of the Schelling model written using Mesa
1+
# Schelling Segregation Model
2+
3+
## Summary
4+
5+
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.
6+
7+
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.
8+
9+
## Installation
10+
11+
To install the dependencies use pip and the requirements.txt in this directory. e.g.
12+
13+
```
14+
$ pip install -r requirements.txt
15+
```
16+
17+
## How to Run
18+
19+
To run the model interactively, run ``run.py`` in this directory. e.g.
20+
21+
```
22+
$ python run.py
23+
```
24+
25+
Then open your browser to [http://127.0.0.1:8888/](http://127.0.0.1:8888/) and press Reset, then Run.
26+
27+
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/).
28+
29+
## Files
30+
31+
* ``run.py``: Launches a model visualization server.
32+
* ``schelling.py``: Contains the agent class, and the overall model class.
33+
* ``server.py``: Defines classes for visualizing the model in the browser via Mesa's modular server, and instantiates a visualization server.
34+
* ``analysis.ipybn``: Notebook demonstrating how to run experiments and parameter sweeps on the model.
35+
36+
## Further Reading
37+
38+
Schelling's original paper describing the model:
39+
40+
[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)
41+
42+
An interactive, browser-based explanation and implementation:
43+
44+
[Parable of the Polygons](http://ncase.me/polygons/), by Vi Hart and Nicky Case.

0 commit comments

Comments
 (0)