Utopia  2
Framework for studying models of complex & adaptive systems.
species.hh
Go to the documentation of this file.
1 #ifndef UTOPIA_MODELS_PREDATORPREY_SPECIES_HH
2 #define UTOPIA_MODELS_PREDATORPREY_SPECIES_HH
3 
4 #include <utility>
5 
6 #include "utopia/core/types.hh"
7 
9 
11 struct SpeciesState {
13  bool on_cell;
14 
16  double resources;
17 
18  // .. Constructors ........................................................
21  on_cell{false},
22  resources{0.}
23  {}
24 };
25 
28  // .. Living ..............................................................
31 
34 
37 
39  double resource_max;
40 
41  // .. Reproduction ........................................................
43  double repro_cost;
44 
46  double repro_prob;
47 
48  // .. Constructors ........................................................
51  :
52  cost_of_living(get_as<double>("cost_of_living", cfg)),
53  resource_intake(get_as<double>("resource_intake", cfg)),
54  repro_resource_requ(get_as<double>("repro_resource_requ", cfg)),
55  resource_max(get_as<double>("resource_max", cfg)),
56  repro_cost(get_as<double>("repro_cost", cfg)),
57  repro_prob(get_as<double>("repro_prob", cfg))
58  {
59  // Perform some checks
61  throw std::invalid_argument("Parameter repro_cost needs to be "
62  "smaller than or equal to the minimal resources required for "
63  "reproduction!");
64  }
65  }
66 
67  SpeciesBaseParams() = delete;
68 };
69 
72  // .. Constructors ........................................................
75  :
77  {};
78 
80  PredatorParams() = delete;
81 };
82 
84 struct PreyParams : public SpeciesBaseParams {
85  // .. Interaction .........................................................
87  double p_flee;
88 
89  // .. Constructors ........................................................
92  :
93  SpeciesBaseParams(cfg),
94  p_flee(get_as<double>("p_flee", cfg))
95  {};
96 
98  PreyParams() = delete;
99 };
100 
102 
109 
112 
113  // .. Constructors ........................................................
116  :
117  prey(cfg["prey"]),
118  predator(cfg["predator"])
119  {};
120 
122  SpeciesParams() = delete;
123 };
124 
125 
126 } // Utopia::Models::PredatorPrey
127 
128 #endif // UTOPIA_MODELS_PREDATORPREY_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
Definition: PredatorPrey.hh:17
Struct that holds all predator-specific parameters.
Definition: species.hh:71
PredatorParams()=delete
The default constructor.
PredatorParams(const Utopia::DataIO::Config &cfg)
Construct a predator object from a configuration node.
Definition: species.hh:74
Struct that holds all prey-species specific parameters.
Definition: species.hh:84
PreyParams(const Utopia::DataIO::Config &cfg)
Construct a prey object from a configuration node.
Definition: species.hh:91
double p_flee
Probability to flee from a predator if on the same cell.
Definition: species.hh:87
PreyParams()=delete
The default constructor.
Struct that holds all species-specific parameters.
Definition: species.hh:27
double resource_intake
Resource intake from eating.
Definition: species.hh:33
double repro_cost
Cost of reproduction.
Definition: species.hh:43
double resource_max
Maximal resource level.
Definition: species.hh:39
double cost_of_living
Cost of living that is taken each time step.
Definition: species.hh:30
double repro_resource_requ
Minimal reproduction resources requirements.
Definition: species.hh:36
SpeciesBaseParams(const Utopia::DataIO::Config &cfg)
Load species parameters from a configuration node.
Definition: species.hh:50
double repro_prob
Reproduction probability.
Definition: species.hh:46
The parameter of all species.
Definition: species.hh:106
SpeciesParams()=delete
Default constructor.
PredatorParams predator
Predator parameters.
Definition: species.hh:111
PreyParams prey
Prey parameters.
Definition: species.hh:108
SpeciesParams(const Utopia::DataIO::Config &cfg)
Construct through a configuration file.
Definition: species.hh:115
Struct that holds all species states.
Definition: species.hh:11
double resources
The internal resources reservoir.
Definition: species.hh:16
SpeciesState()
The default constructor.
Definition: species.hh:20
bool on_cell
Whether the species is on the cell.
Definition: species.hh:13