Skip to content

Commit 5cc816a

Browse files
pre-commit-ci[bot]mgemaakbar
authored andcommitted
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 21e9539 commit 5cc816a

File tree

1 file changed

+19
-9
lines changed
  • mesa/examples/advanced/wolf_sheep

1 file changed

+19
-9
lines changed

mesa/examples/advanced/wolf_sheep/model.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,16 @@
1010
"""
1111

1212
import math
13+
import random
14+
15+
import numpy as np
1316

1417
from mesa import Model
1518
from mesa.datacollection import DataCollector
1619
from mesa.examples.advanced.wolf_sheep.agents import GrassPatch, Sheep, Wolf
1720
from mesa.experimental.cell_space import OrthogonalVonNeumannGrid
18-
from mesa.experimental.devs import ABMSimulator
1921
from mesa.experimental.cell_space.property_layer import PropertyLayer
20-
import numpy as np
21-
import random
22+
from mesa.experimental.devs import ABMSimulator
2223

2324

2425
class WolfSheep(Model):
@@ -74,7 +75,10 @@ def __init__(
7475

7576
# Create grid using experimental cell space
7677
self.grid = OrthogonalVonNeumannGrid(
77-
(self.height, self.width), # use tuple instead of list, otherwise it would fail the dimension check in add_property_layer
78+
(
79+
self.height,
80+
self.width,
81+
), # use tuple instead of list, otherwise it would fail the dimension check in add_property_layer
7882
torus=True,
7983
capacity=math.inf,
8084
random=self.random,
@@ -92,10 +96,13 @@ def __init__(
9296

9397
self.datacollector = DataCollector(model_reporters)
9498

95-
cliff_arr = [[False]*self.width for i in range(self.height)]
96-
97-
cliff_coord = set([(random.randrange(self.height), random.randrange(self.width)) for i in range((width*height)//3)] ) # set is used because the random number gen might return the same coordinate
98-
for i,j in cliff_coord:
99+
cliff_arr = [[False] * self.width for i in range(self.height)]
100+
101+
cliff_coord = {
102+
(random.randrange(self.height), random.randrange(self.width))
103+
for i in range((width * height) // 3)
104+
} # set is used because the random number gen might return the same coordinate
105+
for i, j in cliff_coord:
99106
cliff_arr[i][j] = True
100107

101108
cliff_arr = np.array(cliff_arr)
@@ -104,7 +111,10 @@ def __init__(
104111

105112
possibleCells = []
106113
for cell in self.grid.all_cells.cells:
107-
if (cell.coordinate[0], cell.coordinate[1]) not in cliff_coord: # so we don't create wolf or sheep on cliff cells
114+
if (
115+
cell.coordinate[0],
116+
cell.coordinate[1],
117+
) not in cliff_coord: # so we don't create wolf or sheep on cliff cells
108118
possibleCells.append(cell)
109119

110120
# Create sheep:

0 commit comments

Comments
 (0)