DATACLASSES

Dataclasses provides the basic class framework to build a population

Overview:

DATACLASSES

class Population

Class representing a population.

Public Functions

Population()

Construct a new Population:: Population object.

~Population()

Destroy the Population:: Population object.

void forEachCell(std::function<bool(Cell*)> callback)

Callback each Cell in Population. callback function is applied to each cell. stops if callback function returns false.

Parameters:

callback – Callback to apply to each cell

void forEachPlace(std::function<bool(Place*)> callback)

Callback each Place in Population.

Callback function is applied to each place Terminates early if callback function returns false

Parameters:

callback – Callback to apply to each place

std::vector<CellPtr> &cells()

Get reference to population’s cells vector.

Returns:

std::vector<CellPtr>& Reference to population’s cells vector

std::vector<Place> &places()

Get reference to population’s places vector.

Returns:

std::vector<Place>& Reference to population’s places vector

void initialize()

Pre-simulation start initialization Called by simulation class post initialization to setup any helper structures.

class Cell

Public Functions

Cell(size_t index)

Construct a new Cell:: Cell object.

Parameters:

indexCell’s index in population’s cells vector

~Cell()

Destroy the Cell:: Cell object.

Cell(const Cell&) = delete
Cell(Cell&&) = default
size_t index() const

Get index of cell within Population::m_cells;

Returns:

size_t

void forEachMicrocell(std::function<bool(Microcell*)> callback)

Apply callback on each microcell in cell.

Callback function can return false to terminate loop early.

Parameters:

callback – Callback function applied to each microcell

void forEachPerson(std::function<bool(Person*)> callback)

Apply callback on each person in cell.

Callback function can return false to terminate loop early

Parameters:

callback – Callback function to apply to each person

void forEachInfectious(std::function<bool(Person*)> callback)

Apply callback on each infectious person in the cell.

Callback function can return false to terminate loop early

Parameters:

callback – Callback function to apply to each infectious person

void forEachNonInfectious(std::function<bool(Person*)> callback)

Apply callback on each non-infectious person in the cell.

Callback function can return false to terminate loop early

Parameters:

callback – Callback function to apply to each non-infectious person

void forEachExposed(std::function<bool(Person*)> callback)

Apply callback on each exposed person in the cell.

Callback function can return false to terminate loop early

Parameters:

callback – Callback function to apply to each exposed person

Person &getPerson(size_t i)

Retrieve ith person in cell.

Parameters:

i – Index of person to retrieve

Returns:

Person& Reference to ith person

Microcell &getMicrocell(size_t i)

Retrieve ith microcell in cell.

Parameters:

i – Index of microcell to retrieve

Returns:

Microcell& Reference to ith microcell

void processQueue(std::function<void(size_t)> callback)

Callback each queued person. Dequeues people on callback.

Parameters:

callback

bool enqueuePerson(size_t personIndex)

Add person to the cell’s queue Used for applying new infections at the end of all infection transmitting sweeps.

Same person cannot be added twice Returns true if person was successfully added

Parameters:

personIndex – Index of person to enqueue

Returns:

true Returns true if successfully enqueued

Returns:

false Returns false if unable to enqueue person (person already queued)

std::vector<Person> &people()

Reference to cell’s people vector.

Returns:

std::vector<Person>& Reference to people vector

std::vector<Microcell> &microcells()

Reference to cell’s microcells vector.

Returns:

std::vector<Microcell>& Reference to microcells vector

void initializeInfectiousGrouping()

Initialize Sorted People Vectors This must be called before using markInfectious or markNonInfectious.

Initialize framework for fast looping through infectious / susceptible Cell can maintain a vector of people where all the infectious are at the start. This is to allow quick looping through only infectious people without looping through all people and checking their status.

bool markInfectious(size_t personIndex)

Mark Person as Infectious for Fast Looping through Infectious People Mark a person as infectious. Used for fast looping through infectious or non-infectious people without looping through all people and checking their statuses. Cell::initializeInfectiousGroupings must have been called once before for this function to be used.

Parameters:

newInfectedPerson who is becoming infectious.

Returns:

true Successfully changed person’s state to infectious.

Returns:

false Person was already infectious.

bool markNonInfectious(size_t personIndex)

Mark Person as Non-Infectious for Fast Looping through Infectious People Mark a person as non-infectious. Used for fast looping through infectious or non-infectious people without looping through all people and checking their statuses. Cell::initializeInfectiousGroupings must have been called once before this can be used.

Parameters:

oldInfectedPerson who is no longer infectious.

Returns:

true Successfully changed person’s state to non-infectious.

Returns:

false Person was already marked as non-infectious.

