Skip to content

Commit

Permalink
advanced examples: ruff format, pre-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
pre-commit-ci[bot] authored and EwoutH committed Oct 24, 2024
1 parent 3174cb0 commit 495e4e2
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 38 deletions.
5 changes: 2 additions & 3 deletions mesa/examples/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
from mesa.examples.advanced.epstein_civil_violence.model import EpsteinCivilViolence
from mesa.examples.advanced.pd_grid.model import PdGrid
from mesa.examples.basic.boid_flockers.model import BoidFlockers
from mesa.examples.basic.boltzmann_wealth_model.model import BoltzmannWealthModel
from mesa.examples.basic.conways_game_of_life.model import ConwaysGameOfLife
from mesa.examples.basic.schelling.model import Schelling
from mesa.examples.basic.virus_on_network.model import VirusOnNetwork

from mesa.examples.advanced.epstein_civil_violence.model import EpsteinCivilViolence
from mesa.examples.advanced.pd_grid.model import PdGrid

__all__ = [
"BoidFlockers",
"BoltzmannWealthModel",
Expand Down
23 changes: 12 additions & 11 deletions mesa/examples/advanced/epstein_civil_violence/app.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
from mesa.visualization import SolaraViz, Slider, make_space_matplotlib, make_plot_measure

from mesa.examples.advanced.epstein_civil_violence.agents import Citizen, Cop
from mesa.examples.advanced.epstein_civil_violence.model import EpsteinCivilViolence
from mesa.visualization import (
Slider,
SolaraViz,
make_plot_measure,
make_space_matplotlib,
)

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

portrayal = {
"size": 25,
# "shape": "circle",
"x": agent.cell.coordinate[0],
"y": agent.cell.coordinate[1],
# "filled": True,
"shape": "s", # square marker
}

if isinstance(agent, Citizen):
color = AGENT_QUIET_COLOR if agent.condition == "Quiescent" else AGENT_REBEL_COLOR
color = (
AGENT_QUIET_COLOR if agent.condition == "Quiescent" else AGENT_REBEL_COLOR
)
color = JAIL_COLOR if agent.jail_sentence else color
shape = JAIL_SHAPE if agent.jail_sentence else "circle"
portrayal["color"] = color
portrayal["shape"] = shape
if shape == "rect":
if shape == "s":
portrayal["w"] = 0.9
portrayal["h"] = 0.9
else:
Expand Down Expand Up @@ -62,9 +65,7 @@ def citizen_cop_portrayal(agent):

page = SolaraViz(
epstein_model,
components=[
space_component,
chart_component],
components=[space_component, chart_component],
model_params=model_params,
name="Epstein Civil Violence",
)
Expand Down
7 changes: 4 additions & 3 deletions mesa/examples/advanced/epstein_civil_violence/model.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import mesa

from mesa.examples.advanced.epstein_civil_violence.agents import Citizen, Cop


Expand Down Expand Up @@ -43,7 +42,7 @@ def __init__(
arrest_prob_constant=2.3,
movement=True,
max_iters=1000,
seed=None
seed=None,
):
super().__init__(seed=seed)
self.width = width
Expand All @@ -60,7 +59,9 @@ def __init__(
self.max_iters = max_iters
self.iteration = 0

self.grid = mesa.experimental.cell_space.OrthogonalMooreGrid((width, height), capacity=1, torus=True, random=self.random)
self.grid = mesa.experimental.cell_space.OrthogonalMooreGrid(
(width, height), capacity=1, torus=True, random=self.random
)

model_reporters = {
"Quiescent": lambda m: self.count_type_citizens(m, "Quiescent"),
Expand Down
25 changes: 6 additions & 19 deletions mesa/examples/advanced/pd_grid/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
Solara-based visualization for the Spatial Prisoner's Dilemma Model.
"""

import solara
from mesa.visualization import SolaraViz, make_space_matplotlib, make_plot_measure
from mesa.visualization.UserParam import Slider
from mesa.examples.advanced.pd_grid.model import PdGrid
from mesa.visualization import SolaraViz, make_plot_measure, make_space_matplotlib
from mesa.visualization.UserParam import Slider


def pd_agent_portrayal(agent):
Expand All @@ -21,26 +20,14 @@ def pd_agent_portrayal(agent):

# Model parameters
model_params = {
"width": Slider(
"Grid Width",
value=50,
min=10,
max=100,
step=1
),
"height": Slider(
"Grid Height",
value=50,
min=10,
max=100,
step=1
),
"width": Slider("Grid Width", value=50, min=10, max=100, step=1),
"height": Slider("Grid Height", value=50, min=10, max=100, step=1),
"activation_order": {
"type": "Select",
"value": "Random",
"values": PdGrid.activation_regimes,
"label": "Activation Regime"
}
"label": "Activation Regime",
},
}


Expand Down
3 changes: 1 addition & 2 deletions mesa/examples/advanced/pd_grid/model.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import mesa
from mesa.experimental.cell_space import OrthogonalMooreGrid

from mesa.examples.advanced.pd_grid.agents import PDAgent
from mesa.experimental.cell_space import OrthogonalMooreGrid


class PdGrid(mesa.Model):
Expand Down

0 comments on commit 495e4e2

Please sign in to comment.