Skip to content

Commit 495e4e2

Browse files
pre-commit-ci[bot]EwoutH
authored andcommitted
advanced examples: ruff format, pre-commit
1 parent 3174cb0 commit 495e4e2

File tree

5 files changed

+25
-38
lines changed

5 files changed

+25
-38
lines changed

mesa/examples/__init__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1+
from mesa.examples.advanced.epstein_civil_violence.model import EpsteinCivilViolence
2+
from mesa.examples.advanced.pd_grid.model import PdGrid
13
from mesa.examples.basic.boid_flockers.model import BoidFlockers
24
from mesa.examples.basic.boltzmann_wealth_model.model import BoltzmannWealthModel
35
from mesa.examples.basic.conways_game_of_life.model import ConwaysGameOfLife
46
from mesa.examples.basic.schelling.model import Schelling
57
from mesa.examples.basic.virus_on_network.model import VirusOnNetwork
68

7-
from mesa.examples.advanced.epstein_civil_violence.model import EpsteinCivilViolence
8-
from mesa.examples.advanced.pd_grid.model import PdGrid
9-
109
__all__ = [
1110
"BoidFlockers",
1211
"BoltzmannWealthModel",

mesa/examples/advanced/epstein_civil_violence/app.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
from mesa.visualization import SolaraViz, Slider, make_space_matplotlib, make_plot_measure
2-
31
from mesa.examples.advanced.epstein_civil_violence.agents import Citizen, Cop
42
from mesa.examples.advanced.epstein_civil_violence.model import EpsteinCivilViolence
3+
from mesa.visualization import (
4+
Slider,
5+
SolaraViz,
6+
make_plot_measure,
7+
make_space_matplotlib,
8+
)
59

610
COP_COLOR = "#000000"
711
AGENT_QUIET_COLOR = "#648FFF"
@@ -16,19 +20,18 @@ def citizen_cop_portrayal(agent):
1620

1721
portrayal = {
1822
"size": 25,
19-
# "shape": "circle",
20-
"x": agent.cell.coordinate[0],
21-
"y": agent.cell.coordinate[1],
22-
# "filled": True,
23+
"shape": "s", # square marker
2324
}
2425

2526
if isinstance(agent, Citizen):
26-
color = AGENT_QUIET_COLOR if agent.condition == "Quiescent" else AGENT_REBEL_COLOR
27+
color = (
28+
AGENT_QUIET_COLOR if agent.condition == "Quiescent" else AGENT_REBEL_COLOR
29+
)
2730
color = JAIL_COLOR if agent.jail_sentence else color
2831
shape = JAIL_SHAPE if agent.jail_sentence else "circle"
2932
portrayal["color"] = color
3033
portrayal["shape"] = shape
31-
if shape == "rect":
34+
if shape == "s":
3235
portrayal["w"] = 0.9
3336
portrayal["h"] = 0.9
3437
else:
@@ -62,9 +65,7 @@ def citizen_cop_portrayal(agent):
6265

6366
page = SolaraViz(
6467
epstein_model,
65-
components=[
66-
space_component,
67-
chart_component],
68+
components=[space_component, chart_component],
6869
model_params=model_params,
6970
name="Epstein Civil Violence",
7071
)

mesa/examples/advanced/epstein_civil_violence/model.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import mesa
2-
32
from mesa.examples.advanced.epstein_civil_violence.agents import Citizen, Cop
43

54

@@ -43,7 +42,7 @@ def __init__(
4342
arrest_prob_constant=2.3,
4443
movement=True,
4544
max_iters=1000,
46-
seed=None
45+
seed=None,
4746
):
4847
super().__init__(seed=seed)
4948
self.width = width
@@ -60,7 +59,9 @@ def __init__(
6059
self.max_iters = max_iters
6160
self.iteration = 0
6261

63-
self.grid = mesa.experimental.cell_space.OrthogonalMooreGrid((width, height), capacity=1, torus=True, random=self.random)
62+
self.grid = mesa.experimental.cell_space.OrthogonalMooreGrid(
63+
(width, height), capacity=1, torus=True, random=self.random
64+
)
6465

6566
model_reporters = {
6667
"Quiescent": lambda m: self.count_type_citizens(m, "Quiescent"),

mesa/examples/advanced/pd_grid/app.py

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22
Solara-based visualization for the Spatial Prisoner's Dilemma Model.
33
"""
44

5-
import solara
6-
from mesa.visualization import SolaraViz, make_space_matplotlib, make_plot_measure
7-
from mesa.visualization.UserParam import Slider
85
from mesa.examples.advanced.pd_grid.model import PdGrid
6+
from mesa.visualization import SolaraViz, make_plot_measure, make_space_matplotlib
7+
from mesa.visualization.UserParam import Slider
98

109

1110
def pd_agent_portrayal(agent):
@@ -21,26 +20,14 @@ def pd_agent_portrayal(agent):
2120

2221
# Model parameters
2322
model_params = {
24-
"width": Slider(
25-
"Grid Width",
26-
value=50,
27-
min=10,
28-
max=100,
29-
step=1
30-
),
31-
"height": Slider(
32-
"Grid Height",
33-
value=50,
34-
min=10,
35-
max=100,
36-
step=1
37-
),
23+
"width": Slider("Grid Width", value=50, min=10, max=100, step=1),
24+
"height": Slider("Grid Height", value=50, min=10, max=100, step=1),
3825
"activation_order": {
3926
"type": "Select",
4027
"value": "Random",
4128
"values": PdGrid.activation_regimes,
42-
"label": "Activation Regime"
43-
}
29+
"label": "Activation Regime",
30+
},
4431
}
4532

4633

mesa/examples/advanced/pd_grid/model.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import mesa
2-
from mesa.experimental.cell_space import OrthogonalMooreGrid
3-
42
from mesa.examples.advanced.pd_grid.agents import PDAgent
3+
from mesa.experimental.cell_space import OrthogonalMooreGrid
54

65

76
class PdGrid(mesa.Model):

0 commit comments

Comments
 (0)