Utopia 2
Framework for studying models of complex & adaptive systems.
|
PredatorPrey Model on grid cells. More...
#include <PredatorPrey.hh>
Public Types | |
using | Base = Model< PredatorPrey, ModelTypes > |
The base model. | |
using | DataSet = typename Base::DataSet |
Data type for a dataset. | |
using | CellManager = Utopia::CellManager< CellTraits, PredatorPrey > |
The type of the cell manager. | |
using | Cell = typename CellManager::Cell |
The type of a cell. | |
using | Rule = typename CellManager::RuleFunc |
Type of the update rules. | |
![]() | |
using | Config = typename ModelTypes::Config |
Data type that holds the configuration. | |
using | DataManager = DataIO::Default::DefaultDataManager< PredatorPrey > |
The data manager to use, specialized with the derived model. | |
using | DataGroup = typename ModelTypes::DataGroup |
Data type that is used for storing datasets. | |
using | DataSet = typename ModelTypes::DataSet |
Data type that is used for storing data. | |
using | RNG = typename ModelTypes::RNG |
Data type of the shared RNG. | |
using | Space = typename ModelTypes::Space |
Data type of the space this model resides in. | |
using | Time = typename ModelTypes::Time |
Data type for the model time. | |
using | Monitor = typename ModelTypes::Monitor |
Data type for the monitor. | |
using | MonitorManager = typename ModelTypes::MonitorManager |
Data type for the monitor manager. | |
using | Level = typename ModelTypes::Level |
Data type for the hierarchical level. | |
Public Member Functions | |
template<class ParentModel > | |
PredatorPrey (const std::string &name, ParentModel &parent_model, const DataIO::Config &custom_cfg={}) | |
Construct the PredatorPrey model. | |
void | perform_step () |
Perform an iteration step. | |
void | monitor () |
Monitor model information. | |
void | write_data () |
Write data. | |
![]() | |
Model (const std::string &name, const ParentModel &parent_model, const Config &custom_cfg={}, std::tuple< WriterArgs... > w_args={}, const DataIO::Default::DefaultDecidermap< PredatorPrey > &w_deciders=DataIO::Default::default_deciders< PredatorPrey >, const DataIO::Default::DefaultTriggermap< PredatorPrey > &w_triggers=DataIO::Default::default_triggers< PredatorPrey >) | |
Constructs a Model instance. | |
const std::shared_ptr< Space > & | get_space () const |
Return the space this model resides in. | |
Time | get_time () const |
Return the current time of this model. | |
Time | get_time_max () const |
Return the maximum time possible for this model. | |
Config | get_cfg () const |
Return the config node of this model. | |
std::string | get_name () const |
Return the name of this model instance. | |
std::string | get_full_name () const |
Return the full name of this model within the model hierarchy. | |
std::shared_ptr< DataGroup > | get_hdfgrp () const |
Return a pointer to the HDF group this model stores data in. | |
Time | get_write_start () const |
Return the parameter that controls when write_data is called first. | |
Time | get_write_every () const |
Return the parameter that controls how often write_data is called. | |
DataManager | get_datamanager () const |
return the datamanager | |
hsize_t | get_remaining_num_writes () const |
Return the number of remaining write_data calls this model will make. | |
std::shared_ptr< RNG > | get_rng () const |
Return a pointer to the shared RNG. | |
std::shared_ptr< spdlog::logger > | get_logger () const |
Return a pointer to the logger of this model. | |
Monitor | get_monitor () const |
Return the monitor of this model. | |
std::shared_ptr< MonitorManager > | get_monitor_manager () const |
Get the monitor manager of the root model. | |
Level | get_level () const |
Return the hierarchical level within the model hierarchy. | |
virtual void | prolog () |
A function that is called before starting model iteration. | |
virtual void | epilog () |
A function that is called after the last iteration of a model. | |
void | iterate () |
Iterate one (time) step of this model. | |
void | run () |
Run the model from the current time to the maximum time. | |
std::shared_ptr< DataSet > | create_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. | |
std::shared_ptr< DataSet > | create_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. | |
std::shared_ptr< DataSet > | create_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. | |
std::shared_ptr< DataSet > | create_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. | |
Private Member Functions | |
void | move_predator_to_nb_cell (const std::shared_ptr< Cell > &cell, const std::shared_ptr< Cell > &nb_cell) |
Move a predator to a neighboring cell. | |
void | move_prey_to_nb_cell (const std::shared_ptr< Cell > &cell, const std::shared_ptr< Cell > &nb_cell) |
Move a prey to a neighboring cell. | |
Private Attributes | |
CellManager | _cm |
The cell manager. | |
SpeciesParams | _params |
Predator-specific model parameters. | |
CellContainer< Cell > | _prey_cell |
A container to temporarily accumulate the prey neighbour cells. | |
CellContainer< Cell > | _empty_cell |
A container to temporarily accumulate empty neighbour cells. | |
CellContainer< Cell > | _repro_cell |
A container to temporarily accumulate neighbour cells for reproduction. | |
std::uniform_real_distribution< double > | _prob_distr |
const std::shared_ptr< DataSet > | _dset_prey |
Dataset of Prey locations on the grid. | |
const std::shared_ptr< DataSet > | _dset_predator |
Dataset of Predator locations on the grid. | |
const std::shared_ptr< DataSet > | _dset_resource_prey |
Dataset of Prey resources on the grid. | |
const std::shared_ptr< DataSet > | _dset_resource_predator |
Dataset of Predator resources on the grid. | |
Rule | _cost_of_living |
Cost of Living. | |
Rule | _move_predator |
Define the movement rule of predator. | |
Rule | _flee_prey |
Define the movement rule of prey. | |
Rule | _eat |
Define the eating rule. | |
Rule | _repro |
Define the reproduction rule. | |
Rule | _reset_predator_movement |
Resets the movement flag of predators to "false" for next turn. | |
Additional Inherited Members | |
![]() | |
void | __perform_step () |
Perform the computation of a step. | |
void | __monitor () |
Monitor information in the terminal. | |
void | __write_data () |
Write data; calls the implementation's write_data method. | |
void | __write_initial_state () |
Write the initial state. | |
void | increment_time (const Time dt=1) |
Increment time. | |
void | __prolog () |
The default prolog of a model. | |
void | __epilog () |
The default epilog of a model. | |
PredatorPrey & | impl () |
cast to the derived class | |
const PredatorPrey & | impl () const |
const cast to the derived interface | |
![]() | |
const std::string | _name |
Name of the model instance. | |
const std::string | _full_name |
The full name within the model hierarchy. | |
const Level | _level |
The level within the model hierarchy. | |
const Config | _cfg |
Config node belonging to this model instance. | |
const std::shared_ptr< RNG > | _rng |
The RNG shared between models. | |
const std::shared_ptr< spdlog::logger > | _log |
The (model) logger. | |
std::shared_ptr< Space > | _space |
The space this model resides in. | |
Time | _time |
Model-internal current time stamp. | |
const Time | _time_max |
Model-internal maximum time stamp. | |
const std::shared_ptr< DataGroup > | _hdfgrp |
The HDF group this model instance should write its data to. | |
const Time | _write_start |
First time at which write_data is called. | |
const Time | _write_every |
How often to call write_data from iterate. | |
Monitor | _monitor |
The monitor. | |
DataManager | _datamanager |
Manager object for handling data output; see DataManager. | |
![]() | |
static constexpr WriteMode | _write_mode |
Which data-writing mode the base model should use. | |
PredatorPrey Model on grid cells.
Predators and prey correspond to the Population state of each cell, either empty, prey, predator or both. Cells are updated based on the following interactions: 1) resource levels are reduced by a cost_of_living for both species and individuals are removed if resource <= 0 2) predators move to neighbouring cells if there is a no prey on their own cell. Prey flees with a certain probability, if there is a predator on the same cell 3) predators eat prey if on the same cell, else if there is only a prey it takes up resources 4) both predators and prey reproduce if resources are sufficient and if there is a cell in their neighbourhood not already occupied by the same species
The base model.
The type of a cell.
using Utopia::Models::PredatorPrey::PredatorPrey::CellManager = Utopia::CellManager<CellTraits, PredatorPrey> |
The type of the cell manager.
Data type for a dataset.
Type of the update rules.
|
inline |
Construct the PredatorPrey model.
name | Name of this model instance; is used to extract the configuration from the parent model and set up a HDFGroup for this instance |
parent_model | The parent model this model instance resides in |
custom_cfg | A custom configuration to use instead of the one extracted from the parent model using the instance name |
|
inline |
Monitor model information.
Calculate the densities for both species
|
inlineprivate |
Move a predator to a neighboring cell.
This function resets the states predator state and updates the neighboring predator state.
|
inlineprivate |
Move a prey to a neighboring cell.
This function resets the states prey state and updates the neighboring prey state.
|
inline |
Perform an iteration step.
An iteration step consists of:
|
inline |
Write data.
When invoked, stores cell positions and resources of both prey and predators.
|
private |
The cell manager.
|
private |
Cost of Living.
subtract the cost of living from the resources of an individual and map the values below zero back to zero, then remove all individuals that do not have sufficient resources
Dataset of Predator locations on the grid.
Dataset of Prey locations on the grid.
|
private |
Dataset of Predator resources on the grid.
|
private |
Dataset of Prey resources on the grid.
|
private |
Define the eating rule.
Update procedure is as follows:
|
private |
A container to temporarily accumulate empty neighbour cells.
|
private |
Define the movement rule of prey.
If a prey is on the same cell as a predator, determine whether it may flee and where to.
|
private |
Define the movement rule of predator.
If a predator is on the given cell, it moves random to a neighbour cell with prey on it. If no prey is available on neighbour cells, it moves randomly to an empty cell, if there is on. Otherwise it stays on its current cell.
|
private |
Predator-specific model parameters.
|
private |
A container to temporarily accumulate the prey neighbour cells.
|
private |
|
private |
Define the reproduction rule.
If space is available reproduce with reproduction probabilities of predator and prey respectively.
|
private |
A container to temporarily accumulate neighbour cells for reproduction.
|
private |