Actor

This is an overview over the Actor Class

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

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

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

add_location(location, weight=None)[source]

Add this actor to a given location. If weight is None, it will be set to 1.

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

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

Return type:

None

add_locations(locations, weight=None)[source]

Add this actor to multiple locations.

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

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

Return type:

None

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

Connects this actor with a given other actor via an instance of a given location class. If location_cls is None, the default pop2net.Location class is used to create a new location instance. If weight is None, it will be set to 1.

Parameters:
  • actor (p2n.Actor) – An actor 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 actors and the location. Defaults to None.

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

Disconnects this actor from a given other actor 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 actors from the given location instance but also to remove the location instance from the model. Keep in mind that this may affect other actors that are still connected with the location instance.

Parameters:
  • neighbor (Actor) – An actor 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 actor 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_actor_weight(actor, location_labels=None)[source]

Returns the edge weight between this actor and a given other actor.

This is summed over all shared locations.

Parameters:
  • actor (Actor) – The other actor.

  • 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 actors.

get_location_weight(location)[source]

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

Parameters:

location (_type_) – A location.

Returns:

The edge weight.

Return type:

float

property location_labels: list[str]

Returns a list of labels of the locations this actor is associated with.

Returns:

A list of location labels.

Return type:

list[str]

property locations: list

Returns a list of locations that this actor is associated with.

Returns:

A list of locations.

neighbors(location_labels=None)[source]

Return all neighbors of an actor.

Convenience method that returns all neighbors over all locations this actor 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:

list

Returns:

All actors co-located with this actor over all locations.

remove_location(location)[source]

Remove this actor from a given location.

Parameters:

location (Location) – Remove actor from this location.

Return type:

None

remove_locations(locations)[source]

Remove this Actor from the given locations.

Parameters:

locations (list) – A list of location instances.

Return type:

None

shared_locations(actor, location_labels=None)[source]

Returns all locations that this actor shares with another actor. Use location_labels to specify which type of locations should be included in the search for shared locations.

Parameters:
  • actor (p2n.Actor) – The other actor.

  • location_labels (list[str] | None, optional) – A list of location_labels. Defaults to None.

Returns:

Shared locations.

Return type:

list