171 if (terminals.
size() > 2) {
177 switch (terminals.
size()) {
188 if(pred[terminals.
back()] !=
nullptr) {
190 for (
node t = terminals.
back(); t != terminals.
front(); t = pred[t]->opposite(t)) {
191 const edge e = pred[t];
210 if (!
isTree(steinerTree)) {
215 for(
node v : terminals) {
217 if (!u || (terminals.size() > 1 && u->
degree() < 1)) {
224 if (!isTerminal[steinerTree.
original(u)]
237 if (!isTerminal[v]) {
238 for (
adjEntry adj = v->firstAdj(); adj; adj = adj->
succ()) {
239 if (!isTerminal[adj->twinNode()]) {
255 && !isTerminal[steinerTree.
original(u)]) {
269 for (
node v : start) {
281 && !isTerminal[steinerTree.
original(u)]) {
298 for (
edge nextEdge, e = steinerTree.
firstEdge(); e; e = nextEdge) {
299 oldCost += steinerTree.
weight(e);
300 nextEdge = e->
succ();
302 if (e->source()->degree() == 2) {
305 if (e->target()->degree() == 2) {
312 return oldCost - newCost;
321 distance.
init(G, numeric_limits<T>::max());
322 pred.
init(G,
nullptr);
325 distance[source] = 0;
327 queue.
push(v, distance[v]);
330 while (!queue.
empty()) {
334 if (isTerminal[v] && v != source) {
337 if (distance[v] == numeric_limits<T>::max()) {
343 if (distance[w] > distance[v] + G.
weight(e)) {
355 distance.
init(G, numeric_limits<T>::max());
356 pred.
init(G,
nullptr);
359 distance[source] = 0;
361 queue.
push(v, distance[v]);
371 if (distance[w] > G.
weight(e)) {
377 while (!queue.
empty()) {
381 if (distance[v] == numeric_limits<T>::max()) {
387 T dist = distance[v] + G.
weight(e);
388 if (distance[w] > dist) {
389 queue.
decrease(w, (distance[w] = dist));
390 if (isTerminal[v] || pred[v] ==
nullptr) {
396 if (distance[w] == dist
397 && pred[w] !=
nullptr) {
398 if (isTerminal[v] || pred[v] ==
nullptr) {
412 distance.
init(G, numeric_limits<T>::max());
413 pred.
init(G,
nullptr);
416 distance[source] = 0;
418 queue.
push(v, distance[v]);
421 while (!queue.
empty()) {
425 if (isTerminal[v] && v != source) {
428 if (distance[v] == numeric_limits<T>::max()) {
434 if (distance[w] > distance[v] + G.
weight(e)) {
447 distance[u].init(G, numeric_limits<T>::max());
448 pred[u].init(G,
nullptr);
451 const node u = e->source(), v = e->target();
452 distance[u][v] = G.
weight(e);
453 distance[v][u] = G.
weight(e);
459 for(
node v : nonterminals) {
461 const T duv = distance[u][v];
462 if (duv < numeric_limits<T>::max()) {
464 const T dvw = distance[v][w];
465 if (dvw < numeric_limits<T>::max()
466 && duv + dvw < distance[u][w]) {
467 distance[w][u] = distance[u][w] = duv + dvw;
468 pred[u][w] = pred[v][w];
469 pred[w][u] = pred[v][u];
482 distance[u].init(G, numeric_limits<T>::max());
483 pred[u].init(G,
nullptr);
487 distance[u][v] = distance[v][u] = G.
weight(e);
488 pred[u][v] = pred[v][u] = e;
495 const T duv = distance[u][v];
496 if (duv < numeric_limits<T>::max()) {
498 const T dvw = distance[v][w];
499 const T duvw = duv + dvw;
500 if (dvw < numeric_limits<T>::max()
501 && duvw <= distance[u][w]) {
502 distance[w][u] = distance[u][w] = duvw;
503 pred[w][u] = pred[u][w] =
nullptr;
510 const T duv = distance[u][v];
511 if (duv < numeric_limits<T>::max()) {
513 const T dvw = distance[v][w];
514 const T duvw = duv + dvw;
515 if (dvw < numeric_limits<T>::max()
516 && duvw < distance[u][w]) {
517 distance[w][u] = distance[u][w] = duvw;
518 pred[u][w] = (pred[u][v] ? pred[v][w] :
nullptr);
519 pred[w][u] = (pred[w][v] ? pred[v][u] :
nullptr);
533 distance[u].init(G, numeric_limits<T>::max());
534 pred[u].init(G,
nullptr);
537 const node u = e->source(), v = e->target();
538 distance[u][v] = G.
weight(e);
539 distance[v][u] = G.
weight(e);
545 for (
node v : nonterminals) {
547 const T duv = distance[u][v];
548 if (duv < numeric_limits<T>::max()) {
550 const T dvw = distance[v][w];
551 if (dvw < numeric_limits<T>::max()
552 && duv + dvw < distance[u][w]) {
553 distance[w][u] = distance[u][w] = duv + dvw;
554 pred[u][w] = pred[v][w];
555 pred[w][u] = pred[v][u];
579 std::stringstream out;
581 if (isTerminal[steinerTree.
original(v)]) {
591 GA.
label(v) = out.str();
602 ofstream writeStream(filename, std::ofstream::out);
630 std::stringstream out;
641 if (steinerTree.
copy(v)) {
649 GA.
label(v) = out.str();
661 ofstream writeStream(filename, std::ofstream::out);
node target() const
Returns the target node of the edge.
virtual ~MinSteinerTreeModule()
static void allPairShortestPathsDetour(const EdgeWeightedGraph< T > &G, const List< node > &nonterminals, NodeArray< NodeArray< T > > &distance, NodeArray< NodeArray< edge > > &pred)
void pop()
Removes the topmost element from the queue.
bool newInitialPlacement() const
Returns the current setting of option newInitialPlacement.
double width(node v) const
Returns the width of the bounding box of node v.
Declaration of class GraphAttributes which extends a Graph by additional attributes.
edge theEdge() const
Returns the edge associated with this adjacency entry.
node copy(node v) const
Returns the node in the graph copy corresponding to v.
static const int edgeGraphics
Corresponds to edge attribute bends(edge).
node newNode(node vOrig)
Creates a new node in the graph copy with original node vOrig.
FMMMOptions::QualityVsSpeed qualityVersusSpeed() const
Returns the current setting of option qualityVersusSpeed.
iterator pushBack(const E &x)
Adds element x at the end of the list.
const Color & fillColor(node v) const
Returns the fill color of node v.
static const int edgeStyle
Corresponds to edge attributes strokeColor(edge), strokeType(edge), and strokeWidth(edge).
double unitEdgeLength() const
Returns the current setting of option unitEdgeLength.
void push(const E &element, const P &priority)
Adds a new element to the queue.
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.
void init()
Reinitializes the array. Associates the array with no graph.
T computeMinST(const Graph &G, const EdgeArray< T > &weight, EdgeArray< bool > &isInTree)
Computes a minimum spanning tree using Prim's algorithm.
static void allPairShortestPaths(const EdgeWeightedGraph< T > &G, const List< node > &nonterminals, NodeArray< NodeArray< T > > &distance, NodeArray< NodeArray< edge > > &pred)
Undirected All-pair-shortest-paths (Floyd-Warshall) over non-terminal nodes of G. ...
T call(const Graph &graph, const EdgeArray< T > &cost, const node source, const node target, NodeArray< edge > &predecessor, std::function< T(node)> heuristic=[](node) { return T(0);})
Computes the shortests path between source and target.
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.
const Color & strokeColor(node v) const
Returns the stroke color of node v.
This class serves as an interface for various methods to compute minimum or approximations of minimum...
int degree() const
Returns the degree of the node (indegree + outdegree).
edge newEdge(node u, node v, T weight)
const EdgeArray< T > & edgeWeights() const
node firstNode() const
Returns the first node in the list of all nodes.
static const int nodeGraphics
Corresponds to node attributes x(node), y(node), width(node), height(node), and shape(node).
Extends the GraphCopy concept to weighted graphs.
bool directed() const
Returns if the graph is directed.
node succ() const
Returns the successor in the list of all nodes.
Prioritized queue interface wrapper for heaps.
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 const int nodeStyle
Corresponds to node attributes strokeColor(node), strokeType(node), strokeWidth(node), fillPattern(node), fillColor(node), and fillBgColor(node).
T weight(const edge e) const
double height(node v) const
Returns the height of the bounding box of node v.
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.
virtual void delEdge(edge e) override
Removes edge e and clears the list of edges corresponding to e's original edge.
The fast multipole multilevel layout algorithm.
void createEmpty(const Graph &wG)
internal::GraphObjectContainer< EdgeElement > edges
The container containing all edge objects.
int numberOfEdges() const
Returns the number of edges in the graph.
static const int edgeLabel
Corresponds to edge attribute label(edge).
const E & topElement() const
Returns the topmost element in the queue.
const string & label(node v) const
Returns the label of node v.
edge firstEdge() const
Returns the first edge in the list of all edges.
static T pruneDanglingSteinerPathsFrom(EdgeWeightedGraphCopy< T > &steinerTree, const NodeArray< bool > &isTerminal, const List< node > &start)
Prune dangling Steiner paths beginning at given nodes only.
const_reference front() const
Returns a const reference to the first element.
static const int nodeLabel
Corresponds to node attribute label(node).
const EdgeArray< T > & edgeWeights() const
Stores additional attributes of a graph (like layout information).
Doubly linked lists (maintaining the length of the list).
void decrease(const E &element, const P &priority)
Decreases the priority of the given element.
node twinNode() const
Returns the associated node of the corresponding adjacency entry (shorthand for twin()->theNode()).
Class for the representation of edges.
Class for the representation of nodes.
Priority queue interface wrapping various heaps.
Declaration of Fast Multipole Multilevel Method (FM^3).
bool useHighLevelOptions() const
Returns the current setting of option useHighLevelOptions.
node opposite(node v) const
Returns the adjacent node different from v.
Definition of a Triple used in contraction-based approximation algorithm for the minimum Steiner tree...
const Graph & original() const
Returns a reference to the original graph.
static void singleSourceShortestPathsDetour(const EdgeWeightedGraph< T > &G, node source, const NodeArray< bool > &isTerminal, NodeArray< T > &distance, NodeArray< edge > &pred)
static T pruneAllDanglingSteinerPaths(EdgeWeightedGraphCopy< T > &steinerTree, const NodeArray< bool > &isTerminal)
Prune Steiner nodes with degree 1 and their paths to terminal or branching nodes. ...
edge succ() const
Returns the successor in the list of all edges.
bool empty() const
Checks whether the queue is empty.
A-Star informed search algorithm.
adjEntry succ() const
Returns the successor in the adjacency list.
int size() const
Returns the number of elements in the list.
virtual T computeSteinerTree(const EdgeWeightedGraph< T > &G, const List< node > &terminals, const NodeArray< bool > &isTerminal, EdgeWeightedGraphCopy< T > *&finalSteinerTree)=0
virtual void call(GraphAttributes &GA) override
Calls the algorithm for graph GA and returns the layout information in GA.
static T removeCyclesFrom(EdgeWeightedGraphCopy< T > &steinerTree, const NodeArray< bool > &isTerminal)
Remove remaining cycles from an Steiner "almost" tree.
Declaration of simple graph algorithms.
bool isTree(const Graph &G)
Returns true iff G is a tree, i.e. contains no undirected cycle and is connected. ...
node source() const
Returns the source node of the edge.
The namespace for all OGDF objects.
Declaration of extended graph algorithms.
float strokeWidth(node v) const
Returns the stroke width of node v.
static void allPairShortestPathsStrict(const EdgeWeightedGraph< T > &G, const NodeArray< bool > &isTerminal, NodeArray< NodeArray< T > > &distance, NodeArray< NodeArray< edge > > &pred)
static void singleSourceShortestPaths(const EdgeWeightedGraph< T > &G, node source, const NodeArray< bool > &isTerminal, NodeArray< T > &distance, NodeArray< edge > &pred)
Undirected Single-source-shortest-paths (Dijkstra) over non-terminal nodes of G.
static void drawSteinerTreeSVG(const EdgeWeightedGraphCopy< T > &steinerTree, const NodeArray< bool > &isTerminal, const char *filename)
Writes a SVG that shows only the given Steiner tree.
int numberOfNodes() const
Returns the number of nodes in the graph.
virtual void delNode(node v) override
Removes node v and all its adjacent edges cleaning-up their corresponding lists of original edges...
Declares class GraphIO which provides access to all graph read and write functionality.
internal::GraphObjectContainer< NodeElement > nodes
The container containing all node objects.
static T pruneDanglingSteinerPathFrom(EdgeWeightedGraphCopy< T > &steinerTree, const NodeArray< bool > &isTerminal, node start)
Prune the dangling Steiner path beginning at a given node only.
adjEntry firstAdj() const
Returns the first entry in the adjaceny list.
bool isConnected(const Graph &G)
Returns true iff G is connected.
Implementation of the A* informed search algorithm.
static void singleSourceShortestPathsStrict(const EdgeWeightedGraph< T > &G, node source, const NodeArray< bool > &isTerminal, NodeArray< T > &distance, NodeArray< edge > &pred)
static bool drawSVG(const GraphAttributes &A, const string &filename, const SVGSettings &settings=svgSettings)
Class for adjacency list elements.
Shape shape(node v) const
Returns the shape type of node v.
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
T weight(const edge e) const
const_reference back() const
Returns a const reference to the last element.
internal::GraphObjectContainer< AdjElement > adjEntries
The container containing all entries in the adjacency list of this node.