Hegselmann-Krause opinion update function.
26{
27 double expectation = 0;
28 size_t num_interaction_partners = 0;
29
30
31
32 if constexpr (Utils::is_directed<NWType>()) {
33 VertexDescType nb;
35 nb = target(e, nw);
36 if (Utils::opinion_difference(v, nb, nw) <= tolerance) {
37 expectation += nw[nb].opinion * nw[e].weight;
38 ++num_interaction_partners;
39 }
40 }
41
42
43
44 if (num_interaction_partners != 0) {
45 expectation *= static_cast<double>(boost::out_degree(v, nw)) /
46 num_interaction_partners;
47 }
48 else {
49 expectation = nw[v].opinion;
50 }
51 }
52
53
54 else {
56 auto nb = boost::target(e, nw);
57 if (Utils::opinion_difference(v, nb, nw) <= tolerance) {
58 expectation += nw[nb].opinion;
59 ++num_interaction_partners;
60 }
61 }
62
63
64
65 if (num_interaction_partners != 0) {
66 expectation /= num_interaction_partners;
67 }
68 else {
69 expectation = nw[v].opinion;
70 }
71 }
72
73
74 nw[v].opinion += susceptibility * (expectation - nw[v].opinion);
75
76 if (opinion_space == Opinion_space_type::discrete) {
77 nw[v].opinion = round(nw[v].opinion);
78 }
79}
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
@ out_edges
Iterate over the out edges of a vertex.