Utopia  2
Framework for studying models of complex & adaptive systems.
Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
Utopia::Models::CopyMeGraph::CopyMeGraph Class Reference

The CopyMeGraph Model; a good start for a graph-based model. More...

#include <CopyMeGraph.hh>

Inheritance diagram for Utopia::Models::CopyMeGraph::CopyMeGraph:
Inheritance graph
[legend]
Collaboration diagram for Utopia::Models::CopyMeGraph::CopyMeGraph:
Collaboration graph
[legend]

Public Types

using Base = Model< CopyMeGraph, ModelTypes >
 The type of the Model base class of this derived class. More...
 
using DataGroup = typename Base::DataGroup
 Data type of the group to write model data to, holding datasets. More...
 
using DataSet = typename Base::DataSet
 Data type for a dataset. More...
 
using VertexDesc = typename boost::graph_traits< GraphType >::vertex_descriptor
 Data type for a vertex descriptor. More...
 
using EdgeDesc = typename boost::graph_traits< GraphType >::edge_descriptor
 Data type for an edge descriptor. More...
 
using VertexVoidRule = typename std::function< void(VertexDesc, GraphType &)>
 Data type for a rule function operating on vertices returning void. More...
 
using VertexStateRule = typename std::function< VertexState(VertexDesc, GraphType &)>
 Data type for a rule function operating on vertices returning a state. More...
 
using EdgeVoidRule = typename std::function< void(EdgeDesc, GraphType &)>
 Data type for a rule function operating on edges returning void. More...
 
using EdgeStateRule = typename std::function< EdgeState(EdgeDesc, GraphType &)>
 Data type for a rule function operating on edges returning a state. More...
 
- Public Types inherited from Utopia::Model< CopyMeGraph, ModelTypes >
using Config = typename ModelTypes::Config
 Data type that holds the configuration. More...
 
using DataManager = DataIO::Default::DefaultDataManager< CopyMeGraph >
 The data manager to use, specialized with the derived model. More...
 
using DataGroup = typename ModelTypes::DataGroup
 Data type that is used for storing datasets. More...
 
using DataSet = typename ModelTypes::DataSet
 Data type that is used for storing data. More...
 
using RNG = typename ModelTypes::RNG
 Data type of the shared RNG. More...
 
using Space = typename ModelTypes::Space
 Data type of the space this model resides in. More...
 
using Time = typename ModelTypes::Time
 Data type for the model time. More...
 
using Monitor = typename ModelTypes::Monitor
 Data type for the monitor. More...
 
using MonitorManager = typename ModelTypes::MonitorManager
 Data type for the monitor manager. More...
 
using Level = typename ModelTypes::Level
 Data type for the hierarchical level. More...
 

Public Member Functions

template<class ParentModel >
 CopyMeGraph (const std::string &name, ParentModel &parent_model, const DataIO::Config &custom_cfg={})
 Construct the CopyMeGraph model. More...
 
void perform_step ()
 Iterate a single step. More...
 
void monitor ()
 Monitor model information. More...
 
void write_data ()
 Write data. More...
 
- Public Member Functions inherited from Utopia::Model< CopyMeGraph, ModelTypes >
 Model (const std::string &name, const ParentModel &parent_model, const Config &custom_cfg={}, std::tuple< WriterArgs... > w_args={}, const DataIO::Default::DefaultDecidermap< CopyMeGraph > &w_deciders=DataIO::Default::default_deciders< CopyMeGraph >, const DataIO::Default::DefaultTriggermap< CopyMeGraph > &w_triggers=DataIO::Default::default_triggers< CopyMeGraph >)
 Constructs a Model instance. More...
 
const std::shared_ptr< Space > & get_space () const
 Return the space this model resides in. More...
 
Time get_time () const
 Return the current time of this model. More...
 
Time get_time_max () const
 Return the maximum time possible for this model. More...
 
Config get_cfg () const
 Return the config node of this model. More...
 
std::string get_name () const
 Return the name of this model instance. More...
 
std::string get_full_name () const
 Return the full name of this model within the model hierarchy. More...
 
std::shared_ptr< DataGroupget_hdfgrp () const
 Return a pointer to the HDF group this model stores data in. More...
 
Time get_write_start () const
 Return the parameter that controls when write_data is called first. More...
 
Time get_write_every () const
 Return the parameter that controls how often write_data is called. More...
 
DataManager get_datamanager () const
 return the datamanager More...
 
hsize_t get_remaining_num_writes () const
 Return the number of remaining write_data calls this model will make. More...
 
std::shared_ptr< RNGget_rng () const
 Return a pointer to the shared RNG. More...
 
std::shared_ptr< spdlog::logger > get_logger () const
 Return a pointer to the logger of this model. More...
 
Monitor get_monitor () const
 Return the monitor of this model. More...
 
std::shared_ptr< MonitorManagerget_monitor_manager () const
 Get the monitor manager of the root model. More...
 
Level get_level () const
 Return the hierarchical level within the model hierarchy. More...
 
