251 if (pred[u] ==
nullptr) {
252 dist[u] = numeric_limits<T>::max();
268 const T tmp = dist1[x] + dist2[x] + dist3[x];
270 && dist1[x] != numeric_limits<T>::max()
271 && dist2[x] != numeric_limits<T>::max()
272 && dist3[x] != numeric_limits<T>::max()) {
285 const double gain = save.
gain(u, v, w);
286 const double win =
calcWin(gain, minCost);
291 Triple<T> triple(u, v, w, center, minCost, win);
333 isNewTerminal[triple.
z()] =
true;
364 return gain / cost - 1.0;
422 isNewTerminal[v] =
true;
425 if (terminals.
size() >= 3) {
499 const node u = *it_u;
502 const node v = *it_v;
505 const node w = *it_w;
508 node center =
nullptr;
509 T minCost = numeric_limits<T>::max();
511 for (
node x : voronoi.nodesInRegion(u)) {
514 for (
node x : voronoi.nodesInRegion(v)) {
517 for (
node x : voronoi.nodesInRegion(w)) {
531 const node u = *it_u;
534 const node v = *it_v;
537 const node w = *it_w;
540 node center =
nullptr;
541 T minCost = numeric_limits<T>::max();
560 T best = numeric_limits<T>::max();
574 for (
node s : *m_terminals) {
576 ||
m_distance[s][v] == numeric_limits<T>::max()) {
581 if (!s1 || best < tmp) {
594 for (
node s : *m_terminals) {
597 ||
m_distance[s][v] == numeric_limits<T>::max()) {
607 if (!s2 || best < tmpWin) {
617 && best > maxTriple.
win()) {
629 if (maxTriple.
win() > 0) {
632 }
while (maxTriple.
win() > 0);
639 class TripleComparer {
642 return x2.
win() - x1.
win();
650 if (
calcWin(
double(save.
gain(t.s0(), t.s1(), t.s2())), t.cost()) > 0) {
void generateTriple(node u, node v, node w, node center, const T &minCost, const Save< T > &save)
Add a found triple to the triples list.
generate triples "on the fly", only usable with WinCalculation::absolute
const NodeArray< bool > * m_isTerminal
Incidence vector for terminal nodes.
Pass
Enables a heuristic version (for TG exhaustive and voronoi only)
This class behaves basically the same as SaveDynamic except that the update of the weighted graph is ...
WinCalculation winCalculation() const
Returns type of gain calculation currently in use.
void tripleOnDemand(Save< T > &save, NodeArray< bool > &isNewTerminal)
Contraction phase for algorithm generating triples on demand.
node newNode(node vOrig)
Creates a new node in the graph copy with original node vOrig.
keeps triples all the time
virtual ~MinSteinerTreeZelikovsky()
virtual T call(const EdgeWeightedGraph< T > &G, const List< node > &terminals, const NodeArray< bool > &isTerminal, EdgeWeightedGraphCopy< T > *&finalSteinerTree)
Builds a minimum Steiner tree given a weighted graph and a list of terminals.
This class serves as an interface for various methods to compute minimum or approximations of minimum...
Dynamically updatable weighted Tree for determining save edges via LCA computation.
edge newEdge(node u, node v, T weight)
#define OGDF_AUGMENT_STATICCOMPARER(type)
Add this macro to your class to turn it into a full static comparer.
const List< node > * m_terminals
List of terminal nodes.
Interface of Minimum Steiner Tree Algorithms.
virtual T gain(node u, node v, node w) const =0
Returns the gain (sum of the save edges) of a node triple.
heuristic: evaluate all triples, sort them descending by gain, traverse sorted triples once...
Extends the GraphCopy concept to weighted graphs.
void pass(Pass p)
Sets type of pass.
TripleReduction
Switches immediate triple dropping.
long numberOfGeneratedTriples() const
Returns the number of generated triples.
T makeMinimumSpanningTree(Graph &G, const EdgeArray< T > &weight)
Reduce a graph to its minimum spanning tree (MST) using Kruskal's algorithm.
void saveCalculation(SaveCalculation sv)
Sets type of save calculation.
node succ() const
Returns the successor in the list of all nodes.
MinSteinerTreeZelikovsky(WinCalculation wc=WinCalculation::absolute, TripleGeneration tg=TripleGeneration::voronoi, SaveCalculation sc=SaveCalculation::hybrid, TripleReduction tr=TripleReduction::on, Pass pass=Pass::multi)
virtual void update(const Triple< T > &t)=0
Updates the weighted tree data structure given a contracted triple.
This class implements the 11/6-approximation algorithm by Zelikovsky for the minimum Steiner tree pro...
WinCalculation
Choice of objective function.
Same as staticLCATree but each time a triple has been contracted the "weight tree" is updated dynamic...
ListIteratorBase< E, isConst > succ() const
Returns successor iterator.
void multiPass(Save< T > &save, NodeArray< bool > &isNewTerminal)
Contraction phase for the original version of the algorithm.
TripleReduction tripleReduction() const
Returns type of triple reduction currently in use.
A weighted tree as auxiliary data structure for contraction based algorithms.
Implementation of the staticLCATree option for calculating save edges in Zelikovsky's 11/6-approximat...
long m_tripleLookUps
Number of triple lookups.
void createEmpty(const Graph &wG)
TripleGeneration
Choice of triple generation.
bool m_ssspDistances
True iff we only compute SSSP from terminals instead of APSP for full component construction.
Computes Voronoi regions in an edge weighted graph.
TripleReduction m_tripleReduction
Chosen option for triple reduction.
const EdgeArray< T > & edgeWeights() const
WinCalculation m_winCalculation
Chosen option for gain calculation.
long numberOfContractedTriples() const
Returns the number of contracted triples.
void generateVoronoiTriples(const Save< T > &save)
Generates triples according to voronoi regions.
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.
void computeDistanceMatrix()
Computes the distance matrix for the original graph.
Class for the representation of edges.
const EdgeWeightedGraph< T > * m_originalGraph
The original edge-weighted graph.
Pass pass() const
Returns type of pass currently in use.
double calcWin(double gain, T cost) const
Calculate the win.
Pass m_pass
Chosen option for pass.
Class for the representation of nodes.
Encapsulates a pointer to a list element.
void tripleReduction(TripleReduction tr)
Sets type of triple reduction.
Definition of a Triple used in contraction-based approximation algorithm for the minimum Steiner tree...
T obtainFinalSteinerTree(const EdgeWeightedGraph< T > &G, const NodeArray< bool > &isTerminal, const NodeArray< bool > &isOriginalTerminal, EdgeWeightedGraphCopy< T > *&finalSteinerTree)
This class computes save edges recursively and stores for every node pair their save edge in a HashAr...
SaveCalculation saveCalculation() const
Returns type of save calculation currently in use.
Uses staticEnum for the triple generation phase (many queries) and dynamicLCATree during the contract...
const Graph & original() const
Returns a reference to the original graph.
void tripleGeneration(TripleGeneration tg)
Sets type of triple generation.
void generateInitialTerminalSpanningTree(EdgeWeightedGraphCopy< T > &steinerTree)
void markUnreachablesInDistanceMatrix(NodeArray< T > &dist, const NodeArray< edge > &pred)
Mark unreachable nodes in distance matrix by setting their distance to infinity (numeric_limits<T>::m...
virtual edge saveEdge(node u, node v) const =0
Returns the save edge between two nodes.
TripleGeneration tripleGeneration() const
Returns type of triple generation currently in use.
void forceAPSP(bool force=true)
For the 3-restricted case, it is sufficient to compute an SSSP from every terminal instead of doing a...
int size() const
Returns the number of elements in the list.
virtual T call(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 contractTriple(const Triple< T > &triple, Save< T > &save, NodeArray< bool > &isNewTerminal)
Contracts a triple and updates the save data structure.
Algorithms used by at least two functions of Steiner tree code or its internal helpers.
long m_triplesGenerated
Number of generated triples.
long m_triplesContracted
Number of contracted triples.
The namespace for all OGDF objects.
removes triples as soon as their gain is known to be non positive
Implementation of Voronoi regions in an EdgeWeightedGraph.
List< Triple< T > > m_triples
The list of triples during the algorithm.
void generateExhaustiveTriples(const Save< T > &save)
Generates all possible triples.
static void allPairShortestPathsStrict(const EdgeWeightedGraph< T > &G, const NodeArray< bool > &isTerminal, NodeArray< NodeArray< T > > &distance, NodeArray< NodeArray< edge > > &pred)
void onePass(Save< T > &save, NodeArray< bool > &isNewTerminal)
Contraction phase for the one pass heuristic.
NodeArray< NodeArray< T > > m_distance
The distance matrix.
Implementation of the staticTree option for calculating save edges in Zelikovsky's 11/6-approximation...
TripleGeneration m_tripleGeneration
Chosen option for triple generation.
void generateTriples(const Save< T > &save)
Generates triples according to the chosen option.
internal::GraphObjectContainer< NodeElement > nodes
The container containing all node objects.
long numberOfTripleLookUps() const
Returns the number of triple lookups during execution time.
This class serves as an interface for different approaches concerning the calculation of save edges...
static void singleSourceShortestPathsStrict(const EdgeWeightedGraph< T > &G, node source, const NodeArray< bool > &isTerminal, NodeArray< T > &distance, NodeArray< edge > &pred)
Builds a "weight tree" (save edges are inner nodes, terminals are leaves and searches save edges via ...
void updateBestCenter(node x, node ¢er, T &minCost, const NodeArray< T > &dist1, const NodeArray< T > &dist2, const NodeArray< T > &dist3) const
Update center node if it is the best so far.
This class represents a triple used by various contraction-based minimum Steiner tree approximations...
virtual T saveWeight(node u, node v) const =0
Returns the weight of the save edge between two nodes.
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
SaveCalculation m_saveCalculation
Chosen option for save calculation.
void winCalculation(WinCalculation wc)
Sets type of gain calculation.
Declaration of doubly linked lists and iterators.
SaveCalculation
Different methods for obtaining save edges.
Stores explicitly the save edge for every pair of terminals. Needs O(n^2) space but has fast query ti...