Utopia 2
Framework for studying models of complex & adaptive systems.
Loading...
Searching...
No Matches
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.
 
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 VertexDesc = typename boost::graph_traits< GraphType >::vertex_descriptor
 Data type for a vertex descriptor.
 
using EdgeDesc = typename boost::graph_traits< GraphType >::edge_descriptor
 Data type for an edge descriptor.
 
using VertexVoidRule = typename std::function< void(VertexDesc, GraphType &)>
 Data type for a rule function operating on vertices returning void.
 
using VertexStateRule = typename std::function< VertexState(VertexDesc, GraphType &)>
 Data type for a rule function operating on vertices returning a state.
 
using EdgeVoidRule = typename std::function< void(EdgeDesc, GraphType &)>
 Data type for a rule function operating on edges returning void.
 
using EdgeStateRule = typename std::function< EdgeState(EdgeDesc, GraphType &)>
 Data type for a rule function operating on edges returning a state.
 
- Public Types inherited from Utopia::Model< CopyMeGraph, ModelTypes >
using Config = typename ModelTypes::Config
 Data type that holds the configuration.
 
using DataManager = DataIO::Default::DefaultDataManager< CopyMeGraph >
 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 >
 CopyMeGraph (const std::string &name, ParentModel &parent_model, const DataIO::Config &custom_cfg={})
 Construct the CopyMeGraph model.
 
void perform_step ()
 Iterate a single step.
 
void monitor ()
 Monitor model information.
 
void write_data ()
 Write data.
 
- 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.
 
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< DataGroupget_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< RNGget_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< MonitorManagerget_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< 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.
 
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.
 
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.
 
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.
 

Private Member Functions

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

Private Attributes

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

Additional Inherited Members

- Protected Member Functions inherited from Utopia::Model< CopyMeGraph, 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.
 
CopyMeGraph & impl ()
 cast to the derived class
 
const CopyMeGraph & impl () const
 const cast to the derived interface
 
