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)

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)

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: 8 additions & 13 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):
@@ -44,9 +44,7 @@ def step(self):
4444
# Create a new sheep:
4545
if self.model.grass:
4646
self.energy /= 2
47-
lamb = Sheep(
48-
self.model.next_id(), self.pos, self.model, self.moore, self.energy
49-
)
47+
lamb = Sheep(self.model.next_id(), self.model, self.moore, self.energy)
5048
self.model.grid.place_agent(lamb, self.pos)
5149
self.model.schedule.add(lamb)
5250

@@ -58,8 +56,8 @@ class Wolf(RandomWalker):
5856

5957
energy = None
6058

61-
def __init__(self, unique_id, pos, model, moore, energy=None):
62-
super().__init__(unique_id, pos, model, moore=moore)
59+
def __init__(self, unique_id, model, moore, energy=None):
60+
super().__init__(unique_id, model, moore=moore)
6361
self.energy = energy
6462

6563
def step(self):
@@ -86,10 +84,8 @@ def step(self):
8684
if self.random.random() < self.model.wolf_reproduce:
8785
# Create a new wolf cub
8886
self.energy /= 2
89-
cub = Wolf(
90-
self.model.next_id(), self.pos, self.model, self.moore, self.energy
91-
)
92-
self.model.grid.place_agent(cub, cub.pos)
87+
cub = Wolf(self.model.next_id(), self.model, self.moore, self.energy)
88+
self.model.grid.place_agent(cub, self.pos)
9389
self.model.schedule.add(cub)
9490

9591

@@ -98,7 +94,7 @@ class GrassPatch(mesa.Agent):
9894
A patch of grass that grows at a fixed rate and it is eaten by sheep
9995
"""
10096

101-
def __init__(self, unique_id, pos, model, fully_grown, countdown):
97+
def __init__(self, unique_id, model, fully_grown, countdown):
10298
"""
10399
Creates a new patch of grass
104100
@@ -109,7 +105,6 @@ def __init__(self, unique_id, pos, model, fully_grown, countdown):
109105
super().__init__(unique_id, model)
110106
self.fully_grown = fully_grown
111107
self.countdown = countdown
112-
self.pos = pos
113108

114109
def step(self):
115110
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)