From 4bce8d49bbaa03df8d9efa2407c382ebbdce631e Mon Sep 17 00:00:00 2001 From: Jan Kwakkel Date: Mon, 11 Nov 2024 23:09:08 +0100 Subject: [PATCH] updates examples to explicitly set ranom on new style grid spaces (#235) --- examples/caching_and_replay/model.py | 2 +- examples/charts/charts/model.py | 4 +++- examples/color_patches/color_patches/model.py | 2 +- examples/forest_fire/forest_fire/model.py | 2 +- examples/hex_snowflake/hex_snowflake/model.py | 6 +++--- examples/hotelling_law/hotelling_law/model.py | 4 ++-- examples/shape_example/shape_example/model.py | 2 +- 7 files changed, 12 insertions(+), 10 deletions(-) diff --git a/examples/caching_and_replay/model.py b/examples/caching_and_replay/model.py index cd35e88b..d04c818d 100644 --- a/examples/caching_and_replay/model.py +++ b/examples/caching_and_replay/model.py @@ -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( diff --git a/examples/charts/charts/model.py b/examples/charts/charts/model.py index 22d3945d..6785c55f 100644 --- a/examples/charts/charts/model.py +++ b/examples/charts/charts/model.py @@ -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 diff --git a/examples/color_patches/color_patches/model.py b/examples/color_patches/color_patches/model.py index ca1aa263..f779c37a 100644 --- a/examples/color_patches/color_patches/model.py +++ b/examples/color_patches/color_patches/model.py @@ -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() diff --git a/examples/forest_fire/forest_fire/model.py b/examples/forest_fire/forest_fire/model.py index 14eca705..45366de2 100644 --- a/examples/forest_fire/forest_fire/model.py +++ b/examples/forest_fire/forest_fire/model.py @@ -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"), diff --git a/examples/hex_snowflake/hex_snowflake/model.py b/examples/hex_snowflake/hex_snowflake/model.py index 0ea43138..fd2bd312 100644 --- a/examples/hex_snowflake/hex_snowflake/model.py +++ b/examples/hex_snowflake/hex_snowflake/model.py @@ -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: diff --git a/examples/hotelling_law/hotelling_law/model.py b/examples/hotelling_law/hotelling_law/model.py index cc2bdc0a..0ebde89b 100644 --- a/examples/hotelling_law/hotelling_law/model.py +++ b/examples/hotelling_law/hotelling_law/model.py @@ -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() diff --git a/examples/shape_example/shape_example/model.py b/examples/shape_example/shape_example/model.py index bb7c4717..728f8266 100644 --- a/examples/shape_example/shape_example/model.py +++ b/examples/shape_example/shape_example/model.py @@ -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