- Protected Attributes inherited from Utopia::Model< CopyMeGraph, 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< CopyMeGraph, ModelTypes >
static constexpr WriteMode _write_mode
 Which data-writing mode the base model should use.
 

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

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

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
250 {}
251 )
252 :
253 // Initialize first via base model
255
256 // Initialize the uniform real distribution to range [0., 1.]
257 _prob_distr(0., 1.),
258
259 // Now initialize the graph
261
262 // Initialize model parameters
263 _some_parameter(get_as<double>("some_parameter", this->_cfg)),
264 // ...
265
266 // Datagroups
267 // For saving graph-related data, it is recommended to use a so-called
268 // graph group. This is a normal datagroup (opened with the open_group
269 // method) but with additional attributes such as information about the
270 // graph itself. This allows for later loading the data from the graph
271 // group directly into a NetworkX graph object in Python.
274
275 // Datasets
276 // For setting up datasets that store Graph data, you can use the
277 // Model::create_dset helper method which already takes care of using
278 // the correct length into the time dimension (depending on the
279 // num_steps and write_every parameters). Additionally, the parent
280 // datagroup can be specified. The syntax is:
281 //
282 // this->create_dset("a_number", dgrp, {}) // 1D {#writes}
283 // this->create_dset("a_vec", dgrp, {num_cols}) // 2D {#writes, #cols}
284 //
285 // This is also done here for storing two vertex properties in the
286 // static graph group.
287 _dset_some_state(this->create_dset("some_state",
289 {boost::num_vertices(_g)})),
290 _dset_some_trait(this->create_dset("some_trait",
292 {boost::num_vertices(_g)}))
293 {
294 // Can do remaining initialization steps here ...
295
296 // Set the second dimension name to 'vertex_idx'. The first dimension's
297 // name is 'time'. Also, specify the coordinates for the vertex_idx
298 // dimension, which are just the trivial coordinates 0, ..., N-1,
299 // where N is the number of vertices.
300 // NOTE The IDs of the vertices do not necessarily line up with the
301 // indices of the vertices when iterating over the graph. That's
302 // why the dimension is called vertex_idx, not vertex_id.
303 _dset_some_state->add_attribute("dim_name__1", "vertex_idx");
304 _dset_some_state->add_attribute("coords_mode__vertex_idx", "trivial");
305
306 _dset_some_trait->add_attribute("dim_name__1", "vertex_idx");
307 _dset_some_state->add_attribute("coords_mode__vertex_idx", "trivial");
308
309 // NOTE The initial state need and should NOT be written here. The
310 // write_data method is invoked first at time `write_start`.
311 // However, this is a good place to store data that is constant
312 // during the run and needs to be written at some point.
313
314 // In the case of a static graph, the topology can be saved once using
315 // the DataIO::save_graph function. It saves the graph structure to the
316 // specified datagroup by writing the vertex id's in a dataset named
317 // `_vertices` and the edges in a dataset named `_edges`.
319
320 // Initialization should be finished here.
321 this->_log->debug("{} model fully set up.", this->_name);
322 }
const std::shared_ptr< DataGroup > _hdfgrp
The HDF group this model instance should write its data to.
Definition model.hh:176
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
const std::shared_ptr< spdlog::logger > _log
The (model) logger.
Definition model.hh:164
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
double _some_parameter
Some parameter.
Definition CopyMeGraph.hh:205
std::shared_ptr< DataGroup > _dgrp_g_dynamic
A datagroup for a dynamic graph.
Definition CopyMeGraph.hh:223
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
std::shared_ptr< DataGroup > _dgrp_g_static
A datagroup for a static graph.
Definition CopyMeGraph.hh:220
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
std::shared_ptr< DataSet > _dset_some_state
A dataset for storing all vertices' some_state.
Definition CopyMeGraph.hh:229
std::uniform_real_distribution< double > _prob_distr
A re-usable uniform real distribution to evaluate probabilities.
Definition CopyMeGraph.hh:199
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
std::shared_ptr< HDFGroup > create_graph_group(const Graph &g, const std::shared_ptr< HDFGroup > &parent_grp, const std::string &name)
Definition graph_utils.hh:291
void save_graph(const Graph &g, const std::shared_ptr< HDFGroup > &grp)
Write function for a boost::Graph.
Definition graph_utils.hh:332

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.

396 {
397 auto sum = 0.;
398 for (const auto v : range<IterateOver::vertices>(_g)) {
399 sum += _g[v].state.some_state;
400 }
401 return sum / boost::num_vertices(_g);
402 }
IterateOver
Over which graph entity to iterate.
Definition iterator.hh:19
decltype(auto) range(const Graph &g)
Get the iterator range over selected graph entities.
Definition iterator.hh:149
@ vertices
Iterate over vertices.

◆ initialize_edges()

void Utopia::Models::CopyMeGraph::CopyMeGraph::initialize_edges ( GraphType g)
inlineprivate
365 {
366 // Define a rule that acts on an edge
367 auto initialize_edge = [this](const auto e, auto& g) {
368 // Get the initial weight from the configuration
369 g[e].state.weight = get_as<double>("init_weight", this->_cfg);
370
371 // If set in the configuration randomize the weight by
372 // multiplying a random number between drawn uniformaly from [0,1].
373 if (get_as<bool>("init_random_weight", this->_cfg)) {
374 // Here you see, how to generate a random number using the
375 // random number generated from the parent model.
376 // Remember that the member variable is a shared pointer,
377 // so you need to dereference it by writing '*' in front of it.
378 g[e].state.weight *= _prob_distr(*this->_rng);
379 }
380 };
381
382 // Apply the single edge initialization rule to all edges
383 // NOTE that you should distinguish between in_edges and out_edges
384 // if your graph is directed.
387 g);
388 }
const std::shared_ptr< RNG > _rng
The RNG shared between models.
Definition model.hh:161

