Measurement

class piperabm.model.Measurement(path=None, name: str = '')

Bases: object

Class used for result measurements.

Parameters:
  • name (str, optional) – The label to distinguish this model and its results when running multiple instances. In single runs, this can left empty.

  • path (str, optional) – Directory for saving/loading simulation results.

add_accessibility(id: int, value: float) None

Add new accessibility value

add_time(value: float) None

Add new point in time

add_travel_distance(value: float) None

Add new travel distance value

delta_times(_from: int = None, _to: int = None) list

Return delta times

deserialize(data: dict) None

Deserialize

filter_times(_from: int = None, _to: int = None) list

Filter times list

property len: int

Return total number of entries

load()

Load to file

measure(report=True, resume=False)
property result_directory

Return result directory

save()

Save to file

serialize() dict

Serialize

type = 'measurement'
class piperabm.model.measurement.accessibility.Accessibility(measurement)

Bases: object

Manage accessibility measurement

add(id: int, value: float) None

Add new accessibility value

property agents

Return a list of agents id

average(agents='all', resources='all', _from=None, _to=None) float

Calculate total average.

For each agent i, time t, and resource r:

\[A_{i,t,r} = \frac{R_{i,t}}{R^{\max}_i}\]

To aggregate across resources:

\[A_{i,t} = \left(\prod_{r=1}^R A_{i,t,r}\right)^{1/R}\]

Community average at time t:

\[A_t = \frac{1}{N}\sum_{i=1}^N A_{i,t}\]

And over the full duration T:

\[A = \frac{\int_0^T A_t\,dt}{\int_0^T A_\max\,dt}\]
Parameters:
  • agents (default='all') – Accepts either ‘all’, single id of an agent, or a list of agents id. These are the agents that their accessibility values will be calulcated as sum.

  • resources (default='all') – Accepts either ‘all’, name of a single resource, or a list of resource names. These are the resources that accessibility to them will be calculated.

  • _from (int, default=None) – The step number in time to start summation. If None, the earliest step will be considered.

  • _to (int, default=None) – The step number in time to end summation. If None, the latest step will be considered.

create_plot(agents='all', resources='all', _from=None, _to=None, info=None)

Create plot for accessibility.

Parameters:
  • agents (default='all') – Accepts either ‘all’, single id of an agent, or a list of agents id. These are the agents that their accessibility values will be calulcated as sum.

  • resources (default='all') – Accepts either ‘all’, name of a single resource, or a list of resource names. These are the resources that accessibility to them will be calculated.

  • _from (int, default=None) – The step number in time to start summation. If None, the earliest step will be considered.

  • _to (int, default=None) – The step number in time to end summation. If None, the latest step will be considered.

deserialize(data: dict) None

Deserialize

get(agent: int, resource: str, time_step: int)

Get the desired entry

property len: int

Return total number of entries

rearrange(agents='all', resources='all', _from=None, _to=None)

Return accessibility values for all resources for across agents.

Parameters:
  • agents (default='all') – Accepts either ‘all’, single id of an agent, or a list of agents id. These are the agents that their accessibility values will be calulcated as sum.

  • resources (default='all') – Accepts either ‘all’, name of a single resource, or a list of resource names. These are the resources that accessibility to them will be calculated.

  • _from (int, default=None) – The step number in time to start summation. If None, the earliest step will be considered.

  • _to (int, default=None) – The step number in time to end summation. If None, the latest step will be considered.

save(agents='all', resources='all', _from=None, _to=None, info=None)

Save plot

serialize() dict

Serialize

show(agents='all', resources='all', _from=None, _to=None, info=None)

Draw plot for accessibility over time.

Parameters:
  • agents (default='all') – Accepts either ‘all’, single id of an agent, or a list of agents id. These are the agents that their accessibility values will be calulcated as sum.

  • resources (default='all') – Accepts either ‘all’, name of a single resource, or a list of resource names. These are the resources that accessibility to them will be calculated.

  • _from (int, default=None) – The step number in time to start summation. If None, the earliest step will be considered.

  • _to (int, default=None) – The step number in time to end summation. If None, the latest step will be considered.

sum_agents(agents='all', resources='all', _from=None, _to=None) list

Sum of accessibility for agents.

For each agent i, time t, and resource r:

\[A_{i,t,r} = \frac{R_{i,t}}{R^{\max}_i}\]

Community average at time t:

\[A_{t,r} = \frac{1}{N}\sum_{i=1}^N A_{i,t,r}\]
Parameters:
  • agents (default='all') – Accepts either ‘all’, single id of an agent, or a list of agents id. These are the agents that their accessibility values will be calulcated as sum.

  • resources (default='all') – Accepts either ‘all’, name of a single resource, or a list of resource names. These are the resources that accessibility to them will be calculated.

  • _from (int, default=None) – The step number in time to start summation. If None, the earliest step will be considered.

  • _to (int, default=None) – The step number in time to end summation. If None, the latest step will be considered.

sum_resources(agents='all', resources='all', _from=None, _to=None) dict

Sum the accessibility to resources.

For each agent i, time t, and resource r:

\[A_{i,t,r} = \frac{R_{i,t}}{R^{\max}_i}\]

To aggregate across resources:

\[A_{i,t} = \left(\prod_{r=1}^R A_{i,t,r}\right)^{1/R}\]

The reason is, if any of the resources reach zero, life will become challenging.

Parameters:
  • agents (default='all') – Accepts either ‘all’, single id of an agent, or a list of agents id. These are the agents that their accessibility values will be calulcated as sum.

  • resources (default='all') – Accepts either ‘all’, name of a single resource, or a list of resource names. These are the resources that accessibility to them will be calculated.

  • _from (int, default=None) – The step number in time to start summation. If None, the earliest step will be considered.

  • _to (int, default=None) – The step number in time to end summation. If None, the latest step will be considered.

type = 'accessibility'
class piperabm.model.measurement.travel_distance.TravelDistance(measurement)

Bases: object

Manage travel distance measurement

add(value: float) None

Add new travel distance value.

average(_from=None, _to=None) float

Calculate total average.

Parameters:
  • _from (int, default=None) – The step number in time to start summation. If None, the earliest step will be considered.

  • _to (int, default=None) – The step number in time to end summation. If None, the latest step will be considered.

create_plot(_from=None, _to=None, info=None)

Create plot.

Parameters:
  • _from (int, default=None) – The step number in time to start summation. If None, the earliest step will be considered.

  • _to (int, default=None) – The step number in time to end summation. If None, the latest step will be considered.

deserialize(data: dict) None

Deserialize.

filter(_from=None, _to=None)

Filter values in a specific range.

Parameters:
  • _from (int, default=None) – The step number in time to start summation. If None, the earliest step will be considered.

  • _to (int, default=None) – The step number in time to end summation. If None, the latest step will be considered.

save(_from=None, _to=None, info=None)

Save plot.

Parameters:
  • _from (int, default=None) – The step number in time to start summation. If None, the earliest step will be considered.

  • _to (int, default=None) – The step number in time to end summation. If None, the latest step will be considered.

  • info (str, default=None) – The extra information shown in the plot.

serialize() dict

Serialize.

show(_from=None, _to=None, info: str = None)

Draw plot.

Parameters:
  • _from (int, default=None) – The step number in time to start summation. If None, the earliest step will be considered.

  • _to (int, default=None) – The step number in time to end summation. If None, the latest step will be considered.

  • info (str, default=None) – The extra information shown in the plot.

type = 'travel distance'