From 53b4ca8ee705a990757d44eb0e58b6b5eb7512bc Mon Sep 17 00:00:00 2001 From: Jan Kwakkel Date: Mon, 7 Oct 2024 09:19:59 +0200 Subject: [PATCH] bring in line with main --- examples/aco_tsp/aco_tsp/model.py | 4 ++-- examples/bank_reserves/bank_reserves/agents.py | 4 ++-- examples/bank_reserves/bank_reserves/model.py | 2 +- .../boltzmann_wealth_model/model.py | 6 +++--- examples/boltzmann_wealth_model_experimental/model.py | 6 +++--- .../boltzmann_wealth_model_network/model.py | 10 +++++----- examples/charts/charts/agents.py | 4 ++-- examples/charts/charts/model.py | 2 +- examples/color_patches/color_patches/model.py | 6 +++--- .../conways_game_of_life/conways_game_of_life/cell.py | 4 ++-- .../conways_game_of_life/conways_game_of_life/model.py | 2 +- .../epstein_civil_violence/agent.py | 4 ++-- .../epstein_civil_violence/model.py | 2 +- 13 files changed, 28 insertions(+), 28 deletions(-) diff --git a/examples/aco_tsp/aco_tsp/model.py b/examples/aco_tsp/aco_tsp/model.py index cf9303b8..0b08ba93 100644 --- a/examples/aco_tsp/aco_tsp/model.py +++ b/examples/aco_tsp/aco_tsp/model.py @@ -3,7 +3,7 @@ import mesa import networkx as nx import numpy as np -from mesa.spaces import CellAgent, Network +from mesa.experimental.cell_space import CellAgent, Network @dataclass @@ -116,7 +116,7 @@ def decide_next_city(self): # Random # new_city = self.random.choice(list(self.model.all_cities - set(self.cities_visited))) # Choose closest city not yet visited - neighbors = self.cell.neighborhood() + neighbors = self.cell.neighborhood candidates = [n for n in neighbors if n not in self._cities_visited] if len(candidates) == 0: return self.cell diff --git a/examples/bank_reserves/bank_reserves/agents.py b/examples/bank_reserves/bank_reserves/agents.py index b0596a65..b94826a8 100644 --- a/examples/bank_reserves/bank_reserves/agents.py +++ b/examples/bank_reserves/bank_reserves/agents.py @@ -10,7 +10,7 @@ Northwestern University, Evanston, IL. """ -from mesa.spaces import CellAgent +from mesa.experimental.cell_space import CellAgent class Bank: @@ -176,7 +176,7 @@ def take_out_loan(self, amount): def step(self): # move to a cell in my Moore neighborhood - self.move_to(self.cell.neighborhood().select_random_cell()) + self.cell = self.cell.neighborhood.select_random_cell() # trade self.do_business() # deposit money or take out a loan diff --git a/examples/bank_reserves/bank_reserves/model.py b/examples/bank_reserves/bank_reserves/model.py index 4c9e82d2..2671980d 100644 --- a/examples/bank_reserves/bank_reserves/model.py +++ b/examples/bank_reserves/bank_reserves/model.py @@ -12,7 +12,7 @@ import mesa import numpy as np -from mesa.spaces import OrthogonalMooreGrid +from mesa.experimental.cell_space import OrthogonalMooreGrid from .agents import Bank, Person diff --git a/examples/boltzmann_wealth_model/boltzmann_wealth_model/model.py b/examples/boltzmann_wealth_model/boltzmann_wealth_model/model.py index 37fa7f1e..97141763 100644 --- a/examples/boltzmann_wealth_model/boltzmann_wealth_model/model.py +++ b/examples/boltzmann_wealth_model/boltzmann_wealth_model/model.py @@ -20,7 +20,7 @@ class BoltzmannWealthModel(mesa.Model): def __init__(self, N=100, width=10, height=10): super().__init__() self.num_agents = N - self.grid = mesa.spaces.OrthogonalMooreGrid( + self.grid = mesa.experimental.cell_space.OrthogonalMooreGrid( (width, height), torus=True, random=self.random ) @@ -49,7 +49,7 @@ def run_model(self, n): self.step() -class MoneyAgent(mesa.spaces.CellAgent): +class MoneyAgent(mesa.experimental.cell_space.CellAgent): """An agent with fixed initial wealth.""" def __init__(self, model): @@ -66,6 +66,6 @@ def give_money(self): self.wealth -= 1 def step(self): - self.move_to(self.cell.neighborhood().select_random_cell()) + self.cell = self.cell.neighborhood.select_random_cell() if self.wealth > 0: self.give_money() diff --git a/examples/boltzmann_wealth_model_experimental/model.py b/examples/boltzmann_wealth_model_experimental/model.py index 6a2fd32b..db9b44fc 100644 --- a/examples/boltzmann_wealth_model_experimental/model.py +++ b/examples/boltzmann_wealth_model_experimental/model.py @@ -20,7 +20,7 @@ class BoltzmannWealthModel(mesa.Model): def __init__(self, N=100, width=10, height=10): super().__init__() self.num_agents = N - self.grid = mesa.spaces.OrthogonalMooreGrid( + self.grid = mesa.experimental.cell_space.OrthogonalMooreGrid( (width, height), torus=True, random=self.random ) @@ -49,7 +49,7 @@ def run_model(self, n): self.step() -class MoneyAgent(mesa.spaces.CellAgent): +class MoneyAgent(mesa.experimental.cell_space.CellAgent): """An agent with fixed initial wealth.""" def __init__(self, model): @@ -64,6 +64,6 @@ def give_money(self): self.wealth -= 1 def step(self): - self.move_to(self.cell.neighborhood().select_random_cell()) + self.cell = self.cell.neighborhood.select_random_cell() if self.wealth > 0: self.give_money() diff --git a/examples/boltzmann_wealth_model_network/boltzmann_wealth_model_network/model.py b/examples/boltzmann_wealth_model_network/boltzmann_wealth_model_network/model.py index 06d4d57e..ef1f563a 100644 --- a/examples/boltzmann_wealth_model_network/boltzmann_wealth_model_network/model.py +++ b/examples/boltzmann_wealth_model_network/boltzmann_wealth_model_network/model.py @@ -18,7 +18,7 @@ def __init__(self, num_agents=7, num_nodes=10): self.num_agents = num_agents self.num_nodes = num_nodes if num_nodes >= self.num_agents else self.num_agents self.G = nx.erdos_renyi_graph(n=self.num_nodes, p=0.5) - self.grid = mesa.spaces.Network(self.G, random=self.random, capacity=1) + self.grid = mesa.experimental.cell_space.Network(self.G, random=self.random, capacity=1) self.datacollector = mesa.DataCollector( model_reporters={"Gini": compute_gini}, @@ -47,7 +47,7 @@ def run_model(self, n): self.step() -class MoneyAgent(mesa.spaces.CellAgent): +class MoneyAgent(mesa.experimental.cell_space.CellAgent): """An agent with fixed initial wealth.""" def __init__(self, model): @@ -55,16 +55,16 @@ def __init__(self, model): self.wealth = 1 def give_money(self): - neighbors = [agent for agent in self.cell.neighborhood().agents if not self] + neighbors = [agent for agent in self.cell.neighborhood.agents if not self] if len(neighbors) > 0: other = self.random.choice(neighbors) other.wealth += 1 self.wealth -= 1 def step(self): - empty_neighbors = [cell for cell in self.cell.neighborhood() if cell.is_empty] + empty_neighbors = [cell for cell in self.cell.neighborhood if cell.is_empty] if empty_neighbors: - self.move_to(self.random.choice(empty_neighbors)) + self.cell = self.random.choice(empty_neighbors) if self.wealth > 0: self.give_money() diff --git a/examples/charts/charts/agents.py b/examples/charts/charts/agents.py index 1255bb08..2eeb5b4f 100644 --- a/examples/charts/charts/agents.py +++ b/examples/charts/charts/agents.py @@ -10,7 +10,7 @@ Northwestern University, Evanston, IL. """ -from mesa.spaces import CellAgent +from mesa.experimental.cell_space import CellAgent class Bank: @@ -178,7 +178,7 @@ def take_out_loan(self, amount): def step(self): # move to a cell in my Moore neighborhood - self.move_to(self.cell.neighborhood().select_random_cell()) + self.cell = self.cell.neighborhood.select_random_cell() # trade self.do_business() # deposit money or take out a loan diff --git a/examples/charts/charts/model.py b/examples/charts/charts/model.py index 1430b088..3308cbfc 100644 --- a/examples/charts/charts/model.py +++ b/examples/charts/charts/model.py @@ -14,7 +14,7 @@ import numpy as np from .agents import Bank, Person -from mesa.spaces import OrthogonalMooreGrid +from mesa.experimental.cell_space import OrthogonalMooreGrid """ If you want to perform a parameter sweep, call batch_run.py instead of run.py. diff --git a/examples/color_patches/color_patches/model.py b/examples/color_patches/color_patches/model.py index c84c3a95..6a1fbd28 100644 --- a/examples/color_patches/color_patches/model.py +++ b/examples/color_patches/color_patches/model.py @@ -7,7 +7,7 @@ import mesa -class ColorCell(mesa.spaces.CellAgent): +class ColorCell(mesa.experimental.cell_space.CellAgent): """ Represents a cell's opinion (visualized by a color) """ @@ -37,7 +37,7 @@ def determine_opinion(self): A choice is made at random in case of a tie The next state is stored until all cells have been polled """ - neighbors = self.cell.neighborhood().agents + neighbors = self.cell.neighborhood.agents neighbors_opinion = Counter(n.state for n in neighbors) # Following is a a tuple (attribute, occurrences) polled_opinions = neighbors_opinion.most_common() @@ -66,7 +66,7 @@ def __init__(self, width=20, height=20): The agents next state is first determined before updating the grid """ super().__init__() - self._grid = mesa.spaces.OrthogonalMooreGrid((width, height), torus=False) + self._grid = mesa.experimental.cell_space.OrthogonalMooreGrid((width, height), torus=False) # self._grid.coord_iter() # --> should really not return content + col + row diff --git a/examples/conways_game_of_life/conways_game_of_life/cell.py b/examples/conways_game_of_life/conways_game_of_life/cell.py index 2edc0cb6..40f3b22e 100644 --- a/examples/conways_game_of_life/conways_game_of_life/cell.py +++ b/examples/conways_game_of_life/conways_game_of_life/cell.py @@ -1,7 +1,7 @@ import mesa -class Cell(mesa.spaces.CellAgent): +class Cell(mesa.experimental.cell_space.CellAgent): """Represents a single ALIVE or DEAD cell in the simulation.""" DEAD = 0 @@ -21,7 +21,7 @@ def is_alive(self): @property def neighbors(self): - return self.cell.neighborhood().agents + return self.cell.neighborhood.agents def determine_state(self): """ diff --git a/examples/conways_game_of_life/conways_game_of_life/model.py b/examples/conways_game_of_life/conways_game_of_life/model.py index 15636d37..66b11c75 100644 --- a/examples/conways_game_of_life/conways_game_of_life/model.py +++ b/examples/conways_game_of_life/conways_game_of_life/model.py @@ -15,7 +15,7 @@ def __init__(self, width=50, height=50): """ super().__init__() # Use a simple grid, where edges wrap around. - self.grid = mesa.spaces.OrthogonalMooreGrid((width, height), torus=True) + self.grid = mesa.experimental.cell_space.OrthogonalMooreGrid((width, height), torus=True) # Place a cell at each location, with some initialized to # ALIVE and some to DEAD. diff --git a/examples/epstein_civil_violence/epstein_civil_violence/agent.py b/examples/epstein_civil_violence/epstein_civil_violence/agent.py index f98a4db2..edd1d1eb 100644 --- a/examples/epstein_civil_violence/epstein_civil_violence/agent.py +++ b/examples/epstein_civil_violence/epstein_civil_violence/agent.py @@ -3,12 +3,12 @@ import mesa -class EpsteinAgent(mesa.spaces.CellAgent): +class EpsteinAgent(mesa.experimental.cell_space.CellAgent): def update_neighbors(self): """ Look around and see who my neighbors are """ - self.neighborhood = self.cell.neighborhood(radius=self.vision) + self.neighborhood = self.cell.get_neighborhood(radius=self.vision) self.neighbors = self.neighborhood.agents self.empty_neighbors = [c for c in self.neighborhood if c.is_empty] diff --git a/examples/epstein_civil_violence/epstein_civil_violence/model.py b/examples/epstein_civil_violence/epstein_civil_violence/model.py index d921b1a9..8bf06bf1 100644 --- a/examples/epstein_civil_violence/epstein_civil_violence/model.py +++ b/examples/epstein_civil_violence/epstein_civil_violence/model.py @@ -59,7 +59,7 @@ def __init__( self.max_iters = max_iters self.iteration = 0 - self.grid = mesa.spaces.OrthogonalMooreGrid( + self.grid = mesa.experimental.cell_space.OrthogonalMooreGrid( (width, height), capacity=1, torus=True )