Code Documentation 3.8
Social Network Visualizer
Loading...
Searching...
No Matches
distance_engine.h
Go to the documentation of this file.
1
15
16#ifndef SOCNETV_DISTANCE_ENGINE_H
17#define SOCNETV_DISTANCE_ENGINE_H
18
21
22#include <QVector>
23
24class Graph;
25
27{
28public:
29 explicit DistanceEngine(Graph &g);
30 void compute(const bool computeCentralities,
31 const bool considerWeights,
32 const bool inverseWeights,
33 const bool dropIsolates,
34 const bool allowNegativeWeights = false);
35
36 // Public probe for the potentials pass - see distance_engine.cpp for the doc comment.
37 bool bellmanFordPotentials(const bool inverseWeights, QVector<qreal> &outPotentials);
38
39private:
41
60 void initRun(const bool computeCentralities,
61 const bool considerWeights,
62 const bool inverseWeights,
63 const bool dropIsolates,
64 const bool allowNegativeWeights,
65 struct DistanceScratch &ds,
66 struct CentralityScratchSSSP &csssp,
67 struct CentralityScratchFinalize &csfin,
69
70 // Bellman-Ford reweighting pass - see distance_engine.cpp for the doc comment.
71 bool bellmanFordPotentials(const bool inverseWeights, struct DistanceScratch &ds);
72
86 void runAllSources(const bool computeCentralities,
87 const bool considerWeights,
88 const bool inverseWeights,
89 const bool dropIsolates,
90 struct DistanceScratch &ds,
92
106 void finalize(const bool computeCentralities,
107 const bool dropIsolates,
108 struct DistanceScratch &ds,
109 struct CentralityScratchFinalize &csfin,
111
112 // Breadth-First Search SSSP for unweighted graphs.
113 // Writes distances, sigma, and Ps (predecessor lists) to pss. Graph-wide aggregates
114 // (distance sum, geodesics count, diameter) and centrality accumulators that depend on the
115 // final settled shortest-path DAG (BC, SC) are computed post-hoc from pss.Ps/pss.sigma in
116 // runAllSources()'s Brandes back-propagation loop, not accumulated here.
117 void bfsSSSP(const int &s, const int &si,
118 const bool &computeCentralities,
119 const bool &dropIsolates,
120 PerSourceScratch &pss);
121
122 // Dijkstra SSSP for weighted graphs (directed or not).
123 // Same contract as bfsSSSP: unsafe graph-wide writes and DAG-dependent centralities go
124 // through pss scratch fields, not touched directly here.
125 // potentials: empty for a plain Dijkstra run (the default); when non-empty, indexed by
126 // vertex position like pss.dist, each edge weight is reweighted inline as
127 // weight + potentials[ui] - potentials[wi] before relaxation (Johnson's algorithm - see
128 // bellmanFordPotentials()). Caller is responsible for un-reweighting pss.dist afterward.
129 void dijkstraSSSP(const int &s, const int &si,
130 const bool &computeCentralities,
131 const bool &inverseWeights,
132 const bool &dropIsolates,
133 PerSourceScratch &pss,
134 const QVector<qreal> &potentials = QVector<qreal>());
135};
136
137#endif // SOCNETV_DISTANCE_ENGINE_H
bool bellmanFordPotentials(const bool inverseWeights, QVector< qreal > &outPotentials)
Public entry point for the potentials pass below, for callers with no DistanceScratch of their own (c...
Definition distance_engine.cpp:536
Graph & graph
Definition distance_engine.h:40
void compute(const bool computeCentralities, const bool considerWeights, const bool inverseWeights, const bool dropIsolates, const bool allowNegativeWeights=false)
Runs the full geodesic distance (and optionally centrality) computation pipeline.
Definition distance_engine.cpp:170
void finalize(const bool computeCentralities, const bool dropIsolates, struct DistanceScratch &ds, struct CentralityScratchFinalize &csfin, IDistanceProgressSink &sink)
Single-threaded aggregation pass run after runAllSources() completes: scans for vertex pairs left unr...
Definition distance_engine.cpp:977
void dijkstraSSSP(const int &s, const int &si, const bool &computeCentralities, const bool &inverseWeights, const bool &dropIsolates, PerSourceScratch &pss, const QVector< qreal > &potentials=QVector< qreal >())
Definition distance_engine.cpp:1528
DistanceEngine(Graph &g)
Definition distance_engine.cpp:140
void initRun(const bool computeCentralities, const bool considerWeights, const bool inverseWeights, const bool dropIsolates, const bool allowNegativeWeights, struct DistanceScratch &ds, struct CentralityScratchSSSP &csssp, struct CentralityScratchFinalize &csfin, IDistanceProgressSink &sink)
Phase 0 of compute(): resets every scratch/aggregate field this run will populate,...
Definition distance_engine.cpp:295
void bfsSSSP(const int &s, const int &si, const bool &computeCentralities, const bool &dropIsolates, PerSourceScratch &pss)
Definition distance_engine.cpp:1352
void runAllSources(const bool computeCentralities, const bool considerWeights, const bool inverseWeights, const bool dropIsolates, struct DistanceScratch &ds, IDistanceProgressSink &sink)
Runs SSSP (BFS or Dijkstra, per considerWeights) from every enabled vertex, in parallel across CPU co...
Definition distance_engine.cpp:663
The Graph class This is the main class for a Graph, used in conjuction with GraphVertex,...
Definition graph.h:105
Definition distance_progress_sink.h:21
Declares the GraphDistanceProgressSink class, which forwards DistanceEngine's status messages and can...
Per-source scratch state for the Brandes SSSP / centrality computation.
Scratch for the finalize() phase — the single-threaded pass that runs once after runAllSources() comp...
Definition distance_engine.cpp:130
Per-run scratch for centrality values computed once per SSSP source, before the parallel per-source l...
Definition distance_engine.cpp:104
Per-run scratch state for DistanceEngine::compute(), scoped to one compute() call.
Definition distance_engine.cpp:60
Definition per_source_scratch.h:25