Implementation of Shore, Foulds and Gibbons exact branch and bound algorithm for solving Steiner tree problems. More...
#include <ogdf/graphalg/MinSteinerTreeShore.h>
Public Member Functions | |
MinSteinerTreeShore () | |
virtual | ~MinSteinerTreeShore () |
Public Member Functions inherited from ogdf::MinSteinerTreeModule< T > | |
virtual | ~MinSteinerTreeModule () |
Do nothing on destruction. More... | |
virtual T | call (const EdgeWeightedGraph< T > &G, const List< node > &terminals, const NodeArray< bool > &isTerminal, EdgeWeightedGraphCopy< T > *&finalSteinerTree) |
Calls the Steiner tree algorithm for nontrivial cases but handles trivial cases directly. More... | |
Protected Member Functions | |
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. More... | |
Protected Attributes | |
const T | MAX_WEIGHT |
Private Member Functions | |
T | bnbInternal (T prevCost, List< edge > ¤tEdges) |
Calculates the optimal Steinter tree recursivly. More... | |
edge | deleteEdge (edge e) |
Removes the specified edge from the graph. More... | |
edge | determineBranchingEdge (T prevCost) const |
Decides which edge to branch on. More... | |
bool | isTerminal (const node v) const |
Returns whether this node is a terminal or a Steiner node. More... | |
edge | lookupEdge (const node u, const node v) const |
Retrieves the edge incident to both node u and v. More... | |
void | moveSource (edge e, node v) |
Moves the source of the edge to the specified node. More... | |
void | moveTarget (edge e, node v) |
Moves the target of the edge to the specified node. More... | |
edge | newEdge (node source, node target, const edge originalEdge) |
Creates a new edge. More... | |
void | printSVG () |
Prints the current recursion status as a SVG image of the current reduced STP. More... | |
void | setEdgeLookup (const node u, const node v, const edge e) |
Sets the edge incident to both node u and v. More... | |
void | setTerminal (const node v, bool makeTerminal) |
Updates the status of the given node to either terminal or Steiner node. More... | |
T | solve (List< edge > &chosenEdges) |
Solves the current STP instance. More... | |
bool | validateMapping () const |
Used to validate the current mapping of edges to orignal edges Used solely for debugging. More... | |
T | weightOf (edge e) const |
Returns the cost of the specified edge. More... | |
Private Attributes | |
List< edge > | m_chosenEdges |
Array2D< edge > | m_edges |
Graph | m_graph |
EdgeArray< edge > | m_mapping |
const EdgeWeightedGraph< T > * | m_originalGraph |
const List< node > * | m_originalTerminals |
int | m_recursionDepth |
std::unique_ptr< NodeSet<> > | m_terminals |
T | m_upperBound |
Additional Inherited Members | |
Static Public Member Functions inherited from ogdf::MinSteinerTreeModule< T > | |
static void | getNonterminals (ArrayBuffer< node > &nonterminals, const EdgeWeightedGraph< T > &G, const NodeArray< bool > &isTerminal) |
Generates a list (as ArrayBuffer<node>) of all nonterminals. More... | |
static void | getTerminals (List< node > &terminals, const EdgeWeightedGraph< T > &G, const NodeArray< bool > &isTerminal) |
Generates a list (as List<node>) of all terminals. More... | |
static bool | isQuasiBipartite (const EdgeWeightedGraph< T > &G, const NodeArray< bool > &isTerminal) |
Checks in O(n + m) time if a given Steiner tree problem instance is quasi-bipartite. More... | |
static bool | isSteinerTree (const EdgeWeightedGraph< T > &G, const List< node > &terminals, const NodeArray< bool > &isTerminal, const EdgeWeightedGraphCopy< T > &steinerTree) |
Checks in O(n) time if a given tree is acually a Steiner Tree. More... | |
static void | sortTerminals (List< node > &terminals) |
Sort terminals by index. More... | |
static T | pruneAllDanglingSteinerPaths (EdgeWeightedGraphCopy< T > &steinerTree, const NodeArray< bool > &isTerminal) |
Prunes nonterminal leaves and their paths to terminal or branching nodes. More... | |
static T | pruneDanglingSteinerPathFrom (EdgeWeightedGraphCopy< T > &steinerTree, const NodeArray< bool > &isTerminal, node start) |
Prunes the dangling Steiner path beginning at a given nonterminal leaf only. More... | |
static T | pruneDanglingSteinerPathsFrom (EdgeWeightedGraphCopy< T > &steinerTree, const NodeArray< bool > &isTerminal, const List< node > &start) |
Prunes dangling Steiner paths beginning at given nonterminal leaves only. More... | |
static T | removeCyclesFrom (EdgeWeightedGraphCopy< T > &steinerTree, const NodeArray< bool > &isTerminal) |
Remove remaining cycles from a Steiner "almost" tree. More... | |
static void | singleSourceShortestPathsPreferringTerminals (const EdgeWeightedGraph< T > &G, node source, const NodeArray< bool > &isTerminal, NodeArray< T > &distance, NodeArray< edge > &pred) |
Modified single-source-shortest-paths (Dijkstra) with heuristic to prefer paths over terminals. More... | |
static void | singleSourceShortestPathsStandard (const EdgeWeightedGraph< T > &G, node source, const NodeArray< bool > &, NodeArray< T > &distance, NodeArray< edge > &pred) |
Standard single-source-shortest-paths algoritm (Dijkstra) More... | |
static void | singleSourceShortestPaths (const EdgeWeightedGraph< T > &G, node source, const NodeArray< bool > &isTerminal, NodeArray< T > &distance, NodeArray< edge > &pred) |
The default single-source-shortest-paths algorithm. More... | |
static void | allTerminalShortestPathsStandard (const EdgeWeightedGraph< T > &G, const List< node > &terminals, const NodeArray< bool > &isTerminal, NodeArray< NodeArray< T >> &distance, NodeArray< NodeArray< edge >> &pred) |
Runs singleSourceShortestPathsStandard from all terminals. More... | |
static void | allTerminalShortestPathsPreferringTerminals (const EdgeWeightedGraph< T > &G, const List< node > &terminals, const NodeArray< bool > &isTerminal, NodeArray< NodeArray< T >> &distance, NodeArray< NodeArray< edge >> &pred) |
Runs singleSourceShortestPathsPreferringTerminals from all terminals. More... | |
static void | allTerminalShortestPaths (const EdgeWeightedGraph< T > &G, const List< node > &terminals, const NodeArray< bool > &isTerminal, NodeArray< NodeArray< T >> &distance, NodeArray< NodeArray< edge >> &pred, std::function< void(const EdgeWeightedGraph< T > &, node, const NodeArray< bool > &, NodeArray< T > &, NodeArray< edge > &)> ssspFunc=singleSourceShortestPaths) |
Runs a given (or the default) single-source-shortest-paths function from all terminals. More... | |
static void | allNodeShortestPathsStandard (const EdgeWeightedGraph< T > &G, const List< node > &terminals, const NodeArray< bool > &isTerminal, NodeArray< NodeArray< T >> &distance, NodeArray< NodeArray< edge >> &pred) |
Runs singleSourceShortestPathsStandard from all nodes. More... | |
static void | allNodeShortestPathsPreferringTerminals (const EdgeWeightedGraph< T > &G, const List< node > &terminals, const NodeArray< bool > &isTerminal, NodeArray< NodeArray< T >> &distance, NodeArray< NodeArray< edge >> &pred) |
Runs singleSourceShortestPathsPreferringTerminals from all nodes. More... | |
static void | allNodeShortestPaths (const EdgeWeightedGraph< T > &G, const List< node > &terminals, const NodeArray< bool > &isTerminal, NodeArray< NodeArray< T >> &distance, NodeArray< NodeArray< edge >> &pred, std::function< void(const EdgeWeightedGraph< T > &, node, const NodeArray< bool > &, NodeArray< T > &, NodeArray< edge > &)> ssspFunc=singleSourceShortestPaths) |
Runs a given (or the default) single-source-shortest-paths function from all nodes. More... | |
static void | allPairShortestPathsPreferringTerminals (const EdgeWeightedGraph< T > &G, const NodeArray< bool > &isTerminal, NodeArray< NodeArray< T >> &distance, NodeArray< NodeArray< edge >> &pred) |
Modified all-pair-shortest-paths algorithm (Floyd-Warshall) with heuristic to prefer paths over terminals. More... | |
static void | allPairShortestPathsStandard (const EdgeWeightedGraph< T > &G, const NodeArray< bool > &, NodeArray< NodeArray< T >> &distance, NodeArray< NodeArray< edge >> &pred) |
Standard all-pair-shortest-paths algorithm (Floyd-Warshall) More... | |
static void | allPairShortestPaths (const EdgeWeightedGraph< T > &G, const NodeArray< bool > &isTerminal, NodeArray< NodeArray< T >> &distance, NodeArray< NodeArray< edge >> &pred) |
The default all-pair-shortest-paths algorithm. More... | |
static void | drawSVG (const EdgeWeightedGraph< T > &G, const NodeArray< bool > &isTerminal, const EdgeWeightedGraphCopy< T > &steinerTree, const char *filename) |
Writes an SVG file of a minimum Steiner tree in the original graph. More... | |
static void | drawSVG (const EdgeWeightedGraph< T > &G, const NodeArray< bool > &isTerminal, const char *filename) |
Writes an SVG file of the instance graph. More... | |
static void | drawSteinerTreeSVG (const EdgeWeightedGraphCopy< T > &steinerTree, const NodeArray< bool > &isTerminal, const char *filename) |
Writes a SVG that shows only the given Steiner tree. More... | |
Implementation of Shore, Foulds and Gibbons exact branch and bound algorithm for solving Steiner tree problems.
(Shore M.L., Foulds, L.R., and Gibbons, P.B. An Algorithm for the Steiner Problem in Graphs Networks 10:323-333, 1982.)
Definition at line 71 of file MinSteinerTreeShore.h.
|
inline |
Definition at line 73 of file MinSteinerTreeShore.h.
|
inlinevirtual |
Definition at line 74 of file MinSteinerTreeShore.h.
|
private |
Calculates the optimal Steinter tree recursivly.
Should not be called directly but by STPSolver::solve. Each edge is either included or excluded, which gives rise to up to two new branches in each step.
prevCost | the cost accumulated in previous recursion steps (previously included edges) |
currentEdges | the current edges |
Definition at line 507 of file MinSteinerTreeShore.h.
|
overrideprotectedvirtual |
Builds a minimum Steiner tree given a weighted graph and a list of terminals.
G | The weighted input graph |
terminals | The list of terminal nodes |
isTerminal | A bool array of terminals |
finalSteinerTree | The final Steiner tree |
Implements ogdf::MinSteinerTreeModule< T >.
Definition at line 275 of file MinSteinerTreeShore.h.
|
private |
Removes the specified edge from the graph.
The corresponding original edge is returned.
Definition at line 367 of file MinSteinerTreeShore.h.
|
private |
Decides which edge to branch on.
Might return nullptr if current upper bound can not be reached with this graph.
prevCost | the cost of previously chosen edges used for comparing to current upper bound |
Definition at line 431 of file MinSteinerTreeShore.h.
|
private |
Returns whether this node is a terminal or a Steiner node.
v | the node to check |
Definition at line 402 of file MinSteinerTreeShore.h.
|
private |
Retrieves the edge incident to both node u and v.
u | one of the nodes of the undirected edge |
v | the opposite node of u |
Definition at line 357 of file MinSteinerTreeShore.h.
|
private |
Moves the source of the edge to the specified node.
e | the edge to be moved |
v | the new source of e |
Definition at line 386 of file MinSteinerTreeShore.h.
|
private |
Moves the target of the edge to the specified node.
e | the edge to be moved |
v | the new target of e |
Definition at line 394 of file MinSteinerTreeShore.h.
|
private |
Creates a new edge.
source | the source node of the new edge |
target | the target node of the new edge |
originalEdge | the corresponding edge in the original graph |
Definition at line 377 of file MinSteinerTreeShore.h.
|
private |
Prints the current recursion status as a SVG image of the current reduced STP.
Definition at line 696 of file MinSteinerTreeShore.h.
|
private |
Sets the edge incident to both node u and v.
Used for faster lookup.
u | one of the nodes of the undirected edge |
v | the opposite node of u |
e | the incident edge |
Definition at line 362 of file MinSteinerTreeShore.h.
|
private |
Updates the status of the given node to either terminal or Steiner node.
No side-effects occur even if status is already correct.
v | the node to be updated |
makeTerminal | true to set it to terminal false to set it to nonterminal |
Definition at line 407 of file MinSteinerTreeShore.h.
|
private |
Solves the current STP instance.
Will return the total cost of the optimal solution.
chosenEdges | will hold the included edges |
Definition at line 416 of file MinSteinerTreeShore.h.
|
private |
Used to validate the current mapping of edges to orignal edges Used solely for debugging.
The mapping is validated by using OGDF_ASSERT.
Definition at line 348 of file MinSteinerTreeShore.h.
|
private |
Returns the cost of the specified edge.
Looks up the corresponding edge in the original graph and retrieves its weight.
Definition at line 334 of file MinSteinerTreeShore.h.
|
private |
Definition at line 106 of file MinSteinerTreeShore.h.
|
private |
Definition at line 105 of file MinSteinerTreeShore.h.
|
private |
Definition at line 101 of file MinSteinerTreeShore.h.
|
private |
Definition at line 103 of file MinSteinerTreeShore.h.
|
private |
Definition at line 98 of file MinSteinerTreeShore.h.
|
private |
Definition at line 99 of file MinSteinerTreeShore.h.
|
private |
Definition at line 107 of file MinSteinerTreeShore.h.
|
private |
Definition at line 102 of file MinSteinerTreeShore.h.
|
private |
Definition at line 104 of file MinSteinerTreeShore.h.
|
protected |
Definition at line 95 of file MinSteinerTreeShore.h.