Open
Graph Drawing
Framework

 v. snapshot-2017-02-16
 

MinSteinerTreeModule.h
Go to the documentation of this file.
1 
32 #pragma once
33 
43 #include <sstream>
44 
45 namespace ogdf {
46 
53 template<typename T>
55 public:
57 
58  virtual ~MinSteinerTreeModule() { }
59 
68  virtual T call(const EdgeWeightedGraph<T> &G,
69  const List<node> &terminals,
70  const NodeArray<bool> &isTerminal,
71  EdgeWeightedGraphCopy<T> *&finalSteinerTree
72  );
73 
80  static T pruneAllDanglingSteinerPaths(EdgeWeightedGraphCopy<T> &steinerTree, const NodeArray<bool> &isTerminal);
81 
85  static T pruneDanglingSteinerPathsFrom(EdgeWeightedGraphCopy<T> &steinerTree, const NodeArray<bool> &isTerminal, const List<node> &start);
86 
90  static T pruneDanglingSteinerPathFrom(EdgeWeightedGraphCopy<T> &steinerTree, const NodeArray<bool> &isTerminal, node start);
91 
96  static T removeCyclesFrom(EdgeWeightedGraphCopy<T> &steinerTree, const NodeArray<bool> &isTerminal);
97 
106  static void singleSourceShortestPaths(const EdgeWeightedGraph<T> &G, node source, const NodeArray<bool> &isTerminal, NodeArray<T> &distance, NodeArray<edge> &pred);
107  static void singleSourceShortestPathsStrict(const EdgeWeightedGraph<T> &G, node source, const NodeArray<bool> &isTerminal, NodeArray<T> &distance, NodeArray<edge> &pred);
108  static void singleSourceShortestPathsDetour(const EdgeWeightedGraph<T> &G, node source, const NodeArray<bool> &isTerminal, NodeArray<T> &distance, NodeArray<edge> &pred);
109 
117  static void allPairShortestPaths(const EdgeWeightedGraph<T> &G, const List<node> &nonterminals, NodeArray< NodeArray<T> > &distance, NodeArray< NodeArray<edge> > &pred);
118  static void allPairShortestPathsStrict(const EdgeWeightedGraph<T> &G, const NodeArray<bool> &isTerminal, NodeArray< NodeArray<T> > &distance, NodeArray< NodeArray<edge> > &pred);
119  static void allPairShortestPathsDetour(const EdgeWeightedGraph<T> &G, const List<node> &nonterminals, NodeArray< NodeArray<T> > &distance, NodeArray< NodeArray<edge> > &pred);
120 
128  static void drawSVG(const EdgeWeightedGraph<T> &G, const NodeArray<bool> &isTerminal, const EdgeWeightedGraphCopy<T> &steinerTree, const char *filename);
129 
136  static void drawSteinerTreeSVG(const EdgeWeightedGraphCopy<T> &steinerTree, const NodeArray<bool> &isTerminal, const char *filename);
137 
146  static bool isSteinerTree(const EdgeWeightedGraph<T> &G, const List<node> &terminals, const NodeArray<bool> &isTerminal, const EdgeWeightedGraphCopy<T> &steinerTree);
147 
154  static bool isQuasiBipartite(const EdgeWeightedGraph<T> &G, const NodeArray<bool> &isTerminal);
155 
156 protected:
157  virtual T computeSteinerTree(const EdgeWeightedGraph<T> &G,
158  const List<node> &terminals,
159  const NodeArray<bool> &isTerminal,
160  EdgeWeightedGraphCopy<T> *&finalSteinerTree
161  ) = 0;
162 };
163 
164 template<typename T>
166  const List<node> &terminals,
167  const NodeArray<bool> &isTerminal,
168  EdgeWeightedGraphCopy<T> *&finalSteinerTree
169  )
170 {
171  if (terminals.size() > 2) {
172  return this->computeSteinerTree(G, terminals, isTerminal, finalSteinerTree);
173  }
174 
175  finalSteinerTree = new EdgeWeightedGraphCopy<T>();
176  finalSteinerTree->createEmpty(G);
177  switch (terminals.size()) {
178  case 1:
179  finalSteinerTree->newNode(terminals.front());
180  case 0:
181  return 0;
182  case 2:
183  T cost(0);
184  AStarSearch<T> astar;
185  NodeArray<edge> pred;
186  NodeArray<T> dist;
187  astar.call(G, G.edgeWeights(), terminals.front(), terminals.back(), pred);
188  if(pred[terminals.back()] != nullptr) {
189  finalSteinerTree->newNode(terminals.back());
190  for (node t = terminals.back(); t != terminals.front(); t = pred[t]->opposite(t)) {
191  const edge e = pred[t];
192  finalSteinerTree->newNode(e->opposite(t));
193  finalSteinerTree->newEdge(e, G.weight(e));
194  cost += G.weight(e);
195  }
196  return cost;
197  }
198  }
199  return -1; // unreachable
200 }
201 
202 template<typename T>
204  const EdgeWeightedGraph<T> &G,
205  const List<node> &terminals,
206  const NodeArray<bool> &isTerminal,
207  const EdgeWeightedGraphCopy<T> &steinerTree)
208 {
209  // the Steiner tree is actually a tree
210  if (!isTree(steinerTree)) {
211  return false;
212  }
213 
214  // all terminal nodes are in the graph and have degree >= 1
215  for(node v : terminals) {
216  const node u = steinerTree.copy(v);
217  if (!u || (terminals.size() > 1 && u->degree() < 1)) {
218  return false;
219  }
220  }
221 
222  // all Steiner nodes are inner nodes
223  for(node u : steinerTree.nodes) {
224  if (!isTerminal[steinerTree.original(u)]
225  && u->degree() <= 1) {
226  return false;
227  }
228  }
229 
230  return true;
231 }
232 
233 template<typename T>
235 {
236  for (node v = G.firstNode(); v; v = v->succ()) {
237  if (!isTerminal[v]) {
238  for (adjEntry adj = v->firstAdj(); adj; adj = adj->succ()) {
239  if (!isTerminal[adj->twinNode()]) {
240  return false;
241  }
242  }
243  }
244  }
245  return true;
246 }
247 
248 template<typename T>
250 {
251  OGDF_ASSERT(isConnected(steinerTree));
252  T delWeights(0);
253  node u = start;
254  while (u->degree() == 1
255  && !isTerminal[steinerTree.original(u)]) {
256  const adjEntry adj = u->firstAdj();
257  const node v = adj->twinNode();
258  delWeights += steinerTree.weight(adj->theEdge());
259  steinerTree.delNode(u);
260  u = v;
261  }
262  return delWeights;
263 }
264 
265 template<typename T>
267 {
268  T delWeights(0);
269  for (node v : start) {
270  delWeights += pruneDanglingSteinerPathFrom(steinerTree, isTerminal, v);
271  }
272  return delWeights;
273 }
274 
275 template<typename T>
277 {
278  List<node> start;
279  for (node u : steinerTree.nodes) {
280  if (u->degree() == 1
281  && !isTerminal[steinerTree.original(u)]) {
282  start.pushBack(u);
283  }
284  }
285 
286  return pruneDanglingSteinerPathsFrom(steinerTree, isTerminal, start);
287 }
288 
289 template<typename T>
291 {
292  if (steinerTree.numberOfEdges() > steinerTree.numberOfNodes() - 1) {
293  EdgeArray<bool> isInTree(steinerTree);
294  T oldCost(0);
295  T newCost(computeMinST(steinerTree, steinerTree.edgeWeights(), isInTree));
296 
297  List<node> pendant; // collect resulting pendant edges
298  for (edge nextEdge, e = steinerTree.firstEdge(); e; e = nextEdge) {
299  oldCost += steinerTree.weight(e);
300  nextEdge = e->succ();
301  if (!isInTree[e]) {
302  if (e->source()->degree() == 2) {
303  pendant.pushBack(e->source());
304  }
305  if (e->target()->degree() == 2) {
306  pendant.pushBack(e->target());
307  }
308  steinerTree.delEdge(e);
309  }
310  }
311  newCost -= MinSteinerTreeModule<T>::pruneDanglingSteinerPathsFrom(steinerTree, isTerminal, pendant);
312  return oldCost - newCost;
313  }
314  return 0;
315 }
316 
317 template<typename T>
319 {
321  distance.init(G, numeric_limits<T>::max());
322  pred.init(G, nullptr);
323 
324  // initialization
325  distance[source] = 0;
326  for (node v : G.nodes) {
327  queue.push(v, distance[v]);
328  }
329 
330  while (!queue.empty()) {
331  node v = queue.topElement();
332  queue.pop();
333 
334  if (isTerminal[v] && v != source) { // v is a terminal, ignore
335  continue;
336  }
337  if (distance[v] == numeric_limits<T>::max()) { // min is unreachable, finished
338  break;
339  }
340  for (adjEntry adj : v->adjEntries) {
341  edge e = adj->theEdge();
342  node w = adj->twinNode();
343  if (distance[w] > distance[v] + G.weight(e)) {
344  queue.decrease(w, (distance[w] = distance[v] + G.weight(e)));
345  pred[w] = e;
346  }
347  }
348  }
349 }
350 
351 template<typename T>
353 {
355  distance.init(G, numeric_limits<T>::max());
356  pred.init(G, nullptr);
357 
358  // initialization
359  distance[source] = 0;
360  for (node v : G.nodes) {
361  queue.push(v, distance[v]);
362  }
363 
364  node v = queue.topElement();
365  queue.pop();
366 
367  OGDF_ASSERT(v == source);
368  for (adjEntry adj : v->adjEntries) {
369  edge e = adj->theEdge();
370  node w = adj->twinNode();
371  if (distance[w] > G.weight(e)) { // this check is only necessary for multigraphs, otherwise this is always true
372  queue.decrease(w, (distance[w] = G.weight(e)));
373  pred[w] = e;
374  }
375  }
376 
377  while (!queue.empty()) {
378  v = queue.topElement();
379  queue.pop();
380 
381  if (distance[v] == numeric_limits<T>::max()) { // min is unreachable, finished
382  break;
383  }
384  for (adjEntry adj : v->adjEntries) {
385  edge e = adj->theEdge();
386  node w = adj->twinNode();
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) { // w is on a path with terminal
391  pred[w] = nullptr;
392  } else {
393  pred[w] = e;
394  }
395  } else
396  if (distance[w] == dist
397  && pred[w] != nullptr) { // tie
398  if (isTerminal[v] || pred[v] == nullptr) { // w is on a path with terminal
399  pred[w] = nullptr;
400  } else {
401  pred[w] = e;
402  }
403  }
404  }
405  }
406 }
407 
408 template<typename T>
410 {
412  distance.init(G, numeric_limits<T>::max());
413  pred.init(G, nullptr);
414 
415  // initialization
416  distance[source] = 0;
417  for (node v : G.nodes) {
418  queue.push(v, distance[v]);
419  }
420 
421  while (!queue.empty()) {
422  node v = queue.topElement();
423  queue.pop();
424 
425  if (isTerminal[v] && v != source) { // v is a terminal, ignore
426  continue;
427  }
428  if (distance[v] == numeric_limits<T>::max()) { // min is unreachable, finished
429  break;
430  }
431  for (adjEntry adj : v->adjEntries) {
432  edge e = adj->theEdge();
433  node w = adj->twinNode();
434  if (distance[w] > distance[v] + G.weight(e)) {
435  queue.decrease(w, (distance[w] = distance[v] + G.weight(e)));
436  pred[w] = e;
437  }
438  }
439  }
440 }
441 
442 template<typename T>
444 {
445  // initialization
446  for (node u = G.firstNode(); u; u = u->succ()) {
447  distance[u].init(G, numeric_limits<T>::max());
448  pred[u].init(G, nullptr);
449  }
450  for (edge e = G.firstEdge(); e; e = e->succ()) {
451  const node u = e->source(), v = e->target();
452  distance[u][v] = G.weight(e);
453  distance[v][u] = G.weight(e);
454  pred[u][v] = e;
455  pred[v][u] = e;
456  }
457 
458  // main loop
459  for(node v : nonterminals) {
460  for (node u : G.nodes) {
461  const T duv = distance[u][v];
462  if (duv < numeric_limits<T>::max()) {
463  for (node w = u->succ(); w; w = w->succ()) {
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];
470  }
471  }
472  }
473  }
474  }
475 }
476 
477 template<typename T>
479 {
480  // initialization
481  for (node u : G.nodes) {
482  distance[u].init(G, numeric_limits<T>::max());
483  pred[u].init(G, nullptr);
484  }
485  for (edge e : G.edges) {
486  const node u = e->source(), v = e->target();
487  distance[u][v] = distance[v][u] = G.weight(e);
488  pred[u][v] = pred[v][u] = e;
489  }
490 
491  // main loop
492  for (node v : G.nodes) {
493  if (isTerminal[v]) { // v is a terminal
494  for (node u : G.nodes) {
495  const T duv = distance[u][v];
496  if (duv < numeric_limits<T>::max()) {
497  for (node w = u->succ(); w; w = w->succ()) {
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]) { // prefer terminals
502  distance[w][u] = distance[u][w] = duvw;
503  pred[w][u] = pred[u][w] = nullptr;
504  }
505  }
506  }
507  }
508  } else { // v is not a terminal
509  for (node u : G.nodes) {
510  const T duv = distance[u][v];
511  if (duv < numeric_limits<T>::max()) {
512  for (node w = u->succ(); w; w = w->succ()) {
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]) { // do not prefer nonterminals
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);
520  }
521  }
522  }
523  }
524  }
525  }
526 }
527 
528 template<typename T>
530 {
531  // initialization
532  for (node u = G.firstNode(); u; u = u->succ()) {
533  distance[u].init(G, numeric_limits<T>::max());
534  pred[u].init(G, nullptr);
535  }
536  for (edge e = G.firstEdge(); e; e = e->succ()) {
537  const node u = e->source(), v = e->target();
538  distance[u][v] = G.weight(e);
539  distance[v][u] = G.weight(e);
540  pred[u][v] = e;
541  pred[v][u] = e;
542  }
543 
544  // main loop
545  for (node v : nonterminals) {
546  for (node u : G.nodes) {
547  const T duv = distance[u][v];
548  if (duv < numeric_limits<T>::max()) {
549  for (node w = u->succ(); w; w = w->succ()) {
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];
556  }
557  }
558  }
559  }
560  }
561 }
562 
563 template<typename T>
564 void MinSteinerTreeModule<T>::drawSteinerTreeSVG(const EdgeWeightedGraphCopy<T> &steinerTree, const NodeArray<bool> &isTerminal, const char *filename)
565 {
566  GraphAttributes GA(steinerTree,
573 
574  GA.directed() = false;
575 
576  string s;
577 
578  for (node v : steinerTree.nodes) {
579  std::stringstream out;
580  GA.width(v) = GA.height(v) = 25.0;
581  if (isTerminal[steinerTree.original(v)]) {
582  out << "T";
583  GA.shape(v) = Shape::Rect;
584  GA.fillColor(v) = Color::Name::Red;
585  } else {
586  out << "S";
587  GA.shape(v) = Shape::Ellipse;
589  }
590  out << steinerTree.original(v);
591  GA.label(v) = out.str();
592  }
593 
594  FMMMLayout fmmm;
595 
596  fmmm.useHighLevelOptions(true);
597  fmmm.unitEdgeLength(44.0);
598  fmmm.newInitialPlacement(true);
600 
601  fmmm.call(GA);
602  ofstream writeStream(filename, std::ofstream::out);
603  GraphIO::drawSVG(GA, writeStream);
604 }
605 
606 template<typename T>
607 void MinSteinerTreeModule<T>::drawSVG(const EdgeWeightedGraph<T> &G, const NodeArray<bool> &isTerminal, const EdgeWeightedGraphCopy<T> &steinerTree, const char *filename)
608 {
609  GraphAttributes GA(G,
616 
617  GA.directed() = false;
618 
619  for (edge e : G.edges) {
621  GA.label(e) = to_string(G.weight(e));
622  GA.strokeWidth(e) = 1;
623  }
624  for (edge e : steinerTree.edges) {
625  GA.strokeColor(steinerTree.original(e)) = Color::Name::Red;
626  GA.strokeWidth(steinerTree.original(e)) = 2;
627  }
628 
629  for (node v : G.nodes) {
630  std::stringstream out;
631  GA.width(v) = GA.height(v) = 25.0;
633  if (isTerminal[v]) {
634  out << "T" << v;
635  GA.shape(v) = Shape::Rect;
636  GA.fillColor(v) = Color::Name::Red;
637  GA.strokeWidth(v) = 2;
638  } else {
639  out << "S" << v;
640  GA.shape(v) = Shape::Ellipse;
641  if (steinerTree.copy(v)) {
643  GA.strokeWidth(v) = 2;
644  } else {
646  GA.strokeWidth(v) = 1;
647  }
648  }
649  GA.label(v) = out.str();
650  }
651 
652  FMMMLayout fmmm;
653 
654  fmmm.useHighLevelOptions(true);
655  fmmm.unitEdgeLength(44.0);
656  fmmm.newInitialPlacement(true);
658 
659  fmmm.call(GA);
660 
661  ofstream writeStream(filename, std::ofstream::out);
662  GraphIO::drawSVG(GA, writeStream);
663 }
664 
665 } // end namespace ogdf
node target() const
Returns the target node of the edge.
Definition: Graph_d.h:327
static void allPairShortestPathsDetour(const EdgeWeightedGraph< T > &G, const List< node > &nonterminals, NodeArray< NodeArray< T > > &distance, NodeArray< NodeArray< edge > > &pred)
bool newInitialPlacement() const
Returns the current setting of option newInitialPlacement.
Definition: FMMMLayout.h:337
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.
Definition: Graph_d.h:95
node copy(node v) const
Returns the node in the graph copy corresponding to v.
Definition: GraphCopy.h:336
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.
Definition: GraphCopy.h:413
FMMMOptions::QualityVsSpeed qualityVersusSpeed() const
Returns the current setting of option qualityVersusSpeed.
Definition: FMMMLayout.h:343
iterator pushBack(const E &x)
Adds element x at the end of the list.
Definition: List.h:1316
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.
Definition: FMMMLayout.h:326
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.
Definition: NodeArray.h:292
T computeMinST(const Graph &G, const EdgeArray< T > &weight, EdgeArray< bool > &isInTree)
Computes a minimum spanning tree using Prim&#39;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.
Definition: AStarSearch.h:96
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).
Definition: Graph_d.h:208
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.
Definition: Graph_d.h:598
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.
Definition: Graph_d.h:216
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&#39;s original edge.
The fast multipole multilevel layout algorithm.
Definition: FMMMLayout.h:232
void createEmpty(const Graph &wG)
internal::GraphObjectContainer< EdgeElement > edges
The container containing all edge objects.
Definition: Graph_d.h:548
int numberOfEdges() const
Returns the number of edges in the graph.
Definition: Graph_d.h:581
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.
Definition: Graph_d.h:603
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.
Definition: List.h:254
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).
Definition: List.h:39
node twinNode() const
Returns the associated node of the corresponding adjacency entry (shorthand for twin()->theNode()).
Definition: Graph_d.h:105
Class for the representation of edges.
Definition: Graph_d.h:291
Class for the representation of nodes.
Definition: Graph_d.h:167
Priority queue interface wrapping various heaps.
Declaration of Fast Multipole Multilevel Method (FM^3).
bool useHighLevelOptions() const
Returns the current setting of option useHighLevelOptions.
Definition: FMMMLayout.h:311
node opposite(node v) const
Returns the adjacent node different from v.
Definition: Graph_d.h:335
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.
Definition: GraphCopy.h:287
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.
Definition: Graph_d.h:340
bool empty() const
Checks whether the queue is empty.
A-Star informed search algorithm.
Definition: AStarSearch.h:52
adjEntry succ() const
Returns the successor in the adjacency list.
Definition: Graph_d.h:145
int size() const
Returns the number of elements in the list.
Definition: List.h:1255
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.
Definition: Graph_d.h:325
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.
Definition: Graph_d.h:578
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.
Definition: Graph_d.h:545
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.
Definition: Graph_d.h:211
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.
Definition: Graph_d.h:78
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.
Definition: basic.h:41
const_reference back() const
Returns a const reference to the last element.
Definition: List.h:272
internal::GraphObjectContainer< AdjElement > adjEntries
The container containing all entries in the adjacency list of this node.
Definition: Graph_d.h:198