virtual void prolog ()
 A function that is called before starting model iteration. More...
 
virtual void epilog ()
 A function that is called after the last iteration of a model. More...
 
void iterate ()
 Iterate one (time) step of this model. More...
 
void run ()
 Run the model from the current time to the maximum time. More...
 
std::shared_ptr< DataSetcreate_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. More...
 
std::shared_ptr< DataSetcreate_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. More...
 
std::shared_ptr< DataSetcreate_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. More...
 
std::shared_ptr< DataSetcreate_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. More...
 

Private Member Functions

GraphType initialize_graph ()
 Initialize the graph. More...
 
void initialize_vertices (GraphType &g)
 
void initialize_edges (GraphType &g)
 
double calc_some_state_mean () const
 Calculate the mean of all vertices' some_state. More...
 

Private Attributes

std::uniform_real_distribution< double > _prob_distr
 A re-usable uniform real distribution to evaluate probabilities. More...
 
GraphType _g
 The graph. More...
 
double _some_parameter
 Some parameter. More...
 
std::shared_ptr< DataGroup_dgrp_g_static
 A datagroup for a static graph. More...
 
std::shared_ptr< DataGroup_dgrp_g_dynamic
 A datagroup for a dynamic graph. More...
 
std::shared_ptr< DataSet_dset_some_state
 A dataset for storing all vertices' some_state. More...
 
std::shared_ptr< DataSet_dset_some_trait
 A dataset for storing all vertices' some_trait. More...
 
VertexVoidRule some_interaction
 An interaction function of a single vertex with its neighbors. More...
 
VertexStateRule some_other_rule
 Some other rule function. More...
 

Additional Inherited Members

- Protected Member Functions inherited from Utopia::Model< CopyMeGraph, ModelTypes >
void __perform_step ()
 Perform the computation of a step. More...
 
void __monitor ()
 Monitor information in the terminal. More...
 
void __write_data ()
 Write data; calls the implementation's write_data method. More...
 
void __write_initial_state ()
 Write the initial state. More...
 
void increment_time (const Time dt=1)
 Increment time. More...
 
void __prolog ()
 The default prolog of a model. More...
 
void __epilog ()
 The default epilog of a model. More...
 
CopyMeGraph & impl ()
 cast to the derived class More...
 
const CopyMeGraph & impl () const
 const cast to the derived interface More...
 
- Protected Attributes inherited from Utopia::Model< CopyMeGraph, ModelTypes >
const std::string _name
 Name of the model instance. More...
 
const std::string _full_name
 The full name within the model hierarchy. More...
 
const Level _level
 The level within the model hierarchy. More...
 
const Config _cfg
 Config node belonging to this model instance. More...
 
const std::shared_ptr< RNG_rng
 The RNG shared between models. More...
 
const std::shared_ptr< spdlog::logger > _log
 The (model) logger. More...
 
std::shared_ptr< Space_space
 The space this model resides in. More...
 
Time _time
 Model-internal current time stamp. More...
 
const Time _time_max
 Model-internal maximum time stamp. More...
 
const std::shared_ptr< DataGroup_hdfgrp
 The HDF group this model instance should write its data to. More...
 
const Time _write_start
 First time at which write_data is called. More...
 
const Time _write_every
 How often to call write_data from iterate. More...
 
Monitor _monitor
 The monitor. More...
 
DataManager _datamanager
 Manager object for handling data output; see DataManager. More...
 
- Static Protected Attributes inherited from Utopia::Model< CopyMeGraph, ModelTypes >
static constexpr WriteMode _write_mode
 Which data-writing mode the base model should use. More...
 

Detailed Description

The CopyMeGraph Model; a good start for a graph-based model.

TODO Add your model description here. This model's sole purpose of existing is to be a template for new models. That means its functionality is only meant to show how actually useful functionality could be implemented.

Member Typedef Documentation

◆ Base

The type of the Model base class of this derived class.

◆ DataGroup

Data type of the group to write model data to, holding datasets.

◆ DataSet

Data type for a dataset.

◆ EdgeDesc

using Utopia::Models::CopyMeGraph::CopyMeGraph::EdgeDesc = typename boost::graph_traits<GraphType>::edge_descriptor

Data type for an edge descriptor.

◆ EdgeStateRule

Data type for a rule function operating on edges returning a state.

◆ EdgeVoidRule

Data type for a rule function operating on edges returning void.

◆ VertexDesc

using Utopia::Models::CopyMeGraph::CopyMeGraph::VertexDesc = typename boost::graph_traits<GraphType>::vertex_descriptor

Data type for a vertex descriptor.

◆ VertexStateRule

Data type for a rule function operating on vertices returning a state.

◆ VertexVoidRule

Data type for a rule function operating on vertices returning void.

Constructor & Destructor Documentation

◆ CopyMeGraph()

template<class ParentModel >
Utopia::Models::CopyMeGraph::CopyMeGraph::CopyMeGraph ( const std::string &  name,
ParentModel &  parent_model,
const DataIO::Config custom_cfg = {} 
)
inline

