Environment
- class pop2net.Environment(model=None, framework=None, enable_p2n_warnings=True)[source]
Class that organizes actors and locations.
- property actors: list
Show a iterable view of all actors in the environment.
Important: While you can make changes to the objects in this list, you cannot modify this attribute itself. Instead you have to use methods like Environment.add_actor() or Environment.remove_actor(), for instance.
- Returns:
A non-mutable list of all actors in the environment.
- Return type:
- actors_between_locations(location1, location2, actor_types=None)[source]
Return all actors between two locations.
- actors_of_location(location)[source]
Return the list of actors associated with a specific location.
- Parameters:
location (
Location) – The desired location.- Returns:
A list of actors.
- add_actor(actor)[source]
Add an actor to the environment.
The added actor will have no connections to other actors or locatons by default. If the actor is already in the current environment, this methods does nothing.
- add_actor_to_location(location, actor, weight=None, **kwargs)[source]
Add an actor to a specific location.
Both the actor and the location have to be defined beforehand. All additional keyword arguments will be edge attributes for this connection.
- Parameters:
- Raises:
- Return type:
- add_location(location)[source]
Add a location to the environment.
The added location will have no connections to other actors or locatons by default. If the location is already in the current environment, this methods does nothing.
- connect_actors(actors, location_cls, weight=None)[source]
Connects multiple actors via an instance of a given location class.
- disconnect_actors(actors, location_labels=None, remove_locations=False)[source]
Disconnects actors 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 given actors from the given location instance but also to remove the location instance from the environment. Use this method with care because removing actors from locations also disconnects those actors from all other actors connected to the location. Removing the location instance from the environment could have even more sideeffects to those actors still connected with this location!
- Parameters:
actors (list) – A list of actors.
location_labels (list | None, optional) – A list of location types to specify which
None. (shared locations are considered. Defaults to)
remove_locations (bool, optional) – A bool that determines whether the shared locations shall be removed from the environment. Defaults to False.
- export_actor_network(node_attrs=None, include_0_weights=True)[source]
Creates a projection of the environment’s bipartite network.
- Parameters:
- Return type:
- Returns:
A weighted graph created from a environment’s actor list. Actors are connected if they are neighbors in the environment. Their connecting edge include the contact_weight as “weight” attribute.
- property locations: list
Show a iterable view of all locations in the environment.
Important: While you can make changes to the objects in this list, you cannot modify this attribute itself. Instead you have to use methods like Environment.add_location() or Environment.remove_location(), for instance.
- Returns:
a non-mutable LocationList of all locations in the environment.
- Return type:
LocationList
- locations_between_actors(actor1, actor2, location_labels=None)[source]
Return all locations that connects two actors.
- neighbors_of_actor(actor, location_labels=None)[source]
Return a list of neighboring actors for a specific actor.
The locations to be considered can be defined with location_labels.
- remove_actor(actor)[source]
Remove an actor from the environment.
If the actor does not exist in the environment, this method does nothing.
- remove_actor_from_location(location, actor)[source]
Remove an actor from a location.
- Parameters:
- Raises:
- Return type:
- remove_location(location)[source]
Remove a location from the environment.
If the location does not exist in the environment, this method does nothing.
- set_weight(actor, location, weight=None)[source]
Set the weight of an actor at a location.
If weight is None the method location.weight() will be used to generate a weight.