126 int source_index = MT.
u->
index();
127 int target_index = MT.
v->
index();
129 if (source_index < target_index)
144 int source_index = MT.
u->
index();
145 int target_index = MT.
v->
index();
147 if (source_index < target_index)
190 for (
node v : terminals) {
194 bridges.
init(completeTerminalGraph);
204 if (triple.
u != triple.
v) {
217 int currentSource = triples.
front().u->index();
218 int currentTarget = triples.
front().v->index();
221 bridges.
init(completeTerminalGraph);
224 if (((*mtIt).u->index() == currentSource && (*mtIt).v->index() == currentTarget)
225 || ((*mtIt).u->index() == currentTarget && (*mtIt).v->index() == currentSource)) {
226 if ((*mtIt).value < (*minTriple).value) {
231 edge tmp = completeTerminalGraph.
newEdge(completeTerminalGraph.
copy((*minTriple).u),
232 completeTerminalGraph.
copy((*minTriple).v), (*minTriple).value);
233 bridges[tmp] = (*minTriple).bridge;
235 currentSource = (*mtIt).u->index();
236 currentTarget = (*mtIt).v->index();
241 if (minTriple.
valid()) {
242 edge tmp = completeTerminalGraph.
newEdge(completeTerminalGraph.
copy((*minTriple).u),
243 completeTerminalGraph.
copy((*minTriple).v), (*minTriple).value);
244 bridges[tmp] = (*minTriple).bridge;
257 if (mstPred[u] !=
nullptr) {
264 finalSteinerTree.
setEdge(bridge, e);
276 node currentTarget = finalSteinerTree.
copy(u);
277 if (!currentTarget) {
278 currentTarget = finalSteinerTree.
newNode(u);
282 while (e && finalSteinerTree.
chain(e).
empty()) {
283 if ((currentSource = finalSteinerTree.
copy(e->
opposite(finalSteinerTree.
original(currentTarget)))) ==
nullptr) {
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 {
node target() const
Returns the target node of the edge.
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
Serves as an interface for various methods to compute or approximate minimum Steiner trees on undirec...
edge newEdge(node u, node v, T weight)
Declaration of ogdf::MinSteinerTreeModule.
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.
bool valid() const
Returns true iff the iterator points to an element.
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)
Prunes nonterminal leaves 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)
T constructTerminalSpanningTreeUsingVoronoiRegions(EdgeWeightedGraphCopy< T > &terminalSpanningTree, const EdgeWeightedGraph< T > &graph, const List< node > &terminals)
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.
Definition of ogdf::Voronoi class template.
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.
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.