XX CMake Package
Loading...
Searching...
No Matches
XXGraphAlgorithm.h
Go to the documentation of this file.
1#ifndef XXDiscreteMathsAlgorithmH
2#define XXDiscreteMathsAlgorithmH
3
4#include "XXMathExportDef.h"
5
6#include <QList>
7
8#include "XXGraph.h"
9#include "XXGraphEdge.h"
10#include "XXGraphVertex.h"
11
12namespace XX
13{
16
18 {
19 public:
21 using IndexList = QList<int>;
22
24 struct Path
25 {
26 static const double invalidDistance;
27
30
31 using Map = QMap<int, Path>; // end vertex index vs path
32 };
33
36 {
38 {
39 int vertexIndex = -1;
41 int depth = 0;
42
43 using List = QList<VertexData>;
44 };
45
46 VertexData::List verticies; // visited in order
47
48 Path compilePath(const int vertexIndex) const;
49 int compileDepth(const int vertexIndex) const;
50
52 };
53
56 {
57 IndexList treeEdges; // edges used for visit
58 IndexList forwardEdges; // unvisited, in order
59 IndexList backEdges; // unvisted, against order
60 };
61
62 public:
63 Algorithm(const Graph* graph);
64
65 public:
66 Tree depthFirst(const Vertex* vertexStart) const;
67 Tree breadthFirst(const Vertex* vertexStart) const;
68
69 Path::Map pathDijkstra(const Vertex* vertexStart) const;
70 TreeEdges compileTreeEdges(const Tree& tree) const;
71
73
74 private:
75 struct EdgeData
76 {
77 double weight = Edge::invalidWeight;
78 int index = -1;
79 bool forward = true;
80
81 using Row = QVector<EdgeData>;
82 using Matrix = QVector<Row>;
83 };
84
85 private:
86 int findEdgeIndex(const int vertexIndexA, const int vertexIndexB) const;
87
88 IndexList compileAdjacencyList(const int vertexIndex) const;
89
90 private:
91 const Graph* graph;
92 EdgeData::Matrix edgeMatrix;
93 };
94} // namespace XX
95
96#endif // NOT XXDiscreteMathsAlgorithmH
#define XXMATH_DECLSPEC
Definition XXMathExportDef.h:17
Algorithm(const Graph *graph)
IndexList topologicalSort() const
TreeEdges compileTreeEdges(const Tree &tree) const
Path::Map pathDijkstra(const Vertex *vertexStart) const
QList< int > IndexList
list of vertex or edge indexes
Definition XXGraphAlgorithm.h:21
Tree breadthFirst(const Vertex *vertexStart) const
Tree depthFirst(const Vertex *vertexStart) const
static const double invalidWeight
Definition XXGraphEdge.h:19
a vertex in a graph
Definition XXGraphVertex.h:16
int vertexIndex(const Vertex *vertex) const
int findEdgeIndex(const Vertex *vertexA, const Vertex *vertexB) const
Definition XXPopulatedAbstract.h:11
path from one vertex to another
Definition XXGraphAlgorithm.h:25
IndexList verticies
Definition XXGraphAlgorithm.h:29
static const double invalidDistance
Definition XXGraphAlgorithm.h:26
QMap< int, Path > Map
Definition XXGraphAlgorithm.h:31
double distance
Definition XXGraphAlgorithm.h:28
Definition XXGraphAlgorithm.h:38
int parentVertexIndex
Definition XXGraphAlgorithm.h:40
QList< VertexData > List
Definition XXGraphAlgorithm.h:43
int depth
Definition XXGraphAlgorithm.h:41
int vertexIndex
Definition XXGraphAlgorithm.h:39
graph algorithms
Definition XXGraphAlgorithm.h:56
IndexList backEdges
Definition XXGraphAlgorithm.h:59
IndexList forwardEdges
Definition XXGraphAlgorithm.h:58
IndexList treeEdges
Definition XXGraphAlgorithm.h:57
result tree of graph traversal
Definition XXGraphAlgorithm.h:36
VertexData findData(const int vertexIndex) const
int compileDepth(const int vertexIndex) const
Path compilePath(const int vertexIndex) const
VertexData::List verticies
Definition XXGraphAlgorithm.h:46