45class 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);
204 triple.
u = voronoi.
seed(e->source());
205 triple.
v = voronoi.
seed(e->target());
206 if (triple.
u != triple.
v) {
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;
297namespace steiner_tree {
306 terminalSpanningTree);
Extends the GraphCopy concept to weighted graphs.
Includes declaration of graph class.
Declaration of doubly linked lists and iterators.
Declaration of ogdf::MinSteinerTreeModule.
Definition of ogdf::Voronoi class template.
Basic declarations, included by all source files.
Abstract base class for bucket functions.
Class for the representation of edges.
node opposite(node v) const
Returns the adjacent node different from v.
node target() const
Returns the target node of the edge.
node source() const
Returns the source node of the edge.
edge newEdge(node u, node v, T weight)
void setOriginalGraph(const Graph *wG) override
Re-initializes the copy using G (which might be null), but does not create any nodes or edges.
const EdgeArray< T > & edgeWeights() const
T weight(const edge e) const
const EdgeArray< T > & edgeWeights() const
node newNode(node vOrig)
Creates a new node in the graph copy with original node vOrig.
const Graph & original() const
Returns a reference to the original graph.
const List< edge > & chain(edge e) const
Returns the list of edges coresponding to edge e.
edge copy(edge e) const override
Returns the first edge in the list of edges corresponding to edge e.
void setEdge(edge eOrig, edge eCopy)
sets eOrig to be the corresponding original edge of eCopy and vice versa
int maxNodeIndex() const
Returns the largest used node index.
int numberOfNodes() const
Returns the number of nodes in the graph.
internal::GraphObjectContainer< NodeElement > nodes
The container containing all node objects.
internal::GraphObjectContainer< EdgeElement > edges
The container containing all edge objects.
Doubly linked lists (maintaining the length of the list).
iterator pushBack(const E &x)
Adds element x at the end of the list.
Encapsulates a pointer to a list element.
bool valid() const
Returns true iff the iterator points to an element.
ListIteratorBase< E, isConst, isReverse > succ() const
Returns successor iterator.
iterator begin()
Returns an iterator to the first element of the list.
const_reference front() const
Returns a const reference to the first element.
void bucketSort(int l, int h, BucketFunc< E > &f)
Sorts the list using bucket sort.
bool empty() const
Returns true iff the list is empty.
Helper class to sort MehlhornTriples lexicographically.
MehlhornTripleBucketMaxFunc()
int getBucket(const MehlhornTriple &MT)
Helper class to sort MehlhornTriples lexicographically.
MehlhornTripleBucketMinFunc()
int getBucket(const MehlhornTriple &MT)
This class implements the Minimum Steiner Tree 2-approximation algorithm by Mehlhorn.
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.
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...
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.
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.
virtual ~MinSteinerTreeMehlhorn()
Serves as an interface for various methods to compute or approximate minimum Steiner trees on undirec...
static T pruneAllDanglingSteinerPaths(EdgeWeightedGraphCopy< T > &steinerTree, const NodeArray< bool > &isTerminal)
Prunes nonterminal leaves and their paths to terminal or branching nodes.
Class for the representation of nodes.
int index() const
Returns the (unique) node index.
void init(const Base *base=nullptr)
Reinitializes the array. Associates the array with the matching registry of base.
Computes Voronoi regions in an edge-weighted graph.
T distance(node v) const
Returns the distance between v and its Voronoi seed.
node seed(node v) const
Returns the Voronoi seed of node v.
edge predecessorEdge(node v) const
Returns the edge incident to v and its predecessor. Note that the predecessor of a terminal is nullpt...
RegisteredArray for edges of a graph, specialized for EdgeArray<edge>.
RegisteredArray for nodes, edges and adjEntries of a graph.
Declaration of extended graph algorithms.
T makeMinimumSpanningTree(Graph &G, const EdgeArray< T > &weight)
Reduce a graph to its minimum spanning tree (MST) using Kruskal's algorithm.
T computeMinST(const Graph &G, const EdgeArray< T > &weight, EdgeArray< bool > &isInTree)
Computes a minimum spanning tree using Prim's algorithm.
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
T constructTerminalSpanningTreeUsingVoronoiRegions(EdgeWeightedGraphCopy< T > &terminalSpanningTree, const EdgeWeightedGraph< T > &graph, const List< node > &terminals)
The namespace for all OGDF objects.
Represents a triple as specified in the algorithms description (see paper)