1#ifndef UTOPIA_MODELS_COPYMEGRAPH_HH
2#define UTOPIA_MODELS_COPYMEGRAPH_HH
10#include <boost/graph/adjacency_list.hpp>
11#include <boost/range.hpp>
144 boost::bidirectionalS,
174 typename boost::graph_traits<GraphType>::vertex_descriptor;
177 using EdgeDesc =
typename boost::graph_traits<GraphType>::edge_descriptor;
246 template<
class ParentModel>
248 const std::string& name,
289 {boost::num_vertices(
_g)})),
292 {boost::num_vertices(
_g)}))
321 this->
_log->debug(
"{} model fully set up.", this->
_name);
330 this->
_log->debug(
"Create and initialize the graph ...");
332 auto g = Graph::create_graph<GraphType>(this->
_cfg[
"create_graph"],
345 g[
v].state.some_state =
351 g[
v].state.is_a_vip_vertex =
true;
354 g[
v].state.is_a_vip_vertex =
false;
399 sum +=
_g[
v].state.some_state;
401 return sum / boost::num_vertices(
_g);
413 g[
v].state.some_state += 1;
419 g[
v].state.some_trait +=
g[
nb].state.some_trait;
438 auto state =
g[
v].state;
442 state.some_state = 0;
479 this->
_monitor.set_entry(
"some_value", 42);
496 auto [
v,
v_end] = boost::vertices(
_g);
500 return this->
_g[
v].state.some_state;
505 return this->
_g[
v].state.some_trait;
523 [](
auto vd,
auto&
g) {
524 return boost::get(boost::vertex_index_t(),
g,
vd);
526 std::make_tuple(
"some_state",
527 [](
auto vd,
auto&
g) {
528 return g[
vd].state.some_state;
530 std::make_tuple(
"some_trait", [](
auto vd,
auto&
g) {
531 return g[
vd].state.some_trait;
542 std::make_tuple(
"source",
543 [](
auto ed,
auto&
g) {
544 return boost::get(boost::vertex_index_t(),
546 boost::source(
ed,
g));
548 std::make_tuple(
"target",
549 [](
auto ed,
auto&
g) {
550 return boost::get(boost::vertex_index_t(),
552 boost::target(
ed,
g));
554 std::make_tuple(
"weights", [](
auto ed,
auto&
g) {
555 return g[
ed].state.weight;
565 save_vertex_properties(
_g,
569 save_edge_properties(
_g,
A graph entity is a slightly specialized state container.
Definition entity.hh:42
Base class interface for Models using the CRT Pattern.
Definition model.hh:112
const std::shared_ptr< DataGroup > _hdfgrp
The HDF group this model instance should write its data to.
Definition model.hh:176
Monitor _monitor
The monitor.
Definition model.hh:188
typename ModelTypes::DataSet DataSet
Data type that is used for storing data.
Definition model.hh:125
const Config _cfg
Config node belonging to this model instance.
Definition model.hh:158
const std::string _name
Name of the model instance.
Definition model.hh:149
Time get_time() const
Return the current time of this model.
Definition model.hh:393
typename ModelTypes::DataGroup DataGroup
Data type that is used for storing datasets.
Definition model.hh:122
const std::shared_ptr< spdlog::logger > _log
The (model) logger.
Definition model.hh:164
const std::shared_ptr< RNG > _rng
The RNG shared between models.
Definition model.hh:161
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.
Definition model.hh:752
The CopyMeGraph Model; a good start for a graph-based model.
Definition CopyMeGraph.hh:160
void monitor()
Monitor model information.
Definition CopyMeGraph.hh:477
double calc_some_state_mean() const
Calculate the mean of all vertices' some_state.
Definition CopyMeGraph.hh:395
typename Base::DataSet DataSet
Data type for a dataset.
Definition CopyMeGraph.hh:169
double _some_parameter
Some parameter.
Definition CopyMeGraph.hh:205
CopyMeGraph(const std::string &name, ParentModel &parent_model, const DataIO::Config &custom_cfg={})
Construct the CopyMeGraph model.
Definition CopyMeGraph.hh:247
typename std::function< EdgeState(EdgeDesc, GraphType &)> EdgeStateRule
Data type for a rule function operating on edges returning a state.
Definition CopyMeGraph.hh:191
std::shared_ptr< DataGroup > _dgrp_g_dynamic
A datagroup for a dynamic graph.
Definition CopyMeGraph.hh:223
void perform_step()
Iterate a single step.
Definition CopyMeGraph.hh:456
void initialize_vertices(GraphType &g)
Definition CopyMeGraph.hh:341
std::shared_ptr< DataSet > _dset_some_trait
A dataset for storing all vertices' some_trait.
Definition CopyMeGraph.hh:232
GraphType initialize_graph()
Initialize the graph.
Definition CopyMeGraph.hh:328
typename boost::graph_traits< GraphType >::vertex_descriptor VertexDesc
Data type for a vertex descriptor.
Definition CopyMeGraph.hh:174
void initialize_edges(GraphType &g)
Definition CopyMeGraph.hh:364
std::shared_ptr< DataGroup > _dgrp_g_static
A datagroup for a static graph.
Definition CopyMeGraph.hh:220
typename std::function< void(EdgeDesc, GraphType &)> EdgeVoidRule
Data type for a rule function operating on edges returning void.
Definition CopyMeGraph.hh:187
void write_data()
Write data.
Definition CopyMeGraph.hh:488
GraphType _g
The graph.
Definition CopyMeGraph.hh:202
Model< CopyMeGraph, ModelTypes > Base
The type of the Model base class of this derived class.
Definition CopyMeGraph.hh:163
typename std::function< VertexState(VertexDesc, GraphType &)> VertexStateRule
Data type for a rule function operating on vertices returning a state.
Definition CopyMeGraph.hh:184
typename std::function< void(VertexDesc, GraphType &)> VertexVoidRule
Data type for a rule function operating on vertices returning void.
Definition CopyMeGraph.hh:180
std::shared_ptr< DataSet > _dset_some_state
A dataset for storing all vertices' some_state.
Definition CopyMeGraph.hh:229
typename boost::graph_traits< GraphType >::edge_descriptor EdgeDesc
Data type for an edge descriptor.
Definition CopyMeGraph.hh:177
VertexVoidRule some_interaction
An interaction function of a single vertex with its neighbors.
Definition CopyMeGraph.hh:411
std::uniform_real_distribution< double > _prob_distr
A re-usable uniform real distribution to evaluate probabilities.
Definition CopyMeGraph.hh:199
typename Base::DataGroup DataGroup
Data type of the group to write model data to, holding datasets.
Definition CopyMeGraph.hh:166
VertexStateRule some_other_rule
Some other rule function.
Definition CopyMeGraph.hh:436
YAML::Node Config
Type of a variadic dictionary-like data structure used throughout Utopia.
Definition types.hh:71
ReturnType get_as(const std::string &key, const DataIO::Config &node)
This function is a wrapper around the yaml-cpp YAML::Node::as function.
Definition cfg_utils.hh:158
Container select_entities(const Manager &mngr, const DataIO::Config &sel_cfg)
Select entities according to parameters specified in a configuration.
Definition select.hh:213
Definition CopyMeGraph.hh:19
boost::vecS VertexContainer
The vertex container type.
Definition CopyMeGraph.hh:97
boost::listS EdgeContainer
The edge container type.
Definition CopyMeGraph.hh:124
GraphEntity< VertexTraits > Vertex
A vertex is a graph entity with vertex traits.
Definition CopyMeGraph.hh:91
boost::adjacency_list< EdgeContainer, VertexContainer, boost::bidirectionalS, Vertex, Edge > GraphType
The type of the graph.
Definition CopyMeGraph.hh:146
The entity traits struct gathers types to be used for specializing an entity.
Definition entity.hh:49
Wrapper struct for defining model class data types.
Definition model.hh:92
The edge state.
Definition CopyMeGraph.hh:106
double weight
Every parameter should be usefully documented :)
Definition CopyMeGraph.hh:108
The vertex state.
Definition CopyMeGraph.hh:73
int some_trait
Another useful documentation string, yeah.
Definition CopyMeGraph.hh:78
bool is_a_vip_vertex
Whether this vertex is very important.
Definition CopyMeGraph.hh:81
double some_state
A useful documentation string.
Definition CopyMeGraph.hh:75