Skip to content

Commit a3f20ae

Browse files
authored
gis: Remove unique_id from Agent init (#204)
Now handled automatically in Mesa 3.0
1 parent 8d0c722 commit a3f20ae

File tree

9 files changed

+22
-31
lines changed

9 files changed

+22
-31
lines changed

gis/agents_and_networks/src/agent/building.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ class Building(mg.GeoAgent):
1919
function: float # 1.0 for work, 2.0 for home, 0.0 for neither
2020
entrance_pos: mesa.space.FloatCoordinate # nearest vertex on road
2121

22-
def __init__(self, unique_id, model, geometry, crs) -> None:
23-
super().__init__(unique_id=unique_id, model=model, geometry=geometry, crs=crs)
22+
def __init__(self, model, geometry, crs) -> None:
23+
super().__init__(model=model, geometry=geometry, crs=crs)
2424
self.entrance = None
2525
self.name = str(uuid.uuid4())
2626
self.function = randrange(3)

gis/agents_and_networks/src/agent/commuter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ class Commuter(mg.GeoAgent):
4141
SPEED: float
4242
CHANCE_NEW_FRIEND: float # percent chance to make a new friend every 5 min
4343

44-
def __init__(self, unique_id, model, geometry, crs) -> None:
45-
super().__init__(unique_id, model, geometry, crs)
44+
def __init__(self, model, geometry, crs) -> None:
45+
super().__init__(model, geometry, crs)
4646
self.my_home = None
4747
self.start_time_h = round(np.random.normal(6.5, 1))
4848
while self.start_time_h < 6 or self.start_time_h > 9:

gis/agents_and_networks/src/agent/geo_agents.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ class Driveway(mg.GeoAgent):
1010
geometry: Point
1111
crs: pyproj.CRS
1212

13-
def __init__(self, unique_id, model, geometry, crs) -> None:
14-
super().__init__(unique_id, model, geometry, crs)
13+
def __init__(self, model, geometry, crs) -> None:
14+
super().__init__(model, geometry, crs)
1515

1616

1717
class LakeAndRiver(mg.GeoAgent):
@@ -20,8 +20,8 @@ class LakeAndRiver(mg.GeoAgent):
2020
geometry: Point
2121
crs: pyproj.CRS
2222

23-
def __init__(self, unique_id, model, geometry, crs) -> None:
24-
super().__init__(unique_id, model, geometry, crs)
23+
def __init__(self, model, geometry, crs) -> None:
24+
super().__init__(model, geometry, crs)
2525

2626

2727
class Walkway(mg.GeoAgent):
@@ -30,5 +30,5 @@ class Walkway(mg.GeoAgent):
3030
geometry: Point
3131
crs: pyproj.CRS
3232

33-
def __init__(self, unique_id, model, geometry, crs) -> None:
34-
super().__init__(unique_id, model, geometry, crs)
33+
def __init__(self, model, geometry, crs) -> None:
34+
super().__init__(model, geometry, crs)

gis/geo_schelling/model.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ def get_largest_connected_components(gdf):
2727
class SchellingAgent(mg.GeoAgent):
2828
"""Schelling segregation agent."""
2929

30-
def __init__(self, unique_id, model, geometry, crs, agent_type=None):
30+
def __init__(self, model, geometry, crs, agent_type=None):
3131
"""Create a new Schelling agent.
3232
3333
Args:
3434
unique_id: Unique identifier for the agent.
3535
agent_type: Indicator for the agent's type (minority=1, majority=0)
3636
"""
37-
super().__init__(unique_id, model, geometry, crs)
37+
super().__init__(model, geometry, crs)
3838
self.atype = agent_type
3939

4040
def step(self):

gis/geo_schelling_points/geo_schelling_points/agents.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
class PersonAgent(mg.GeoAgent):
88
SIMILARITY_THRESHOLD = 0.3
99

10-
def __init__(self, unique_id, model, geometry, crs, is_red, region_id):
11-
super().__init__(unique_id, model, geometry, crs)
10+
def __init__(self, model, geometry, crs, is_red, region_id):
11+
super().__init__(model, geometry, crs)
1212
self.is_red = is_red
1313
self.region_id = region_id
1414

@@ -36,8 +36,8 @@ class RegionAgent(mg.GeoAgent):
3636
red_cnt: int
3737
blue_cnt: int
3838

39-
def __init__(self, unique_id, model, geometry, crs, init_num_people=5):
40-
super().__init__(unique_id, model, geometry, crs)
39+
def __init__(self, model, geometry, crs, init_num_people=5):
40+
super().__init__(model, geometry, crs)
4141
self.init_num_people = init_num_people
4242
self.red_cnt = 0
4343
self.blue_cnt = 0

gis/geo_schelling_points/geo_schelling_points/model.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import random
2-
import uuid
32
from pathlib import Path
43

54
import mesa
@@ -34,7 +33,6 @@ def __init__(self, red_percentage=0.5, similarity_threshold=0.5):
3433
for region in regions:
3534
for _ in range(region.init_num_people):
3635
person = PersonAgent(
37-
unique_id=uuid.uuid4().int,
3836
model=self,
3937
crs=self.space.crs,
4038
geometry=region.random_point(),

gis/geo_sir/agents.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ class PersonAgent(mg.GeoAgent):
77

88
def __init__(
99
self,
10-
unique_id,
1110
model,
1211
geometry,
1312
crs,
@@ -19,14 +18,13 @@ def __init__(
1918
):
2019
"""
2120
Create a new person agent.
22-
:param unique_id: Unique identifier for the agent
2321
:param model: Model in which the agent runs
2422
:param geometry: Shape object for the agent
2523
:param agent_type: Indicator if agent is infected
2624
("infected", "susceptible", "recovered" or "dead")
2725
:param mobility_range: Range of distance to move in one step
2826
"""
29-
super().__init__(unique_id, model, geometry, crs)
27+
super().__init__(model, geometry, crs)
3028
# Agent parameters
3129
self.atype = agent_type
3230
self.mobility_range = mobility_range
@@ -84,9 +82,7 @@ def __repr__(self):
8482
class NeighbourhoodAgent(mg.GeoAgent):
8583
"""Neighbourhood agent. Changes color according to number of infected inside it."""
8684

87-
def __init__(
88-
self, unique_id, model, geometry, crs, agent_type="safe", hotspot_threshold=1
89-
):
85+
def __init__(self, model, geometry, crs, agent_type="safe", hotspot_threshold=1):
9086
"""
9187
Create a new Neighbourhood agent.
9288
:param unique_id: Unique identifier for the agent
@@ -97,7 +93,7 @@ def __init__(
9793
:param hotspot_threshold: Number of infected agents in region
9894
to be considered a hot-spot
9995
"""
100-
super().__init__(unique_id, model, geometry, crs)
96+
super().__init__(model, geometry, crs)
10197
self.atype = agent_type
10298
self.hotspot_threshold = (
10399
hotspot_threshold # When a neighborhood is considered a hot-spot

gis/population/population/model.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import math
22
import random
3-
import uuid
43
from pathlib import Path
54

65
import mesa
@@ -17,8 +16,8 @@ class Person(mg.GeoAgent):
1716
MOBILITY_RANGE_X = 0.0
1817
MOBILITY_RANGE_Y = 0.0
1918

20-
def __init__(self, unique_id, model, geometry, crs, img_coord):
21-
super().__init__(unique_id, model, geometry, crs)
19+
def __init__(self, model, geometry, crs, img_coord):
20+
super().__init__(model, geometry, crs)
2221
self.img_coord = img_coord
2322

2423
def set_random_world_coord(self):
@@ -84,7 +83,6 @@ def _create_agents(self):
8483
point = Point(self.space.population_layer.transform * cell.indices)
8584
if not point.within(self.space.lake):
8685
person = Person(
87-
unique_id=uuid.uuid4().int,
8886
model=self,
8987
crs=self.space.crs,
9088
geometry=point,

gis/rainfall/rainfall/model.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@
1212

1313

1414
class RaindropAgent(mg.GeoAgent):
15-
def __init__(self, unique_id, model, pos):
15+
def __init__(self, model, pos):
1616
super().__init__(
17-
unique_id,
1817
model,
1918
geometry=None,
2019
crs=model.space.crs,

0 commit comments

Comments
 (0)