Skip to content

Commit

Permalink
gis: Remove unique_id from Agent init (#204)
Browse files Browse the repository at this point in the history
Now handled automatically in Mesa 3.0
  • Loading branch information
EwoutH committed Sep 25, 2024
1 parent 8d0c722 commit a3f20ae
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 31 deletions.
4 changes: 2 additions & 2 deletions gis/agents_and_networks/src/agent/building.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ class Building(mg.GeoAgent):
function: float # 1.0 for work, 2.0 for home, 0.0 for neither
entrance_pos: mesa.space.FloatCoordinate # nearest vertex on road

def __init__(self, unique_id, model, geometry, crs) -> None:
super().__init__(unique_id=unique_id, model=model, geometry=geometry, crs=crs)
def __init__(self, model, geometry, crs) -> None:
super().__init__(model=model, geometry=geometry, crs=crs)
self.entrance = None
self.name = str(uuid.uuid4())
self.function = randrange(3)
Expand Down
4 changes: 2 additions & 2 deletions gis/agents_and_networks/src/agent/commuter.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ class Commuter(mg.GeoAgent):
SPEED: float
CHANCE_NEW_FRIEND: float # percent chance to make a new friend every 5 min

def __init__(self, unique_id, model, geometry, crs) -> None:
super().__init__(unique_id, model, geometry, crs)
def __init__(self, model, geometry, crs) -> None:
super().__init__(model, geometry, crs)
self.my_home = None
self.start_time_h = round(np.random.normal(6.5, 1))
while self.start_time_h < 6 or self.start_time_h > 9:
Expand Down
12 changes: 6 additions & 6 deletions gis/agents_and_networks/src/agent/geo_agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ class Driveway(mg.GeoAgent):
geometry: Point
crs: pyproj.CRS

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


class LakeAndRiver(mg.GeoAgent):
Expand All @@ -20,8 +20,8 @@ class LakeAndRiver(mg.GeoAgent):
geometry: Point
crs: pyproj.CRS

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


class Walkway(mg.GeoAgent):
Expand All @@ -30,5 +30,5 @@ class Walkway(mg.GeoAgent):
geometry: Point
crs: pyproj.CRS

def __init__(self, unique_id, model, geometry, crs) -> None:
super().__init__(unique_id, model, geometry, crs)
def __init__(self, model, geometry, crs) -> None:
super().__init__(model, geometry, crs)
4 changes: 2 additions & 2 deletions gis/geo_schelling/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ def get_largest_connected_components(gdf):
class SchellingAgent(mg.GeoAgent):
"""Schelling segregation agent."""

def __init__(self, unique_id, model, geometry, crs, agent_type=None):
def __init__(self, model, geometry, crs, agent_type=None):
"""Create a new Schelling agent.
Args:
unique_id: Unique identifier for the agent.
agent_type: Indicator for the agent's type (minority=1, majority=0)
"""
super().__init__(unique_id, model, geometry, crs)
super().__init__(model, geometry, crs)
self.atype = agent_type

def step(self):
Expand Down
8 changes: 4 additions & 4 deletions gis/geo_schelling_points/geo_schelling_points/agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
class PersonAgent(mg.GeoAgent):
SIMILARITY_THRESHOLD = 0.3

def __init__(self, unique_id, model, geometry, crs, is_red, region_id):
super().__init__(unique_id, model, geometry, crs)
def __init__(self, model, geometry, crs, is_red, region_id):
super().__init__(model, geometry, crs)
self.is_red = is_red
self.region_id = region_id

Expand Down Expand Up @@ -36,8 +36,8 @@ class RegionAgent(mg.GeoAgent):
red_cnt: int
blue_cnt: int

def __init__(self, unique_id, model, geometry, crs, init_num_people=5):
super().__init__(unique_id, model, geometry, crs)
def __init__(self, model, geometry, crs, init_num_people=5):
super().__init__(model, geometry, crs)
self.init_num_people = init_num_people
self.red_cnt = 0
self.blue_cnt = 0
Expand Down
2 changes: 0 additions & 2 deletions gis/geo_schelling_points/geo_schelling_points/model.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import random
import uuid
from pathlib import Path

import mesa
Expand Down Expand Up @@ -34,7 +33,6 @@ def __init__(self, red_percentage=0.5, similarity_threshold=0.5):
for region in regions:
for _ in range(region.init_num_people):
person = PersonAgent(
unique_id=uuid.uuid4().int,
model=self,
crs=self.space.crs,
geometry=region.random_point(),
Expand Down
10 changes: 3 additions & 7 deletions gis/geo_sir/agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ class PersonAgent(mg.GeoAgent):

def __init__(
self,
unique_id,
model,
geometry,
crs,
Expand All @@ -19,14 +18,13 @@ def __init__(
):
"""
Create a new person agent.
:param unique_id: Unique identifier for the agent
:param model: Model in which the agent runs
:param geometry: Shape object for the agent
:param agent_type: Indicator if agent is infected
("infected", "susceptible", "recovered" or "dead")
:param mobility_range: Range of distance to move in one step
"""
super().__init__(unique_id, model, geometry, crs)
super().__init__(model, geometry, crs)
# Agent parameters
self.atype = agent_type
self.mobility_range = mobility_range
Expand Down Expand Up @@ -84,9 +82,7 @@ def __repr__(self):
class NeighbourhoodAgent(mg.GeoAgent):
"""Neighbourhood agent. Changes color according to number of infected inside it."""

def __init__(
self, unique_id, model, geometry, crs, agent_type="safe", hotspot_threshold=1
):
def __init__(self, model, geometry, crs, agent_type="safe", hotspot_threshold=1):
"""
Create a new Neighbourhood agent.
:param unique_id: Unique identifier for the agent
Expand All @@ -97,7 +93,7 @@ def __init__(
:param hotspot_threshold: Number of infected agents in region
to be considered a hot-spot
"""
super().__init__(unique_id, model, geometry, crs)
super().__init__(model, geometry, crs)
self.atype = agent_type
self.hotspot_threshold = (
hotspot_threshold # When a neighborhood is considered a hot-spot
Expand Down
6 changes: 2 additions & 4 deletions gis/population/population/model.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import math
import random
import uuid
from pathlib import Path

import mesa
Expand All @@ -17,8 +16,8 @@ class Person(mg.GeoAgent):
MOBILITY_RANGE_X = 0.0
MOBILITY_RANGE_Y = 0.0

def __init__(self, unique_id, model, geometry, crs, img_coord):
super().__init__(unique_id, model, geometry, crs)
def __init__(self, model, geometry, crs, img_coord):
super().__init__(model, geometry, crs)
self.img_coord = img_coord

def set_random_world_coord(self):
Expand Down Expand Up @@ -84,7 +83,6 @@ def _create_agents(self):
point = Point(self.space.population_layer.transform * cell.indices)
if not point.within(self.space.lake):
person = Person(
unique_id=uuid.uuid4().int,
model=self,
crs=self.space.crs,
geometry=point,
Expand Down
3 changes: 1 addition & 2 deletions gis/rainfall/rainfall/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@


class RaindropAgent(mg.GeoAgent):
def __init__(self, unique_id, model, pos):
def __init__(self, model, pos):
super().__init__(
unique_id,
model,
geometry=None,
crs=model.space.crs,
Expand Down

0 comments on commit a3f20ae

Please sign in to comment.