diff --git a/examples/caching_and_replay/app.py b/examples/caching_and_replay/app.py new file mode 100644 index 000000000..52b7e1fbe --- /dev/null +++ b/examples/caching_and_replay/app.py @@ -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 diff --git a/examples/el_farol/el_farol/app.py b/examples/el_farol/el_farol/app.py new file mode 100644 index 000000000..1d807e0e7 --- /dev/null +++ b/examples/el_farol/el_farol/app.py @@ -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 diff --git a/examples/el_farol/el_farol/model.py b/examples/el_farol/el_farol/model.py index 4c927f00e..41a3c8694 100644 --- a/examples/el_farol/el_farol/model.py +++ b/examples/el_farol/el_farol/model.py @@ -1,7 +1,6 @@ import mesa import numpy as np - -from .agents import BarCustomer +from agents import BarCustomer class ElFarolBar(mesa.Model): diff --git a/examples/shape_example/shape_example/app.py b/examples/shape_example/shape_example/app.py new file mode 100644 index 000000000..bcbfbe339 --- /dev/null +++ b/examples/shape_example/shape_example/app.py @@ -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