Skip to content

Commit

Permalink
updates examples to explicitly set ranom on new style grid spaces (#235)
Browse files Browse the repository at this point in the history
  • Loading branch information
quaquel authored Nov 11, 2024
1 parent 59106a8 commit 4bce8d4
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion examples/caching_and_replay/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def __init__(
self.homophily = homophily
self.radius = radius

self.grid = OrthogonalMooreGrid((width, height), torus=True)
self.grid = OrthogonalMooreGrid((width, height), torus=True, random=self.random)

self.happy = 0
self.datacollector = mesa.DataCollector(
Expand Down
4 changes: 3 additions & 1 deletion examples/charts/charts/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ def __init__(
self.width = width
self.init_people = init_people

self.grid = OrthogonalMooreGrid((self.width, self.height), torus=True)
self.grid = OrthogonalMooreGrid(
(self.width, self.height), torus=True, random=self.random
)
# rich_threshold is the amount of savings a person needs to be considered "rich"
self.rich_threshold = rich_threshold
self.reserve_percent = reserve_percent
Expand Down
2 changes: 1 addition & 1 deletion examples/color_patches/color_patches/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def __init__(self, width=20, height=20):
"""
super().__init__()
self._grid = mesa.experimental.cell_space.OrthogonalMooreGrid(
(width, height), torus=False
(width, height), torus=False, random=self.random
)

# self._grid.coord_iter()
Expand Down
2 changes: 1 addition & 1 deletion examples/forest_fire/forest_fire/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def __init__(self, width=100, height=100, density=0.65, seed=None):

# Set up model objects

self.grid = OrthogonalMooreGrid((width, height), capacity=1)
self.grid = OrthogonalMooreGrid((width, height), capacity=1, random=self.random)
self.datacollector = mesa.DataCollector(
{
"Fine": lambda m: self.count_type(m, "Fine"),
Expand Down
6 changes: 3 additions & 3 deletions examples/hex_snowflake/hex_snowflake/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ class HexSnowflake(mesa.Model):
of cells with adjacency rules specific to hexagons.
"""

def __init__(self, width=50, height=50):
def __init__(self, width=50, height=50, seed=None):
"""
Create a new playing area of (width, height) cells.
"""
super().__init__()
super().__init__(seed=seed)
# Use a hexagonal grid, where edges wrap around.
self.grid = HexGrid((width, height), capacity=1, torus=True)
self.grid = HexGrid((width, height), capacity=1, torus=True, random=self.random)

# Place a dead cell at each location.
for entry in self.grid.all_cells:
Expand Down
4 changes: 2 additions & 2 deletions examples/hotelling_law/hotelling_law/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,11 @@ def __init__(
# Initialize the spatial grid based on the specified environment type.
if environment_type == "grid":
self.grid = OrthogonalMooreGrid(
(width, height), True
(width, height), torus=True, random=self.random
) # A grid where multiple agents can occupy the same cell.
elif environment_type == "line":
self.grid = OrthogonalMooreGrid(
(1, height), True
(1, height), torus=True, random=self.random
) # A grid representing a line (single occupancy per cell).

self._initialize_agents()
Expand Down
2 changes: 1 addition & 1 deletion examples/shape_example/shape_example/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def __init__(self, N=2, width=20, height=10):
super().__init__()
self.N = N # num of agents
self.headings = ((1, 0), (0, 1), (-1, 0), (0, -1)) # tuples are fast
self.grid = OrthogonalMooreGrid((width, height), torus=True)
self.grid = OrthogonalMooreGrid((width, height), torus=True, random=self.random)

self.make_walker_agents()
self.running = True
Expand Down

0 comments on commit 4bce8d4

Please sign in to comment.