Skip to content

Commit 53b4ca8

Browse files
committed
bring in line with main
1 parent 51b116b commit 53b4ca8

File tree

13 files changed

+28
-28
lines changed

13 files changed

+28
-28
lines changed

examples/aco_tsp/aco_tsp/model.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import mesa
44
import networkx as nx
55
import numpy as np
6-
from mesa.spaces import CellAgent, Network
6+
from mesa.experimental.cell_space import CellAgent, Network
77

88

99
@dataclass
@@ -116,7 +116,7 @@ def decide_next_city(self):
116116
# Random
117117
# new_city = self.random.choice(list(self.model.all_cities - set(self.cities_visited)))
118118
# Choose closest city not yet visited
119-
neighbors = self.cell.neighborhood()
119+
neighbors = self.cell.neighborhood
120120
candidates = [n for n in neighbors if n not in self._cities_visited]
121121
if len(candidates) == 0:
122122
return self.cell

examples/bank_reserves/bank_reserves/agents.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
Northwestern University, Evanston, IL.
1111
"""
1212

13-
from mesa.spaces import CellAgent
13+
from mesa.experimental.cell_space import CellAgent
1414

1515

1616
class Bank:
@@ -176,7 +176,7 @@ def take_out_loan(self, amount):
176176

177177
def step(self):
178178
# move to a cell in my Moore neighborhood
179-
self.move_to(self.cell.neighborhood().select_random_cell())
179+
self.cell = self.cell.neighborhood.select_random_cell()
180180
# trade
181181
self.do_business()
182182
# deposit money or take out a loan

examples/bank_reserves/bank_reserves/model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
import mesa
1414
import numpy as np
15-
from mesa.spaces import OrthogonalMooreGrid
15+
from mesa.experimental.cell_space import OrthogonalMooreGrid
1616

1717
from .agents import Bank, Person
1818

examples/boltzmann_wealth_model/boltzmann_wealth_model/model.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class BoltzmannWealthModel(mesa.Model):
2020
def __init__(self, N=100, width=10, height=10):
2121
super().__init__()
2222
self.num_agents = N
23-
self.grid = mesa.spaces.OrthogonalMooreGrid(
23+
self.grid = mesa.experimental.cell_space.OrthogonalMooreGrid(
2424
(width, height), torus=True, random=self.random
2525
)
2626

@@ -49,7 +49,7 @@ def run_model(self, n):
4949
self.step()
5050

5151

52-
class MoneyAgent(mesa.spaces.CellAgent):
52+
class MoneyAgent(mesa.experimental.cell_space.CellAgent):
5353
"""An agent with fixed initial wealth."""
5454

5555
def __init__(self, model):
@@ -66,6 +66,6 @@ def give_money(self):
6666
self.wealth -= 1
6767

6868
def step(self):
69-
self.move_to(self.cell.neighborhood().select_random_cell())
69+
self.cell = self.cell.neighborhood.select_random_cell()
7070
if self.wealth > 0:
7171
self.give_money()

examples/boltzmann_wealth_model_experimental/model.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class BoltzmannWealthModel(mesa.Model):
2020
def __init__(self, N=100, width=10, height=10):
2121
super().__init__()
2222
self.num_agents = N
23-
self.grid = mesa.spaces.OrthogonalMooreGrid(
23+
self.grid = mesa.experimental.cell_space.OrthogonalMooreGrid(
2424
(width, height), torus=True, random=self.random
2525
)
2626

@@ -49,7 +49,7 @@ def run_model(self, n):
4949
self.step()
5050

5151

52-
class MoneyAgent(mesa.spaces.CellAgent):
52+
class MoneyAgent(mesa.experimental.cell_space.CellAgent):
5353
"""An agent with fixed initial wealth."""
5454

5555
def __init__(self, model):
@@ -64,6 +64,6 @@ def give_money(self):
6464
self.wealth -= 1
6565

6666
def step(self):
67-
self.move_to(self.cell.neighborhood().select_random_cell())
67+
self.cell = self.cell.neighborhood.select_random_cell()
6868
if self.wealth > 0:
6969
self.give_money()

examples/boltzmann_wealth_model_network/boltzmann_wealth_model_network/model.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def __init__(self, num_agents=7, num_nodes=10):
1818
self.num_agents = num_agents
1919
self.num_nodes = num_nodes if num_nodes >= self.num_agents else self.num_agents
2020
self.G = nx.erdos_renyi_graph(n=self.num_nodes, p=0.5)
21-
self.grid = mesa.spaces.Network(self.G, random=self.random, capacity=1)
21+
self.grid = mesa.experimental.cell_space.Network(self.G, random=self.random, capacity=1)
2222

2323
self.datacollector = mesa.DataCollector(
2424
model_reporters={"Gini": compute_gini},
@@ -47,24 +47,24 @@ def run_model(self, n):
4747
self.step()
4848

4949

50-
class MoneyAgent(mesa.spaces.CellAgent):
50+
class MoneyAgent(mesa.experimental.cell_space.CellAgent):
5151
"""An agent with fixed initial wealth."""
5252

5353
def __init__(self, model):
5454
super().__init__(model)
5555
self.wealth = 1
5656

5757
def give_money(self):
58-
neighbors = [agent for agent in self.cell.neighborhood().agents if not self]
58+
neighbors = [agent for agent in self.cell.neighborhood.agents if not self]
5959
if len(neighbors) > 0:
6060
other = self.random.choice(neighbors)
6161
other.wealth += 1
6262
self.wealth -= 1
6363

6464
def step(self):
65-
empty_neighbors = [cell for cell in self.cell.neighborhood() if cell.is_empty]
65+
empty_neighbors = [cell for cell in self.cell.neighborhood if cell.is_empty]
6666
if empty_neighbors:
67-
self.move_to(self.random.choice(empty_neighbors))
67+
self.cell = self.random.choice(empty_neighbors)
6868

6969
if self.wealth > 0:
7070
self.give_money()

examples/charts/charts/agents.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
Northwestern University, Evanston, IL.
1111
"""
1212

