Utopia  2
Framework for studying models of complex & adaptive systems.
Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
Utopia::Models::SimpleEG::SimpleEG Class Reference

Simple model of evolutionary games on grids. More...

#include <SimpleEG.hh>

Inheritance diagram for Utopia::Models::SimpleEG::SimpleEG:
Inheritance graph
[legend]
Collaboration diagram for Utopia::Models::SimpleEG::SimpleEG:
Collaboration graph
[legend]

Public Types

using Base = Model< SimpleEG, ModelTypes >
 The base model. More...
 
using Config = typename Base::Config
 Data type that holds the configuration. More...
 
using DataSet = typename Base::DataSet
 Data type for a dataset. More...
 
using CellManager = Utopia::CellManager< CellTraits, SimpleEG >
 Type of the CellManager to use. More...
 
using RuleFunc = typename CellManager::RuleFunc
 Extract the type of the rule function from the CellManager. More...
 
using RNG = typename Base::RNG
 Data type of the shared RNG. More...
 
using IAMatrixType = typename std::array< std::array< double, 2 >, 2 >
 Type of the interaction matrix. More...
 
- Public Types inherited from Utopia::Model< SimpleEG, ModelTypes >
using Config = typename ModelTypes::Config
 Data type that holds the configuration. More...
 
using DataManager = DataIO::Default::DefaultDataManager< SimpleEG >
 The data manager to use, specialized with the derived model. More...
 
using DataGroup = typename ModelTypes::DataGroup
 Data type that is used for storing datasets. More...
 
using DataSet = typename ModelTypes::DataSet
 Data type that is used for storing data. More...
 
using RNG = typename ModelTypes::RNG
 Data type of the shared RNG. More...
 
using Space = typename ModelTypes::Space
 Data type of the space this model resides in. More...
 
using Time = typename ModelTypes::Time
 Data type for the model time. More...
 
using Monitor = typename ModelTypes::Monitor
 Data type for the monitor. More...
 
using MonitorManager = typename ModelTypes::MonitorManager
 Data type for the monitor manager. More...
 
using Level = typename ModelTypes::Level
 Data type for the hierarchical level. More...
 

Public Member Functions

template<class ParentModel >
 SimpleEG (const std::string &name, ParentModel &parent_model, const DataIO::Config &custom_cfg={})
 Construct the SimpleEG model. More...
 
void perform_step ()
 Iterate a single step. More...
 
void monitor ()
 Monitor model information. More...
 
void write_data ()
 Write data: the strategy and payoff of each cell. More...
 
- Public Member Functions inherited from Utopia::Model< SimpleEG, ModelTypes >
 Model (const std::string &name, const ParentModel &parent_model, const Config &custom_cfg={}, std::tuple< WriterArgs... > w_args={}, const DataIO::Default::DefaultDecidermap< SimpleEG > &w_deciders=DataIO::Default::default_deciders< SimpleEG >, const DataIO::Default::DefaultTriggermap< SimpleEG > &w_triggers=DataIO::Default::default_triggers< SimpleEG >)
 Constructs a Model instance. More...
 
const std::shared_ptr< Space > & get_space () const
 Return the space this model resides in. More...
 
Time get_time () const
 Return the current time of this model. More...
 
Time get_time_max () const
 Return the maximum time possible for this model. More...
 
Config get_cfg () const
 Return the config node of this model. More...
 
std::string get_name () const
 Return the name of this model instance. More...
 
std::string get_full_name () const
 Return the full name of this model within the model hierarchy. More...
 
std::shared_ptr< DataGroupget_hdfgrp () const
 Return a pointer to the HDF group this model stores data in. More...
 
Time get_write_start () const
 Return the parameter that controls when write_data is called first. More...
 
Time get_write_every () const
 Return the parameter that controls how often write_data is called. More...
 
DataManager get_datamanager () const
 return the datamanager More...
 
hsize_t get_remaining_num_writes () const
 Return the number of remaining write_data calls this model will make. More...
 
std::shared_ptr< RNGget_rng () const
 Return a pointer to the shared RNG. More...
 
std::shared_ptr< spdlog::logger > get_logger () const
 Return a pointer to the logger of this model. More...
 
Monitor get_monitor () const
 Return the monitor of this model. More...
 
std::shared_ptr< MonitorManagerget_monitor_manager () const
 Get the monitor manager of the root model. More...
 
Level get_level () const
 Return the hierarchical level within the model hierarchy. More...
 
virtual void prolog ()
 A function that is called before starting model iteration. More...
 
virtual void epilog ()
 A function that is called after the last iteration of a model. More...
 
void iterate ()
 Iterate one (time) step of this model. More...
 
void run ()
 Run the model from the current time to the maximum time. More...
 
