Skip to content

Commit b51d334

Browse files
committed
Update coord_iter to Mesa 2.0 API
1 parent cd04cc1 commit b51d334

File tree

14 files changed

+16
-19
lines changed

14 files changed

+16
-19
lines changed

examples/boltzmann_wealth_model/app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
my_bar.progress((i / num_ticks), text="Simulation progress")
6969
placeholder.text("Step = %d" % i)
7070
for cell in model.grid.coord_iter():
71-
cell_content, x, y = cell
71+
cell_content, (x, y) = cell
7272
agent_count = len(cell_content)
7373
selected_row = df_grid[(df_grid["x"] == x) & (df_grid["y"] == y)]
7474
df_grid.loc[

examples/caching_and_replay/model.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@ def __init__(self, width=20, height=20, density=0.8, minority_pc=0.2, homophily=
6363
# the coordinates of a cell as well as
6464
# its contents. (coord_iter)
6565
for cell in self.grid.coord_iter():
66-
x = cell[1]
67-
y = cell[2]
66+
x, y = cell[1]
6867
if self.random.random() < self.density:
6968
agent_type = 1 if self.random.random() < self.minority_pc else 0
7069

examples/color_patches/color_patches/model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def __init__(self, width=20, height=20):
8080
# -->but only col & row
8181
# for (contents, col, row) in self._grid.coord_iter():
8282
# replaced content with _ to appease linter
83-
for _, row, col in self._grid.coord_iter():
83+
for _, (row, col) in self._grid.coord_iter():
8484
cell = ColorCell(
8585
(row, col), self, ColorCell.OPINIONS[self.random.randrange(0, 16)]
8686
)

examples/conways_game_of_life/app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
model.step()
5050
my_bar.progress((i / num_ticks), text="Simulation progress")
5151
placeholder.text("Step = %d" % i)
52-
for contents, x, y in model.grid.coord_iter():
52+
for contents, (x, y) in model.grid.coord_iter():
5353
# print('x:',x,'y:',y, 'state:',contents)
5454
selected_row = df_grid[(df_grid["x"] == x) & (df_grid["y"] == y)]
5555
df_grid.loc[

examples/conways_game_of_life/conways_game_of_life/model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def __init__(self, width=50, height=50):
2727

2828
# Place a cell at each location, with some initialized to
2929
# ALIVE and some to DEAD.
30-
for contents, x, y in self.grid.coord_iter():
30+
for contents, (x, y) in self.grid.coord_iter():
3131
cell = Cell((x, y), self)
3232
if self.random.random() < 0.1:
3333
cell.state = cell.ALIVE

examples/epstein_civil_violence/epstein_civil_violence/model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def __init__(
8181
unique_id = 0
8282
if self.cop_density + self.citizen_density > 1:
8383
raise ValueError("Cop density + citizen density must be less than 1")
84-
for contents, x, y in self.grid.coord_iter():
84+
for contents, (x, y) in self.grid.coord_iter():
8585
if self.random.random() < self.cop_density:
8686
cop = Cop(unique_id, self, (x, y), vision=self.cop_vision)
8787
unique_id += 1

examples/forest_fire/forest_fire/model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def __init__(self, width=100, height=100, density=0.65):
2929
)
3030

3131
# Place a tree in each cell with Prob = density
32-
for contents, x, y in self.grid.coord_iter():
32+
for contents, (x, y) in self.grid.coord_iter():
3333
if self.random.random() < density:
3434
# Create a tree
3535
new_tree = TreeCell((x, y), self)

examples/hex_snowflake/hex_snowflake/model.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ def __init__(self, width=50, height=50):
2525
self.grid = mesa.space.HexGrid(width, height, torus=True)
2626

2727
# Place a dead cell at each location.
28-
for contents, x, y in self.grid.coord_iter():
29-
cell = Cell((x, y), self)
30-
self.grid.place_agent(cell, (x, y))
28+
for contents, pos in self.grid.coord_iter():
29+
cell = Cell(pos, self)
30+
self.grid.place_agent(cell, pos)
3131
self.schedule.add(cell)
3232

3333
# activate the center(ish) cell.

examples/pd_grid/analysis.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
" if not ax:\n",
6969
" fig, ax = plt.subplots(figsize=(6, 6))\n",
7070
" grid = np.zeros((model.grid.width, model.grid.height))\n",
71-
" for agent, x, y in model.grid.coord_iter():\n",
71+
" for agent, (x, y) in model.grid.coord_iter():\n",
7272
" if agent.move == \"D\":\n",
7373
" grid[y][x] = 1\n",
7474
" else:\n",

examples/schelling/model.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@ def __init__(self, width=20, height=20, density=0.8, minority_pc=0.2, homophily=
6161
# the coordinates of a cell as well as
6262
# its contents. (coord_iter)
6363
for cell in self.grid.coord_iter():
64-
x = cell[1]
65-
y = cell[2]
64+
x, y = cell[1]
6665
if self.random.random() < self.density:
6766
agent_type = 1 if self.random.random() < self.minority_pc else 0
6867

0 commit comments

Comments
 (0)