Skip to content
Open
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
67 changes: 67 additions & 0 deletions examples/caching_and_replay/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
"""
Solara visualisation for the Schelling Caching and Replay example.

Run with:
solara run app.py
"""

import mesa.visualization
from model import Schelling


def agent_portrayal(agent):
return {
"color": "#185FA5" if agent.type == 0 else "#D85A30",
"marker": "s",
"size": 25,
}


model_params = {
"height": 20,
"width": 20,
"homophily": {
"type": "SliderInt",
"value": 3,
"label": "Homophily",
"min": 0,
"max": 8,
"step": 1,
},
"density": {
"type": "SliderFloat",
"value": 0.8,
"label": "Density",
"min": 0.1,
"max": 1.0,
"step": 0.1,
},
"minority_pc": {
"type": "SliderFloat",
"value": 0.3,
"label": "Minority fraction",
"min": 0.0,
"max": 1.0,
"step": 0.05,
},
"radius": {
"type": "SliderInt",
"value": 1,
"label": "Radius",
"min": 1,
"max": 5,
"step": 1,
},
"rng": 42,
}

page = mesa.visualization.SolaraViz(
Schelling,
components=[
mesa.visualization.make_space_component(agent_portrayal),
mesa.visualization.make_plot_component(["happy"]),
],
model_params=model_params,
name="Schelling Segregation — with caching and replay",
)
page
54 changes: 54 additions & 0 deletions examples/el_farol/el_farol/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
"""
Solara visualisation for the El Farol Bar model.

Run with:
solara run app.py
"""

import mesa.visualization
from model import ElFarolBar

model_params = {
"num_agents": {
"type": "SliderInt",
"value": 100,
"label": "Number of agents",
"min": 10,
"max": 300,
"step": 10,
},
"crowd_threshold": {
"type": "SliderInt",
"value": 60,
"label": "Crowd threshold",
"min": 1,
"max": 100,
"step": 1,
},
"num_strategies": {
"type": "SliderInt",
"value": 10,
"label": "Strategies per agent",
"min": 1,
"max": 20,
"step": 1,
},
"memory_size": {
"type": "SliderInt",
"value": 10,
"label": "Memory size",
"min": 1,
"max": 20,
"step": 1,
},
}

page = mesa.visualization.SolaraViz(
ElFarolBar,
components=[
mesa.visualization.make_plot_component(["Customers"]),
],
model_params=model_params,
name="El Farol Bar Model",
)
page
3 changes: 1 addition & 2 deletions examples/el_farol/el_farol/model.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import mesa
import numpy as np

from .agents import BarCustomer
from agents import BarCustomer


class ElFarolBar(mesa.Model):
Expand Down
50 changes: 50 additions & 0 deletions examples/shape_example/shape_example/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
"""
Solara visualisation for the Shape Example.

Run with:
solara run app.py
"""

import mesa.visualization
from model import ShapeExample


def agent_portrayal(agent):
"""Render each walker as an arrow pointing in its heading direction."""
heading_to_angle = {
(1, 0): 0, # right
(0, 1): 90, # up
(-1, 0): 180, # left
(0, -1): 270, # down
}
return {
"color": "#1D9E75",
"shape": "arrowHead",
"scale": 0.8,
"heading_x": agent.heading[0],
"heading_y": agent.heading[1],
}


model_params = {
"num_agents": {
"type": "SliderInt",
"value": 2,
"label": "Number of agents",
"min": 1,
"max": 20,
"step": 1,
},
"width": 20,
"height": 10,
}

page = mesa.visualization.SolaraViz(
ShapeExample,
components=[
mesa.visualization.make_space_component(agent_portrayal),
],
model_params=model_params,
name="Shape Example — directional agents on a grid",
)
page