std::shared_ptr< DataSetcreate_dset (const std::string name, const std::shared_ptr< DataGroup > &hdfgrp, std::vector< hsize_t > add_write_shape, const std::size_t compression_level=1, const std::vector< hsize_t > chunksize={})
 Create a new dataset within the given group. More...
 
std::shared_ptr< DataSetcreate_dset (const std::string name, const std::vector< hsize_t > add_write_shape, const std::size_t compression_level=1, const std::vector< hsize_t > chunksize={})
 Create a new dataset within the model's base data group. More...
 
std::shared_ptr< DataSetcreate_cm_dset (const std::string name, const CellManager &cm, const std::size_t compression_level=1, const std::vector< hsize_t > chunksize={})
 Create a dataset storing data from a CellManager. More...
 
std::shared_ptr< DataSetcreate_am_dset (const std::string name, const AgentManager &am, const std::size_t compression_level=1, const std::vector< hsize_t > chunksize={})
 Create a dataset storing data from a AgentManager. More...
 

Private Member Functions

void initialize_cells ()
 Initialize the cells according to initial_state config parameter. More...
 
IAMatrixType extract_ia_matrix () const
 Extract the interaction matrix from the config file. More...
 

Private Attributes

CellManager _cm
 The cell manager. More...
 
const IAMatrixType _ia_matrix
 The interaction matrix (extracted during initialization) More...
 
CellContainer< typename CellManager::Cell_fittest_cells_in_nbhood
 A container to temporarily accumulate the fittest neighbor cells in. More...
 
std::uniform_real_distribution< double > _prob_distr
 Uniform real distribution in [0., 1.) used for evaluating probabilities. More...
 
std::shared_ptr< DataSet_dset_strategy
 Stores cell strategies over time. More...
 
std::shared_ptr< DataSet_dset_payoff
 Stores cell payoffs over time. More...
 
RuleFunc _interaction
 The interaction between players. More...
 
RuleFunc _update
 The update rule. More...
 

Additional Inherited Members

- Protected Member Functions inherited from Utopia::Model< SimpleEG, ModelTypes >
void __perform_step ()
 Perform the computation of a step. More...
 
void __monitor ()
 Monitor information in the terminal. More...
 
void __write_data ()
 Write data; calls the implementation's write_data method. More...
 
void __write_initial_state ()
 Write the initial state. More...
 
void increment_time (const Time dt=1)
 Increment time. More...
 
void __prolog ()
 The default prolog of a model. More...
 
void __epilog ()
 The default epilog of a model. More...
 
SimpleEG & impl ()
 cast to the derived class More...
 
const SimpleEG & impl () const
 const cast to the derived interface More...
 
- Protected Attributes inherited from Utopia::Model< SimpleEG, ModelTypes >
const std::string _name
 Name of the model instance. More...
 
const std::string _full_name
 The full name within the model hierarchy. More...
 
const Level _level
 The level within the model hierarchy. More...
 
const Config _cfg
 Config node belonging to this model instance. More...
 
const std::shared_ptr< RNG_rng
 The RNG shared between models. More...
 
const std::shared_ptr< spdlog::logger > _log
 The (model) logger. More...
 
std::shared_ptr< Space_space
 The space this model resides in. More...
 
Time _time
 Model-internal current time stamp. More...
 
const Time _time_max
 Model-internal maximum time stamp. More...
 
const std::shared_ptr< DataGroup_hdfgrp
 The HDF group this model instance should write its data to. More...
 
const Time _write_start
 First time at which write_data is called. More...
 
const Time _write_every
 How often to call write_data from iterate. More...
 
Monitor _monitor
 The monitor. More...
 
DataManager _datamanager
 Manager object for handling data output; see DataManager. More...
 
- Static Protected Attributes inherited from Utopia::Model< SimpleEG, ModelTypes >
static constexpr WriteMode _write_mode
 Which data-writing mode the base model should use. More...
 

Detailed Description

Simple model of evolutionary games on grids.

In this model, cells have an internal strategy, which determines their success in the interactions with their neighboring cells. The success is given by an interaction matrix. In one interaction step, every cell interacts with all its neighboring cells (interaction lambda function). Afterwards, all cells are updated synchronously (update lambda function). From a cells perspective, the mechanism is as follows: Look around in you neighborhood for the cell, which had the highest payoff from the interactions. Change your state to this fittest neighboring cell's state. If multiple cells within a neighborhood have the same payoff choose randomly between their strategies.

Member Typedef Documentation

◆ Base

The base model.

◆ CellManager

Type of the CellManager to use.

◆ Config

Data type that holds the configuration.

◆ DataSet

Data type for a dataset.

◆ IAMatrixType

using Utopia::Models::SimpleEG::SimpleEG::IAMatrixType = typename std::array<std::array<double, 2>, 2>

Type of the interaction matrix.

◆ RNG

Data type of the shared RNG.

