Skip to content

Commit 4bce8d4

Browse files
authored
updates examples to explicitly set ranom on new style grid spaces (#235)
1 parent 59106a8 commit 4bce8d4

File tree

7 files changed

+12
-10
lines changed

7 files changed

+12
-10
lines changed

examples/caching_and_replay/model.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def __init__(
6868
self.homophily = homophily
6969
self.radius = radius
7070

71-
self.grid = OrthogonalMooreGrid((width, height), torus=True)
71+
self.grid = OrthogonalMooreGrid((width, height), torus=True, random=self.random)
7272

7373
self.happy = 0
7474
self.datacollector = mesa.DataCollector(

examples/charts/charts/model.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,9 @@ def __init__(
101101
self.width = width
102102
self.init_people = init_people
103103

104-
self.grid = OrthogonalMooreGrid((self.width, self.height), torus=True)
104+
self.grid = OrthogonalMooreGrid(
105+
(self.width, self.height), torus=True, random=self.random
106+
)
105107
# rich_threshold is the amount of savings a person needs to be considered "rich"
106108
self.rich_threshold = rich_threshold
107109
self.reserve_percent = reserve_percent

examples/color_patches/color_patches/model.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def __init__(self, width=20, height=20):
6767
"""
6868
super().__init__()
6969
self._grid = mesa.experimental.cell_space.OrthogonalMooreGrid(
70-
(width, height), torus=False
70+
(width, height), torus=False, random=self.random
7171
)
7272

7373
# self._grid.coord_iter()

examples/forest_fire/forest_fire/model.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def __init__(self, width=100, height=100, density=0.65, seed=None):
2121

2222
# Set up model objects
2323

24-
self.grid = OrthogonalMooreGrid((width, height), capacity=1)
24+
self.grid = OrthogonalMooreGrid((width, height), capacity=1, random=self.random)
2525
self.datacollector = mesa.DataCollector(
2626
{
2727
"Fine": lambda m: self.count_type(m, "Fine"),

examples/hex_snowflake/hex_snowflake/model.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ class HexSnowflake(mesa.Model):
1010
of cells with adjacency rules specific to hexagons.
1111
"""
1212

13-
def __init__(self, width=50, height=50):
13+
def __init__(self, width=50, height=50, seed=None):
1414
"""
1515
Create a new playing area of (width, height) cells.
1616
"""
17-
super().__init__()
17+
super().__init__(seed=seed)
1818
# Use a hexagonal grid, where edges wrap around.
19-
self.grid = HexGrid((width, height), capacity=1, torus=True)
19+
self.grid = HexGrid((width, height), capacity=1, torus=True, random=self.random)
2020

2121
# Place a dead cell at each location.
2222
for entry in self.grid.all_cells:

examples/hotelling_law/hotelling_law/model.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,11 @@ def __init__(
9797
# Initialize the spatial grid based on the specified environment type.
9898
if environment_type == "grid":
9999
self.grid = OrthogonalMooreGrid(
100-
(width, height), True
100+
(width, height), torus=True, random=self.random
101101
) # A grid where multiple agents can occupy the same cell.
102102
elif environment_type == "line":
103103
self.grid = OrthogonalMooreGrid(
104-
(1, height), True
104+
(1, height), torus=True, random=self.random
105105
) # A grid representing a line (single occupancy per cell).
106106

107107
self._initialize_agents()

examples/shape_example/shape_example/model.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def __init__(self, N=2, width=20, height=10):
1414
super().__init__()
1515
self.N = N # num of agents
1616
self.headings = ((1, 0), (0, 1), (-1, 0), (0, -1)) # tuples are fast
17-
self.grid = OrthogonalMooreGrid((width, height), torus=True)
17+
self.grid = OrthogonalMooreGrid((width, height), torus=True, random=self.random)
1818

1919
self.make_walker_agents()
2020
self.running = True

0 commit comments

Comments
 (0)