Utopia 2
Framework for studying models of complex & adaptive systems.
Loading...
Searching...
No Matches
Typedefs | Functions
Utopia::Models::Environment::StateFunctionCollection Namespace Reference

Typedefs

using Config = DataIO::Config
 Configuration node type alias.
 

Functions

template<typename EnvModel , class DistType , class EnvStateFunc = typename EnvModel::EnvStateFunc>
EnvStateFunc build_rng_env_state_func (EnvModel &model, DistType &&dist, const std::string &param_name, const ValMode &mode)
 Create a rule function that uses a random number distribution.
 
template<typename EnvModel , class EnvStateFunc = typename EnvModel::EnvStateFunc>
std::pair< EnvStateFunc, Updateesf_noise (const EnvModel &model, const std::string &param_name, const Config &cfg)
 Creates a rule function for noisy parameter values.
 
template<typename EnvModel , typename Extent , class EnvStateFunc = typename EnvModel::EnvStateFunc>
std::pair< EnvStateFunc, Updateesf_slope (const EnvModel &, const std::string &param_name, const Config &cfg, const Extent &extent)
 Creates a rule function for spatially linearly parameter values.
 
template<typename EnvModel , class EnvStateFunc = typename EnvModel::EnvStateFunc>
std::pair< EnvStateFunc, Updateesf_steps (const EnvModel &, const std::string &param_name, const Config &cfg)
 Creates a rule function for spatial steps in the parameter values.
 
template<typename EnvModel , class EnvStateFunc = typename EnvModel::EnvStateFunc>
std::pair< EnvStateFunc, Updateesf_uniform (const EnvModel &, const std::string &param_name, const Config &cfg)
 Creates a rule function for spatially uniform parameter values.
 

Typedef Documentation

◆ Config

Configuration node type alias.

Function Documentation

◆ build_rng_env_state_func()

template<typename EnvModel , class DistType , class EnvStateFunc = typename EnvModel::EnvStateFunc>
EnvStateFunc Utopia::Models::Environment::StateFunctionCollection::build_rng_env_state_func ( EnvModel model,
DistType &&  dist,
const std::string &  param_name,
const ValMode mode 
)

Create a rule function that uses a random number distribution.

This constructs a mutable EnvStateFunc lambda, moving the dist into the capture.

25{
26 // NOTE It is VITAL to move-construct the perfectly-forwarded dist into
27 // the lambda; otherwise it has to be stored outside, which is a
28 // real pita. Also, the lambda has to be declared mutable such
29 // that the captured object are allowed to be changed; again, this
30 // is only relevant for the distribution's internal state ...
31 return
32 [&model, param_name, mode, dist{std::move(dist)}]
33 (const auto& env_cell) mutable {
34 auto& env_state = env_cell->state;
35
36 double current_value = 0.;
37 if (mode == ValMode::Add) {
38 current_value = env_state.get_env(param_name);
39 }
40 const double rn = dist(*model.get_rng());
41
42 env_state.set_env(param_name, current_value + rn);
43 return env_state;
44 };
45}