1 #ifndef UTOPIA_MODELS_OPINIONET_REVISION
2 #define UTOPIA_MODELS_OPINIONET_REVISION
19 template<
typename NWType,
typename VertexDescType>
21 const VertexDescType v,
23 const double susceptibility,
24 const double tolerance,
27 double expectation = 0;
28 size_t num_interaction_partners = 0;
32 if constexpr (Utils::is_directed<NWType>()) {
34 for (
const auto e : range<IterateOver::out_edges>(v, nw)) {
37 expectation += nw[nb].opinion * nw[e].weight;
38 ++num_interaction_partners;
44 if (num_interaction_partners != 0) {
45 expectation *=
static_cast<double>(boost::out_degree(v, nw)) /
46 num_interaction_partners;
49 expectation = nw[v].opinion;
55 for (
const auto e : range<IterateOver::out_edges>(v, nw)) {
56 auto nb = boost::target(e, nw);
58 expectation += nw[nb].opinion;
59 ++num_interaction_partners;
65 if (num_interaction_partners != 0) {
66 expectation /= num_interaction_partners;
69 expectation = nw[v].opinion;
74 nw[v].opinion += susceptibility * (expectation - nw[v].opinion);
77 nw[v].opinion = round(nw[v].opinion);
82 template<
typename NWType,
typename RNGType,
typename VertexDescType>
84 const VertexDescType v,
86 const double susceptibility,
87 const double tolerance,
89 std::uniform_real_distribution<double>&
prob_distr,
99 if (interaction_probability < susceptibility) {
100 nw[v].opinion = nw[nb].opinion;
108 nw[v].opinion += susceptibility * (nw[nb].opinion - nw[v].opinion);
117 template<
typename NWType,
typename RNGType>
120 const double tolerance,
121 const double weighting,
124 using namespace boost;
127 const auto e = random_edge(nw,
rng);
128 const auto s = source(e, nw);
131 const auto new_target = random_vertex(nw,
rng);
133 if (new_target != s and not edge(s, new_target, nw).second)
136 add_edge(s, new_target, nw);
138 if constexpr (Utils::is_directed<NWType>()) {
148 template<
typename NWType,
typename RNGType>
151 const double susceptibility,
152 const double tolerance,
153 const double weighting,
157 std::uniform_real_distribution<double>&
prob_distr,
161 const auto v = boost::random_vertex(nw,
rng);
163 if (boost::out_degree(v, nw) != 0) {
167 v, nw, susceptibility, tolerance, opinion_space
173 v, nw, susceptibility, tolerance, opinion_space,
178 if constexpr (Utils::is_directed<NWType>()) {
Opinion_space_type
Definition: modes.hh:13
@ discrete
Definition: modes.hh:15
Interaction_type
Definition: modes.hh:8
@ Deffuant
Definition: modes.hh:9
@ HegselmannKrause
Definition: modes.hh:10
Rewiring
Definition: modes.hh:18
@ RewiringOn
Definition: modes.hh:19
Definition: revision.hh:10
std::uniform_real_distribution< double > prob_distr
Definition: test_revision.cc:18
void rewire_random_edge(NWType &nw, const double tolerance, const double weighting, RNGType &rng)
Definition: revision.hh:118
void update_opinion_HK(const VertexDescType v, NWType &nw, const double susceptibility, const double tolerance, const Opinion_space_type opinion_space)
Hegselmann-Krause opinion update function.
Definition: revision.hh:20
void revision(NWType &nw, const double susceptibility, const double tolerance, const double weighting, const Interaction_type interaction, const Opinion_space_type opinion_space, const Rewiring rewire, std::uniform_real_distribution< double > &prob_distr, RNGType &rng)
Performs an opinion update and edge rewiring (if enabled).
Definition: revision.hh:149
void update_opinion_Deffuant(const VertexDescType v, NWType &nw, const double susceptibility, const double tolerance, const Opinion_space_type opinion_space, std::uniform_real_distribution< double > &prob_distr, RNGType &rng)
Deffuant opinion update function.
Definition: revision.hh:83
std::mt19937 rng
– Type definitions ----------------------------------------------------—
Definition: test_revision.cc:17
double opinion_difference(VertexDescType v, VertexDescType w, NWType &nw)
Calculate the absolute opinion difference of two vertices.
Definition: utils.hh:87
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