Utopia 2
Framework for studying models of complex & adaptive systems.
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | List of all members
Utopia::Models::ForestFire::State Struct Reference

The full cell struct for the ForestFire model. More...

#include <ForestFire.hh>

Collaboration diagram for Utopia::Models::ForestFire::State:
Collaboration graph
[legend]

Public Member Functions

 State ()=delete
 Remove default constructor, for safety.
 
template<class RNG >
 State (const DataIO::Config &cfg, const std::shared_ptr< RNG > &rng)
 Construct a cell from a configuration node and an RNG.
 

Public Attributes

Kind kind
 The kind of object that populates this cell, e.g. a tree.
 
unsigned short age
 The age of the tree on this cell.
 
unsigned int cluster_id
 An ID denoting to which cluster this cell belongs (if it is a tree)
 

Detailed Description

The full cell struct for the ForestFire model.

Constructor & Destructor Documentation

◆ State() [1/2]

Utopia::Models::ForestFire::State::State ( )
delete

Remove default constructor, for safety.

◆ State() [2/2]

template<class RNG >
Utopia::Models::ForestFire::State::State ( const DataIO::Config cfg,
const std::shared_ptr< RNG > &  rng 
)
inline

Construct a cell from a configuration node and an RNG.

44 :
45 kind(Kind::empty),
46 age(0),
47 cluster_id(0)
48 {
49 // Get the desired probability to be a tree
50 const auto p_tree = get_as<double>("p_tree", cfg);
51
52 // Check obvious cases (no need to draw a random number)
54 throw std::invalid_argument("p_tree needs to be in interval "
55 "[0., 1.], but was not!");
56 }
57 else if (p_tree == 0.) {
58 return;
59 }
60 else if (p_tree == 1.) {
61 kind = Kind::tree;
62 return;
63 }
64
65 // With this probability, the cell state is a tree
66 if (std::uniform_real_distribution<double>(0., 1.)(*rng) < p_tree) {
67 kind = Kind::tree;
68 }
69 // NOTE Although the distribution object is created each time, this
70 // is not a significant slow-down compared to re-using an
71 // existing distribution object (<4%). When compiled with
72 // optimization flags, that slowdown is even smaller...
73 }
Container select_entities(const Manager &mngr, const DataIO::Config &sel_cfg)
Select entities according to parameters specified in a configuration.
Definition select.hh:213
unsigned int cluster_id
An ID denoting to which cluster this cell belongs (if it is a tree)
Definition ForestFire.hh:36
unsigned short age
The age of the tree on this cell.
Definition ForestFire.hh:33
Kind kind
The kind of object that populates this cell, e.g. a tree.
Definition ForestFire.hh:30

Member Data Documentation

◆ age

unsigned short Utopia::Models::ForestFire::State::age

The age of the tree on this cell.

◆ cluster_id

unsigned int Utopia::Models::ForestFire::State::cluster_id

An ID denoting to which cluster this cell belongs (if it is a tree)

◆ kind

Kind Utopia::Models::ForestFire::State::kind

The kind of object that populates this cell, e.g. a tree.


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