QuadWell< InfectionState > Class Template Reference

CPP API: QuadWell< InfectionState > Class Template Reference

Implementation of diffusive ABM, see dabm::Model. More...

#include <quad_well.h>

Classes

struct  Agent
 Struct defining an agent for the diffusive ABM. More...
 

Public Types

using Status = InfectionState
 

Public Member Functions

ScalarType adoption_rate (const Agent &agent, const Status &new_status) const
 Calculate adoption rate for an Agent. More...
 
std::map< std::tuple< mio::regions::Region, Status, Status >, mio::AdoptionRate< ScalarType, Status > > & get_adoption_rates ()
 Get AdoptionRate mapping. More...
 
mio::RandomNumberGenerator & get_rng ()
 Get the RandomNumberGenerator used by this Model for random events. More...
 
void move (const ScalarType, const ScalarType dt, Agent &agent)
 Perform one integration step of the diffusion process for a given Agent using the Euler-Maruyama method. More...
 
std::vector< Eigen::MatrixX< ScalarType > > & number_transitions ()
 
const std::vector< Eigen::MatrixX< ScalarType > > & number_transitions () const
 Get the number of spatial transitions that happened until the current system state. More...
 
 QuadWell (const std::vector< Agent > &agents, const std::vector< mio::AdoptionRate< ScalarType, Status >> &rates, ScalarType contact_radius=0.4, ScalarType sigma=0.4, std::vector< Status > non_moving_states={})
 Set up a diffusive ABM using the quadwell potential F(x,y) = (x^2 -1)^2+(y^2-1)^2. More...
 
void set_non_moving_regions (std::vector< size_t > non_moving_regions)
 Set regions where no movement happens. More...
 
Eigen::VectorX< ScalarTypetime_point () const
 Calculate the current system state i.e. More...
 

Static Public Member Functions

static constexpr void adopt (Agent &agent, const Status &new_status)
 Perform infection state adoption for an Agent. More...
 

Public Attributes

std::vector< Agentpopulations
 Vector containing all Agents in the model. More...
 

Private Member Functions

bool is_contact (const Agent &agent, const Agent &contact) const
 Evaluate whether two agents are within their contact radius. More...
 
bool is_in_domain (const Position &p) const
 Restrict domain to [-2, 2]^2 where "escaping" is impossible. More...
 

Static Private Member Functions

static Position grad_U (const Position x)
 Claculate the gradient of the potential at a given position. More...
 

Private Attributes

std::map< std::tuple< mio::regions::Region, Status, Status >, mio::AdoptionRate< ScalarType, Status > > m_adoption_rates
 Map of AdoptionRates according to their region index and their from -> to infection states. More...
 
ScalarType m_contact_radius
 Agents' interaction radius. Within this radius agents are considered as contacts. More...
 
std::vector< size_t > m_non_moving_regions {}
 Regions without movement. More...
 
std::vector< Statusm_non_moving_states
 Infection states within which agents do not change their location. More...
 
std::vector< Eigen::MatrixX< ScalarType > > m_number_transitions
 Vector that contains for every infection state a matrix with entry (k,l) the number of spatial transitions from Region k to Regionl. More...
 
mio::RandomNumberGenerator m_rng
 Model's random number generator. More...
 
ScalarType m_sigma
 Noise term of the diffusion process. More...
 

Detailed Description

template<class InfectionState>
class QuadWell< InfectionState >

Implementation of diffusive ABM, see dabm::Model.

This implementation defines a diffusion process for the potential F(x,y) = (x^2 -1)^2+(y^2-1)^2.

Template Parameters
InfectionStateAn infection state enum.

Member Typedef Documentation

◆ Status

template<class InfectionState >
using QuadWell< InfectionState >::Status = InfectionState

Constructor & Destructor Documentation

◆ QuadWell()

template<class InfectionState >
QuadWell< InfectionState >::QuadWell ( const std::vector< Agent > &  agents,
const std::vector< mio::AdoptionRate< ScalarType, Status >> &  rates,
ScalarType  contact_radius = 0.4,
ScalarType  sigma = 0.4,
std::vector< Status non_moving_states = {} 
)
inline

Set up a diffusive ABM using the quadwell potential F(x,y) = (x^2 -1)^2+(y^2-1)^2.

Parameters
[in]agentsA vector of Agents representing the population.
[in]ratesAdoptionRates defining InfectionState adoptions, see mio::AdoptionRate.
[in]contact_radiusContact radius for second-order adoptions.
[in]sigmaNoise term for the diffusion process.
[in]non_moving_stateInfectionStates that are excluded from movement e.g. Dead.

Member Function Documentation

◆ adopt()

template<class InfectionState >
static constexpr void QuadWell< InfectionState >::adopt ( Agent agent,
const Status new_status 
)
inlinestaticconstexpr

Perform infection state adoption for an Agent.

Parameters
[in,out]agentAgent whose infection state is changed.
[in]new_statusAgent's new infection state.