◆ RuleFunc

Extract the type of the rule function from the CellManager.

This is a function that receives a reference to a cell and returns the new cell state. For more details, check out Utopia::CellManager

Note
Whether the cell state gets applied directly or requires a synchronous update depends on the update mode specified in the cell traits.

Constructor & Destructor Documentation

◆ SimpleEG()

template<class ParentModel >
Utopia::Models::SimpleEG::SimpleEG::SimpleEG ( const std::string &  name,
ParentModel &  parent_model,
const DataIO::Config custom_cfg = {} 
)
inline

Construct the SimpleEG model.

Parameters
nameName of this model instance; is used to extract the configuration from the parent model and set up a HDFGroup for this instance
parent_modelThe parent model this model instance resides in
custom_cfgA custom configuration to use instead of the one extracted from the parent model using the instance name

Member Function Documentation

◆ extract_ia_matrix()

IAMatrixType Utopia::Models::SimpleEG::SimpleEG::extract_ia_matrix ( ) const
inlineprivate

Extract the interaction matrix from the config file.

In the model config file there are three different ways to specify the interaction: 1) Explicitly setting the interaction matrix ia_matrix S0 S1 S0 [ia_00 ia_01] S1 [ia_10 ia_11]

2) Setting a benefit and cost pair bc_pair S0 S1 S0 [b-c -c] S1 [b 0]

3) Setting the benefit parameter b following the paper of Nowak&May1992 S0 S1 S0 [1 0] S1 [b(>1) 0]

If 1) is set, 2) and 3) will be ignored. The function returns the explicitly given ia_matrix. If 1) is not set, then the interaction matrix of 2) will be returned. If 1) and 2) are not set, the interaction matrix of 3) will be returned.

Returns
IAMatrixType The interaction matrix

◆ initialize_cells()

void Utopia::Models::SimpleEG::SimpleEG::initialize_cells ( )
inlineprivate

Initialize the cells according to initial_state config parameter.

The cell initialization for most cases is done directly at cell construction. However, some initialization options depend on the position of the cell on the grid. Only these cases are dealt with in this initialization function.

◆ monitor()

void Utopia::Models::SimpleEG::SimpleEG::monitor ( )
inline

Monitor model information.

◆ perform_step()

void Utopia::Models::SimpleEG::SimpleEG::perform_step ( )
inline

Iterate a single step.

In the config, the following interaction matrix is stored: S0 S1 S0 ( _ia_matrix[0][0] _ia_matrix[0][1] ) S1 ( _ia_matrix[1][0] _ia_matrix[1][1] )

The interaction payoff is given from the perspective of the left-column- strategy. E.g. if S0 interacts with S1, S0 receives the payoff given by _ia_matrix[0][1] whereas S1 receives the payoff given by _ia_matrix[1][0].

◆ write_data()

void Utopia::Models::SimpleEG::SimpleEG::write_data ( )
inline

Write data: the strategy and payoff of each cell.

Member Data Documentation

◆ _cm

CellManager Utopia::Models::SimpleEG::SimpleEG::_cm
private

The cell manager.

◆ _dset_payoff

std::shared_ptr<DataSet> Utopia::Models::SimpleEG::SimpleEG::_dset_payoff
private

Stores cell payoffs over time.

◆ _dset_strategy

std::shared_ptr<DataSet> Utopia::Models::SimpleEG::SimpleEG::_dset_strategy
private

Stores cell strategies over time.

◆ _fittest_cells_in_nbhood

CellContainer<typename CellManager::Cell> Utopia::Models::SimpleEG::SimpleEG::_fittest_cells_in_nbhood
private

A container to temporarily accumulate the fittest neighbor cells in.

◆ _ia_matrix

const IAMatrixType Utopia::Models::SimpleEG::SimpleEG::_ia_matrix
private

The interaction matrix (extracted during initialization)

◆ _interaction

RuleFunc Utopia::Models::SimpleEG::SimpleEG::_interaction
private

The interaction between players.

This rule calculates the payoff for a given cell, depending on the interaction matrix and the payoffs of the neighbors.

◆ _prob_distr

std::uniform_real_distribution<double> Utopia::Models::SimpleEG::SimpleEG::_prob_distr
private

Uniform real distribution in [0., 1.) used for evaluating probabilities.

◆ _update

RuleFunc Utopia::Models::SimpleEG::SimpleEG::_update
private

The update rule.

Update procedure is as follows:

  • Loop through the neighbors and store all neighbors with the highest payoff.
  • Use the member _fittest_cells_in_nbhood for this, such that the vector does not need to be recreated for each cell.
Note
In most cases the vector will contain only one cell. However, there are parameter regimes where multiple cells can have the same payoff; this approach copes with spatial artifacts regardless of the parameter regime.

The documentation for this class was generated from the following file: