|
Utopia 2
Framework for studying models of complex & adaptive systems.
|
The Environment model provides a non-uniform, dynamic parameter background. More...
#include <Environment.hh>


Classes | |
| struct | DummyCellManager |
| A dummy CellManager type that is used in standalone mode. More... | |
Public Types | |
| using | Self = Environment< EnvParam, EnvCellState, standalone > |
| Type of this class. | |
| using | Base = Model< Self, ModelTypes > |
| The type of the Model base class of this derived class. | |
| using | DataGroup = typename Base::DataGroup |
| Data type of the group to write model data to, holding datasets. | |
| using | DataSet = typename Base::DataSet |
| Data type for a dataset. | |
| using | CellTraits = Utopia::CellTraits< EnvCellState, Update::manual > |
| Cell traits specialization using the state type. | |
| using | CellManager = Utopia::CellManager< CellTraits, Self > |
| The type of the cell manager. | |
| using | EnvCellContainer = CellContainer< typename CellManager::Cell > |
| The type of the EnvCellContainer. | |
| using | Time = typename Base::Time |
| The type of the model time. | |
| using | EnvParamFunc = typename std::function< double()> |
| The type of the environment parameter functions. | |
| using | EnvParamFuncBundle = FuncBundle::ParamFuncBundle< EnvParamFunc, Time > |
| The type wrapping EnvParamFunc with metadata. | |
| using | EnvStateFunc = typename CellManager::RuleFunc |
| The type of the environment state functions; basically a rule function. | |
| using | EnvStateFuncBundle = FuncBundle::RuleFuncBundle< EnvStateFunc, Time, EnvCellContainer > |
| The type wrapping EnvStateFunc with metadata. | |
| using | Config = DataIO::Config |
| Configuration node type alias. | |
Public Types inherited from Utopia::Model< Derived, ModelTypes > | |
| using | Config = typename ModelTypes::Config |
| Data type that holds the configuration. | |
| using | DataManager = DataIO::Default::DefaultDataManager< Derived > |
| The data manager to use, specialized with the derived model. | |
| using | DataGroup = typename ModelTypes::DataGroup |
| Data type that is used for storing datasets. | |
| using | DataSet = typename ModelTypes::DataSet |
| Data type that is used for storing data. | |
| using | RNG = typename ModelTypes::RNG |
| Data type of the shared RNG. | |
| using | Space = typename ModelTypes::Space |
| Data type of the space this model resides in. | |
| using | Time = typename ModelTypes::Time |
| Data type for the model time. | |
| using | Monitor = typename ModelTypes::Monitor |
| Data type for the monitor. | |
| using | MonitorManager = typename ModelTypes::MonitorManager |
| Data type for the monitor manager. | |
| using | Level = typename ModelTypes::Level |
| Data type for the hierarchical level. | |
Public Member Functions | |
| template<class ParentModel , class CellManager > | |
| Environment (const std::string &name, ParentModel &parent_model, CellManager &&associate_cm, const DataIO::Config &custom_cfg={}) | |
| Construct the Environment model associated to a CellManager. | |
| template<typename ParentModel > | |
| Environment (const std::string name, ParentModel &parent) | |
| Construct Environment without associated CellManager. | |
| void | perform_step () |
| Iterate a single step. | |
| void | monitor () |
| Monitor model information. | |
| void | write_data () |
| Write data. | |
| double | get_parameter (const std::string ¶m_name) const |
| Return the current value of the parameter with param_name. | |
| void | set_parameter (const std::string ¶m_name, double value) |
| Change the current value of the parameter with param_name. | |
| const auto & | cm () const |
| Return a const reference to the cell manager. | |
| template<class EPFB > | |
| void | add_env_param_func (EPFB &&epfb) |
| Add a rule function at the end of the sequence of parameter functions. | |
| void | add_env_param_func (const std::string &name, const EnvParamFunc &epf, const std::string ¶m_name, std::tuple< bool, bool, std::set< Time > > times_tuple) |
| Add a param function at the end of the sequence of env functions. | |
| void | add_env_param_func_from_cfg (const std::string &name, const EnvParamFunc &epf, const std::string ¶m_name, const Config &cfg={}) |
| Add a param function at the end of the sequence of env functions. | |
| template<bool add_to_initial = false, class ESFB > | |
| void | add_env_state_func (ESFB &&esfb) |
| Add a rule function at the end of the sequence of state functions. | |
| template<bool add_to_initial = false> | |
| void | add_env_state_func (const std::string &name, const EnvStateFunc &esf, const Update &update=Update::sync, std::pair< bool, std::set< Time > > times_pair={true, {}}, Config select_cfg={}) |
| Add a rule function at the end of the sequence of environment functions. | |
| template<bool add_to_initial = false> | |
| void | add_env_state_func_from_cfg (const std::string &name, const EnvStateFunc &esf, const Update &update=Update::sync, const Config &cfg={}) |
| Add a rule function at the end of the sequence of environment functions. | |
| void | track_parameter (const std::string &key) |
| Mark a parameter as being tracked, i.e. store its data in write_data. | |
| void | track_parameters (const std::vector< std::string > &keys) |
| Track multiple parameters. | |
| void | track_state (const std::string &key) |
| Mark a state as being tracked, i.e. store its data in write_data. | |
| void | track_states (const std::vector< std::string > &keys) |
| Track multiple states. | |
Public Member Functions inherited from Utopia::Model< Derived, ModelTypes > | |
| template<class ParentModel , class... WriterArgs> | |
| Model (const std::string &name, const ParentModel &parent_model, const Config &custom_cfg={}, std::tuple< WriterArgs... > w_args={}, const DataIO::Default::DefaultDecidermap< Derived > &w_deciders=DataIO::Default::default_deciders< Derived >, const DataIO::Default::DefaultTriggermap< Derived > &w_triggers=DataIO::Default::default_triggers< Derived >) | |
| Constructs a Model instance. | |
| const std::shared_ptr< Space > & | get_space () const |
| Return the space this model resides in. | |
| Time | get_time () const |
| Return the current time of this model. | |
| Time | get_time_max () const |
| Return the maximum time possible for this model. | |
| Config | get_cfg () const |
| Return the config node of this model. | |
| std::string | get_name () const |
| Return the name of this model instance. | |
| std::string | get_full_name () const |
| Return the full name of this model within the model hierarchy. | |
| std::shared_ptr< DataGroup > | get_hdfgrp () const |
| Return a pointer to the HDF group this model stores data in. | |
| Time | get_write_start () const |
| Return the parameter that controls when write_data is called first. | |
| Time | get_write_every () const |
| Return the parameter that controls how often write_data is called. | |
| DataManager | get_datamanager () const |
| return the datamanager | |
| hsize_t | get_remaining_num_writes () const |
Return the number of remaining write_data calls this model will make. | |
| std::shared_ptr< RNG > | get_rng () const |
| Return a pointer to the shared RNG. | |
| std::shared_ptr< spdlog::logger > | get_logger () const |
| Return a pointer to the logger of this model. | |
| Monitor | get_monitor () const |
| Return the monitor of this model. | |
| std::shared_ptr< MonitorManager > | get_monitor_manager () const |
| Get the monitor manager of the root model. | |
| Level | get_level () const |
| Return the hierarchical level within the model hierarchy. | |
| virtual void | prolog () |
| A function that is called before starting model iteration. | |
| virtual void | epilog () |
| A function that is called after the last iteration of a model. | |
| void | iterate () |
| Iterate one (time) step of this model. | |
| void | run () |
| Run the model from the current time to the maximum time. | |
| std::shared_ptr< DataSet > | create_dset (const std::string name, const std::shared_ptr< DataGroup > &hdfgrp, std::vector< hsize_t > add_write_shape, const std::size_t compression_level=1, const std::vector< hsize_t > chunksize={}) |
| Create a new dataset within the given group. | |
| std::shared_ptr< DataSet > | create_dset (const std::string name, const std::vector< hsize_t > add_write_shape, const std::size_t compression_level=1, const std::vector< hsize_t > chunksize={}) |
| Create a new dataset within the model's base data group. | |
| template<class CellManager > | |
| std::shared_ptr< DataSet > | create_cm_dset (const std::string name, const CellManager &cm, const std::size_t compression_level=1, const std::vector< hsize_t > chunksize={}) |
| Create a dataset storing data from a CellManager. | |
| template<class AgentManager > | |
| std::shared_ptr< DataSet > | create_am_dset (const std::string name, const AgentManager &am, const std::size_t compression_level=1, const std::vector< hsize_t > chunksize={}) |
| Create a dataset storing data from a AgentManager. | |
Private Member Functions | |
| void | setup_env_param_funcs (const Config &cfg) |
| Construct the rule funcs sequencefor EnvParam from cfg. | |
| template<bool add_to_initial = false> | |
| void | setup_env_state_funcs (const Config &cfg) |
| Construct the rule funcs sequence from cfg. | |
| template<class EPFB > | |
| void | apply_env_param_func (EPFB &&epfb, bool initialization=false) |
| Apply a given environment parameter function. | |
| template<class ESFB > | |
| void | apply_env_state_func (ESFB &&esfb) |
| Apply a given environment state function. | |
Private Attributes | |
| CellManager | _cm |
| The cell manager. | |
| EnvParam | _params |
| The environment parameters. | |
| std::vector< EnvParamFuncBundle > | _env_param_funcs |
| Container of functions that are invoked every time step. | |
| std::vector< EnvStateFuncBundle > | _init_env_state_funcs |
| Container of rule functions that are invoked once at initialisation. | |
| std::vector< EnvStateFuncBundle > | _env_state_funcs |
| Container of rule functions that are invoked every time step. | |
| std::unordered_map< std::string, std::shared_ptr< DataSet > > | _dsets_state |
| Dynamically generated map of datasets of cell states. | |
| std::unordered_map< std::string, std::shared_ptr< DataSet > > | _dsets_param |
| Dynamically generated map of datasets of parameters. | |
Additional Inherited Members | |
Protected Member Functions inherited from Utopia::Model< Derived, ModelTypes > | |
| void | __perform_step () |
| Perform the computation of a step. | |
| void | __monitor () |
| Monitor information in the terminal. | |
| void | __write_data () |
| Write data; calls the implementation's write_data method. | |
| void | __write_initial_state () |
| Write the initial state. | |
| void | increment_time (const Time dt=1) |
| Increment time. | |
| void | __prolog () |
| The default prolog of a model. | |
| void | __epilog () |
| The default epilog of a model. | |
| Derived & | impl () |
| cast to the derived class | |
| const Derived & | impl () const |
| const cast to the derived interface | |
Protected Attributes inherited from Utopia::Model< Derived, ModelTypes > | |
| const std::string | _name |
| Name of the model instance. | |
| const std::string | _full_name |
| The full name within the model hierarchy. | |
| const Level | _level |
| The level within the model hierarchy. | |
| const Config | _cfg |
| Config node belonging to this model instance. | |
| const std::shared_ptr< RNG > | _rng |
| The RNG shared between models. | |
| const std::shared_ptr< spdlog::logger > | _log |
| The (model) logger. | |
| std::shared_ptr< Space > | _space |
| The space this model resides in. | |
| Time | _time |
| Model-internal current time stamp. | |
| const Time | _time_max |
| Model-internal maximum time stamp. | |
| const std::shared_ptr< DataGroup > | _hdfgrp |
| The HDF group this model instance should write its data to. | |
| const Time | _write_start |
| First time at which write_data is called. | |
| const Time | _write_every |
| How often to call write_data from iterate. | |
| Monitor | _monitor |
| The monitor. | |
| DataManager | _datamanager |
| Manager object for handling data output; see DataManager. | |
Static Protected Attributes inherited from Utopia::Model< Derived, ModelTypes > | |
| static constexpr WriteMode | _write_mode = ModelTypes::write_mode |
| Which data-writing mode the base model should use. | |
The Environment model provides a non-uniform, dynamic parameter background.
This happens by coupling to another model's CellManager. Additionally, global parameters can also be changed.
| EnvParam | The parameter type of the environment |
| EnvCellState | The cell state type of the environment cells |
| standalone | Whether to have the model as a standalone model |
| using Utopia::Models::Environment::Environment< EnvParam, EnvCellState, standalone >::Base = Model<Self, ModelTypes> |
The type of the Model base class of this derived class.
| using Utopia::Models::Environment::Environment< EnvParam, EnvCellState, standalone >::CellManager = Utopia::CellManager<CellTraits, Self> |
The type of the cell manager.
| using Utopia::Models::Environment::Environment< EnvParam, EnvCellState, standalone >::CellTraits = Utopia::CellTraits<EnvCellState, Update::manual> |
Cell traits specialization using the state type.
| using Utopia::Models::Environment::Environment< EnvParam, EnvCellState, standalone >::Config = DataIO::Config |
Configuration node type alias.
| using Utopia::Models::Environment::Environment< EnvParam, EnvCellState, standalone >::DataGroup = typename Base::DataGroup |
Data type of the group to write model data to, holding datasets.
| using Utopia::Models::Environment::Environment< EnvParam, EnvCellState, standalone >::DataSet = typename Base::DataSet |
Data type for a dataset.
| using Utopia::Models::Environment::Environment< EnvParam, EnvCellState, standalone >::EnvCellContainer = CellContainer<typename CellManager::Cell> |
The type of the EnvCellContainer.
| using Utopia::Models::Environment::Environment< EnvParam, EnvCellState, standalone >::EnvParamFunc = typename std::function<double()> |
The type of the environment parameter functions.
| using Utopia::Models::Environment::Environment< EnvParam, EnvCellState, standalone >::EnvParamFuncBundle = FuncBundle::ParamFuncBundle<EnvParamFunc, Time> |
The type wrapping EnvParamFunc with metadata.
| using Utopia::Models::Environment::Environment< EnvParam, EnvCellState, standalone >::EnvStateFunc = typename CellManager::RuleFunc |
The type of the environment state functions; basically a rule function.
| using Utopia::Models::Environment::Environment< EnvParam, EnvCellState, standalone >::EnvStateFuncBundle = FuncBundle::RuleFuncBundle<EnvStateFunc, Time, EnvCellContainer> |
The type wrapping EnvStateFunc with metadata.
| using Utopia::Models::Environment::Environment< EnvParam, EnvCellState, standalone >::Self = Environment<EnvParam, EnvCellState, standalone> |
Type of this class.
| using Utopia::Models::Environment::Environment< EnvParam, EnvCellState, standalone >::Time = typename Base::Time |
The type of the model time.
|
inline |
Construct the Environment model associated to a CellManager.
| name | Name of this model instance |
| parent_model | The parent model this model instance resides in |
| associate_cm | The CellManager of the associate (i.e. parent) model. The Environment model's CellManager will use the configuration of that CellManager. |
| custom_cfg | A custom configuration to use instead of the one extracted from the parent model using the instance name |
|
inline |
Construct Environment without associated CellManager.
standalone template parameter needs to be set to true. In the the other case the EnvCellState needs to be the default dummy type DummyEnvCellState and the standalone template parameter needs to be false (default).
|
inline |
Add a param function at the end of the sequence of env functions.
| epf | EnvParamFunc that is applied to all cm.cells() |
| times_tuple | invoke_at_initialization, invoke_always, set of times when to invoke the function |
|
inline |
Add a rule function at the end of the sequence of parameter functions.
| epfb | The EnvParamFuncBundle of environment parameter function that is to be added and its metadata. |
|
inline |
Add a param function at the end of the sequence of env functions.
| epf | EnvParamFunc that is applied to all cm.cells() |
| cfg | From which invoke_at_initialization and times to invoke the function is extracted |
|
inline |
Add a rule function at the end of the sequence of environment functions.
| esf | EnvStateFunc that is applied to all cm.cells() |
| update | The Update mode to use with apply_rule(esf, cm.cells) |
| times_pair | invoke_always, Set of times at which to invoke function. |
| select_cfg | Config passed to _cm.select_cells |
|
inline |
Add a rule function at the end of the sequence of state functions.
| esfb | The EnvStateFuncBundle of environment state function that is to be added and its metadata. |
|
inline |
Add a rule function at the end of the sequence of environment functions.
| esf | EnvStateFunc that is applied to all cm.cells() |
| update | The Update mode to use with apply_rule(esf, cm.cells) |
| cfg | The config of the state_func. Here, times and select are extracted; All other entries ignored. Defaults are invoke always and select all cells. |
|
inlineprivate |
Apply a given environment parameter function.
| esf | EnvParamFunc that is applied |
|
inlineprivate |
Apply a given environment state function.
| esf | EnvStateFunc that is applied to _cm.cells() |
|
inline |
Return a const reference to the cell manager.
|
inline |
Return the current value of the parameter with param_name.
|
inline |
Monitor model information.
|
inline |
Iterate a single step.
|
inline |
|
inlineprivate |
Construct the rule funcs sequencefor EnvParam from cfg.
|
inlineprivate |
Construct the rule funcs sequence from cfg.
|
inline |
Mark a parameter as being tracked, i.e. store its data in write_data.
|
inline |
Track multiple parameters.
Invokes track_state for each entry
|
inline |
Mark a state as being tracked, i.e. store its data in write_data.
|
inline |
Track multiple states.
Invokes track_state for each entry
|
inline |
Write data.
For all parameters and states registered for writing, writes the values to the corresponding dataset.
|
private |
The cell manager.
|
private |
Dynamically generated map of datasets of parameters.
|
private |
Dynamically generated map of datasets of cell states.
|
private |
Container of functions that are invoked every time step.
Functions changing a parameter
|
private |
Container of rule functions that are invoked every time step.
Functions changing a state
|
private |
Container of rule functions that are invoked once at initialisation.
Functions changing a state
|
private |
The environment parameters.