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

refactor: Simplify experimental Schelling example #88

Merged
merged 5 commits into from
Jan 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
33 changes: 5 additions & 28 deletions examples/schelling_experimental/app.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from mesa.experimental import JupyterViz, make_text
from mesa.experimental import JupyterViz, Slider, make_text
from model import Schelling


Expand All @@ -10,35 +10,13 @@ def get_happy_agents(model):


def agent_portrayal(agent):
color = "tab:orange" if agent.type == 0 else "tab:blue"
return {"color": color}
return {"color": "tab:orange" if agent.type == 0 else "tab:blue"}


model_params = {
"density": {
"type": "SliderFloat",
"value": 0.8,
"label": "Agent density",
"min": 0.1,
"max": 1.0,
"step": 0.1,
},
"minority_pc": {
"type": "SliderFloat",
"value": 0.2,
"label": "Fraction minority",
"min": 0.0,
"max": 1.0,
"step": 0.05,
},
"homophily": {
"type": "SliderInt",
"value": 3,
"label": "Homophily",
"min": 0,
"max": 8,
"step": 1,
},
"density": Slider("Agent density", 0.8, 0.1, 1.0, 0.1),
"minority_pc": Slider("Fraction minority", 0.2, 0.0, 1.0, 0.05),
"homophily": Slider("Homophily", 3, 0, 8, 1),
"width": 20,
"height": 20,
}
Expand All @@ -47,7 +25,6 @@ def agent_portrayal(agent):
Schelling,
model_params,
measures=["happy", make_text(get_happy_agents)],
name="Schelling",
agent_portrayal=agent_portrayal,
)
page # noqa
2 changes: 2 additions & 0 deletions examples/schelling_experimental/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ def step(self):
"""
self.happy = 0 # Reset counter of happy agents
self.agents.shuffle().do("step")
# Must be before data collection.
self._advance_time() # Temporary API; will be finalized by Mesa 3.0 release
# collect data
self.datacollector.collect(self)

Expand Down