Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Loading...
Searching...
No Matches
ShortestPathAlgorithms.h
Go to the documentation of this file.
1
32#pragma once
33
34#include <ogdf/basic/Array.h>
36#include <ogdf/basic/Graph_d.h>
38#include <ogdf/basic/SList.h>
40
41namespace ogdf {
42
44
49template<typename TCost>
51 for (node v : G.nodes) {
52 bfs_SPSS(v, G, distance[v], edgeCosts);
53 }
54}
55
57
62template<typename TCost>
64 NodeArray<bool> mark(G, false);
66 bfs.pushBack(s);
67 // mark s and set distance to itself 0
68 mark[s] = true;
69 distanceArray[s] = TCost(0);
70 while (!bfs.empty()) {
71 node w = bfs.popFrontRet();
73 for (adjEntry adj : w->adjEntries) {
74 node v = adj->twinNode();
75 if (!mark[v]) {
76 mark[v] = true;
77 bfs.pushBack(v);
78 distanceArray[v] = d;
79 }
80 }
81 }
82}
83
85
92template<typename TCost>
94 const Graph& G = GA.constGraph();
96 double avgCosts = 0;
97 for (edge e : G.edges) {
98 edgeCosts[e] = GA.doubleWeight(e);
99 avgCosts += edgeCosts[e];
100 }
102 return avgCosts / G.numberOfEdges();
103}
104
106
111template<typename TCost>
114 for (node v : G.nodes) {
116 }
117}
118
120
127template<typename TCost>
130 NodeArray<edge> predecessor;
131 Dijkstra<TCost> sssp;
132 sssp.call(G, edgeCosts, s, predecessor, shortestPathMatrix);
133}
134
136
142template<typename TCost>
144 for (node u : G.nodes) {
145 for (node v : G.nodes) {
146 for (node w : G.nodes) {
149 }
150 }
151 }
152}
153
154}
Declaration and implementation of Array class and Array algorithms.
Pure declaration header, find template implementation in Graph.h.
Declaration of class GraphAttributes which extends a Graph by additional attributes.
Declaration and implementation of NodeArray class.
Declaration of singly linked lists and iterators.
Class for adjacency list elements.
Definition Graph_d.h:79
Dijkstra's single source shortest path algorithm.
Definition Dijkstra.h:53
void call(const Graph &G, const EdgeArray< T > &weight, const List< node > &sources, NodeArray< edge > &predecessor, NodeArray< T > &distance, bool directed=false, bool arcsReversed=false, node target=nullptr, T maxLength=std::numeric_limits< T >::max())
Calculates, based on the graph G with corresponding edge costs and source nodes, the shortest paths a...
Definition Dijkstra.h:246
Dynamic arrays indexed with edges.
Definition EdgeArray.h:125
Class for the representation of edges.
Definition Graph_d.h:300
Stores additional attributes of a graph (like layout information).
Data type for general directed graphs (adjacency list representation).
Definition Graph_d.h:521
Dynamic arrays indexed with nodes.
Definition NodeArray.h:125
Class for the representation of nodes.
Definition Graph_d.h:177
internal::GraphObjectContainer< AdjElement > adjEntries
The container containing all entries in the adjacency list of this node.
Definition Graph_d.h:208
Singly linked lists.
Definition SList.h:179
Implementation of Dijkstra's single source shortest path algorithm.
void bfs_SPAP(const Graph &G, NodeArray< NodeArray< TCost > > &distance, TCost edgeCosts)
Computes all-pairs shortest paths in G using breadth-first serach (BFS).
void floydWarshall_SPAP(NodeArray< NodeArray< TCost > > &shortestPathMatrix, const Graph &G)
Computes all-pairs shortest paths in graph G using Floyd-Warshall's algorithm.
void bfs_SPSS(node s, const Graph &G, NodeArray< TCost > &distanceArray, TCost edgeCosts)
Computes single-source shortest paths from s in G using breadth-first search (BFS).
void dijkstra_SPSS(node s, const Graph &G, NodeArray< TCost > &shortestPathMatrix, const EdgeArray< TCost > &edgeCosts)
Computes single-source shortest paths from node s in G using Disjkstra's algorithm.
double dijkstra_SPAP(const GraphAttributes &GA, NodeArray< NodeArray< TCost > > &shortestPathMatrix)
Computes all-pairs shortest paths in GA using Dijkstra's algorithm.
static MultilevelBuilder * getDoubleFactoredZeroAdjustedMerger()
void updateMin(T &min, const T &newValue)
Stores the minimum of min and newValue in min.
Definition Math.h:98
The namespace for all OGDF objects.