Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Sep 18, 2024
1 parent 3109a0d commit 0c178cb
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
2 changes: 2 additions & 0 deletions examples/charts/charts/agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
Center for Connected Learning and Computer-Based Modeling,
Northwestern University, Evanston, IL.
"""

from mesa.spaces import CellAgent


class Bank:
"""Note that the Bank class is not a Mesa Agent, but just a regular Python
class. This is because there is only one bank in this model, and it does not
Expand Down
3 changes: 1 addition & 2 deletions examples/color_patches/color_patches/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ def __init__(self, width=20, height=20):
# for (contents, col, row) in self._grid.coord_iter():
# replaced content with _ to appease linter
for cell in self._grid.all_cells:
agent = ColorCell(self, ColorCell.OPINIONS[self.random.randrange(0, 16)]
)
agent = ColorCell(self, ColorCell.OPINIONS[self.random.randrange(0, 16)])
agent.move_to(cell)

self.running = True
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import mesa

class EpsteinAgent(mesa.spaces.CellAgent):

class EpsteinAgent(mesa.spaces.CellAgent):
def update_neighbors(self):
"""
Look around and see who my neighbors are
Expand Down Expand Up @@ -91,7 +91,6 @@ def step(self):
new_cell = self.random.choice(self.empty_neighbors)
self.move_to(new_cell)


def update_estimated_arrest_probability(self):
"""
Based on the ratio of cops to actives in my neighborhood, estimate the
Expand Down Expand Up @@ -157,4 +156,3 @@ def step(self):
if self.model.movement and self.empty_neighbors:
new_pos = self.random.choice(self.empty_neighbors)
self.move_to(new_pos)

17 changes: 13 additions & 4 deletions examples/epstein_civil_violence/epstein_civil_violence/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ def __init__(
self.max_iters = max_iters
self.iteration = 0

self.grid = mesa.spaces.OrthogonalMooreGrid((width, height), capacity=1,torus=True)
self.grid = mesa.spaces.OrthogonalMooreGrid(
(width, height), capacity=1, torus=True
)

model_reporters = {
"Quiescent": lambda m: self.count_type_citizens(m, "Quiescent"),
Expand Down Expand Up @@ -119,15 +121,22 @@ def count_type_citizens(model, condition, exclude_jailed=True):
citizens = model.agents_by_type[Citizen]

if exclude_jailed:
return len([c for c in citizens if (c.condition == condition) and (c.jail_sentence==0)])
return len(
[
c
for c in citizens
if (c.condition == condition) and (c.jail_sentence == 0)
]
)
else:
return len([c for c in citizens if c.condition==condition])
return len([c for c in citizens if c.condition == condition])

@staticmethod
def count_jailed(model):
"""
Helper method to count jailed agents.
"""
return len([a for a in model.agents_by_type[Citizen] if a.jail_sentence > 0 ])
return len([a for a in model.agents_by_type[Citizen] if a.jail_sentence > 0])

@staticmethod
def count_cops(model):
Expand Down

0 comments on commit 0c178cb

Please sign in to comment.