Utopia 2
Framework for studying models of complex & adaptive systems.
Loading...
Searching...
No Matches
species.hh
Go to the documentation of this file.
1#ifndef UTOPIA_MODELS_PREDATORPREYPLANT_SPECIES_HH
2#define UTOPIA_MODELS_PREDATORPREYPLANT_SPECIES_HH
3
4#include <utility>
5
7
9
10
14 bool on_cell;
15
17
25 unsigned int regeneration_counter = 0;
26};
27
29enum class GrowthModel {
31 none,
36};
37
42
44 const unsigned int regen_time;
45
47 const double regen_prob;
48
49 // .. Constructors ........................................................
52 :
53 // Set the growth model from the configuration
54 growth_model([&cfg](){
55 auto gm = get_as<std::string>("growth_model", cfg);
56 if (gm == "deterministic") return GrowthModel::deterministic;
57 else if (gm == "stochastic") return GrowthModel::stochastic;
58 else return GrowthModel::none;
59 }()),
60 // Extract regeneration time and probability
61 regen_time([&cfg](){
62 const auto t = get_as<int>("regen_time", cfg);
63 return t;
64 }()),
65 regen_prob(get_as<double>("regen_prob", cfg))
66 {};
67
68 // Do not allow the default constructor
69 PlantParams() = delete;
70};
71
75 unsigned int move_limit;
76
77 // .. Constructors ........................................................
80 :
81 PredatorPrey::SpeciesBaseParams(cfg),
82 move_limit([&cfg](){
83 const auto lim = get_as<int>("move_limit", cfg);
84 return lim;
85 }())
86 {}
87
89};
90
93 // .. Constructors ........................................................
96 :
98 {
99 double repro_cost = get_as<double>("repro_cost", cfg);
100 double repro_resource_requ = get_as<double>("repro_resource_requ", cfg);
102 throw std::invalid_argument("Parameter repro_cost needs to be "
103 "smaller than or equal to the minimal resources required for "
104 "reproduction!");
105 }
106 };
107
109 PredatorParams() = delete;
110};
111
114 // .. Interaction .........................................................
116 double p_flee;
117
118 // .. Constructors ........................................................
121 :
123 p_flee(get_as<double>("p_flee", cfg))
124 {
125 double repro_cost = get_as<double>("repro_cost", cfg);
126 double repro_resource_requ = get_as<double>("repro_resource_requ", cfg);
128 throw std::invalid_argument("Parameter repro_cost needs to be "
129 "smaller than or equal to the minimal resources required for "
130 "reproduction!");
131 }
132 };
133
135 PreyParams() = delete;
136};
137
139
146
149
152
153 // .. Constructors ........................................................
156 :
157 prey(cfg["prey"]),
158 predator(cfg["predator"]),
159 plant(cfg["plant"])
160 {};
161
163 SpeciesParams() = delete;
164};
165
166
167} // namespace Utopia::Models::PredatorPreyPlant
168
169#endif // UTOPIA_MODELS_PREDATORPREYPLANT_SPECIES_HH
YAML::Node Config
Type of a variadic dictionary-like data structure used throughout Utopia.
Definition types.hh:71
ReturnType get_as(const std::string &key, const DataIO::Config &node)
This function is a wrapper around the yaml-cpp YAML::Node::as function.
Definition cfg_utils.hh:158
Container select_entities(const Manager &mngr, const DataIO::Config &sel_cfg)
Select entities according to parameters specified in a configuration.
Definition select.hh:213
Definition PredatorPreyPlant.hh:18
GrowthModel
The growth model to use for plants.
Definition species.hh:29
@ none
Plant level is ignored; prey are always able to eat.
@ stochastic
Once eaten, a plant regrows with probability regen_prob
@ deterministic
Once eaten, a plant requires regen_time time to regenerate.
Struct that holds all species-specific parameters.
Definition species.hh:27
double repro_cost
Cost of reproduction.
Definition species.hh:43
double repro_resource_requ
Minimal reproduction resources requirements.
Definition species.hh:36
The parameters characterizing plants.
Definition species.hh:39
const unsigned int regen_time
The deterministic regeneration time.
Definition species.hh:44
const GrowthModel growth_model
The growth model of the plant.
Definition species.hh:41
PlantParams(const Utopia::DataIO::Config &cfg)
Construct a species from a configuration node.
Definition species.hh:51
const double regen_prob
The regeneration probability, evaluated each time step.
Definition species.hh:47
Struct that holds all plant characterising states.
Definition species.hh:12
unsigned int regeneration_counter
The regeneration time counter.
Definition species.hh:25
bool on_cell
Whether a plant is on the cell.
Definition species.hh:14
Struct that holds all predator-specific parameters.
Definition species.hh:92
PredatorParams(const Utopia::DataIO::Config &cfg)
Construct a predator object from a configuration node.
Definition species.hh:95
PredatorParams()=delete
The default constructor.
Struct that holds all prey-species specific parameters.
Definition species.hh:113
double p_flee
Probability to flee from a predator if on the same cell.
Definition species.hh:116
PreyParams()=delete
The default constructor.
PreyParams(const Utopia::DataIO::Config &cfg)
Construct a prey object from a configuration node.
Definition species.hh:120
Struct that holds all species-specific parameters.
Definition species.hh:73
unsigned int move_limit
Movement limit.
Definition species.hh:75
SpeciesBaseParams(const Utopia::DataIO::Config &cfg)
Construct a species from a configuration node.
Definition species.hh:79
The parameter of all species.
Definition species.hh:143
PreyParams prey
Prey parameters.
Definition species.hh:145
PlantParams plant
Plant parameters.
Definition species.hh:151
SpeciesParams()=delete
Default constructor.
SpeciesParams(const Utopia::DataIO::Config &cfg)
Construct through a configuration file.
Definition species.hh:155
PredatorParams predator
Predator parameters.
Definition species.hh:148