◆ adoption_rate()

template<class InfectionState >
ScalarType QuadWell< InfectionState >::adoption_rate ( const Agent agent,
const Status new_status 
) const
inline

Calculate adoption rate for an Agent.

Parameters
[in]agentAgent for whom the adoption rate is calculated.
[in]new_statusTarget infection state of the adoption rate, see mio::AdoptionRate.to.
Returns
Value of agent-dependent AdoptionRate.

◆ get_adoption_rates()

template<class InfectionState >
std::map<std::tuple<mio::regions::Region, Status, Status>, mio::AdoptionRate<ScalarType, Status> >& QuadWell< InfectionState >::get_adoption_rates ( )
inline

Get AdoptionRate mapping.

Returns
Map of AdoptionRates based on their region index and source and target infection state.

◆ get_rng()

template<class InfectionState >
mio::RandomNumberGenerator& QuadWell< InfectionState >::get_rng ( )
inline

Get the RandomNumberGenerator used by this Model for random events.

Returns
The random number generator.

◆ grad_U()

template<class InfectionState >
static Position QuadWell< InfectionState >::grad_U ( const Position  x)
inlinestaticprivate

Claculate the gradient of the potential at a given position.

Parameters
[in]xPosition at which the gradient is evaluated.
Returns
Value of potential gradient.

◆ is_contact()

template<class InfectionState >
bool QuadWell< InfectionState >::is_contact ( const Agent agent,
const Agent contact 
) const
inlineprivate

Evaluate whether two agents are within their contact radius.

Parameters
[in]agentAgent whose position specifies the contact area.
[in]contactPotential contact of agent.
Returns
Boolean specifying whether are within each others contact radius.

◆ is_in_domain()

template<class InfectionState >
bool QuadWell< InfectionState >::is_in_domain ( const Position p) const
inlineprivate

Restrict domain to [-2, 2]^2 where "escaping" is impossible.

Parameters
[in]pPosition to check.
Returns
Boolean specifying whether p is in [-2, 2]^2.

◆ move()

template<class InfectionState >
void QuadWell< InfectionState >::move ( const  ScalarType,
const ScalarType  dt,
Agent agent 
)
inline

Perform one integration step of the diffusion process for a given Agent using the Euler-Maruyama method.

Parameters
[in]dtStep size.
[in]agentAgent to be moved.

◆ number_transitions() [1/2]

template<class InfectionState >
std::vector<Eigen::MatrixX<ScalarType> >& QuadWell< InfectionState >::number_transitions ( )
inline

◆ number_transitions() [2/2]

template<class InfectionState >
const std::vector<Eigen::MatrixX<ScalarType> >& QuadWell< InfectionState >::number_transitions ( ) const
inline

Get the number of spatial transitions that happened until the current system state.

Returns
Matrix with entries (from_well, to_well) for every infection state.

◆ set_non_moving_regions()

template<class InfectionState >
void QuadWell< InfectionState >::set_non_moving_regions ( std::vector< size_t >  non_moving_regions)
inline

Set regions where no movement happens.

◆ time_point()

template<class InfectionState >
Eigen::VectorX<ScalarType> QuadWell< InfectionState >::time_point ( ) const
inline

Calculate the current system state i.e.

the populations for each region and infection state.

Returns
Vector containing the number of agents per infection state for each region.

Member Data Documentation

◆ m_adoption_rates

template<class InfectionState >
std::map<std::tuple<mio::regions::Region, Status, Status>, mio::AdoptionRate<ScalarType, Status> > QuadWell< InfectionState >::m_adoption_rates
private

Map of AdoptionRates according to their region index and their from -> to infection states.

◆ m_contact_radius

template<class InfectionState >
ScalarType QuadWell< InfectionState >::m_contact_radius
private

Agents' interaction radius. Within this radius agents are considered as contacts.

◆ m_non_moving_regions

template<class InfectionState >
std::vector<size_t> QuadWell< InfectionState >::m_non_moving_regions {}
private

Regions without movement.

◆ m_non_moving_states

template<class InfectionState >
std::vector<Status> QuadWell< InfectionState >::m_non_moving_states
private

Infection states within which agents do not change their location.

◆ m_number_transitions

template<class InfectionState >
std::vector<Eigen::MatrixX<ScalarType> > QuadWell< InfectionState >::m_number_transitions
private

Vector that contains for every infection state a matrix with entry (k,l) the number of spatial transitions from Region k to Regionl.

◆ m_rng

template<class InfectionState >
mio::RandomNumberGenerator QuadWell< InfectionState >::m_rng
private

Model's random number generator.

◆ m_sigma

template<class InfectionState >
ScalarType QuadWell< InfectionState >::m_sigma
private

Noise term of the diffusion process.

◆ populations

template<class InfectionState >
std::vector<Agent> QuadWell< InfectionState >::populations

Vector containing all Agents in the model.