Location

The location class represents a base class that can be used to implement realistic location in which agents can meet and interact.

class pop2net.Location(model)[source]

Base class for location objects.

add_agent(agent, weight=None)[source]

Assigns the given agent to this location.

Parameters:
  • agent (Agent) – The agent that should be added to the location.

  • weight (Optional[float]) – The edge weight between the agent and the location. Defaults to None. If weight is set to None, the weight is generated by location.weight(), which returns 1 by default.

Return type:

None

add_agents(agents, weight=None)[source]

Add multiple agents at once.

Parameters:
  • agents (list) – An iterable over agents.

  • weight (float | None) – The edge weight between the agents and the location. Defaults to None. If weight is set to None, the weight is generated by location.weight(), which returns 1 by default.

Return type:

None

property agents: AgentList

Return the list of agents affiliated with this location.

Returns:

List of agents at this location.

get_weight(agent)[source]

Return the edge weight between an agent and the location.

Parameters:

agent (Agent) – Agent of which the edge weight should be returned.

Return type:

float

Returns:

Edge weight.

neighbors(agent)[source]

Returns a list of agents which are connected to the given agent via this location.

Parameters:

agent (Agent) – Agent of whom the neighbors at this location are to be returned.

Returns:

A list of all agents at this location except the passed agent.

Return type:

AgentList

project_weights(agent1, agent2)[source]

Calculates the edge weight between two agents assigned to the same location instance.

Defines how the weights are combined when the edge weight between two agents is determined. Can be completely rewritten to have location-specific methods of this kind with the same name or can be used as it is in the simulation code.

Parameters:
  • agent1 (Agent) – First agent of the pair.

  • agent2 (Agent) – Second agent of the pair.

Raises:

Exception – Raised if self.weight_projection_function is not in [“average”, “simultan”]

Return type:

float

Returns:

Combined edge weight.

remove_agent(agent)[source]

Removes the given agent from this location.

Parameters:

agent (Agent) – Agent that is to be removed.

Return type:

None

remove_agents(agents)[source]

Remove multiple agents at once.

Parameters:

agents (list) – An iterable over agents.

Return type:

None

set_weight(agent, weight=None)[source]

Set the weight of an agent at the current location.

If weight is None the method location.weight() will be used to generate a weight.

Parameters:
  • agent (Agent) – The agent.

  • weight (float) – The weight.

Return type:

None

weight(agent)[source]

Generates the edge weight between a given agent and the location instance.

Parameters:

agent (_type_) – An agent.

Returns:

The weight between the given agent and the location.

Return type:

float