Modular Megafauna Model 1.1.5
A physiological, dynamic herbivore simulator in C++.
Loading...
Searching...
No Matches
world.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2020 W. Traylor <wolfgang.traylor@senckenberg.de>
2//
3// SPDX-License-Identifier: LGPL-3.0-or-later
4
11#ifndef FAUNA_WORLD_H
12#define FAUNA_WORLD_H
13
14#include <list>
15#include <memory>
16#include <vector>
17
18namespace Fauna {
19// Forward declarations
20class Date;
21class Habitat;
22class Hft;
23struct Parameters;
24class SimulationUnit;
25class WorldConstructor;
26
27// Repeat typedef from hft.h
28typedef std::vector<std::shared_ptr<const Hft> > HftList;
29
30namespace Output {
31class Aggregator;
32class WriterInterface;
33} // namespace Output
34
36enum class SimMode {
38
39 Lint,
42};
43
45class World {
46 public:
48
57 World(const std::string instruction_filename,
59
61
70 World(const std::shared_ptr<const Parameters> params,
71 const std::shared_ptr<const HftList> hftlist);
72
74
82 World();
83
86
88
102 void create_simulation_unit(std::shared_ptr<Habitat> habitat);
103
105
112 const Parameters& get_params() const;
113
115
119 const std::list<SimulationUnit>& get_sim_units() const { return sim_units; }
120
122 const bool is_activated() const { return mode == SimMode::Simulate; }
123
128
130
131 bool do_herbivores = true;
132
134
145 bool reset_date = false;
146 };
147
149
177 void simulate_day(const Date& date,
178 const SimDayOptions& opts = SimDayOptions());
179
181
186 void simulate_day(const Date& date, const bool do_herbivores) {
187 SimDayOptions opts;
188 opts.do_herbivores = do_herbivores;
189 simulate_day(date, opts);
190 }
191
192 private:
194
200
202 const HftList& get_hfts() const;
203
205
211
214
216
224
226
236 const std::shared_ptr<const HftList> hftlist;
238 const std::shared_ptr<const Parameters> params;
240
243
245
249 std::unique_ptr<Fauna::Date> last_date;
250
252 const std::unique_ptr<Output::Aggregator> output_aggregator;
253
255 std::unique_ptr<Output::WriterInterface> output_writer;
256
258 static InsfileContent read_instruction_file(const std::string& filename);
259
261
264 std::list<SimulationUnit> sim_units;
265
267 const std::unique_ptr<WorldConstructor> world_constructor;
268};
269} // namespace Fauna
270#endif // FAUNA_WORLD_H
Helper class to hold an absolute simulation day.
Definition: date.h:19
Central class to construct and own megafauna habitats and populations.
Definition: world.h:45
void simulate_day(const Date &date, const bool do_herbivores)
Iterate through all simulation units and perform simulation for this day.
Definition: world.h:186
bool simulation_units_checked
Whether the habitat counts per aggregation unit have been checked.
Definition: world.h:223
void simulate_day(const Date &date, const SimDayOptions &opts=SimDayOptions())
Iterate through all simulation units and perform simulation for this day.
Definition: world.cpp:169
void create_simulation_unit(std::shared_ptr< Habitat > habitat)
Compose a new simulation from an external habitat and new populations.
Definition: world.cpp:76
static InsfileContent read_instruction_file(const std::string &filename)
Helper function to initialize World::InsfileContent object.
Definition: world.cpp:156
int days_since_last_establishment
Number of days since extinct populations were re-established.
Definition: world.h:242
std::list< SimulationUnit > sim_units
List of all the simulation units in the world.
Definition: world.h:264
const bool is_activated() const
Whether this World object is in SimMode::Simulate mode.
Definition: world.h:122
struct Fauna::World::InsfileContent insfile
~World()
Default destructor.
const std::unique_ptr< Output::Aggregator > output_aggregator
Collects output data per time interval and aggregation unit.
Definition: world.h:252
const std::unique_ptr< WorldConstructor > world_constructor
Helper class to construct various elements of the megafauna world.
Definition: world.h:267
std::unique_ptr< Output::WriterInterface > output_writer
Output writer as selected by Parameters::output_format.
Definition: world.h:255
const Parameters & get_params() const
Get global simulation parameters.
Definition: world.cpp:110
const std::list< SimulationUnit > & get_sim_units() const
List of all the simulation units in the world.
Definition: world.h:119
std::unique_ptr< Fauna::Date > last_date
The date from the last call to simulate_day()
Definition: world.h:249
const HftList & get_hfts() const
Get the immutable list of herbivore functional types.
Definition: world.cpp:101
Output::WriterInterface * construct_output_writer() const
Create Output::WriterInterface implementation according to params.
Definition: world.cpp:30
const SimMode mode
Whether this object is going to simulate or just lint an instruction file.
Definition: world.h:213
int get_habitat_count_per_agg_unit() const
Get the number of habitats per aggregation unit.
Definition: world.cpp:119
World()
Constructor: Create deactivated World object.
Definition: world.cpp:70
Definition: average.h:16
SimMode
Mode of the whole simulation program: What is it started for?
Definition: world.h:36
@ Simulate
Default mode: We want to simulate herbivores.
@ Lint
Only check (“lint”) the instruction file, don’t perform simulations.
std::vector< std::shared_ptr< const Hft > > HftList
List of pointers to Hft objects.
Definition: world.h:28
Interface class for all classes that implement writing output.
Definition: writer_interface.h:20
Parameters for the herbivory module.
Definition: parameters.h:65
All simulation instructions from the TOML instruction file.
Definition: world.h:234
const std::shared_ptr< const Parameters > params
Global, immutable set of simulation parameters.
Definition: world.h:238
const std::shared_ptr< const HftList > hftlist
Global, immutable list of herbivore functional types.
Definition: world.h:236
Options passed to simulate_day()
Definition: world.h:125
bool do_herbivores
Whether to perform herbivore simulations.
Definition: world.h:131
bool reset_date
Whether to reset the simulation so we start from the beginning.
Definition: world.h:145
SimDayOptions()
Constructor.
Definition: world.h:127