144 sssp.
call(G, G.edgeWeights(), source, pred, distance);
151#ifdef OGDF_MINSTEINERTREEMODULE_SHORTEST_PATHS_STANDARD
231#ifdef OGDF_MINSTEINERTREEMODULE_SHORTEST_PATHS_STANDARD
261 const char* filename) {
309 for (
node v : G.nodes) {
330 for (
node v : G.nodes) {
331 if (!isTerminal[v]) {
357 for (
node u : G.nodes) {
358 const T
duv = distance[u][v];
359 if (
duv < std::numeric_limits<T>::max()) {
361 if (distance[v][w] < std::numeric_limits<T>::max()) {
362 func(u, w,
duv + distance[v][w]);
370 template<
typename NODELIST>
379 for (
node u : nodes) {
380 ssspFunc(G, u, isTerminal, distance[u], pred[u]);
390 if (terminals.
size() > 2) {
391 return this->computeSteinerTree(G, terminals, isTerminal,
finalSteinerTree);
396 if (!terminals.
empty()) {
399 if (terminals.
size() <= 1) {
408 astar.call(G, G.edgeWeights(), terminals.
front(), terminals.
back(), pred);
411 const edge e = pred[
t];
429 for (
node v : terminals) {
431 if (!u || (terminals.
size() > 1 && u->
degree() < 1)) {
438 if (!isTerminal[
steinerTree.original(u)] && u->degree() <= 1) {
449 for (
node v = G.firstNode(); v; v = v->
succ()) {
450 if (!isTerminal[v]) {
451 for (
adjEntry adj = v->firstAdj(); adj; adj = adj->
succ()) {
452 if (!isTerminal[adj->twinNode()]) {
481 for (
node v : start) {
492 if (u->degree() == 1 && !isTerminal[
steinerTree.original(u)]) {
497 return pruneDanglingSteinerPathsFrom(
steinerTree, isTerminal, start);
513 if (e->source()->degree() == 2) {
516 if (e->target()->degree() == 2) {
532 distance.
init(G, std::numeric_limits<T>::max());
533 distance[source] = 0;
535 for (
node v : G.nodes) {
536 queue.push(v, distance[v]);
539 pred.
init(G,
nullptr);
547 ssspInit(G, source,
queue, distance, pred);
554 edge e = adj->theEdge();
555 node w = adj->twinNode();
556 if (distance[w] > G.weight(
558 queue.decrease(w, (distance[w] = G.weight(e)));
567 while (!
queue.empty()) {
568 v =
queue.topElement();
571 if (distance[v] == std::numeric_limits<T>::max()) {
575 edge e = adj->theEdge();
576 node w = adj->twinNode();
577 T
dist = distance[v] + G.weight(e);
578 if (distance[w] >
dist) {
581 }
else if (distance[w] ==
dist && pred[w] !=
nullptr) {
592 apspInit(G, distance, pred);
594 for (
node v : G.nodes) {
596 apspInnerLoop(v, G, distance, [&distance, &pred](
node u,
node w, T
duvw) {
597 if (
duvw <= distance[u][w]) {
598 distance[w][u] = distance[u][w] =
duvw;
599 pred[w][u] = pred[u][w] =
nullptr;
603 apspInnerLoop(v, G, distance, [&v, &distance, &pred](
node u,
node w, T
duvw) {
604 if (
duvw < distance[u][w]) {
605 distance[w][u] = distance[u][w] =
duvw;
606 pred[u][w] = (pred[u][v] ? pred[v][w] :
nullptr);
607 pred[w][u] = (pred[w][v] ? pred[v][u] :
nullptr);
612 for (
node u : G.nodes) {
622 for (
node u : G.nodes) {
623 distance[u].init(G, std::numeric_limits<T>::max());
624 pred[u].init(G,
nullptr);
626 for (
edge e : G.edges) {
627 const node u = e->source(), v = e->target();
628 distance[u][v] = distance[v][u] = G.weight(e);
629 pred[u][v] = pred[v][u] = e;
636 apspInit(G, distance, pred);
638 for (
node v : G.nodes) {
639 apspInnerLoop(v, G, distance, [&v, &distance, &pred](
node u,
node w, T
duvw) {
640 if (
duvw < distance[u][w]) {
641 distance[w][u] = distance[u][w] =
duvw;
642 pred[u][w] = pred[v][w];
643 pred[w][u] = pred[v][u];
647 for (
node u : G.nodes) {
660 GA.directed() =
false;
665 std::stringstream out;
666 GA.width(v) =
GA.height(v) = 25.0;
677 GA.label(v) = out.str();
688 std::ofstream
writeStream(filename, std::ofstream::out);
695 const char* filename) {
701 GA.directed() =
false;
703 for (
edge e : G.edges) {
705 GA.label(e) = to_string(G.weight(e));
706 GA.strokeWidth(e) = 1;
713 for (
node v : G.nodes) {
714 std::stringstream out;
715 GA.width(v) =
GA.height(v) = 25.0;
721 GA.strokeWidth(v) = 2;
727 GA.strokeWidth(v) = 2;
730 GA.strokeWidth(v) = 1;
733 GA.label(v) = out.str();
745 std::ofstream
writeStream(filename, std::ofstream::out);
Implementation of the A* informed search algorithm.
Extends the GraphCopy concept to weighted graphs.
Declaration of Fast Multipole Multilevel Method (FM^3).
Declaration of class GraphAttributes which extends a Graph by additional attributes.
Declares class GraphIO which provides access to all graph read and write functionality.
Priority queue interface wrapping various heaps.
Definition of a Triple used in contraction-based approximation algorithm for the minimum Steiner tree...
A-Star informed search algorithm.
Class for adjacency list elements.
adjEntry succ() const
Returns the successor in the adjacency list.
edge theEdge() const
Returns the edge associated with this adjacency entry.
node twinNode() const
Returns the associated node of the corresponding adjacency entry (shorthand for twin()->theNode()).
An array that keeps track of the number of inserted elements; also usable as an efficient stack.
Dijkstra's single source shortest path algorithm.
void call(const Graph &G, const EdgeArray< T > &weight, const List< node > &sources, NodeArray< edge > &predecessor, NodeArray< T > &distance, bool directed=false, bool arcsReversed=false, node target=nullptr, T maxLength=std::numeric_limits< T >::max())
Calculates, based on the graph G with corresponding edge costs and source nodes, the shortest paths a...
Dynamic arrays indexed with edges.
Class for the representation of edges.
node opposite(node v) const
Returns the adjacent node different from v.
void createEmpty(const Graph &wG)
The fast multipole multilevel layout algorithm.
FMMMOptions::QualityVsSpeed qualityVersusSpeed() const
Returns the current setting of option qualityVersusSpeed.
double unitEdgeLength() const
Returns the current setting of option unitEdgeLength.
bool useHighLevelOptions() const
Returns the current setting of option useHighLevelOptions.
virtual void call(GraphAttributes &GA) override
Calls the algorithm for graph GA and returns the layout information in GA.
bool newInitialPlacement() const
Returns the current setting of option newInitialPlacement.
@ GorgeousAndEfficient
Best quality.
Stores additional attributes of a graph (like layout information).
static const long edgeLabel
Corresponds to edge attribute label(edge).
static const long edgeStyle
Corresponds to edge attributes strokeColor(edge), strokeType(edge), and strokeWidth(edge).
static const long nodeLabel
Corresponds to node attribute label(node).
static const long nodeStyle
Corresponds to node attributes strokeColor(node), strokeType(node), strokeWidth(node),...
static const long edgeGraphics
Corresponds to edge attribute bends(edge).
static const long nodeGraphics
Corresponds to node attributes x(node), y(node), width(node), height(node), and shape(node).
static bool drawSVG(const GraphAttributes &A, std::ostream &os, const SVGSettings &settings)
Doubly linked lists (maintaining the length of the list).
int size() const
Returns the number of elements in the list.
iterator pushBack(const E &x)
Adds element x at the end of the list.
const_reference front() const
Returns a const reference to the first element.
const_reference back() const
Returns a const reference to the last element.
bool empty() const
Returns true iff the list is empty.
void quicksort()
Sorts the list using Quicksort.
Serves as an interface for various methods to compute or approximate minimum Steiner trees on undirec...
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.
static void allNodesByListShortestPaths(const EdgeWeightedGraph< T > &G, const List< node > &terminals, const NodeArray< bool > &isTerminal, const NODELIST &nodes, NodeArray< NodeArray< T > > &distance, NodeArray< NodeArray< edge > > &pred, std::function< void(const EdgeWeightedGraph< T > &, node, const NodeArray< bool > &, NodeArray< T > &, NodeArray< edge > &)> ssspFunc)
Runs a given (or the default) single-source-shortest-paths function from all nodes.
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.
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.
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.
static T pruneAllDanglingSteinerPaths(EdgeWeightedGraphCopy< T > &steinerTree, const NodeArray< bool > &isTerminal)
Prunes nonterminal leaves and their paths to terminal or branching nodes.
static void getTerminals(List< node > &terminals, const EdgeWeightedGraph< T > &G, const NodeArray< bool > &isTerminal)
Generates a list (as List<node>) of all terminals.
static T pruneDanglingSteinerPathFrom(EdgeWeightedGraphCopy< T > &steinerTree, const NodeArray< bool > &isTerminal, node start)
Prunes the dangling Steiner path beginning at a given nonterminal leaf only.
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 termi...
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.
static void apspInit(const EdgeWeightedGraph< T > &G, NodeArray< NodeArray< T > > &distance, NodeArray< NodeArray< edge > > &pred)
Common initialization routine for APSP algorithms.
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.
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.
virtual T computeSteinerTree(const EdgeWeightedGraph< T > &G, const List< node > &terminals, const NodeArray< bool > &isTerminal, EdgeWeightedGraphCopy< T > *&finalSteinerTree)=0
Computes the actual Steiner tree.
static void ssspInit(const EdgeWeightedGraph< T > &G, node source, PrioritizedMapQueue< node, T > &queue, NodeArray< T > &distance, NodeArray< edge > &pred)
Common initialization routine for SSSP algorithms.
static T removeCyclesFrom(EdgeWeightedGraphCopy< T > &steinerTree, const NodeArray< bool > &isTerminal)
Remove remaining cycles from a Steiner "almost" tree.
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.
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.
static void sortTerminals(List< node > &terminals)
Sort terminals by index.
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)
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.
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)
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.
static void apspInnerLoop(node v, const EdgeWeightedGraph< T > &G, NodeArray< NodeArray< T > > &distance, std::function< void(node, node, T)> func)
The inner loop for APSP algorithm to avoid code duplication.
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.
static void drawSVG(const EdgeWeightedGraph< T > &G, const NodeArray< bool > &isTerminal, const char *filename)
Writes an SVG file of the instance graph.
static void drawSteinerTreeSVG(const EdgeWeightedGraphCopy< T > &steinerTree, const NodeArray< bool > &isTerminal, const char *filename)
Writes a SVG that shows only the given Steiner tree.
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.
static T pruneDanglingSteinerPathsFrom(EdgeWeightedGraphCopy< T > &steinerTree, const NodeArray< bool > &isTerminal, const List< node > &start)
Prunes dangling Steiner paths beginning at given nonterminal leaves only.
static void getNonterminals(ArrayBuffer< node > &nonterminals, const EdgeWeightedGraph< T > &G, const NodeArray< bool > &isTerminal)
Generates a list (as ArrayBuffer<node>) of all nonterminals.
virtual ~MinSteinerTreeModule()
Do nothing on destruction.
Dynamic arrays indexed with nodes.
void init()
Reinitializes the array. Associates the array with no graph.
Class for the representation of nodes.
int degree() const
Returns the degree of the node (indegree + outdegree).
internal::GraphObjectContainer< AdjElement > adjEntries
The container containing all entries in the adjacency list of this node.
node succ() const
Returns the successor in the list of all nodes.
int index() const
Returns the (unique) node index.
adjEntry firstAdj() const
Returns the first entry in the adjaceny list.
Prioritized queue interface wrapper for heaps.
Declaration of extended graph algorithms.
Implementation of Dijkstra's single source shortest path algorithm.
bool isConnected(const Graph &G)
Returns true iff G is connected.
T computeMinST(const Graph &G, const EdgeArray< T > &weight, EdgeArray< bool > &isInTree)
Computes a minimum spanning tree using Prim's algorithm.
bool isTree(const Graph &G)
Returns true iff G is a tree, i.e. contains no undirected cycle and is connected.
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
static MultilevelBuilder * getDoubleFactoredZeroAdjustedMerger()
The namespace for all OGDF objects.
Declaration of simple graph algorithms.
Compare elements based on a single comparable attribute.