Event

class archABM.event.Event(model: archABM.event_model.EventModel, place: archABM.place.Place, duration: int)[source]

Event primitive

An event is defined by an activity EventModel, that happens at some physical location Place`, for a finite period of time, in minutes (duration).

model: archABM.event_model.EventModel
place: archABM.place.Place
duration: int

Event Model

class archABM.event_model.EventModel(params: archABM.parameters.Parameters)[source]

Defines an event model, also called “activity”

An event model is defined by these parameters:

  • Activity name: str

  • Schedule: list of tuple (in minutes int)

  • Repetitions range: minimum (int) and maximum (int)

  • Duration range: minimum (int) and maximum (int) in minutes

  • Other parameters:

    • mask efficiency ratio: float

    • collective event: bool

    • shared event: bool

The schedule defines the allowed periods of time in which an activity can happen. For example, schedule=[(120,180),(240,300)] allows people to carry out this activity from the time 120 to 180 and also from time 240 until 300. Notice that the schedule units are in minutes.

Each activity is limited to a certain duration, and its priority follows a piecewise linear function, parametrized by:

  • r: repeatmin

  • R: repeatmax

  • e: event count

\[\begin{split}Priority(e) = \left\{\begin{matrix} 1-(1-\alpha)\cfrac{e}{r}\,,\quad 0 \leq e < r \\ \alpha\cfrac{R-e}{R-r}\,,\quad r \leq e < R \ \end{matrix}\right.\end{split}\]

Figure made with TikZ

id: int = -1
params: archABM.parameters.Parameters
count: int
noise: int
classmethod reset()None[source]

Resets EventModel ID.

static next()None[source]

Increments one unit the EventModel ID.

get_noise()int[source]

Generates random noise

Returns

noise amount in minutes

Return type

int

new()[source]

Generates a EventModel copy, with reset count and noise

Returns

cloned instance

Return type

EventModel

duration(now)int[source]

Generates a random duration between duration_min and duration_max.

Note

If the generated duration, together with the current timestamp, exceeds the allowed schedule, the duration is limited to finish at the scheduled time interval.

The noise attribute is used to model the schedule’s time tolerance.

Parameters

now (int) – current timestamp in minutes

Returns

event duration in minutes

Return type

int

priority()float[source]

Computes the priority of a certain event.

The priority function follows a piecewise linear function, parametrized by:

  • r: repeatmin

  • R: repeatmax

  • e: event count

\[\begin{split}Priority(e) = \left\{\begin{matrix} 1-(1-\alpha)\cfrac{e}{r}\,,\quad 0 \leq e < r \\ \alpha\cfrac{R-e}{R-r}\,,\quad r \leq e < R \ \end{matrix}\right.\end{split}\]
Returns

priority value [0-1]

Return type

float

probability(now: int)float[source]

Wrapper to call the priority function

If the event count is equal to the repeat_max parameters, it yields a 0 probability. Otherwise, it computes the priority() function described above.

Parameters

now (int) – current timestamp in minutes

Returns

event probability [0-1]

Return type

float

valid()bool[source]

Computes whether the event count has reached the repeat_max limit.

It yields True if repeat_max is undefined or if the event count is less than repeat_max. Otherwise, it yields False.

Returns

valid event

Return type

bool

consume()None[source]

Increments one unit the event count

supply()None[source]

Decrements one unit the event count

Event Generator

class archABM.event_generator.EventGenerator(env: simpy.core.Environment, db: archABM.database.Database)[source]

Generates events

An event is defined by an activity EventModel, that happens at a given physical location Place, for a finite period of time, in minutes (duration).

A event generator has certain event models to choose from, each one related to an activity.

env: simpy.core.Environment
db: archABM.database.Database
models: list
activities: list
generate(now: int, person)[source]

Generates events

First, it computes the probabilities and the validity of each EventModel at the current timestamp. Then, the activity is selected based on these probabilities as follows:

  • If there exists any probability among the list of EventModel, the activity is selected randomly according to the relative probabilities.

  • If all EventModel have 0 probability, then the activity is selected randomly among the valid ones.

  • Otherwise a random activity is returned.

Once the activity type EventModel has been selected, the event duration can computed and the physical location Place` can also be chosen.

The selected activity is counted (consumed) from the list of EventModel of the invoking person.

Note

Collective activities are consumed individually after the current event interruption.

Parameters
  • now (int) – current timestamp in minutes

  • person (Person) – person that invokes the event generation

Returns

generated Event, which is a set of a) activity EventModel, b) physical location Place` and c) time duration.

Return type

Event

consume_activity(model: archABM.event_model.EventModel)[source]

Consumes a unit from a given EventModel.

Parameters

model (EventModel) – event model to consume from

valid_activity(model: archABM.event_model.EventModel)[source]

Checks whether a given EventModel is valid.

Parameters

model (EventModel) – event model to check validity from

Returns

whether the event model is valid

Return type

[bool]