13-
from mesa.spaces import CellAgent
13+
from mesa.experimental.cell_space import CellAgent
1414

1515

1616
class Bank:
@@ -178,7 +178,7 @@ def take_out_loan(self, amount):
178178

179179
def step(self):
180180
# move to a cell in my Moore neighborhood
181-
self.move_to(self.cell.neighborhood().select_random_cell())
181+
self.cell = self.cell.neighborhood.select_random_cell()
182182
# trade
183183
self.do_business()
184184
# deposit money or take out a loan

examples/charts/charts/model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import numpy as np
1515

1616
from .agents import Bank, Person
17-
from mesa.spaces import OrthogonalMooreGrid
17+
from mesa.experimental.cell_space import OrthogonalMooreGrid
1818

1919
"""
2020
If you want to perform a parameter sweep, call batch_run.py instead of run.py.

examples/color_patches/color_patches/model.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import mesa
88

99

10-
class ColorCell(mesa.spaces.CellAgent):
10+
class ColorCell(mesa.experimental.cell_space.CellAgent):
1111
"""
1212
Represents a cell's opinion (visualized by a color)
1313
"""
@@ -37,7 +37,7 @@ def determine_opinion(self):
3737
A choice is made at random in case of a tie
3838
The next state is stored until all cells have been polled
3939
"""
40-
neighbors = self.cell.neighborhood().agents
40+
neighbors = self.cell.neighborhood.agents
4141
neighbors_opinion = Counter(n.state for n in neighbors)
4242
# Following is a a tuple (attribute, occurrences)
4343
polled_opinions = neighbors_opinion.most_common()
@@ -66,7 +66,7 @@ def __init__(self, width=20, height=20):
6666
The agents next state is first determined before updating the grid
6767
"""
6868
super().__init__()
69-
self._grid = mesa.spaces.OrthogonalMooreGrid((width, height), torus=False)
69+
self._grid = mesa.experimental.cell_space.OrthogonalMooreGrid((width, height), torus=False)
7070

7171
# self._grid.coord_iter()
7272
# --> should really not return content + col + row

examples/conways_game_of_life/conways_game_of_life/cell.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import mesa
22

33

4-
class Cell(mesa.spaces.CellAgent):
4+
class Cell(mesa.experimental.cell_space.CellAgent):
55
"""Represents a single ALIVE or DEAD cell in the simulation."""
66

77
DEAD = 0
@@ -21,7 +21,7 @@ def is_alive(self):
2121

2222
@property
2323
def neighbors(self):
24-
return self.cell.neighborhood().agents
24+
return self.cell.neighborhood.agents
2525

2626
def determine_state(self):
2727
"""

0 commit comments

Comments
 (0)