|
Open Graph Drawing Framework |
v. 2023.09 (Elderberry)
|
|
|
Go to the documentation of this file.
45 class EdgeWeightedGraph;
131 int source_index = MT.
u->
index();
132 int target_index = MT.
v->
index();
134 if (source_index < target_index) {
150 int source_index = MT.
u->
index();
151 int target_index = MT.
v->
index();
153 if (source_index < target_index) {
168 Voronoi<T> voronoi(G, G.edgeWeights(), terminals);
170 calculateCompleteGraph(G, terminals, voronoi, bridges, completeTerminalGraph);
178 reinsertShortestPaths(completeTerminalGraph, voronoi, mstPred, bridges, *finalSteinerTree, G);
192 for (
node v : terminals) {
193 completeTerminalGraph.
newNode(v);
196 bridges.
init(completeTerminalGraph);
202 for (
edge e : wG.edges) {
206 if (triple.
u != triple.
v) {
217 triples.bucketSort(0, wG.maxNodeIndex(), mtbMax);
218 triples.bucketSort(0, wG.maxNodeIndex(), mtbMin);
220 int currentSource = triples.front().u->index();
221 int currentTarget = triples.front().v->index();
224 bridges.
init(completeTerminalGraph);
227 if (((*mtIt).u->index() == currentSource && (*mtIt).v->index() == currentTarget)
228 || ((*mtIt).u->index() == currentTarget && (*mtIt).v->index() == currentSource)) {
229 if ((*mtIt).value < (*minTriple).value) {
234 edge tmp = completeTerminalGraph.
newEdge(completeTerminalGraph.
copy((*minTriple).u),
235 completeTerminalGraph.
copy((*minTriple).v), (*minTriple).value);
236 bridges[tmp] = (*minTriple).bridge;
238 currentSource = (*mtIt).u->index();
239 currentTarget = (*mtIt).v->index();
244 if (minTriple.
valid()) {
245 edge tmp = completeTerminalGraph.
newEdge(completeTerminalGraph.
copy((*minTriple).u),
246 completeTerminalGraph.
copy((*minTriple).v), (*minTriple).value);
247 bridges[tmp] = (*minTriple).bridge;
255 for (
node u : completeTerminalGraph.
nodes) {
256 if (mstPred[u] !=
nullptr) {
257 edge bridge = bridges[mstPred[u]];
260 insertPath(v, voronoi, finalSteinerTree, wG);
261 insertPath(w, voronoi, finalSteinerTree, wG);
264 finalSteinerTree.
setEdge(bridge, e);
273 node currentTarget = finalSteinerTree.
copy(u);
274 if (!currentTarget) {
275 currentTarget = finalSteinerTree.
newNode(u);
279 while (e && finalSteinerTree.
chain(e).empty()) {
280 if ((currentSource = finalSteinerTree.
copy(
287 newE = finalSteinerTree.
newEdge(currentSource, currentTarget, wG.
weight(e));
289 newE = finalSteinerTree.
newEdge(currentTarget, currentSource, wG.
weight(e));
291 finalSteinerTree.
setEdge(e, newE);
292 currentTarget = currentSource;
297 namespace steiner_tree {
306 terminalSpanningTree);
The namespace for all OGDF objects.
Includes declaration of graph class.
Helper class to sort MehlhornTriples lexicographically.
This class implements the Minimum Steiner Tree 2-approximation algorithm by Mehlhorn.
MehlhornTripleBucketMinFunc()
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
T weight(const edge e) const
int index() const
Returns the (unique) node index.
void setOriginalGraph(const Graph *wG) override
Associates the graph copy with G, but does not create any nodes or edges.
Declaration of extended graph algorithms.
Computes Voronoi regions in an edge-weighted graph.
Represents a triple as specified in the algorithms description (see paper)
T computeMinST(const Graph &G, const EdgeArray< T > &weight, EdgeArray< bool > &isInTree)
Computes a minimum spanning tree using Prim's algorithm.
static void calculateCompleteGraph(const EdgeWeightedGraph< T > &wG, const List< node > &terminals, const Voronoi< T > &voronoi, EdgeArray< edge > &bridges, EdgeWeightedGraphCopy< T > &completeTerminalGraph)
Builds a complete terminal graph.
bool valid() const
Returns true iff the iterator points to an element.
edge newEdge(node u, node v, T weight)
edge predecessorEdge(node v) const
Returns the edge incident to v and its predecessor. Note that the predecessor of a terminal is nullpt...
Abstract base class for bucket functions.
T constructTerminalSpanningTreeUsingVoronoiRegions(EdgeWeightedGraphCopy< T > &terminalSpanningTree, const EdgeWeightedGraph< T > &graph, const List< node > &terminals)
Extends the GraphCopy concept to weighted graphs.
Serves as an interface for various methods to compute or approximate minimum Steiner trees on undirec...
Declaration of ogdf::MinSteinerTreeModule.
void reinsertShortestPaths(EdgeWeightedGraphCopy< T > &completeTerminalGraph, const Voronoi< T > &voronoi, const NodeArray< edge > &mstPred, const EdgeArray< edge > &bridges, EdgeWeightedGraphCopy< T > &finalSteinerTree, const EdgeWeightedGraph< T > &wG)
Swaps an edge in the complete terminal graph with the corresponding shortest path in the original gra...
internal::GraphObjectContainer< NodeElement > nodes
The container containing all node objects.
MehlhornTripleBucketMaxFunc()
int numberOfNodes() const
Returns the number of nodes in the graph.
static T pruneAllDanglingSteinerPaths(EdgeWeightedGraphCopy< T > &steinerTree, const NodeArray< bool > &isTerminal)
Prunes nonterminal leaves and their paths to terminal or branching nodes.
const List< edge > & chain(edge e) const
Returns the list of edges coresponding to edge e.
const EdgeArray< T > & edgeWeights() const
Definition of ogdf::Voronoi class template.
int getBucket(const MehlhornTriple &MT)
node source() const
Returns the source node of the edge.
node newNode(node vOrig)
Creates a new node in the graph copy with original node vOrig.
Doubly linked lists (maintaining the length of the list).
RegisteredArray for nodes, edges and adjEntries of a graph.
int getBucket(const MehlhornTriple &MT)
edge copy(edge e) const override
Returns the first edge in the list of edges corresponding to edge e.
virtual T computeSteinerTree(const EdgeWeightedGraph< T > &G, const List< node > &terminals, const NodeArray< bool > &isTerminal, EdgeWeightedGraphCopy< T > *&finalSteinerTree) override
Builds a minimum Steiner tree given a weighted graph and a list of terminals.
void setEdge(edge eOrig, edge eCopy)
sets eOrig to be the corresponding original edge of eCopy and vice versa
T distance(node v) const
Returns the distance between v and its Voronoi seed.
Basic declarations, included by all source files.
const EdgeArray< T > & edgeWeights() const
T makeMinimumSpanningTree(Graph &G, const EdgeArray< T > &weight)
Reduce a graph to its minimum spanning tree (MST) using Kruskal's algorithm.
node opposite(node v) const
Returns the adjacent node different from v.
Class for the representation of edges.
Declaration of doubly linked lists and iterators.
void init(const Graph *base=nullptr)
Reinitializes the array. Associates the array with the matching registry of base.
void insertPath(node u, const Voronoi< T > &voronoi, EdgeWeightedGraphCopy< T > &finalSteinerTree, const EdgeWeightedGraph< T > &wG)
Inserts a shortest path corresponding to an edge in the complete terminal graph.
Encapsulates a pointer to a list element.
Helper class to sort MehlhornTriples lexicographically.
virtual ~MinSteinerTreeMehlhorn()
node target() const
Returns the target node of the edge.
Class for the representation of nodes.
node seed(node v) const
Returns the Voronoi seed of node v.
iterator pushBack(const E &x)
Adds element x at the end of the list.
const Graph & original() const
Returns a reference to the original graph.
RegisteredArray for edges of a graph, specialized for EdgeArray<edge>.