Code Documentation 3.8
Social Network Visualizer
Loading...
Searching...
No Matches
per_source_scratch.h
Go to the documentation of this file.
1
13
14#ifndef SOCNETV_PER_SOURCE_SCRATCH_H
15#define SOCNETV_PER_SOURCE_SCRATCH_H
16
17#include <stack>
18#include <QHash>
19#include <QList>
20#include <QVector>
21#include <QtGlobal>
22#include <cstdlib> // RAND_MAX
23
25{
26 // Brandes traversal stack — vertices ordered by non-increasing distance from s
27 std::stack<int> Stack;
28
29 // Predecessor lists: Ps[vi] = list of vertices that precede vertex vi
30 // on shortest paths from the current source s. Indexed by vertex position.
31 QVector<QList<int>> Ps;
32
33 // Dependency accumulators for Brandes BC back-propagation.
34 // Indexed by vertex position.
35 QVector<qreal> delta;
36
37 // BFS / Dijkstra distances from current source s.
38 // dist[vi] == RAND_MAX means vertex vi has not been reached.
39 // Indexed by vertex position.
40 QVector<qreal> dist;
41
42 // Shortest-path counts (sigma) from current source s.
43 // Indexed by vertex position.
44 QVector<int> sigma;
45
46 // Number of vertices at each distance order from s (used for Power Centrality).
47 // Key = distance, Value = count.
48 QHash<qreal, int> nthOrder;
49
50 // Size of the connected component reachable from s (used for SPC normalisation).
52
53 // No per-source graph-aggregate accumulators live here: diameter, distance sum, and
54 // geodesics (reachable-pair) count must all be computed from each vertex's FINAL
55 // distance, not a running/duplicated accumulation sampled during or right after
56 // relaxation (a vertex can be relaxed to a smaller distance after an earlier, larger
57 // one) - computed directly from dist[] / the final APSP matrix in runAllSources() and
58 // finalize() instead, after a source's SSSP run has fully settled.
59
60 // Allocate all containers once for totalVertices positions.
61 // Call this once before the source loop.
62 void allocate(int totalVertices)
63 {
64 Ps.resize(totalVertices);
65 delta.resize(totalVertices);
66 dist.resize(totalVertices);
67 sigma.resize(totalVertices);
68 }
69
70 // Reset per-source state before each new source vertex.
71 // computeCentralities controls whether the Brandes-only structures are reset.
72 void resetPerSource(bool computeCentralities)
73 {
74 dist.fill((qreal)RAND_MAX);
75 sigma.fill(0);
76 if (computeCentralities)
77 {
78 while (!Stack.empty())
79 Stack.pop();
80 for (auto &ps : Ps)
81 ps.clear();
82 nthOrder.clear();
83 }
84 // delta is zeroed in the per-source back-propagation setup loop,
85 // not here, to preserve the existing guard on computeCentralities.
86 }
87
88 // Increment the nth-order neighbourhood count for distance d.
89 void nthOrderIncrement(qreal d)
90 {
91 nthOrder.insert(d, nthOrder.value(d, 0) + 1);
92 }
93};
94
95#endif // SOCNETV_PER_SOURCE_SCRATCH_H
Definition per_source_scratch.h:25
QVector< int > sigma
Definition per_source_scratch.h:44
QHash< qreal, int > nthOrder
Definition per_source_scratch.h:48
int componentSize
Definition per_source_scratch.h:51
void allocate(int totalVertices)
Definition per_source_scratch.h:62
QVector< qreal > dist
Definition per_source_scratch.h:40
QVector< qreal > delta
Definition per_source_scratch.h:35
void resetPerSource(bool computeCentralities)
Definition per_source_scratch.h:72
std::stack< int > Stack
Definition per_source_scratch.h:27
void nthOrderIncrement(qreal d)
Definition per_source_scratch.h:89
QVector< QList< int > > Ps
Definition per_source_scratch.h:31