bool markExposed(size_t personIndex)

Mark person as exposed.

Parameters:

newInfected – Index of newly infected person

Returns:

true Returns true if successfully changed person’s state

Returns:

false Returns false if person already marked as exposed

bool markRecovered(size_t personIndex)

Mark person as recovered.

Parameters:

person – Index of recovered person

Returns:

true Returns true if successfully changed person’s state

Returns:

false Returns false if person already marked as recovered

bool markDead(size_t personIndex)

Mark person as dead.

Parameters:

person – Index of dead person

Returns:

true Returns true if successfully changed person’s state

Returns:

false Returns false if person already marked as dead

size_t numSusceptible() const

Get number of susceptible people.

Returns:

size_t Number of susceptible people

size_t numInfectious() const

Get Number of Infectious Get number of currently infectious people. This corresponds to the number of infectious being maintained by the cell for fast looping through infectious / non-infectious. Cell::initializeInfectiousGroupings() must have been called once before this can be used.

Returns:

size_t Number of infectious

size_t numExposed() const

Get number of people marked as exposed.

Returns:

size_t Number of exposed people

size_t numRecovered() const

Get number of people marked as recovered.

Returns:

size_t Number of recovered people

size_t numDead() const

Get number of people marked as dead.

Returns:

size_t Number of dead people

bool sampleInfectious(size_t n, std::function<void(Person*)> callback, std::mt19937_64 &rg)

Randomly sample n infectious people in the cell with replacement.

Parameters:
  • n – Number of people to sample

  • callback – Callback applied to each chosen person

  • rg – Random number generator to use

Returns:

true Success

Returns:

false Returns false if there are no infectious people to sample

bool sampleSusceptible(size_t n, std::function<void(Person*)> callback, std::mt19937_64 &rg)

Randomly sample n susceptible people in the cell with replacement.

Parameters:
  • n – Number of people to sample

  • callback – Callback to apply to each sampled person

  • rg – Random generator to use

Returns:

true Success

Returns:

false Returns false if there are no susceptible people to sample

void initialize()

Initialize the cell.

Automatically called by Population::initialize() as part of the population setup procedure

unsigned int compartmentCount(InfectionStatus status)

Retrieve number of people with specific InfectionStatus.

Parameters:

status – Compartment to retrieve

Returns:

unsigned int Number of people in the compartment

void setLocation(std::pair<double, double> loc)

Set the cell’s location.

Used for spatial sweep distance modifiers

Parameters:

locCell’s location

std::pair<double, double> location() const

Get the cell’s location.

Returns:

std::pair<double, double> Cell’s location

void personStatusChange(Person *person, InfectionStatus newStatus, unsigned short timestep)

Change a person’s status.

Automatically called by Person::updateStatus. Should not be called manually Part of person update status procedure

Parameters:
  • personPerson to alter

  • newStatusPerson’s new status

  • timestep – Time of status change

class Microcell

Class representing a microcell.

Public Functions

Microcell(size_t cellPos)

Construct a new Microcell:: Microcell object.

Parameters:

cellPosMicrocell’s index within parent cell

~Microcell()

Destroy the Microcell:: Microcell object.

Microcell(const Microcell&)
Microcell(Microcell&&)
size_t cellPos() const

Get index of microcell in parent cell.

Returns:

size_t Microcell’s index within parent cell’s microcells vector

void forEachPerson(Cell &cell, std::function<bool(Person*)> callback)

Apply callback to each person in microcell.

Callback can return false to terminate loop early

Parameters:
  • cell – Reference to microcell’s parent cell

  • callback – Callback to apply to each person in microcell

Person &getPerson(Cell &cell, size_t i)

Get person in microcell.

Parameters:
  • cell – Reference to microcell’s parent cell

  • i – Index within microcell’s people vector to retrieve

Returns:

Person& Reference to ith person in microcell’s people vector

HouseholdPtr getHousehold(size_t i)

Get ith houshold in microcell.

Parameters:

i – Index of household to retrieve

Returns:

HouseholdPtr Shared pointer to ith household in microcell

std::vector<size_t> &people()

Get reference to microcell’s people vector.

Each entry in vector corresponds to index of person in parent cell’s vector.

Returns:

std::vector<size_t>& Reference to microcell’s people vector

std::vector<HouseholdPtr> &households()

Get reference to microcell’s households vector.

Returns:

std::vector<HouseholdPtr>& Reference to microcell’s households vector

void initialize(Cell *cell)

Initialize Microcell.

Automatically called by parent cell during Population::initialize(). Part of population’s pre-simulation initialization procedure

Parameters:

cell – Pointer to parent cell

unsigned int compartmentCount(InfectionStatus status)

