Model
- class pop2net.Model(parameters=None, _run_id=None, enable_p2n_warnings=True, **kwargs)[source]
Class the encapsulates a full simluation.
This very closely follows the logic of the
agentpy.Model
package. Seeagentpy.Model
for more information.- add_agent(agent)[source]
Add an agent to the environment.
The added agent will have no connections to other agents or locatons by default. If the agent is already in the current environment, this methods does nothing.
- add_agent_to_location(location, agent, weight=None, **kwargs)[source]
Add an agent to a specific location.
Both the agent 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 agents or locatons by default. If the location is already in the current environment, this methods does nothing.
- property agents: AgentList
Show a iterable view of all agents in the environment.
- Returns:
A non-mutable AgentList of all agents in the environment.
- Return type:
AgentList
- agents_between_locations(location1, location2, agent_types=None)[source]
Return all agents between two locations.
- property agents_by_id: dict
Returns a dictionary which stores the model’s agents by their id.
- Returns:
A dictionary which stores the model’s agents by their id.
- Return type:
- agents_of_location(location)[source]
Return the list of agents associated with a specific location.
- connect_agents(agents, location_cls, weight=None)[source]
Connects multiple agents via an instance of a given location class.
- disconnect_agents(agents, location_labels=None, remove_locations=False)[source]
Disconnects agents 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 agents from the given location instance but also to remove the location instance from the model. Use this method with care because removing agents from locations also disconnects those agents from all other agents connected to the location. Removing the location instance from the model could have even more sideeffects to those agents still connected with this location!
- Parameters:
agents (list) – A list of agents.
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 model. Defaults to False.
- export_agent_network(node_attrs=None, include_0_weights=True)[source]
Creates a projection of the model’s bipartite network.
- Parameters:
- Return type:
- Returns:
A weighted graph created from a model’s agent list. Agents are connected if they are neighbors in the model. Their connecting edge include the contact_weight as “weight” attribute.
- property locations: LocationList
Show a iterable view of all locations in the environment.
- Returns:
a non-mutable LocationList of all locations in the environment.
- Return type:
LocationList
- locations_between_agents(agent1, agent2, location_labels=None)[source]
Return all locations the connect two agents.
- property locations_by_id: dict
Returns a dictionary which stores the model’s locations by their id.
- Returns:
A dictionary which stores the model’s locations by their id.
- Return type:
- locations_of_agent(agent)[source]
Return the list of locations associated with a specific agent.
- Parameters:
agent (
Agent
) – The desired agent.- Return type:
LocationList
- Returns:
A list of locations.
- neighbors_of_agent(agent, location_labels=None)[source]
Return a list of neighboring agents for a specific agent.
The locations to be considered can be defined with location_labels.
- remove_agent(agent)[source]
Remove an agent from the environment.
If the agent does not exist in the environment, this method does nothing.
- remove_agent_from_location(location, agent)[source]
Remove an agent 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(agent, location, weight=None)[source]
Set the weight of an agent at a location.
If weight is None the method location.weight() will be used to generate a weight.