Utopia  2
Framework for studying models of complex & adaptive systems.
func_bundle.hh
Go to the documentation of this file.
1 #ifndef UTOPIA_MODELS_ENVIRONMENT_FUNCBUNDLE_HH
2 #define UTOPIA_MODELS_ENVIRONMENT_FUNCBUNDLE_HH
3 
5 namespace FuncBundle {
6 
12 
16 template<typename Func, typename Time>
17 struct FuncBundle {
18  std::string name;
19  Func func;
22  std::set<Time> times;
23 
24  FuncBundle(std::string name, Func func,
25  bool invoke_at_initialization = true, bool invoke_always = true,
26  std::set<Time> times = {})
27  :
28  name(name),
29  func(func),
32  times(times)
33  {}
34 };
35 
37 
41 template<typename Func, typename Time>
42 struct ParamFuncBundle : FuncBundle<Func, Time> {
44  std::string param_name;
45 
46  ParamFuncBundle(std::string name, Func func, std::string param_name,
47  bool invoke_at_initialization = true, bool invoke_always = true,
48  std::set<Time> times = {})
49  :
53  {}
54 
55  ParamFuncBundle(std::string name, Func func, std::string param_name,
56  std::tuple<bool, bool, std::set<Time>> invoke_times_tuple)
57  :
58  ParamFuncBundle<Func, Time>(name, func, param_name,
59  std::get<0>(invoke_times_tuple),
60  std::get<1>(invoke_times_tuple),
61  std::get<2>(invoke_times_tuple))
62  {}
63 };
64 
66 
70 template<typename RuleFunc, typename Time, typename CellContainer>
71 struct RuleFuncBundle : FuncBundle<RuleFunc, Time> {
74 
75  // Select a subset of cells
82 
83  RuleFuncBundle(std::string name, RuleFunc func,
85  bool invoke_always = true, std::set<Time> times = {},
86  bool fix_selection = false,
87  const CellContainer& cell_selection = {},
88  const DataIO::Config& select_cfg = {})
89  :
90  FuncBundle<RuleFunc, Time>(name, func, invoke_at_initialization,
92  update(update),
96  { }
97 
98  RuleFuncBundle(std::string name, RuleFunc func, Update update,
100  std::pair<bool, std::set<Time>> times_pair,
101  std::tuple<bool, CellContainer, DataIO::Config> select_tuple)
102  :
103  RuleFuncBundle<RuleFunc, Time, CellContainer>(name, func, update,
104  invoke_at_initialization, times_pair.first, times_pair.second,
105  std::get<bool>(select_tuple),
106  std::get<CellContainer>(select_tuple),
107  std::get<DataIO::Config>(select_tuple))
108  {}
109 };
110 
111 // End group Environment
116 } // namespace FuncBundle
117 } // namespace Utopia::Models::Environment
118 
119 #endif
YAML::Node Config
Type of a variadic dictionary-like data structure used throughout Utopia.
Definition: types.hh:71
Update
Update modes when applying rules.
Definition: state.hh:20
@ sync
Synchronous update.
DataIO::Config Config
Configuration node type alias.
Definition: env_param_func_collection.hh:13
Definition: env_param_func_collection.hh:8
EntityContainer< CellType > CellContainer
Type of the variably sized container for cells.
Definition: types.hh:26
Definition: parallel.hh:235
A bundle wrapping a (iterative) function with metadata.
Definition: func_bundle.hh:17
std::set< Time > times
Whether to invoke in every timestep.
Definition: func_bundle.hh:22
bool invoke_always
Whether to invoke at initialization.
Definition: func_bundle.hh:21
FuncBundle(std::string name, Func func, bool invoke_at_initialization=true, bool invoke_always=true, std::set< Time > times={})
When to invoke.
Definition: func_bundle.hh:24
Func func
The name of the function.
Definition: func_bundle.hh:19
std::string name
Definition: func_bundle.hh:18
bool invoke_at_initialization
The function.
Definition: func_bundle.hh:20
A bundle wrapping a (iterative) function with metadata.
Definition: func_bundle.hh:42
std::string param_name
The name of the parameter to which to apply the function.
Definition: func_bundle.hh:44
ParamFuncBundle(std::string name, Func func, std::string param_name, std::tuple< bool, bool, std::set< Time >> invoke_times_tuple)
Definition: func_bundle.hh:55
ParamFuncBundle(std::string name, Func func, std::string param_name, bool invoke_at_initialization=true, bool invoke_always=true, std::set< Time > times={})
Definition: func_bundle.hh:46
A bundle wrapping a (rule-)function with metadata.
Definition: func_bundle.hh:71
Update update
The update mode of the RuleFunc.
Definition: func_bundle.hh:73
RuleFuncBundle(std::string name, RuleFunc func, Update update, bool invoke_at_initialization, std::pair< bool, std::set< Time >> times_pair, std::tuple< bool, CellContainer, DataIO::Config > select_tuple)
Definition: func_bundle.hh:98
DataIO::Config select_cfg
Config node that is passed to the select_cells of the cell manager.
Definition: func_bundle.hh:81
bool fix_selection
Whether the selection of cells is fixed.
Definition: func_bundle.hh:77
RuleFuncBundle(std::string name, RuleFunc func, Update update=Update::sync, bool invoke_at_initialization=true, bool invoke_always=true, std::set< Time > times={}, bool fix_selection=false, const CellContainer &cell_selection={}, const DataIO::Config &select_cfg={})
Definition: func_bundle.hh:83
CellContainer cell_selection
Cell container over which to apply the func, optional.
Definition: func_bundle.hh:79