◆ initialize_graph()

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

Initialize the graph.

329 {
330 this->_log->debug("Create and initialize the graph ...");
331
332 auto g = Graph::create_graph<GraphType>(this->_cfg["create_graph"],
333 *this->_rng);
334
335 this->initialize_vertices(g);
336 this->initialize_edges(g);
337
338 return g;
339 }
void initialize_vertices(GraphType &g)
Definition CopyMeGraph.hh:341
void initialize_edges(GraphType &g)
Definition CopyMeGraph.hh:364

◆ initialize_vertices()

void Utopia::Models::CopyMeGraph::CopyMeGraph::initialize_vertices ( GraphType g)
inlineprivate
342 {
343 // Define a rule that acts on a vertex
344 auto initialize_vertex = [this](const auto v, auto& g) {
345 g[v].state.some_state =
346 get_as<double>("init_some_state", this->_cfg);
347 g[v].state.some_trait = get_as<int>("init_some_trait", this->_cfg);
348
349 // Every 13th vertex (on average) is a VIP vertex
350 if (this->_prob_distr(*this->_rng) < (1. / 13.)) {
351 g[v].state.is_a_vip_vertex = true;
352 }
353 else {
354 g[v].state.is_a_vip_vertex = false;
355 }
356 };
357
358 // Apply the rule to all vertices
361 g);
362 }

◆ 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.

478 {
479 this->_monitor.set_entry("some_value", 42);
480 this->_monitor.set_entry("state_mean", calc_some_state_mean());
481 }
Monitor _monitor
The monitor.
Definition model.hh:188
double calc_some_state_mean() const
Calculate the mean of all vertices' some_state.
Definition CopyMeGraph.hh:395

◆ 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

457 {
458 // Apply the rule 'some_interaction' to all vertices sequentially
461 _g,
462 *this->_rng);
463
464 // Apply 'some_other_rule' synchronously to all vertices
466 }
VertexVoidRule some_interaction
An interaction function of a single vertex with its neighbors.
Definition CopyMeGraph.hh:411
VertexStateRule some_other_rule
Some other rule function.
Definition CopyMeGraph.hh:436

◆ 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

