Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/bank_reserves/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
itertools
mesa~=1.1
mesa~=2.0
numpy
pandas
2 changes: 1 addition & 1 deletion examples/boid_flockers/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
jupyter
matplotlib
mesa~=1.1
mesa~=2.0
2 changes: 1 addition & 1 deletion examples/boltzmann_wealth_model/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
my_bar.progress((i / num_ticks), text="Simulation progress")
placeholder.text("Step = %d" % i)
for cell in model.grid.coord_iter():
cell_content, x, y = cell
cell_content, (x, y) = cell
agent_count = len(cell_content)
selected_row = df_grid[(df_grid["x"] == x) & (df_grid["y"] == y)]
df_grid.loc[
Expand Down
2 changes: 1 addition & 1 deletion examples/boltzmann_wealth_model/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
mesa~=1.1
mesa~=2.0
5 changes: 3 additions & 2 deletions examples/boltzmann_wealth_model_experimental/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
mesa~=1.1
-e git+https://github.com/projectmesa/mesa-examples
mesa~=2.0
solara
git+https://github.com/projectmesa/mesa-examples
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,15 @@ def __init__(self, unique_id, model):
def move(self):
possible_steps = [
node
for node in self.model.grid.get_neighbors(self.pos, include_center=False)
for node in self.model.grid.get_neighborhood(self.pos, include_center=False)
if self.model.grid.is_cell_empty(node)
]
if len(possible_steps) > 0:
new_position = self.random.choice(possible_steps)
self.model.grid.move_agent(self, new_position)

def give_money(self):
neighbors_nodes = self.model.grid.get_neighbors(self.pos, include_center=False)
neighbors = self.model.grid.get_cell_list_contents(neighbors_nodes)
neighbors = self.model.grid.get_neighbors(self.pos, include_center=False)
if len(neighbors) > 0:
other = self.random.choice(neighbors)
other.wealth += 1
Expand Down
2 changes: 1 addition & 1 deletion examples/boltzmann_wealth_model_network/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
jupyter
matplotlib
mesa~=1.1
mesa~=2.0
numpy
networkx
3 changes: 1 addition & 2 deletions examples/caching_and_replay/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ def __init__(self, width=20, height=20, density=0.8, minority_pc=0.2, homophily=
# the coordinates of a cell as well as
# its contents. (coord_iter)
for cell in self.grid.coord_iter():
x = cell[1]
y = cell[2]
x, y = cell[1]
if self.random.random() < self.density:
agent_type = 1 if self.random.random() < self.minority_pc else 0

Expand Down
2 changes: 1 addition & 1 deletion examples/charts/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
itertools
mesa~=1.1
mesa~=2.0
numpy
pandas
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 @@ -80,7 +80,7 @@ def __init__(self, width=20, height=20):
# -->but only col & row
# for (contents, col, row) in self._grid.coord_iter():
# replaced content with _ to appease linter
for _, row, col in self._grid.coord_iter():
for _, (row, col) in self._grid.coord_iter():
cell = ColorCell(
(row, col), self, ColorCell.OPINIONS[self.random.randrange(0, 16)]
)
Expand Down
2 changes: 1 addition & 1 deletion examples/conways_game_of_life/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
model.step()
my_bar.progress((i / num_ticks), text="Simulation progress")
placeholder.text("Step = %d" % i)
for contents, x, y in model.grid.coord_iter():
for contents, (x, y) in model.grid.coord_iter():
# print('x:',x,'y:',y, 'state:',contents)
selected_row = df_grid[(df_grid["x"] == x) & (df_grid["y"] == y)]
df_grid.loc[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def __init__(self, width=50, height=50):

# Place a cell at each location, with some initialized to
# ALIVE and some to DEAD.
for contents, x, y in self.grid.coord_iter():
for contents, (x, y) in self.grid.coord_iter():
cell = Cell((x, y), self)
if self.random.random() < 0.1:
cell.state = cell.ALIVE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def __init__(
unique_id = 0
if self.cop_density + self.citizen_density > 1:
raise ValueError("Cop density + citizen density must be less than 1")
for contents, x, y in self.grid.coord_iter():
for contents, (x, y) in self.grid.coord_iter():
if self.random.random() < self.cop_density:
cop = Cop(unique_id, self, (x, y), vision=self.cop_vision)
unique_id += 1
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 @@ -29,7 +29,7 @@ def __init__(self, width=100, height=100, density=0.65):
)

# Place a tree in each cell with Prob = density
for contents, x, y in self.grid.coord_iter():
for contents, (x, y) in self.grid.coord_iter():
if self.random.random() < density:
# Create a tree
new_tree = TreeCell((x, y), self)
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 @@ -25,9 +25,9 @@ def __init__(self, width=50, height=50):
self.grid = mesa.space.HexGrid(width, height, torus=True)

# Place a dead cell at each location.
for contents, x, y in self.grid.coord_iter():
cell = Cell((x, y), self)
self.grid.place_agent(cell, (x, y))
for contents, pos in self.grid.coord_iter():
cell = Cell(pos, self)
self.grid.place_agent(cell, pos)
self.schedule.add(cell)

# activate the center(ish) cell.
Expand Down
2 changes: 1 addition & 1 deletion examples/hex_snowflake/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
mesa~=1.1
mesa~=2.0
2 changes: 1 addition & 1 deletion examples/pd_grid/analysis.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
" if not ax:\n",
" fig, ax = plt.subplots(figsize=(6, 6))\n",
" grid = np.zeros((model.grid.width, model.grid.height))\n",
" for agent, x, y in model.grid.coord_iter():\n",
" for agent, (x, y) in model.grid.coord_iter():\n",
" if agent.move == \"D\":\n",
" grid[y][x] = 1\n",
" else:\n",
Expand Down
2 changes: 1 addition & 1 deletion examples/pd_grid/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
jupyter
matplotlib
mesa~=1.1
mesa~=2.0
3 changes: 1 addition & 2 deletions examples/schelling/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ def __init__(self, width=20, height=20, density=0.8, minority_pc=0.2, homophily=
# the coordinates of a cell as well as
# its contents. (coord_iter)
for cell in self.grid.coord_iter():
x = cell[1]
y = cell[2]
x, y = cell[1]
if self.random.random() < self.density:
agent_type = 1 if self.random.random() < self.minority_pc else 0

Expand Down
2 changes: 1 addition & 1 deletion examples/schelling/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
jupyter
matplotlib
mesa~=1.1
mesa~=2.0
3 changes: 1 addition & 2 deletions examples/schelling_experimental/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ def __init__(self, width=20, height=20, density=0.8, minority_pc=0.2, homophily=
# the coordinates of a cell as well as
# its contents. (coord_iter)
for cell in self.grid.coord_iter():
x = cell[1]
y = cell[2]
x, y = cell[1]
if self.random.random() < self.density:
agent_type = 1 if self.random.random() < self.minority_pc else 0

Expand Down
5 changes: 3 additions & 2 deletions examples/schelling_experimental/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
jupyter
matplotlib
mesa~=1.1
-e git+https://github.com/projectmesa/mesa-examples
mesa~=2.0
solara
git+https://github.com/projectmesa/mesa-examples
2 changes: 1 addition & 1 deletion examples/shape_example/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
mesa~=1.1
mesa~=2.0
2 changes: 1 addition & 1 deletion examples/sugarscape_cg/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
jupyter
mesa~=1.1
mesa~=2.0
2 changes: 1 addition & 1 deletion examples/sugarscape_cg/sugarscape_cg/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def __init__(self, width=50, height=50, initial_population=100):

sugar_distribution = np.genfromtxt("sugarscape_cg/sugar-map.txt")
agent_id = 0
for _, x, y in self.grid.coord_iter():
for _, (x, y) in self.grid.coord_iter():
max_sugar = sugar_distribution[x, y]
sugar = Sugar(agent_id, (x, y), self, max_sugar)
agent_id += 1
Expand Down
3 changes: 1 addition & 2 deletions examples/sugarscape_g1mt/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ def portray(g):
"trader": {"x": [], "y": [], "c": "tab:red", "marker": "o", "s": 10},
}

# TODO update to Mesa 2.0 API
for content, i, j in g.coord_iter():
for content, (i, j) in g.coord_iter():
for agent in content:
if isinstance(agent, Trader):
layers["trader"]["x"].append(i)
Expand Down
2 changes: 1 addition & 1 deletion examples/sugarscape_g1mt/sugarscape_g1mt/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def __init__(
spice_distribution = np.flip(sugar_distribution, 1)

agent_id = 0
for _, x, y in self.grid.coord_iter():
for _, (x, y) in self.grid.coord_iter():
max_sugar = sugar_distribution[x, y]
if max_sugar > 0:
sugar = Sugar(agent_id, self, (x, y), max_sugar)
Expand Down
2 changes: 1 addition & 1 deletion examples/virus_on_network/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
networkx>=2.0
mesa~=1.1
mesa~=2.0
4 changes: 3 additions & 1 deletion examples/virus_on_network/virus_on_network/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,9 @@ def __init__(
self.gain_resistance_chance = gain_resistance_chance

def try_to_infect_neighbors(self):
neighbors_nodes = self.model.grid.get_neighbors(self.pos, include_center=False)
neighbors_nodes = self.model.grid.get_neighborhood(
self.pos, include_center=False
)
susceptible_neighbors = [
agent
for agent in self.model.grid.get_cell_list_contents(neighbors_nodes)
Expand Down
2 changes: 1 addition & 1 deletion examples/wolf_sheep/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
mesa~=1.1
mesa~=2.0
2 changes: 1 addition & 1 deletion examples/wolf_sheep/wolf_sheep/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def __init__(

# Create grass patches
if self.grass:
for agent, x, y in self.grid.coord_iter():
for agent, (x, y) in self.grid.coord_iter():
fully_grown = self.random.choice([True, False])

if fully_grown:
Expand Down