Infrastructure

class piperabm.infrastructure.Infrastructure(coeff_usage: float = 0, coeff_age: float = 0)

Bases: Query, Generate, Path, Update, Serialize, Graphics, Stat

Represent infrastructure network. Within the object, a nx.Graph() instance is used as backend.

Parameters:
  • coeff_usage (float, optional) – This is used to calculate the adjustment_factor for the elements and acts as the coefficient for amount of usage the element has received.

  • coeff_age (float, optional) – This is used to calculate the adjustment_factor for the elements and acts as the coefficient for age of the element.

add_home(pos: list, id: int = None, name: str = '', report: bool = False)

Add home node. These are the nodes where agents live and belong to. Agents from the same home are a family and together they form a household.

Parameters:
  • pos (list) – A list of [x, y] coordinates showing the position in space.

  • id (int, optional) – The unique id number. The default is None, and if stays None, system will automatically assign a new unique id.

  • name (str, optional) – Optional name of the element.

  • report (bool) – If True, system will report successful creation of this element.

add_junction(pos: list, id: int = None, name: str = '', report: bool = False)

Add junction node. These are the nodes that connect edges in the network and represent a physical point in the world.

Parameters:
  • pos (list) – A list of [x, y] coordinates showing the position in space.

  • id (int, optional) – The unique id number. The default is None, and if stays None, system will automatically assign a new unique id.

  • name (str, optional) – Optional name of the element.

  • report (bool) – If True, system will report successful creation of this element.

add_market(pos: list, resources: dict | ~piperabm.resource.Resource = <piperabm.resource.Resource object>, enough_resources: dict | ~piperabm.resource.Resource | None = None, id: int = None, name: str = '', report: bool = False)

Add market node These are the nodes where resources are bought and sold. The influx of resources to the model only happens through markets. They also act as social hubs in the model.

Parameters:
  • pos (list) – A list of [x, y] coordinates showing the position in space.

  • resources (dict or Resource, optional) – Initial resource stock of the market. This can be provided either as a plain dictionary (e.g., {'food': 100, 'water': 100, 'energy': 100}) or as a piperabm.Resource instance. If a Resource object is provided, it is converted internally to a dictionary before being attached to the underlying graph representation. If not specified, default resource values are used.

  • enough_resources (dict or Resource or None, optional) – Maximum stock capacity for each resource. If provided as a Resource object, it is converted internally to a dictionary. If None, the system initializes this value to match the initial resources levels.

  • id (int, optional) – The unique id number. The default is None, and if stays None, system will automatically assign a new unique id.

  • name (str, optional) – Optional name of the element.

  • report (bool) – If True, system will report successful creation of this element.

add_neighborhood_access(id_1: list, id_2: list, name: str = '', usage_impact: float = 0, age_impact: float = 0, report: bool = False)

Add neighborhood access edge. These edges connect homes and markets to the street network, allowing agents to access these nodes.

Parameters:
  • pos_1 (list) – A list of [x, y] coordinates showing the position of one of the ends in space.

  • pos_2 (list) – A list of [x, y] coordinates showing the position of the other end in space.

  • name (str, optional) – Optional name of the element.

  • usage_impact (float, optional) – The more the element is used, this number will grow. It will be used to calcualte adjustment_facor when computing the degradation. The default is 0.

  • age_impact (float, optional) – The more the element age, this number will grow. It will be used to calcualte adjustment_facor when computing the degradation. The default is 0.

  • report (bool) – If True, system will report successful creation of this element.

add_street(pos_1: list, pos_2: list, name: str = '', usage_impact: float = 0, age_impact: float = 0, report: bool = False)

Add street edge. These edges are used by agents to move around the simulation world.

Parameters:
  • pos_1 (list) – A list of [x, y] coordinates showing the position of one of the ends in space.

  • pos_2 (list) – A list of [x, y] coordinates showing the position of the other end in space.

  • name (str, optional) – Optional name of the element.

  • usage_impact (float, optional) – The more the element is used, this number will grow. It will be used to calcualte adjustment_facor when computing the degradation. The default is 0.

  • age_impact (float, optional) – The more the element age, this number will grow. It will be used to calcualte adjustment_facor when computing the degradation. The default is 0.

  • report (bool) – If True, system will report successful creation of this element.

bake(report: bool = False, proximity_radius: float = 2.220446049250313e-16, search_radius: float = None)

Bake the network using grammar rules