Retrieve number of people with specific InfectionStatus.

Parameters:

status – Compartment to retrieve

Returns:

unsigned int Number of people in the compartment

void personStatusChange(Person *person, InfectionStatus newStatus, unsigned short timestep)

Change a person’s status.

Automatically called during Person::updateStatus by parent Cell::updateStatus. Should not be called manually Part of person update status procedure

Parameters:
  • personPerson to alter

  • newStatusPerson’s new status

  • timestep – Time of status change

class Household

Class representing a household.

Public Functions

Household(size_t mcellPos)

Construct a new Household object.

Parameters:

mcellPos – Index of the household within the host cell

~Household() = default
size_t microcellPos() const

Getter for the household’s index within the host Cell::m_households.

Returns:

size_t Household’s index within Cell::m_households

HouseholdParams &params()

Getter for household’s parameters Used to both access and modify individual household’s parameters.

Returns:

HouseholdParams&

void forEachMember(Cell &cell, Microcell &microcell, std::function<bool(Person*)> callback)

Apply callback to each member of the household.

Callback can return false to terminate loop early

Parameters:
  • cell – Reference to household’s cell

  • microcell – Reference to household’s microcell

  • callback – Callback to apply to each person

bool isMember(size_t person) const

Check if person is a member of the household.

Parameters:

person – Index of person within microcell

Returns:

true

Returns:

false

bool addMember(size_t person)

Add person to the houshold.

Parameters:

person – Index of person within microcell

Returns:

true Successfully added person

Returns:

false Person already in household

std::set<size_t> &members()

Get reference to household’s members set.

Returns:

std::set<size_t>& Set of person indices. Each entry is an index in Microcell’s people vector.

struct HouseholdParams

Structure for household parameters For parameters which are independent to individual households.

Public Members

double susceptibility = 0
double infectiousness = 0
std::pair<double, double> location = {0, 0}
class Place

Class to represent a place.

Public Functions

Place(size_t mPos)

Construct a new Place:: Place object.

Parameters:

mPos – Position of place within population’s places vector.

~Place() = default
size_t populationPos() const

Get index of place within population’s places vector.

Returns:

size_t Index of place within population’s places vector

void forEachMember(Population &population, std::function<bool(Cell*, Person*)> callback)

Loop through all members in the place.

Irrespective of place group Callback can return false to terminate loop early

Parameters:
  • population – Reference to parent population

  • callback – Callback to apply to each member of the place

void forEachMemberInGroup(Population &population, size_t group, std::function<bool(Cell*, Person*)> callback)

Loop through each member in specific place group.

Callback can return false to terminate loop early

Parameters:
  • population – Reference to parent population

  • group – Group number to retrieve members from

  • callback – Callback to apply to each member in place’s group

void forEachMemberGroup(Population &population, std::function<bool(size_t, const std::set<std::pair<size_t, size_t>>&)> callback)

Loop through each member group Callback provides group number and set of people in the group People in group defined by pairs (cell index, person’s index in cell)

Parameters:
  • population – Reference to parent population

  • callback – Callback to apply to member group

bool sampleMembersInGroup(Population &population, size_t group, size_t n, std::function<void(Cell*, Person*)> callback, std::mt19937_64 &rg)

Randomly sample n members in place with specific group number with replacement.

Parameters:
  • population – Reference to parent group

  • groupPlace’s group number to retrieve members from

  • n – Number of members to sample

  • callback – Callback to apply to each sampled member

  • rg – Random number generator to use

Returns:

true Success

Returns:

false Returns false if there are no people in specified place group.

bool isMember(size_t cell, size_t person) const

Check if person is a member of the place.

Parameters:
  • cell – Index of cell within population’s cells vector

  • person – Index of person within cell’s people vector

Returns:

true Person is a member of the place

Returns:

false Person is not a member of the place

bool addMember(size_t cell, size_t person, size_t group = 0)

Add person to a place group.

Parameters:
  • cell – Index of person’s cell within population’s cells vector

  • person – Index of person within cell’s people vector

  • groupPlace group number to add person to

Returns:

true Successfully added person to place group

Returns:

false Person is already a part of that place group

bool removeMemberAllGroups(size_t cell, size_t person)

Remove person from the place.

Irrespective of group number

Parameters:
  • cell – Index of person’s cell within population’s cells vector

  • person – Index of person within parent cell’s people vector

Returns:

true

Returns:

false

bool removeMember(size_t cell, size_t person, size_t group = 0)

Remove person from a specific place group.

Parameters:
  • cell – Index of person’s cell within population’s cells vector

  • person – Index of person within parent cell’s people vector

  • groupPlace group number to remove person from

