This class implements preprocessing strategies for the Steiner tree problem. More...
#include <ogdf/graphalg/SteinerTreePreprocessing.h>
Public Member Functions | |
SteinerTreePreprocessing (const EdgeWeightedGraph< T > &wg, const List< node > &terminals, const NodeArray< bool > &isTerminal) | |
T | solve (MinSteinerTreeModule< T > &mst, EdgeWeightedGraphCopy< T > *&finalSteinerTree) |
A shortcut to get the solution of a reduced instance. | |
Methods on Steiner tree instances | |
These methods reference to the reduced (preprocessed) instance. | |
const EdgeWeightedGraph< T > & | getReducedGraph () const |
Returns the reduced form of the graph. | |
const List< node > & | getReducedTerminals () const |
Returns the list of the terminals corresponding to the reduced graph. | |
void | shuffleReducedTerminals () |
Shuffles the list of reduced terminals. This can have an effect on some tests. | |
const NodeArray< bool > & | getReducedIsTerminal () const |
Returns the NodeArray<bool> isTerminal corresponding to the reduced graph. | |
Methods for Steiner tree solutions | |
These methods allow retrieval of solution information about the original instance using a solution of a preprocessed instance. | |
T | costEdgesAlreadyInserted () const |
Returns the cost of the edges already inserted in solution during the reductions. | |
void | computeOriginalSolution (const EdgeWeightedGraphCopy< T > &reducedGraphSolution, EdgeWeightedGraphCopy< T > &correspondingOriginalSolution) |
Computes the solution for the original graph, given a solution on the reduction. | |
Combined reduction sets | |
Each method applies several reductions iteratively. | |
bool | reduceTrivial () |
Apply trivial (hence amazingly fast) reductions iteratively, that is degree2Test(), makeSimple(), deleteLeaves(). | |
bool | reduceFast () |
Apply fast reductions iteratively (includes trivial reductions). | |
bool | reduceFastAndDualAscent () |
Apply fast reductions and the dual-ascent-based tests iteratively. | |
Single reductions | |
Each method applies a single reduction to the Steiner tree instance. | |
bool | deleteLeaves () |
Deletes the leaves of the graph. | |
bool | makeSimple () |
Deletes parallel edges keeping only the minimum cost one, and deletes self-loops. | |
bool | deleteComponentsWithoutTerminals () |
Deletes connected components with no terminals. | |
bool | leastCostTest () |
Performs a least cost test [DV89] computing the whole shortest path matrix. | |
bool | degree2Test () |
deletes degree-2 nodes and replaces them with one edge with the adjacent edges' sum | |
bool | PTmTest (const int k=3) |
"Paths with many terminals" test, efficient on paths with many terminals. | |
bool | terminalDistanceTest () |
Simple terminal distance test [PV01]. | |
bool | longEdgesTest () |
Long-Edges test from [DV89]. | |
bool | NTDkTest (const int maxTestedDegree=5, const int k=3) |
Non-terminals of degree k test [DV89, PV01]. | |
bool | nearestVertexTest () |
Nearest vertex test using Voronoi regions [DV89, PV01]. | |
bool | shortLinksTest () |
Short links test using Voronoi regions [PV01]. | |
bool | lowerBoundBasedTest (T upperBound) |
Computes for each non-terminal a lower bound of the cost of the minimum Steiner tree containing it. | |
bool | lowerBoundBasedTest () |
Like lowerBoundBasedTest(T upperBound) but the upper bound is computed by computeMinSteinerTreeUpperBound. | |
bool | dualAscentBasedTest (int repetitions, T upperBound) |
Like lowerBoundBasedTest(T upperBound) but uses ogdf::SteinerTreeLowerBoundDualAscent to compute lower bounds. | |
bool | dualAscentBasedTest (int repetitions=1) |
Like dualAscentBasedTest(int repetitions, T upperBound) but the upper bound is computed by computeMinSteinerTreeUpperBound. | |
bool | reachabilityTest (int maxDegreeTest=0, const int k=3) |
Performs a reachability test [DV89]. | |
bool | cutReachabilityTest () |
Performs a cut reachability test [DV89]. | |
Miscellaneous methods | |
These methods allow retrieval of solution information about the original instance using a solution of a preprocessed instance. | |
void | setCostUpperBoundAlgorithm (MinSteinerTreeModule< T > *pMinSteinerTreeModule) |
Set the module option for the algorithm used for computing the MinSteinerTree cost upper bound. | |
Static Public Member Functions | |
static bool | repeat (std::function< bool()> f) |
Auxiliary function: Repeats a function until it returns false (used for iteratively applying reductions) | |
Protected Member Functions | |
bool | addEdgesToSolution (const List< edge > &edgesToBeAddedInSolution) |
The function adds a set of edges in the solution. | |
template<typename TWhat , typename TWhatArray > | |
void | addNew (TWhat x, const std::vector< node > &replacedNodes, const std::vector< edge > &replacedEdges, bool deleteReplacedElements, TWhatArray &whatSonsListIndex) |
Update internal data structures to let a (new) node or edge represent replaced nodes and/or edges. | |
void | addNewEdge (edge e, const std::vector< node > &replacedNodes, const std::vector< edge > &replacedEdges, bool deleteReplacedElements) |
The function is called after a new edge is added to the copy graph during the reductions. | |
void | addNewNode (node v, const std::vector< node > &replacedNodes, const std::vector< edge > &replacedEdges, bool deleteReplacedElements) |
Calls addNew() for a node. | |
void | addToSolution (const int listIndex, Array< bool, int > &isInSolution) const |
Helper method for computeOriginalSolution. | |
T | computeBottleneckDistance (node x, node y, const EdgeWeightedGraphCopy< T > &tprime, const steiner_tree::HeavyPathDecomposition< T > &tprimeHPD, const NodeArray< List< std::pair< node, T > > > &closestTerminals) const |
Heuristic computation [PV01] of the bottleneck Steiner distance between two nodes in a graph. | |
void | computeClosestKTerminals (const int k, NodeArray< List< std::pair< node, T > > > &closestTerminals) const |
Computes for every non-terminal the closest k terminals such that there is no other terminal on the path. | |
T | computeMinSteinerTreeUpperBound () const |
T | computeMinSteinerTreeUpperBound (EdgeWeightedGraphCopy< T > *&finalSteinerTree) const |
template<typename LAMBDA > | |
void | computeOptimalTerminals (node v, LAMBDA dist, node &optimalTerminal1, node &optimalTerminal2, NodeArray< T > &distance) const |
Compute first and second best terminals according to function dist . | |
void | computeRadiusOfTerminals (NodeArray< T > &terminalRadius) const |
Compute radius of terminals. | |
T | computeRadiusSum () const |
Compute the sum of all radii except the two largest. | |
void | computeShortestPathMatrix (NodeArray< NodeArray< T > > &shortestPath) const |
Computes the shortest path matrix corresponding to the m_copyGraph. | |
bool | deleteEdgesAboveUpperBound (const EdgeArray< T > &lowerBoundWithEdge, const T upperBound) |
Deletes the edges whose lowerBoundWithEdge exceeds upperBound. | |
bool | deleteNodesAboveUpperBound (const NodeArray< T > &lowerBoundWithNode, const T upperBound) |
Deletes the nodes whose lowerBoundWithNode exceeds upperBound. | |
void | deleteSteinerDegreeTwoNode (node v, const EdgeWeightedGraphCopy< T > &tprime, const steiner_tree::HeavyPathDecomposition< T > &tprimeHPD, const NodeArray< List< std::pair< node, T > > > &closestTerminals) |
Deletes a node that is known to have degree 2 in at least one minimum Steiner tree. | |
void | findClosestNonTerminals (node source, List< node > &reachedNodes, NodeArray< T > &distance, T maxDistance, int expandedEdges) const |
Heuristic approach to computing the closest non-terminals for one node, such that there is no terminal on the path from it to a "close non-terminal" and a maximum constant number of expandedEdges are expanded during the computation. | |
void | findTwoMinimumCostEdges (node v, edge &first, edge &second) const |
Finds the first and second smallest edges incident to v . | |
void | floydWarshall (NodeArray< NodeArray< T > > &shortestPath) const |
Applies the Floyd-Warshall algorithm on the m_copyGraph. The shortestPath matrix has to be already initialized. | |
void | markSuccessors (node currentNode, const Voronoi< T > &voronoiRegions, NodeArray< bool > &isSuccessorOfMinCostEdge) const |
Mark successors of currentNode in its shortest-path tree in voronoiRegions . | |
void | recomputeTerminalsList () |
Used by reductions to recompute the m_copyTerminals list, according to m_copyIsTerminal; useful when "online" updates to m_copyTerminals are inefficient. | |
Protected Attributes | |
EdgeWeightedGraph< T > | m_copyGraph |
Copy of the original graph; this copy will actually be reduced. | |
NodeArray< bool > | m_copyIsTerminal |
The reduced form of isTerminal. | |
List< node > | m_copyTerminals |
The reduced form of terminals. | |
T | m_costAlreadyInserted |
The cost of the already inserted in solution edges. | |
std::unique_ptr< MinSteinerTreeModule< T > > | m_costUpperBoundAlgorithm |
Algorithm used for computing the upper bound for the cost of a minimum Steiner tree. | |
EdgeArray< int > | m_edgeSonsListIndex |
See m_nodeSonsListIndex but for edges. | |
const EpsilonTest | m_eps |
NodeArray< int > | m_nodeSonsListIndex |
It contains for each node an index i. | |
const EdgeWeightedGraph< T > & | m_origGraph |
Const reference to the original graph. | |
const NodeArray< bool > & | m_origIsTerminal |
Const reference to the original isTerminal. | |
const List< node > & | m_origTerminals |
Const reference to the original list of terminals. | |
std::vector< std::vector< int > > | m_sonsList |
List with lists (corresponding to nodes and containing the indexes of their sons) | |
This class implements preprocessing strategies for the Steiner tree problem.
It contains a subset of strategies from [DV89] and [PV01].
References:
Definition at line 89 of file SteinerTreePreprocessing.h.
ogdf::SteinerTreePreprocessing< T >::SteinerTreePreprocessing | ( | const EdgeWeightedGraph< T > & | wg, |
const List< node > & | terminals, | ||
const NodeArray< bool > & | isTerminal | ||
) |
wg | The initial graph that will be reduced. |
terminals | The list of terminals of the initial graph. |
isTerminal | True if a node is terminal in the initial graph, false otherwise. |
Definition at line 608 of file SteinerTreePreprocessing.h.
|
protected |
The function adds a set of edges in the solution.
It assumes that after the insertion of one edge the next ones can still be added.
edgesToBeAddedInSolution | The list containing the edges that are going to be added in solution. |
Definition at line 1391 of file SteinerTreePreprocessing.h.
|
protected |
Update internal data structures to let a (new) node or edge represent replaced nodes and/or edges.
x | The node or edge that represents the replaced entities. Note that its existing information will be overwritten. |
replacedNodes | The deleted nodes that have to appear in solution iff x appears. |
replacedEdges | The deleted edges that have to appear in solution iff x appears. |
deleteReplacedElements | True iff the replaced nodes and edges should be deleted. |
whatSonsListIndex | An internal data structure (depending on whether you wish to use nodes or edges) |
Definition at line 654 of file SteinerTreePreprocessing.h.
|
inlineprotected |
The function is called after a new edge is added to the copy graph during the reductions.
Definition at line 509 of file SteinerTreePreprocessing.h.
|
inlineprotected |
Calls addNew() for a node.
Definition at line 503 of file SteinerTreePreprocessing.h.
|
protected |
Helper method for computeOriginalSolution.
Definition at line 679 of file SteinerTreePreprocessing.h.
|
protected |
Heuristic computation [PV01] of the bottleneck Steiner distance between two nodes in a graph.
Definition at line 788 of file SteinerTreePreprocessing.h.
|
protected |
Computes for every non-terminal the closest k terminals such that there is no other terminal on the path.
k | The maximum number of close terminals to be computed for every non-terminal node. |
closestTerminals | A reference to a NodeArray of lists where the solution will be saved. |
Definition at line 1135 of file SteinerTreePreprocessing.h.
|
inlineprotected |
Definition at line 540 of file SteinerTreePreprocessing.h.
|
inlineprotected |
Definition at line 533 of file SteinerTreePreprocessing.h.
|
protected |
Compute first and second best terminals according to function dist
.
Definition at line 1833 of file SteinerTreePreprocessing.h.
void ogdf::SteinerTreePreprocessing< T >::computeOriginalSolution | ( | const EdgeWeightedGraphCopy< T > & | reducedGraphSolution, |
EdgeWeightedGraphCopy< T > & | correspondingOriginalSolution | ||
) |
Computes the solution for the original graph, given a solution on the reduction.
reducedGraphSolution | The already computed solution on the reduced graph. |
correspondingOriginalSolution | The solution on the original graph, corresponding to the reducedGraphSolution. |
Definition at line 692 of file SteinerTreePreprocessing.h.
|
protected |
Compute radius of terminals.
Definition at line 1534 of file SteinerTreePreprocessing.h.
|
protected |
Compute the sum of all radii except the two largest.
Definition at line 1717 of file SteinerTreePreprocessing.h.
|
inlineprotected |
Computes the shortest path matrix corresponding to the m_copyGraph.
Definition at line 947 of file SteinerTreePreprocessing.h.
|
inline |
Returns the cost of the edges already inserted in solution during the reductions.
Definition at line 213 of file SteinerTreePreprocessing.h.
bool ogdf::SteinerTreePreprocessing< T >::cutReachabilityTest | ( | ) |
Performs a cut reachability test [DV89].
Definition at line 1864 of file SteinerTreePreprocessing.h.
bool ogdf::SteinerTreePreprocessing< T >::degree2Test | ( | ) |
deletes degree-2 nodes and replaces them with one edge with the adjacent edges' sum
Definition at line 980 of file SteinerTreePreprocessing.h.
bool ogdf::SteinerTreePreprocessing< T >::deleteComponentsWithoutTerminals | ( | ) |
Deletes connected components with no terminals.
Definition at line 1009 of file SteinerTreePreprocessing.h.
|
protected |
Deletes the edges whose lowerBoundWithEdge exceeds upperBound.
Definition at line 1703 of file SteinerTreePreprocessing.h.
bool ogdf::SteinerTreePreprocessing< T >::deleteLeaves | ( | ) |
Deletes the leaves of the graph.
The path to the terminal is included into the solution if the leaf is a terminal.
Definition at line 812 of file SteinerTreePreprocessing.h.
|
protected |
Deletes the nodes whose lowerBoundWithNode exceeds upperBound.
Definition at line 1558 of file SteinerTreePreprocessing.h.
|
protected |
Deletes a node that is known to have degree 2 in at least one minimum Steiner tree.
Definition at line 723 of file SteinerTreePreprocessing.h.
bool ogdf::SteinerTreePreprocessing< T >::dualAscentBasedTest | ( | int | repetitions, |
T | upperBound | ||
) |
Like lowerBoundBasedTest(T upperBound) but uses ogdf::SteinerTreeLowerBoundDualAscent to compute lower bounds.
See [PV01, Section 3.2.2 on DA].
Definition at line 1686 of file SteinerTreePreprocessing.h.
|
inline |
Like dualAscentBasedTest(int repetitions, T upperBound) but the upper bound is computed by computeMinSteinerTreeUpperBound.
Definition at line 439 of file SteinerTreePreprocessing.h.
|
protected |
Heuristic approach to computing the closest non-terminals for one node, such that there is no terminal on the path from it to a "close non-terminal" and a maximum constant number of expandedEdges are expanded during the computation.
source | The source node. |
reachedNodes | A list where the reached nodes are saved. |
distance | A NodeArray where the minimum found distance is saved, infinity where no path is found. |
maxDistance | Constant such that: any distance > maxDistance is not of interest. |
expandedEdges | The maximum number of edges expanded during the computation. |
Definition at line 1059 of file SteinerTreePreprocessing.h.
|
protected |
Finds the first
and second
smallest edges incident to v
.
Definition at line 1365 of file SteinerTreePreprocessing.h.
|
protected |
Applies the Floyd-Warshall algorithm on the m_copyGraph. The shortestPath matrix has to be already initialized.
Definition at line 922 of file SteinerTreePreprocessing.h.
|
inline |
Returns the reduced form of the graph.
Definition at line 194 of file SteinerTreePreprocessing.h.
|
inline |
Returns the NodeArray<bool> isTerminal corresponding to the reduced graph.
Definition at line 203 of file SteinerTreePreprocessing.h.
|
inline |
Returns the list of the terminals corresponding to the reduced graph.
Definition at line 197 of file SteinerTreePreprocessing.h.
bool ogdf::SteinerTreePreprocessing< T >::leastCostTest | ( | ) |
Performs a least cost test [DV89] computing the whole shortest path matrix.
Definition at line 958 of file SteinerTreePreprocessing.h.
bool ogdf::SteinerTreePreprocessing< T >::longEdgesTest | ( | ) |
Long-Edges test from [DV89].
Definition at line 1100 of file SteinerTreePreprocessing.h.
|
inline |
Like lowerBoundBasedTest(T upperBound) but the upper bound is computed by computeMinSteinerTreeUpperBound.
Definition at line 420 of file SteinerTreePreprocessing.h.
bool ogdf::SteinerTreePreprocessing< T >::lowerBoundBasedTest | ( | T | upperBound | ) |
Computes for each non-terminal a lower bound of the cost of the minimum Steiner tree containing it.
Deletes the nodes and edges whose corresponding lower bounds exceed the upperBound
. See [PV01, Observations 3.5, 3.6, and 3.8].
Definition at line 1573 of file SteinerTreePreprocessing.h.
bool ogdf::SteinerTreePreprocessing< T >::makeSimple | ( | ) |
Deletes parallel edges keeping only the minimum cost one, and deletes self-loops.
Definition at line 884 of file SteinerTreePreprocessing.h.
|
protected |
Mark successors of currentNode
in its shortest-path tree in voronoiRegions
.
Definition at line 1347 of file SteinerTreePreprocessing.h.
bool ogdf::SteinerTreePreprocessing< T >::nearestVertexTest | ( | ) |
Nearest vertex test using Voronoi regions [DV89, PV01].
Definition at line 1410 of file SteinerTreePreprocessing.h.
bool ogdf::SteinerTreePreprocessing< T >::NTDkTest | ( | const int | maxTestedDegree = 5 , |
const int | k = 3 |
||
) |
Non-terminals of degree k test [DV89, PV01].
maxTestedDegree | The reduction test is applied to all nodes with degree >= 3 and <= this value |
k | The parameter k for the internal PTmTest, applied to avoid adding useless edges |
Definition at line 1261 of file SteinerTreePreprocessing.h.
bool ogdf::SteinerTreePreprocessing< T >::PTmTest | ( | const int | k = 3 | ) |
"Paths with many terminals" test, efficient on paths with many terminals.
Heuristic approach, as suggested in [PV01].
k | Consider the k nearest terminals to all non-terminals in the heuristic approach |
Definition at line 1231 of file SteinerTreePreprocessing.h.
bool ogdf::SteinerTreePreprocessing< T >::reachabilityTest | ( | int | maxDegreeTest = 0 , |
const int | k = 3 |
||
) |
Performs a reachability test [DV89].
maxDegreeTest | Ignores nodes with degree larger than this. Ignores no node if non-positive (default). |
k | The parameter k for the internal PTmTest, applied to avoid adding useless edges |
Definition at line 1742 of file SteinerTreePreprocessing.h.
|
protected |
Used by reductions to recompute the m_copyTerminals list, according to m_copyIsTerminal; useful when "online" updates to m_copyTerminals are inefficient.
Definition at line 778 of file SteinerTreePreprocessing.h.
|
inline |
Apply fast reductions iteratively (includes trivial reductions).
Definition at line 243 of file SteinerTreePreprocessing.h.
|
inline |
Apply fast reductions and the dual-ascent-based tests iteratively.
Definition at line 288 of file SteinerTreePreprocessing.h.
|
inline |
Apply trivial (hence amazingly fast) reductions iteratively, that is degree2Test(), makeSimple(), deleteLeaves().
Definition at line 232 of file SteinerTreePreprocessing.h.
|
inlinestatic |
Auxiliary function: Repeats a function until it returns false (used for iteratively applying reductions)
Definition at line 480 of file SteinerTreePreprocessing.h.
|
inline |
Set the module option for the algorithm used for computing the MinSteinerTree cost upper bound.
Definition at line 473 of file SteinerTreePreprocessing.h.
bool ogdf::SteinerTreePreprocessing< T >::shortLinksTest | ( | ) |
Short links test using Voronoi regions [PV01].
Definition at line 1482 of file SteinerTreePreprocessing.h.
|
inline |
Shuffles the list of reduced terminals. This can have an effect on some tests.
Definition at line 200 of file SteinerTreePreprocessing.h.
|
inline |
A shortcut to get the solution of a reduced instance.
Note that you have to apply reductions first, e.g., reduceFast() or reduceFastAndDualAscent().
mst | A MinSteinerTreeModule<T> instance that is used to solve the problem |
finalSteinerTree | A pointer to the final Steiner tree (has to be freed) |
Definition at line 132 of file SteinerTreePreprocessing.h.
bool ogdf::SteinerTreePreprocessing< T >::terminalDistanceTest | ( | ) |
Simple terminal distance test [PV01].
Definition at line 1033 of file SteinerTreePreprocessing.h.
|
protected |
Copy of the original graph; this copy will actually be reduced.
Definition at line 96 of file SteinerTreePreprocessing.h.
|
protected |
The reduced form of isTerminal.
Definition at line 98 of file SteinerTreePreprocessing.h.
|
protected |
The reduced form of terminals.
Definition at line 97 of file SteinerTreePreprocessing.h.
|
protected |
The cost of the already inserted in solution edges.
Definition at line 100 of file SteinerTreePreprocessing.h.
|
protected |
Algorithm used for computing the upper bound for the cost of a minimum Steiner tree.
Definition at line 113 of file SteinerTreePreprocessing.h.
|
protected |
See m_nodeSonsListIndex but for edges.
Definition at line 109 of file SteinerTreePreprocessing.h.
|
protected |
Definition at line 94 of file SteinerTreePreprocessing.h.
|
protected |
It contains for each node an index i.
If i is non-negative, m_sonsList[i] is a list containing the indices of the node's sons. A son of the current node is a node or edge that must appear in the solution if the current node appears. If i is negative, it means that the current node is original (i.e., was not created by the applied reductions). The corresponding node is the (-i)-th node of m_origGraph
Definition at line 102 of file SteinerTreePreprocessing.h.
|
protected |
Const reference to the original graph.
Definition at line 91 of file SteinerTreePreprocessing.h.
|
protected |
Const reference to the original isTerminal.
Definition at line 93 of file SteinerTreePreprocessing.h.
|
protected |
Const reference to the original list of terminals.
Definition at line 92 of file SteinerTreePreprocessing.h.
|
protected |
List with lists (corresponding to nodes and containing the indexes of their sons)
Definition at line 110 of file SteinerTreePreprocessing.h.