129 int source_index = MT.
u->
index();
130 int target_index = MT.
v->
index();
132 if (source_index < target_index)
147 int source_index = MT.
u->
index();
148 int target_index = MT.
v->
index();
150 if (source_index < target_index)
193 for (
node v : terminals) {
197 bridges.
init(completeTerminalGraph);
207 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;
260 if (mstPred[u] !=
nullptr) {
267 finalSteinerTree.
setEdge(bridge, e);
279 node currentTarget = finalSteinerTree.
copy(u);
280 if (!currentTarget) {
281 currentTarget = finalSteinerTree.
newNode(u);
285 while (e && finalSteinerTree.
chain(e).
empty()) {
286 if ((currentSource = finalSteinerTree.
copy(e->
opposite(finalSteinerTree.
original(currentTarget)))) ==
nullptr) {
290 newE = finalSteinerTree.
newEdge(currentSource, currentTarget, wG.
weight(e));
292 newE = finalSteinerTree.
newEdge(currentTarget, currentSource, wG.
weight(e));
294 finalSteinerTree.
setEdge(e, newE);
295 currentTarget = currentSource;
node target() const
Returns the target node of the edge.
Declaration of class GraphAttributes which extends a Graph by additional attributes.
node copy(node v) const
Returns the node in the graph copy corresponding to v.
node newNode(node vOrig)
Creates a new node in the graph copy with original node vOrig.
void init()
Reinitializes the array. Associates the array with no graph.
iterator pushBack(const E &x)
Adds element x at the end of the list.
T computeMinST(const Graph &G, const EdgeArray< T > &weight, EdgeArray< bool > &isInTree)
Computes a minimum spanning tree using Prim's algorithm.
void setEdge(edge eOrig, edge eCopy)
sets eOrig to be the corresponding original edge of eCopy and vice versa
This class serves as an interface for various methods to compute minimum or approximations of minimum...
edge newEdge(node u, node v, T weight)
Interface of Minimum Steiner Tree Algorithms.
iterator begin()
Returns an iterator to the first element of the list.
const EdgeArray< T > & edgeWeights() const
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...
Extends the GraphCopy concept to weighted graphs.
T makeMinimumSpanningTree(Graph &G, const EdgeArray< T > &weight)
Reduce a graph to its minimum spanning tree (MST) using Kruskal's algorithm.
Dynamic arrays indexed with edges.
void bucketSort(int l, int h, BucketFunc< E > &f)
Sorts the list using bucket sort.
T weight(const edge e) const
MehlhornTripleBucketMinFunc()
void createEmpty(const Graph &wG)
internal::GraphObjectContainer< EdgeElement > edges
The container containing all edge objects.
Computes Voronoi regions in an edge weighted graph.
const_reference front() const
Returns a const reference to the first element.
const EdgeArray< T > & edgeWeights() const
Doubly linked lists (maintaining the length of the list).
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.
node seed(node v) const
Returns the Voronoi seed of node v.
const List< edge > & chain(edge e) const
Returns the list of edges coresponding to edge e.
virtual ~MinSteinerTreeMehlhorn()
Class for the representation of edges.
Helper class to sort MehlhornTriples lexicographically.
T distance(node v) const
Returns the distance between v and its Voronoi seed.
Class for the representation of nodes.
Encapsulates a pointer to a list element.
node opposite(node v) const
Returns the adjacent node different from v.
Helper class to sort MehlhornTriples lexicographically.
const Graph & original() const
Returns a reference to the original graph.
static T pruneAllDanglingSteinerPaths(EdgeWeightedGraphCopy< T > &steinerTree, const NodeArray< bool > &isTerminal)
Prune Steiner nodes with degree 1 and their paths to terminal or branching nodes. ...
Abstract base class for bucket functions.
MehlhornTripleBucketMaxFunc()
int index() const
Returns the (unique) node index.
int getBucket(const MehlhornTriple &MT)
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.
int maxNodeIndex() const
Returns the largest used node index.
node source() const
Returns the source node of the edge.
The namespace for all OGDF objects.
Implementation of Voronoi regions in an EdgeWeightedGraph.
This class implements the Minimum Steiner Tree 2-approximation algorithm by Mehlhorn.
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.
int numberOfNodes() const
Returns the number of nodes in the graph.
internal::GraphObjectContainer< NodeElement > nodes
The container containing all node objects.
bool empty() const
Returns true iff the list is empty.
bool valid() const
Returns true iff the iterator points to an element.
Represents a triple as specified in the algorithms description (see paper)
int getBucket(const MehlhornTriple &MT)
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
edge predecessorEdge(node v) const
Returns the edge incident to v and its predecessor. Note that the predecessor of a terminal is nullpt...
Declaration of doubly linked lists and iterators.