Skip to content

Commit 2b256f1

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

File tree

11 files changed

+19
-31
lines changed

11 files changed

+19
-31
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/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/sugarscape_g1mt/sugarscape_g1mt/model.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def __init__(
9797
for _, (x, y) in self.grid.coord_iter():
9898
max_sugar = sugar_distribution[x, y]
9999
max_spice = spice_distribution[x, y]
100-
resource = Resource(agent_id, self, (x, y), max_sugar, max_spice)
100+
resource = Resource(agent_id, self, max_sugar, max_spice)
101101
self.schedule.add(resource)
102102
self.grid.place_agent(resource, (x, y))
103103
agent_id += 1
@@ -123,7 +123,6 @@ def __init__(
123123
trader = Trader(
124124
agent_id,
125125
self,
126-
(x, y),
127126
moore=False,
128127
sugar=sugar,
129128
spice=spice,

examples/sugarscape_g1mt/sugarscape_g1mt/resource_agents.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@ class Resource(mesa.Agent):
99
- grows 1 amount of spice at each turn
1010
"""
1111

12-
def __init__(self, unique_id, model, pos, max_sugar, max_spice):
12+
def __init__(self, unique_id, model, max_sugar, max_spice):
1313
super().__init__(unique_id, model)
14-
self.pos = pos
1514
self.sugar_amount = max_sugar
1615
self.max_sugar = max_sugar
1716
self.spice_amount = max_spice

examples/sugarscape_g1mt/sugarscape_g1mt/trader_agents.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ def __init__(
3131
self,
3232
unique_id,
3333
model,
34-
pos,
3534
moore=False,
3635
sugar=0,
3736
spice=0,
@@ -40,7 +39,6 @@ def __init__(
4039
vision=0,
4140
):
4241
super().__init__(unique_id, model)
43-
self.pos = pos
4442
self.moore = moore
4543
self.sugar = sugar
4644
self.spice = spice

examples/wolf_sheep/wolf_sheep/agents.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ class Sheep(RandomWalker):
1212

1313
energy = None
1414

15-
def __init__(self, unique_id, pos, model, moore, energy=None):
16-
super().__init__(unique_id, pos, model, moore=moore)
15+
def __init__(self, unique_id, model, moore, energy=None):
16+
super().__init__(unique_id, model, moore=moore)
1717
self.energy = energy
1818

1919
def step(self):
@@ -58,8 +58,8 @@ class Wolf(RandomWalker):
5858

5959
energy = None
6060

61-
def __init__(self, unique_id, pos, model, moore, energy=None):
62-
super().__init__(unique_id, pos, model, moore=moore)
61+
def __init__(self, unique_id, model, moore, energy=None):
62+
super().__init__(unique_id, model, moore=moore)
6363
self.energy = energy
6464

6565
def step(self):
@@ -98,7 +98,7 @@ class GrassPatch(mesa.Agent):
9898
A patch of grass that grows at a fixed rate and it is eaten by sheep
9999
"""
100100

101-
def __init__(self, unique_id, pos, model, fully_grown, countdown):
101+
def __init__(self, unique_id, model, fully_grown, countdown):
102102
"""
103103
Creates a new patch of grass
104104
@@ -109,7 +109,6 @@ def __init__(self, unique_id, pos, model, fully_grown, countdown):
109109
super().__init__(unique_id, model)
110110
self.fully_grown = fully_grown
111111
self.countdown = countdown
112-
self.pos = pos
113112

114113
def step(self):
115114
if not self.fully_grown:

examples/wolf_sheep/wolf_sheep/model.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def __init__(
9898
x = self.random.randrange(self.width)
9999
y = self.random.randrange(self.height)
100100
energy = self.random.randrange(2 * self.sheep_gain_from_food)
101-
sheep = Sheep(self.next_id(), (x, y), self, True, energy)
101+
sheep = Sheep(self.next_id(), self, True, energy)
102102
self.grid.place_agent(sheep, (x, y))
103103
self.schedule.add(sheep)
104104

@@ -107,7 +107,7 @@ def __init__(
107107
x = self.random.randrange(self.width)
108108
y = self.random.randrange(self.height)
109109
energy = self.random.randrange(2 * self.wolf_gain_from_food)
110-
wolf = Wolf(self.next_id(), (x, y), self, True, energy)
110+
wolf = Wolf(self.next_id(), self, True, energy)
111111
self.grid.place_agent(wolf, (x, y))
112112
self.schedule.add(wolf)
113113

@@ -121,7 +121,7 @@ def __init__(
121121
else:
122122
countdown = self.random.randrange(self.grass_regrowth_time)
123123

124-
patch = GrassPatch(self.next_id(), (x, y), self, fully_grown, countdown)
124+
patch = GrassPatch(self.next_id(), self, fully_grown, countdown)
125125
self.grid.place_agent(patch, (x, y))
126126
self.schedule.add(patch)
127127

examples/wolf_sheep/wolf_sheep/random_walk.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class RandomWalker(mesa.Agent):
1818
y = None
1919
moore = True
2020

21-
def __init__(self, unique_id, pos, model, moore=True):
21+
def __init__(self, unique_id, model, moore=True):
2222
"""
2323
grid: The MultiGrid object in which the agent lives.
2424
x: The agent's current x coordinate
@@ -27,7 +27,6 @@ def __init__(self, unique_id, pos, model, moore=True):
2727
Otherwise, only up, down, left, right.
2828
"""
2929
super().__init__(unique_id, model)
30-
self.pos = pos
3130
self.moore = moore
3231

3332
def random_move(self):

0 commit comments

Comments
 (0)