489 {
490 // .. Writing to the static graph group ...............................
491 // To save data to the already created datasets, the write method can
492 // be called directly using a lambda function to extract the data from
493 // the graph.
494 //
495 // Get the iterator pair of the vertices
496 auto [v, v_end] = boost::vertices(_g);
497
498 // Write out the some_state of all vertices
499 _dset_some_state->write(v, v_end, [this](const auto v) {
500 return this->_g[v].state.some_state;
501 });
502
503 // Write out the some_trait of all vertices
504 _dset_some_trait->write(v, v_end, [this](const auto v) {
505 return this->_g[v].state.some_trait;
506 });
507
508 // .. Writing to the dynamic graph group ..............................
509 // To save data for dynamic graphs, it is recommended to use the
510 // save_<vertex/edge>_properties functions. Since it writes all data in
511 // a single iteration over the graph entities, it ensures that all data
512 // written within one time step is aligned.
513 //
514 // First, two 'adaptor tuples' are defined - one that accesses the data
515 // via a vertex-descriptor and one that does it via an edge-descriptor.
516 // NOTE In order to ensure correct ordering of the data, there must not
517 // be a second adaptor tuple using the same type.
518 // The adaptor tuple for the vertex data contains 1D adaptors which are
519 // tuples of the form: (adaptor_name, adaptor_lambda)
520 const auto get_vertex_data = std::make_tuple(
521 std::make_tuple(
522 "_vertices",
523 [](auto vd, auto& g) {
524 return boost::get(boost::vertex_index_t(), g, vd);
525 }),
526 std::make_tuple("some_state",
527 [](auto vd, auto& g) {
528 return g[vd].state.some_state;
529 }),
530 std::make_tuple("some_trait", [](auto vd, auto& g) {
531 return g[vd].state.some_trait;
532 }));
533
534 // N-dimensional data can also be written. Here, 2D adaptors are used
535 // for the edges and a 1D adaptor for the weights. For more details,
536 // checkout the documentation of the save_<vertex/edge>_properties
537 // functions.
538 const auto get_edge_data = std::make_tuple(
539 std::make_tuple(
540 "_edges",
541 "label",
542 std::make_tuple("source",
543 [](auto ed, auto& g) {
544 return boost::get(boost::vertex_index_t(),
545 g,
546 boost::source(ed, g));
547 }),
548 std::make_tuple("target",
549 [](auto ed, auto& g) {
550 return boost::get(boost::vertex_index_t(),
551 g,
552 boost::target(ed, g));
553 })),
554 std::make_tuple("weights", [](auto ed, auto& g) {
555 return g[ed].state.weight;
556 }));
557 // NOTE When using an adaptor tuple for saving dynamic edges (vertices),
558 // all edge (vertex) properties should also be saved via the
559 // adaptor tuple to ensure correct ordering.
560
561 // Then, the save_<vertex/edge>_properties functions can be called.
562 // NOTE Using the current time as the name of the dataset(s) indexes the
563 // data and allows to later load the data directly into a NetworkX
564 // graph.
567 std::to_string(get_time()),
571 std::to_string(get_time()),
573
574 // When writing in every time step, this will result in the following
575 // data structure:
576 // ...
577 // └┬ graph_group
578 // └┬ _vertices
579 // └┬ 0 < ... shape(num_vertices,)
580 // ├ 1 < ... shape(num_vertices,)
581 // ├ ...
582 // ├ _edges
583 // └┬ 0 < ... shape(num_edges, 2)
584 // ├ 1 < ... shape(num_edges, 2)
585 // ├ ...
586 // ├ ...
587 //
588 // By default, the coordinates 'vertex_idx' and 'edge_idx' are added.
589 }
Time get_time() const
Return the current time of this model.
Definition model.hh:393
void save_edge_properties(Graph &&g, const std::shared_ptr< HDFGroup > &nw_grp, const std::string &label, const std::tuple< Adaptors... > &adaptor_tuple)
Definition graph_utils.hh:573
void save_vertex_properties(Graph &&g, const std::shared_ptr< HDFGroup > &nw_grp, const std::string &label, const std::tuple< Adaptors... > &adaptor_tuple)
Definition graph_utils.hh:542

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;
}
typename boost::graph_traits< GraphType >::vertex_descriptor VertexDesc
Data type for a vertex descriptor.
Definition CopyMeGraph.hh:174
@ neighbors
Iterate over neighbors (adjacent_vertices).
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.

411 {
412 // Increase some_state by one
413 g[v].state.some_state += 1;
414
415 // Iterate over all neighbors of the current vertex
416 for (const auto nb : range<IterateOver::neighbors>(v, g)) {
417 // Obvious thing to do is to increase some_trait by the sum of
418 // some_traits's of the neighbor. Sure thing.
419 g[v].state.some_trait += g[nb].state.some_trait;
420
421 // Let's add a random number in range [-1, +1] as well
422 g[v].state.some_trait += (this->_prob_distr(*this->_rng) * 2. - 1.);
423 }
424
425 // Ahhh and obviously you need to divide some float by
426 // _some_parameter because that makes totally sense
427 g[v].state.some_trait /= this->_some_parameter;
428 };

◆ 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.
436 {
437 // COPY the state -- important for synchronous update
438 auto state = g[v].state;
439
440 // With a probability of 0.3 set the vertex's some_state to 0
441 if (this->_prob_distr(*this->_rng) < 0.3) {
442 state.some_state = 0;
443 }
444
445 return state;
446 };

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