Skip to content

Commit

Permalink
examples: Clean-up Epstein Civil Violence
Browse files Browse the repository at this point in the history
  • Loading branch information
EwoutH committed Oct 16, 2024
1 parent ffe565b commit a827a5d
Show file tree
Hide file tree
Showing 10 changed files with 219 additions and 164 deletions.
186 changes: 145 additions & 41 deletions examples/advanced/epstein_civil_violence/Epstein Civil Violence.ipynb

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions examples/advanced/epstein_civil_violence/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ Then open your browser to [http://127.0.0.1:8521/](http://127.0.0.1:8521/) and p

## Files

* ``EpsteinCivilViolence.py``: Core model and agent code.
* ``EpsteinCivilViolenceServer.py``: Sets up the interactive visualization.
* ``model.py``: Core model code.
* ``agent.py``: Agent classes.
* ``app.py``: Sets up the interactive visualization.
* ``Epstein Civil Violence.ipynb``: Jupyter notebook conducting some preliminary analysis of the model.

## Further Reading
Expand Down
70 changes: 70 additions & 0 deletions examples/advanced/epstein_civil_violence/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
from mesa.visualization import SolaraViz, Slider, make_space_matplotlib, make_plot_measure

from agents import Citizen, Cop
from model import EpsteinCivilViolence

COP_COLOR = "#000000"
AGENT_QUIET_COLOR = "#648FFF"
AGENT_REBEL_COLOR = "#FE6100"
JAIL_COLOR = "#808080"
JAIL_SHAPE = "rect"


def citizen_cop_portrayal(agent):
if agent is None:
return

portrayal = {
"shape": "circle",
"x": agent.pos[0],
"y": agent.pos[1],
"filled": True,
}

if isinstance(agent, Citizen):
color = AGENT_QUIET_COLOR if agent.condition == "Quiescent" else AGENT_REBEL_COLOR
color = JAIL_COLOR if agent.jail_sentence else color
shape = JAIL_SHAPE if agent.jail_sentence else "circle"
portrayal["color"] = color
portrayal["shape"] = shape
if shape == "rect":
portrayal["w"] = 0.9
portrayal["h"] = 0.9
else:
portrayal["r"] = 0.5
portrayal["filled"] = False
portrayal["layer"] = 0

elif isinstance(agent, Cop):
portrayal["color"] = COP_COLOR
portrayal["r"] = 0.9
portrayal["layer"] = 1

return portrayal


model_params = {
"height": 40,
"width": 40,
"citizen_density": Slider("Initial Agent Density", 0.7, 0.0, 0.9, 0.1),
"cop_density": Slider("Initial Cop Density", 0.04, 0.0, 0.1, 0.01),
"citizen_vision": Slider("Citizen Vision", 7, 1, 10, 1),
"cop_vision": Slider("Cop Vision", 7, 1, 10, 1),
"legitimacy": Slider("Government Legitimacy", 0.82, 0.0, 1, 0.01),
"max_jail_term": Slider("Max Jail Term", 30, 0, 50, 1),
}

# space_component = make_space_matplotlib(citizen_cop_portrayal)
chart_component = make_plot_measure(["Quiescent", "Active", "Jailed"])

epstein_model = EpsteinCivilViolence()

page = SolaraViz(
epstein_model,
components=[
# space_component,
chart_component],
model_params=model_params,
name="Epstein Civil Violence",
)
page # noqa
Empty file.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import mesa

from .agent import Citizen, Cop
from agents import Citizen, Cop


class EpsteinCivilViolence(mesa.Model):
Expand Down
3 changes: 0 additions & 3 deletions examples/advanced/epstein_civil_violence/requirements.txt

This file was deleted.

3 changes: 0 additions & 3 deletions examples/advanced/epstein_civil_violence/run.py

This file was deleted.

0 comments on commit a827a5d

Please sign in to comment.