Skip to content

example: Add input sliders to Sugerscape viz #2487

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

Merged
merged 1 commit into from
Nov 11, 2024
Merged
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
20 changes: 18 additions & 2 deletions mesa/examples/advanced/sugarscape_g1mt/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from mesa.examples.advanced.sugarscape_g1mt.agents import Trader
from mesa.examples.advanced.sugarscape_g1mt.model import SugarscapeG1mt
from mesa.visualization import SolaraViz, make_plot_component
from mesa.visualization import Slider, SolaraViz, make_plot_component

Check warning on line 7 in mesa/examples/advanced/sugarscape_g1mt/app.py

View check run for this annotation

Codecov / codecov/patch

mesa/examples/advanced/sugarscape_g1mt/app.py#L7

Added line #L7 was not covered by tests


def SpaceDrawer(model):
Expand Down Expand Up @@ -49,13 +49,29 @@
model_params = {
"width": 50,
"height": 50,
# Population parameters
"initial_population": Slider(
"Initial Population", value=200, min=50, max=500, step=10
),
# Agent endowment parameters
"endowment_min": Slider("Min Initial Endowment", value=25, min=5, max=30, step=1),
"endowment_max": Slider("Max Initial Endowment", value=50, min=30, max=100, step=1),
# Metabolism parameters
"metabolism_min": Slider("Min Metabolism", value=1, min=1, max=3, step=1),
"metabolism_max": Slider("Max Metabolism", value=5, min=3, max=8, step=1),
# Vision parameters
"vision_min": Slider("Min Vision", value=1, min=1, max=3, step=1),
"vision_max": Slider("Max Vision", value=5, min=3, max=8, step=1),
# Trade parameter
"enable_trade": {"type": "Checkbox", "value": True, "label": "Enable Trading"},
}

model1 = SugarscapeG1mt(50, 50)
model1 = SugarscapeG1mt()

Check warning on line 69 in mesa/examples/advanced/sugarscape_g1mt/app.py

View check run for this annotation

Codecov / codecov/patch

mesa/examples/advanced/sugarscape_g1mt/app.py#L69

Added line #L69 was not covered by tests

page = SolaraViz(
model1,
components=[SpaceDrawer, make_plot_component(["Trader", "Price"])],
model_params=model_params,
name="Sugarscape {G1, M, T}",
play_interval=150,
)
Expand Down
Loading