Returns:

true Successfully removed

Returns:

false Person wasn’t part of the place group

std::map<std::pair<size_t, size_t>, size_t> &members()

Get reference to place’s members.

Map of person (cell index, person index) to number of groups that person is part of.

Returns:

std::map<std::pair<size_t, size_t>, size_t>& Reference to place’s members map

std::set<std::pair<size_t, size_t>> &membersInGroup(size_t group = 0)

Get reference to set of members in a place group.

Parameters:

groupPlace group number

Returns:

std::set<std::pair<size_t, size_t>>& Set of (cell index, person index) members in place group.

std::map<size_t, std::set<std::pair<size_t, size_t>>> &memberGroups()

Get reference to all place groups.

Map of place group number to set of (cell index, person index) members part of that place group

Returns:

std::map<size_t, std::set<std::pair<size_t, size_t>>>&

class Person

Class representing a person.

Public Functions

Person(size_t microcell, size_t cellPos, size_t mcellPos)

Construct a new Person:: Person object.

Parameters:
  • microcell – Index of parent microcell within parent cell’s microcells vector

  • cellPos – Index of person within parent cell’s people vector

  • mcellPos – Index of person within parent microcell’s people vector

~Person()

Destroy the Person:: Person object.

InfectionStatus status() const

Get person’s infection status.

Returns:

InfectionStatus Person’s infection status

PersonParams &params()

Get person’s parameters.

Used to access and modify specific person’s parameters

Returns:

PersonParams& Reference to person’s parameters struct

void setStatus(const InfectionStatus status)

Force set status (For configuring population)

Population has to be re-initialized if this is called

Parameters:

statusPerson’s new infection status

void updateStatus(Cell *cell, const InfectionStatus status, const unsigned short timestep)

Update a person’s infection status.

Use this method to update a person’s infection status

Parameters:
  • cell – Pointer to parent cell

  • statusPerson’s new infection status

  • timestep – Time of status change

size_t cellPos() const

Get position of person within parent Cell’s people vector.

Returns:

size_t Index of person within parent cell’s people vector

size_t microcellPos() const

Get position of person within parent microcell’s people vector.

Returns:

size_t Index of person within parent microcell’s people vector

size_t microcell() const

Get index of person’s microcell within parent cell’s microcells vector.

Returns:

size_t Index of person’s microcell within parent cell’s microcell vector

bool setHousehold(size_t hh)

Set person’s household.

Parameters:

hh – Index of household in person’s microcell

Returns:

true Successfuly added person to household

Returns:

false Failed, person is already part of a household

std::optional<size_t> household()

Retrieve index of person’s houshold.

Returns:

std::optional<size_t> Index of household within person’s microcell

void addPlace(Population &population, Cell *cell, size_t place_index, size_t group)

Add person to place.

Parameters:
  • population – Reference to parent population

  • cell – Pointer to parent cell

  • place_index – Index of place in population

  • groupPlace’s group number

void removePlace(Population &population, Cell *cell, size_t place_index, size_t group = 0)

Remove person from a specific place.

Remove person from a specific place and group number.

Parameters:
  • population – Reference to parent population

  • cell – Pointer to parent cell

  • place_index – Index of place in population

  • groupPlace’s group number

void removePlaceAllGroups(Population &population, Cell *cell, size_t place_index)

Remove person from place type.

Removes person from all places (ignoring place group number)

Parameters:
  • population – Reference to parent population

  • cell – Pointer to parent cell

  • place_index – Index of place in population

std::set<std::pair<size_t, size_t>> &places()

Get reference to person’s places set.

Set of place indices which person is a member of. Each entry is a pair of place’s index within Population::m_places and place’s group number. Groups can be used to represent multiple places of the same type.

Returns:

std::set<std::pair<size_t, size_t>>& Set of places which person is a member of

void forEachPlace(Population &population, std::function<void(Place*, size_t)> callback)

Loop through each place Callback provides the place and group within place that the person is part of.

Parameters:
  • population

  • callback

struct PersonParams

Structure for person parameters For parameters which are independent to individual people.

Public Members

unsigned char age_group = 0
float susceptibility = 0
float infectiousness = 0
unsigned short next_status_time = 0
InfectionStatus next_status = InfectionStatus::Susceptible
float initial_infectiousness = 0
unsigned short infection_start_timestep = 0
enum class epiabm::InfectionStatus

Values:

enumerator Susceptible
enumerator Exposed
enumerator InfectASympt
enumerator InfectMild
enumerator InfectGP
enumerator InfectHosp
enumerator InfectICU
enumerator InfectICURecov
enumerator Recovered
enumerator Dead