Agent

This is an overview over the Agent Class

class pop2net.Agent(model, *args, **kwargs)[source]

This is a Base class to represent agents in the simulation.

Agents’ behavior can be implemented in classes that inherit from this.

Examples

For instance, agents could all be instatiated with the is_infected attribute set to false:

class InfectionAgent(Agent):
    def setup(self):
        self.is_infected = False
add_location(location, weight=None)[source]

Add this Agent to a given location.

Parameters:
  • location (Location) – Add agent to this location.

  • weight (float | None) – The edge weight between the agent and the location. Defaults to None.

Return type:

None

add_locations(locations, weight=None)[source]

Add this agent to multiple locations.

Parameters:
  • locations (list) – Add the agent to these locations.

  • weight (float | None) – The edge weight between the agent and the location. Defaults to None.

Return type:

None

connect(agent, location_cls, weight=None)[source]

Connects this agent with a given other agent via an instance of a given location class.

Parameters:
  • agent (list) – An agent to connect with.

  • location_cls (type) – The location class that is used to create a location instance.

  • weight (float | None) – The edge weight between the agents and the location. Defaults to None.

disconnect(neighbor, location_labels=None, remove_self=True, remove_neighbor=True, remove_locations=False)[source]

Disconnects this agent from a given other agent by removing them from shared locations.

If a list of location types is given, only shared locations of the given types are considered. Turn on remove_locations in order to not only remove the agents from the given location instance but also to remove the location instance from the model. Keep in mind that this may affect other agents that are still connected with the location instance.

Parameters:
  • neighbor (Agent) – An agent to disconnect from.

  • location_labels (list | None, optional) – A list of location types to specify which

  • None. (shared locations are considered. Defaults to)

  • remove_self (bool) – Should the agent be removed from the shared locations? Defaults to True.

  • remove_neighbor (bool) – Should the neighbor be removed from the shared locations? Defaults to True.

  • remove_locations (bool, optional) – A bool that determines whether the shared locations shall be removed from the model. Defaults to False.

get_agent_weight(agent, location_labels=None)[source]

Return the edge weight between this agent and a given other agent.

This is summed over all shared locations.

Parameters:
  • agent (Agent) – The other agent.

  • location_labels (list) – A list of location classes to specify the type of locations which are considered.

Return type:

float

Returns:

A weight of the contact between the two agents.

get_location_weight(location)[source]

Return the edge weight between this agent and a given location.

Parameters:

location (_type_) – A location.

Returns:

The edge weight.

Return type:

float

property locations: LocationList

Return a list of locations that this agent is associated with.

Returns:

A list of locations.

neighbors(location_labels=None)[source]

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_labels.

Parameters:

location_labels (Optional[list[str]]) – A list of location_labels.

Return type:

AgentList

Returns:

All agents co-located with this agent over all locations.

remove_location(location)[source]

Remove this Agent from a given location.

Parameters:

location (Location) – Remove agent from this location.

Return type:

None

remove_locations(locations)[source]

Remove this Agent from the given locations.

Parameters:

locations (list) – A list of location instances.

Return type:

None

setup()[source]

Instantiate an Agent.

This is executed on the instantiation of each agent.

Return type:

None