Skip to content

Commit bbec7d7

Browse files
committed
Address duplicate position warning (#122)
1 parent 875bfe2 commit bbec7d7

File tree

16 files changed

+35
-53
lines changed

16 files changed

+35
-53
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_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/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)

examples/sugarscape_cg/sugarscape_cg/agents.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,8 @@ def get_distance(pos_1, pos_2):
1717

1818

1919
class SsAgent(mesa.Agent):
20-
def __init__(
21-
self, unique_id, pos, model, moore=False, sugar=0, metabolism=0, vision=0
22-
):
20+
def __init__(self, unique_id, model, moore=False, sugar=0, metabolism=0, vision=0):
2321
super().__init__(unique_id, model)
24-
self.pos = pos
2522
self.moore = moore
2623
self.sugar = sugar
2724
self.metabolism = metabolism
@@ -74,7 +71,7 @@ def step(self):
7471

7572

7673
class Sugar(mesa.Agent):
77-
def __init__(self, unique_id, pos, model, max_sugar):
74+
def __init__(self, unique_id, model, max_sugar):
7875
super().__init__(unique_id, model)
7976
self.amount = max_sugar
8077
self.max_sugar = max_sugar

examples/sugarscape_cg/sugarscape_cg/model.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def __init__(self, width=50, height=50, initial_population=100):
5050
agent_id = 0
5151
for _, (x, y) in self.grid.coord_iter():
5252
max_sugar = sugar_distribution[x, y]
53-
sugar = Sugar(agent_id, (x, y), self, max_sugar)
53+
sugar = Sugar(agent_id, self, max_sugar)
5454
agent_id += 1
5555
self.grid.place_agent(sugar, (x, y))
5656
self.schedule.add(sugar)
@@ -62,7 +62,7 @@ def __init__(self, width=50, height=50, initial_population=100):
6262
sugar = self.random.randrange(6, 25)
6363
metabolism = self.random.randrange(2, 4)
6464
vision = self.random.randrange(1, 6)
65-
ssa = SsAgent(agent_id, (x, y), self, False, sugar, metabolism, vision)
65+
ssa = SsAgent(agent_id, self, False, sugar, metabolism, vision)
6666
agent_id += 1
6767
self.grid.place_agent(ssa, (x, y))
6868
self.schedule.add(ssa)

0 commit comments

Comments
 (0)