Skip to content

Commit

Permalink
merge experimental schelling into schelling example
Browse files Browse the repository at this point in the history
  • Loading branch information
wang-boyu committed Oct 11, 2024
1 parent a106204 commit 6b99eaa
Show file tree
Hide file tree
Showing 12 changed files with 18 additions and 714 deletions.
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,6 @@ Boltzmann Wealth model with the experimental Juptyer notebook visualization feat

A modified version of the [Bank Reserves](https://github.com/projectmesa/mesa-examples/tree/main/examples/bank_reserves) example made to provide examples of Mesa's charting tools.

### [Schelling Segregation Model (Experimental)](https://github.com/projectmesa/mesa-examples/tree/main/examples/schelling_experimental)

Schelling segregation model with the experimental Juptyer notebook visualization feature.

### [Shape Example](https://github.com/projectmesa/mesa-examples/tree/main/examples/shape_example)

Example of grid display and direction showing agents in the form of arrow-head shape.
Expand Down
17 changes: 4 additions & 13 deletions examples/schelling/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,13 @@ To install the dependencies use pip and the requirements.txt in this directory.

## How to Run

To run the model interactively, run ``mesa runserver`` in this directory. e.g.
To run the model interactively, in this directory, run the following command

```
$ mesa runserver
$ solara run app.py
```

or

Directly run the file ``run.py`` in the terminal. e.g.

```
$ python run.py
```

Then open your browser to [http://127.0.0.1:8521/](http://127.0.0.1:8521/) and press Reset, then Run.
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/).

Expand All @@ -40,10 +32,9 @@ To run the model with the grid displayed as an ASCII text, run `python run_ascii

## Files

* ``run.py``: Launches a model visualization server.
* ``app.py``: Code for the interactive visualization.
* ``run_ascii.py``: Run the model in text mode.
* ``schelling.py``: Contains the agent class, and the overall model class.
* ``server.py``: Defines classes for visualizing the model in the browser via Mesa's modular server, and instantiates a visualization server.
* ``analysis.ipynb``: Notebook demonstrating how to run experiments and parameter sweeps on the model.

## Further Reading
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
from mesa.visualization import Slider, SolaraViz, make_plot_measure
import solara
from mesa.visualization import (
Slider,
SolaraViz,
make_plot_measure,
make_space_matplotlib,
)
from model import Schelling


def get_happy_agents(model):
"""
Display a text count of how many happy agents there are.
"""
return f"Happy agents: {model.happy}"
return solara.Markdown(f"**Happy agents: {model.happy}**")


def agent_portrayal(agent):
Expand All @@ -27,7 +33,11 @@ def agent_portrayal(agent):

page = SolaraViz(
model1,
components=[HappyPlot, get_happy_agents],
components=[
make_space_matplotlib(agent_portrayal),
make_plot_measure("happy"),
get_happy_agents,
],
model_params=model_params,
)
page # noqa
2 changes: 1 addition & 1 deletion examples/schelling/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
jupyter
matplotlib
mesa~=2.0
mesa[viz]~=3.0.0b0
3 changes: 0 additions & 3 deletions examples/schelling/run.py

This file was deleted.

60 changes: 0 additions & 60 deletions examples/schelling/server.py

This file was deleted.

48 changes: 0 additions & 48 deletions examples/schelling_experimental/README.md

This file was deleted.

Empty file.
Loading

0 comments on commit 6b99eaa

Please sign in to comment.