property baked: bool

Check if the network is fully baked

check_id(id)

Check whether id already exists

deserialize(data)

Deserialize

property edges: list

Return all edges ids

edges_closer_than(pos: list, max_distance: float = 0, edges_ids: list = None) list

Filter edges_ids that are within max_distance from pos.

Distance is computed from the point to the edge segment. If no candidate edges are provided, all edges in the graph are considered.

edges_from(id: int) list

All edges from a node

fig(clf: bool = False)

Add infrastructure elements to plt fig ax

generate(homes_num: int = 1, grid_size: list = [1, 1], grid_num: list = [2, 2], imperfection_percentage: float = 0)

Generate a grid world model.

Parameters:
  • homes_num (int) – Number of homes to be generated.

  • grid_size (list) – Size of the grid in meters provided as list of two numbers showing the width and height of the grid.

  • grid_num (list) – Number of grid cells in the provided as a list of two integers showing number of cells in the width and height of the world.

  • imperfection_percentage (float, optional) – Percetnage of random imperfections in the world. This is used to create a more realistic world by introducing some randomness in the grid structure. The percentage is calculated based on the length of the removed edges. The default is 0%.

get_adjusted_length(ids: list) float

Get edges adjusted_length

get_age_impact(ids: list) float

Get edges age_impact

get_balance(id: int) float

Get market balance value

get_edge_attribute(ids: list, attribute: str, default=None)

Get edge attribute from networkx graph

get_edge_attributes(ids: list) dict

Get all edge attribute from networkx graph

get_edge_name(ids: list) str

Get edge name

get_edge_type(ids: list) str

Get edge type

get_enough_resource(id: int, name: str) float

Get market enough_resource value

get_length(ids: list) float

Get edges length

get_node_attribute(id: int, attribute: str, default=None)

Get node attribute from networkx graph

get_node_attributes(id: list) dict

Get all node attribute from networkx graph

get_node_name(id: int) str

Get node name

get_node_type(id: int) str

Get node type

get_pos(id: int)

Get node position

get_resource(id: int, name: str, object=False) float | Resource

Get market resource value. If object is False, return a float, otherwise return a Resource object.

get_resources(id: int, object=False) dict | Resource

Get market resources value. If object is False, return a dict, otherwise return a Resource object.

get_usage_impact(ids: list) float

Get edges usage_impact

has_edge(ids: list) bool

Check whether the network already contains the edge

has_node(id: int) bool

Check whether the network already contains the node

has_path(id_start: int, id_end: int) bool

Rapidly check if there is any path

property homes: list

Return all homes nodes

impact(edges: list = [])

Impact the network by removing a list of edges

is_isolate(id: int) bool

Check if the node is isolated

property junctions: list

Return all junction nodes

property markets: list

Return all market nodes

property neighborhood_accesses: list

Return all neighborhood access edges

new_id()

Generate new unique random id

property nodes: list

Return all nodes id

nodes_closer_than(id: int, search_radius: float = 0, nodes: list = None, include_self: bool = False)

Filter nodes that are within the distance from id

property nonjunctions: list

Return all nonjunction nodes

path(id_start: int, id_end: int) list

Path finding algorythm using A_star

property prices: dict

Alias

random_edges(percent: float = 0)

Filter random edges by their length percentage

remove_edge(ids: list = None, report: bool = False)

Remove edge

remove_node(id: int, report: bool = False)

Remove node

replace_node(id: int, new_id: int, report: int = False) None

Replace a node with another node

property resource_names: list

Alias

serialize()

Serialize

set_adjusted_length(ids: list, value: float) None

Set edge adjusted_length value

set_age_impact(ids: list, value: float) None

Set edge age_impact value

set_balance(id: int, value: float) None

Set market balance value

set_degradation(cls)

Set the degradation class to use for this infrastructure. The class must be a subclass of Degradation.

set_edge_attribute(ids: list, attribute: str, value=None) None

Set edge attribute in networkx graph

set_node_attribute(id: int, attribute: str, value=None) None

Set node attribute in networkx graph

set_resource(id: int, name: str, value: float) None

Set market resource value

set_resources(id: int, values: dict | Resource) None

Set agent resources values.

set_usage_impact(ids: list, value: float) None

Set edge usage_impact value

show()

Show infrastructure elements

property stat

Return stats of the network

property streets: list

Return all street edges

type = 'infrastructure'
update(duration: float)

Update the network