1#ifndef UTOPIA_MODELS_OPINIONET_UTILS
2#define UTOPIA_MODELS_OPINIONET_UTILS
6#include <boost/graph/adjacency_list.hpp>
7#include <boost/graph/graph_traits.hpp>
13template<
typename RT,
typename T,
typename RNGType>
16 throw std::invalid_argument(
17 "Error, invalid parameter range! Upper limit has to be higher "
18 "than the lower limit."
21 if constexpr (std::is_floating_point<RT>()) {
23 std::uniform_real_distribution<RT>(
range.first,
range.second)(rng);
27 std::uniform_int_distribution<RT>(
range.first,
range.second)(rng);
34template<
typename NWType>
36 return std::is_convertible<
37 typename boost::graph_traits<NWType>::directed_category,
38 boost::directed_tag>::value;
43template<
typename NWType,
typename VertexDescType,
typename RNGType>
47 std::make_pair<int, int>(0, boost::out_degree(
v, nw)-1), rng
49 auto nb = boost::adjacent_vertices(
v, nw).first;
56template<
typename NWType,
typename RNGType,
typename VertexDescType>
60 std::uniform_real_distribution<double>& prob_distr,
65 if constexpr (Utils::is_directed<NWType>()) {
86template<
typename NWType,
typename VertexDescType>
88 return fabs(nw[
v].opinion - nw[
w].opinion);
101template<
typename NWType,
typename VertexDescType>
105 const double weighting)
Container select_entities(const Manager &mngr, const DataIO::Config &sel_cfg)
Select entities according to parameters specified in a configuration.
Definition select.hh:213
decltype(auto) range(const Graph &g)
Get the iterator range over selected graph entities.
Definition iterator.hh:149
Definition test_utils.cc:13
double opinion_difference(VertexDescType v, VertexDescType w, NWType &nw)
Calculate the absolute opinion difference of two vertices.
Definition utils.hh:87
constexpr bool is_directed()
Check whether the network type allows for directed edges.
Definition utils.hh:35
auto get_rand_neighbor(const VertexDescType v, NWType &nw, RNGType &rng)
Definition utils.hh:44
RT get_rand(std::pair< T, T > range, RNGType &rng)
Generate a random number within the given range.
Definition utils.hh:14
VertexDescType select_neighbor(const VertexDescType v, NWType &nw, std::uniform_real_distribution< double > &prob_distr, RNGType &rng)
Definition utils.hh:57
void set_and_normalize_weights(const VertexDescType v, NWType &nw, const double weighting)
Set and normalize weights according to opinion difference.
Definition utils.hh:102