Construct the CopyMeGraph model.

Parameters
nameName of this model instance; is used to extract the configuration from the parent model and set up a HDFGroup for this instance
parent_modelThe parent model this model instance resides in
custom_cfgA custom configuration to use instead of the one extracted from the parent model using the instance name

Member Function Documentation

◆ calc_some_state_mean()

double Utopia::Models::CopyMeGraph::CopyMeGraph::calc_some_state_mean ( ) const
inlineprivate

Calculate the mean of all vertices' some_state.

◆ initialize_edges()

void Utopia::Models::CopyMeGraph::CopyMeGraph::initialize_edges ( GraphType g)
inlineprivate

◆ initialize_graph()

GraphType Utopia::Models::CopyMeGraph::CopyMeGraph::initialize_graph ( )
inlineprivate

Initialize the graph.

◆ initialize_vertices()

void Utopia::Models::CopyMeGraph::CopyMeGraph::initialize_vertices ( GraphType g)
inlineprivate

◆ monitor()

void Utopia::Models::CopyMeGraph::CopyMeGraph::monitor ( )
inline

Monitor model information.

Here, functions and values can be supplied to the monitor that are then available to the frontend. The monitor() function is only called if a certain emit interval has passed; thus, the performance hit is small. With this information, you can then define stop conditions on frontend side, that can stop a simulation once a certain set of conditions is fulfilled.

◆ perform_step()

void Utopia::Models::CopyMeGraph::CopyMeGraph::perform_step ( )
inline

Iterate a single step.

Here you can add a detailed description what exactly happens in a single iteration step

◆ write_data()

void Utopia::Models::CopyMeGraph::CopyMeGraph::write_data ( )
inline

Write data.

This function is called to write out data. The model configuration determines at which times data is written. See Utopia::DataIO::Dataset::write

Member Data Documentation

◆ _dgrp_g_dynamic

std::shared_ptr<DataGroup> Utopia::Models::CopyMeGraph::CopyMeGraph::_dgrp_g_dynamic
private

A datagroup for a dynamic graph.

◆ _dgrp_g_static

std::shared_ptr<DataGroup> Utopia::Models::CopyMeGraph::CopyMeGraph::_dgrp_g_static
private

A datagroup for a static graph.

◆ _dset_some_state

std::shared_ptr<DataSet> Utopia::Models::CopyMeGraph::CopyMeGraph::_dset_some_state
private

A dataset for storing all vertices' some_state.

◆ _dset_some_trait

std::shared_ptr<DataSet> Utopia::Models::CopyMeGraph::CopyMeGraph::_dset_some_trait
private

A dataset for storing all vertices' some_trait.

◆ _g

GraphType Utopia::Models::CopyMeGraph::CopyMeGraph::_g
private

The graph.

◆ _prob_distr

std::uniform_real_distribution<double> Utopia::Models::CopyMeGraph::CopyMeGraph::_prob_distr
private

A re-usable uniform real distribution to evaluate probabilities.

◆ _some_parameter

double Utopia::Models::CopyMeGraph::CopyMeGraph::_some_parameter
private

Some parameter.

◆ some_interaction

VertexVoidRule Utopia::Models::CopyMeGraph::CopyMeGraph::some_interaction
private
Initial value:
= [this](const VertexDesc v, GraphType& g) {
g[v].state.some_state += 1;
for (const auto nb : range<IterateOver::neighbors>(v, g)) {
g[v].state.some_trait += g[nb].state.some_trait;
g[v].state.some_trait += (this->_prob_distr(*this->_rng) * 2. - 1.);
}
g[v].state.some_trait /= this->_some_parameter;
}
const std::shared_ptr< RNG > _rng
The RNG shared between models.
Definition: model.hh:161
double _some_parameter
Some parameter.
Definition: CopyMeGraph.hh:205
typename boost::graph_traits< GraphType >::vertex_descriptor VertexDesc
Data type for a vertex descriptor.
Definition: CopyMeGraph.hh:174
std::uniform_real_distribution< double > _prob_distr
A re-usable uniform real distribution to evaluate probabilities.
Definition: CopyMeGraph.hh:199
boost::adjacency_list< EdgeContainer, VertexContainer, boost::bidirectionalS, Vertex, Edge > GraphType
The type of the graph.
Definition: CopyMeGraph.hh:146

An interaction function of a single vertex with its neighbors.

◆ some_other_rule

VertexStateRule Utopia::Models::CopyMeGraph::CopyMeGraph::some_other_rule
private
Initial value:
= [this](const VertexDesc v, GraphType& g) {
auto state = g[v].state;
if (this->_prob_distr(*this->_rng) < 0.3) {
state.some_state = 0;
}
return state;
}

Some other rule function.

Warning
This rule should be applied synchronously, so the vertex state may NOT be changed directly. Instead, the state needs to be copied and changes should be done to the copied state only.

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