Skip to content

Commit d034d19

Browse files
committed
Address duplicate position warning
1 parent 1933cbc commit d034d19

File tree

18 files changed

+41
-59
lines changed

18 files changed

+41
-59
lines changed

examples/boid_flockers/boid_flockers/model.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ def __init__(
2828
self,
2929
unique_id,
3030
model,
31-
pos,
3231
speed,
3332
direction,
3433
vision,
@@ -42,7 +41,6 @@ def __init__(
4241
4342
Args:
4443
unique_id: Unique agent identifier.
45-
pos: Starting position
4644
speed: Distance to move per step.
4745
direction: numpy vector for the Boid's direction of movement.
4846
vision: Radius to look around for nearby Boids.
@@ -52,7 +50,6 @@ def __init__(
5250
match: the relative importance of matching neighbors' headings
5351
"""
5452
super().__init__(unique_id, model)
55-
self.pos = np.array(pos)
5653
self.speed = speed
5754
self.direction = direction
5855
self.vision = vision
@@ -140,7 +137,6 @@ def make_agents(self):
140137
boid = Boid(
141138
unique_id=i,
142139
model=self,
143-
pos=pos,
144140
speed=self.speed,
145141
direction=direction,
146142
vision=self.vision,

examples/boltzmann_wealth_model/app.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@
7171
cell_content, (x, y) = cell
7272
agent_count = len(cell_content)
7373
selected_row = df_grid[(df_grid["x"] == x) & (df_grid["y"] == y)]
74-
df_grid.loc[
75-
selected_row.index, "agent_count"
76-
] = agent_count # random.choice([1,2])
74+
df_grid.loc[selected_row.index, "agent_count"] = (
75+
agent_count # random.choice([1,2])
76+
)
7777

7878
df_gini = pd.concat(
7979
[

examples/boltzmann_wealth_model_network/boltzmann_wealth_model_network/server.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ def network_portrayal(G):
1212
"id": node_id,
1313
"size": 3 if agents else 1,
1414
"color": "#CC0000" if not agents or agents[0].wealth == 0 else "#007959",
15-
"label": None
16-
if not agents
17-
else f"Agent:{agents[0].unique_id} Wealth:{agents[0].wealth}",
15+
"label": (
16+
None
17+
if not agents
18+
else f"Agent:{agents[0].unique_id} Wealth:{agents[0].wealth}"
19+
),
1820
}
1921
for (node_id, agents) in G.nodes.data("agent")
2022
]

examples/color_patches/color_patches/server.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
handles the definition of the canvas parameters and
33
the drawing of the model representation on the canvas
44
"""
5+
56
# import webbrowser
67

78
import mesa

examples/conways_game_of_life/app.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@
5252
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)]
55-
df_grid.loc[
56-
selected_row.index, "state"
57-
] = contents.state # random.choice([1,2])
55+
df_grid.loc[selected_row.index, "state"] = (
56+
contents.state
57+
) # random.choice([1,2])
5858

5959
heatmap = (
6060
alt.Chart(df_grid)

examples/forest_fire/forest_fire/agent.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,14 @@ class TreeCell(mesa.Agent):
1414
practice to give one to each agent anyway.
1515
"""
1616

17-
def __init__(self, pos, model):
17+
def __init__(self, unique_id, model):
1818
"""
1919
Create a new tree.
2020
Args:
21-
pos: The tree's coordinates on the grid.
21+
unique_id: Unique identifier for the agent.
2222
model: standard model reference for agent.
2323
"""
24-
super().__init__(pos, model)
25-
self.pos = pos
24+
super().__init__(unique_id, model)
2625
self.condition = "Fine"
2726

2827
def step(self):

examples/forest_fire/forest_fire/model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def __init__(self, width=100, height=100, density=0.65):
3333
for contents, (x, y) in self.grid.coord_iter():
3434
if self.random.random() < density:
3535
# Create a tree
36-
new_tree = TreeCell((x, y), self)
36+
new_tree = TreeCell(self.next_id(), self)
3737
# Set all trees in the first column on fire.
3838
if x == 0:
3939
new_tree.condition = "On Fire"

examples/pd_grid/pd_grid/agent.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,17 @@
44
class PDAgent(mesa.Agent):
55
"""Agent member of the iterated, spatial prisoner's dilemma model."""
66

7-
def __init__(self, pos, model, starting_move=None):
7+
def __init__(self, unique_id, model, starting_move=None):
88
"""
99
Create a new Prisoner's Dilemma agent.
1010
1111
Args:
12-
pos: (x, y) tuple of the agent's position.
12+
unique_id: Unique identifier for the agent.
1313
model: model instance
1414
starting_move: If provided, determines the agent's initial state:
1515
C(ooperating) or D(efecting). Otherwise, random.
1616
"""
17-
super().__init__(pos, model)
18-
self.pos = pos
17+
super().__init__(unique_id, model)
1918
self.score = 0
2019
if starting_move:
2120
self.move = starting_move

examples/pd_grid/pd_grid/model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def __init__(
3737
# Create agents
3838
for x in range(width):
3939
for y in range(height):
40-
agent = PDAgent((x, y), self)
40+
agent = PDAgent(self.next_id(), self)
4141
self.grid.place_agent(agent, (x, y))
4242
self.schedule.add(agent)
4343

examples/schelling_experimental/model.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,15 @@ class SchellingAgent(mesa.Agent):
66
Schelling segregation agent
77
"""
88

9-
def __init__(self, pos, model, agent_type):
9+
def __init__(self, unique_id, model, agent_type):
1010
"""
1111
Create a new Schelling agent.
1212
1313
Args:
1414
unique_id: Unique identifier for the agent.
15-
pos: Agent initial location.
1615
agent_type: Indicator for the agent's type (minority=1, majority=0)
1716
"""
18-
super().__init__(pos, model)
19-
self.pos = pos
17+
super().__init__(unique_id, model)
2018
self.type = agent_type
2119

2220
def step(self):
@@ -57,7 +55,7 @@ def __init__(self, width=20, height=20, density=0.8, minority_pc=0.2, homophily=
5755
for _, pos in self.grid.coord_iter():
5856
if self.random.random() < density:
5957
agent_type = 1 if self.random.random() < minority_pc else 0
60-
agent = SchellingAgent(pos, self, agent_type)
58+
agent = SchellingAgent(self.next_id(), self, agent_type)
6159
self.grid.place_agent(agent, pos)
6260

6361
self.datacollector.collect(self)

0 commit comments

Comments
 (0)