Skip to content

Commit

Permalink
Merge pull request #127 from mariuzka/mk/seperate_location_and_magicl…
Browse files Browse the repository at this point in the history
…ocation

Mk/seperate location and magiclocation
  • Loading branch information
mariuzka authored Nov 25, 2024
2 parents 5ed0b01 + 563ecd6 commit 0fb5c4c
Show file tree
Hide file tree
Showing 71 changed files with 1,317 additions and 1,073 deletions.
8 changes: 4 additions & 4 deletions src/pop2net/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
from .exceptions import Pop2netException
from .inspector import NetworkInspector
from .location import Location
from .location import MagicLocation
from .location import MeltLocation
from .location_designer import LocationDesigner
from .location_designer import MeltLocationDesigner
from .model import Model
from .sequences import LocationList

Expand All @@ -17,8 +17,8 @@
"Agent",
"Pop2netException",
"Location",
"MagicLocation",
"MeltLocation",
"LocationDesigner",
"MeltLocationDesigner",
"NetworkInspector",
"Model",
"LocationList",
Expand Down
24 changes: 12 additions & 12 deletions src/pop2net/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,25 @@ def setup(self) -> None:
This is executed on the instantiation of each agent.
"""

def neighbors(self, location_classes: list | None = None) -> ap.AgentList:
def neighbors(self, location_labels: list[str] | None = None) -> ap.AgentList:
"""Return all neighbors of an agent.
Convenience method that returns all neighbors over all locations this agent is currently
located in. The locations to be considered can be defined with location_classes.
located in. The locations to be considered can be defined with location_labels.
Args:
location_classes: A list of location_classes.
location_labels: A list of location_labels.
Returns:
All agents co-located with this agent over all locations.
"""
return self.model.neighbors_of_agent(self, location_classes=location_classes)
return self.model.neighbors_of_agent(self, location_labels=location_labels)

def shared_locations(self, agent, location_classes: list | None = None):
def shared_locations(self, agent, location_labels: list[str] | None = None):
return self.model.locations_between_agents(
agent1=self,
agent2=agent,
location_classes=location_classes,
location_labels=location_labels,
)

def add_location(self, location: _location.Location, weight: float | None = None) -> None:
Expand Down Expand Up @@ -112,21 +112,21 @@ def locations(self) -> _sequences.LocationList:
"""
return self.model.locations_of_agent(self)

def get_agent_weight(self, agent: Agent, location_classes: list | None = None) -> float:
def get_agent_weight(self, agent: Agent, location_labels: list | None = None) -> float:
"""Return the edge weight between this agent and a given other agent.
This is summed over all shared locations.
Args:
agent: The other agent.
location_classes (list): A list of location classes to specify the type of locations
location_labels (list): A list of location classes to specify the type of locations
which are considered.
Returns:
A weight of the contact between the two agents.
"""
weight = 0
for location in self.shared_locations(agent=agent, location_classes=location_classes):
for location in self.shared_locations(agent=agent, location_labels=location_labels):
weight += location.project_weights(agent1=self, agent2=agent)
return weight

Expand Down Expand Up @@ -155,7 +155,7 @@ def connect(self, agent: Agent, location_cls: type, weight: float | None = None)
def disconnect(
self,
neighbor: Agent,
location_classes: list | None = None,
location_labels: list | None = None,
remove_self=True,
remove_neighbor=True,
remove_locations: bool = False,
Expand All @@ -169,7 +169,7 @@ def disconnect(
Args:
neighbor (Agent): An agent to disconnect from.
location_classes (list | None, optional): A list of location types to specify which
location_labels (list | None, optional): A list of location types to specify which
shared locations are considered. Defaults to None.
remove_self (bool): Should the agent be removed from the shared locations?
Defaults to True.
Expand All @@ -180,7 +180,7 @@ def disconnect(
"""
shared_locations = self.shared_locations(
agent=neighbor,
location_classes=location_classes,
location_labels=location_labels,
)

for location in shared_locations:
Expand Down
Loading

0 comments on commit 0fb5c4c

Please sign in to comment.