Skip to content

Commit

Permalink
update first examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Corvince committed Sep 4, 2024
1 parent ec07d89 commit f69e643
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 22 deletions.
15 changes: 8 additions & 7 deletions examples/aco_tsp/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@

import networkx as nx
import solara
from mesa.visualization.utils import update_counter
from aco_tsp.model import AcoTspModel, TSPGraph
from matplotlib.figure import Figure
from mesa.visualization import SolaraViz
from mesa.visualization import SolaraViz, make_plot_measure


def circle_portrayal_example(agent):
Expand Down Expand Up @@ -35,6 +36,8 @@ def circle_portrayal_example(agent):
},
}

model = AcoTspModel()


def make_graph(model):
fig = Figure()
Expand All @@ -55,7 +58,7 @@ def make_graph(model):
edge_color="gray",
)

solara.FigureMatplotlib(fig)
return solara.FigureMatplotlib(fig)


def ant_level_distances(model):
Expand All @@ -67,10 +70,8 @@ def ant_level_distances(model):


page = SolaraViz(
AcoTspModel,
model_params,
space_drawer=None,
measures=["best_distance_iter", "best_distance", make_graph],
agent_portrayal=circle_portrayal_example,
model,
components=[make_plot_measure(["best_distance_iter", "best_distance"]), make_graph],
model_params=model_params,
play_interval=1,
)
9 changes: 5 additions & 4 deletions examples/boid_flockers/app.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from boid_flockers.model import BoidFlockers
from mesa.visualization import SolaraViz
from mesa.visualization import SolaraViz, make_space_matplotlib


def boid_draw(agent):
Expand All @@ -15,11 +15,12 @@ def boid_draw(agent):
"separation": 2,
}

model = BoidFlockers(100, 100, 100, 5, 10, 2)

page = SolaraViz(
model_class=BoidFlockers,
model,
[make_space_matplotlib(agent_portrayal=boid_draw)],
model_params=model_params,
measures=[],
name="BoidFlockers",
agent_portrayal=boid_draw,
)
page # noqa
19 changes: 13 additions & 6 deletions examples/boltzmann_wealth_model_experimental/app.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
from mesa.visualization import SolaraViz
from mesa.visualization import (
SolaraViz,
make_plot_measure,
make_space_matplotlib,
)
from model import BoltzmannWealthModel


Expand All @@ -24,11 +28,14 @@ def agent_portrayal(agent):
"height": 10,
}

model = BoltzmannWealthModel(50, 10, 10)

page = SolaraViz(
BoltzmannWealthModel,
model_params,
measures=["Gini"],
name="Money Model",
agent_portrayal=agent_portrayal,
model,
components=[
make_space_matplotlib(agent_portrayal=agent_portrayal),
make_plot_measure("Gini"),
],
model_params=model_params,
)
page # noqa
10 changes: 5 additions & 5 deletions examples/conways_game_of_life_fast/app.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from mesa.visualization import SolaraViz
from mesa.visualization import SolaraViz, make_plot_measure
from model import GameOfLifeModel

model_params = {
Expand All @@ -20,11 +20,11 @@
},
}

model = GameOfLifeModel(10, 10)

page = SolaraViz(
GameOfLifeModel,
model_params,
measures=["Cells alive", "Fraction alive"],
space_drawer=None,
model,
components=[make_plot_measure(["Cells alive", "Fraction alive"])],
name="Game of Life Model",
)
page # noqa

0 comments on commit f69e643

Please sign in to comment.