Open
Graph Drawing
Framework

 v. snapshot-2017-02-16
 

EmbedderMaxFaceBiconnectedGraphsLayers.h
Go to the documentation of this file.
1 
33 #pragma once
34 
39 
40 
41 namespace ogdf {
42 
44 
54 template<class T>
56 {
57 public:
60 
71  static void embed(
72  Graph& G,
73  adjEntry& adjExternal,
74  const NodeArray<T>& nodeLength,
75  const EdgeArray<T>& edgeLength,
76  const node& n = nullptr);
77 
87  static void compute(
88  const Graph& G,
89  const NodeArray<T>& nodeLength,
90  const EdgeArray<T>& edgeLength,
91  StaticSPQRTree *spqrTree,
92  NodeArray< EdgeArray<T> >& edgeLengthSkel);
93 
102  static T computeSize(
103  const Graph& G,
104  const node& n,
105  const NodeArray<T>& nodeLength,
106  const EdgeArray<T>& edgeLength);
107 
119  static T computeSize(
120  const Graph& G,
121  const node& n,
122  const NodeArray<T>& nodeLength,
123  const EdgeArray<T>& edgeLength,
124  StaticSPQRTree *spqrTree);
125 
139  static T computeSize(
140  const Graph& G,
141  const node& n,
142  const NodeArray<T>& nodeLength,
143  const EdgeArray<T>& edgeLength,
144  StaticSPQRTree *spqrTree,
145  const NodeArray< EdgeArray<T> >& edgeLengthSkel);
146 
154  static T computeSize(
155  const Graph& G,
156  const NodeArray<T>& nodeLength,
157  const EdgeArray<T>& edgeLength);
158 
172  static T computeSize(
173  const Graph& G,
174  const NodeArray<T>& nodeLength,
175  const EdgeArray<T>& edgeLength,
176  StaticSPQRTree *spqrTree,
177  NodeArray< EdgeArray<T> >& edgeLengthSkel);
178 
179 private:
190  static void bottomUpTraversal(
191  StaticSPQRTree& spqrTree,
192  const node& mu,
193  const NodeArray<T>& nodeLength,
194  NodeArray< EdgeArray<T> >& edgeLength);
195 
206  static void topDownTraversal(
207  StaticSPQRTree& spqrTree,
208  const node& mu,
209  const NodeArray<T>& nodeLength,
210  NodeArray< EdgeArray<T> >& edgeLength);
211 
223  static T largestFaceContainingNode(
224  const StaticSPQRTree& spqrTree,
225  const node& mu,
226  const node& n,
227  const NodeArray<T>& nodeLength,
228  const NodeArray< EdgeArray<T> >& edgeLength);
229 
239  static T largestFaceInSkeleton(
240  const StaticSPQRTree& spqrTree,
241  const node& mu,
242  const NodeArray<T>& nodeLength,
243  const NodeArray< EdgeArray<T> >& edgeLength);
244 
245  /* \brief Computes recursively the thickness of the skeleton graph of all
246  * nodes in the SPQR-tree.
247  *
248  * \param spqrTree The SPQR-tree of the treated graph.
249  * \param mu a node in the SPQR-tree.
250  * \param thickness saving the computed results - the thickness of each
251  * skeleton graph.
252  * \param nodeLength is saving for each node of the original graph \p G its
253  * length.
254  * \param edgeLength is saving the edge lengths of all edges in each skeleton
255  * graph of all tree nodes.
256  */
257  static void bottomUpThickness(
258  const StaticSPQRTree& spqrTree,
259  const node& mu,
260  NodeArray<T>& thickness,
261  const NodeArray<T>& nodeLength,
262  const NodeArray< EdgeArray<T> >& edgeLength);
263 
264  /* \brief ExpandEdge embeds all edges in the skeleton graph \a S into an
265  * existing embedding and calls recursively itself for all virtual edges
266  * in S.
267  *
268  * \param spqrTree The SPQR-tree of the treated graph.
269  * \param treeNodeTreated is an array saving for each SPQR-tree node \p mu
270  * whether it was already treated by any call of ExpandEdge or not. Every
271  * \p mu should only be treated once.
272  * \param mu is a node in the SPQR-tree.
273  * \param leftNode is the node adjacent to referenceEdge, which should be "left"
274  * in the embedding
275  * \param nodeLength is an array saving the lengths of the nodes of \p G.
276  * \param edgeLength is saving the edge lengths of all edges in each skeleton
277  * graph of all tree nodes.
278  * \param thickness of each skeleton graph.
279  * \param newOrder is saving for each node \p n in \p G the new adjacency
280  * list. This is an output parameter.
281  * \param adjBeforeNodeArraySource is saving for the source of the reference edge
282  * of the skeleton of mu the adjacency entry, before which new entries have
283  * to be inserted.
284  * \param adjBeforeNodeArrayTarget is saving for the target of the reference edge
285  * of the skeleton of mu the adjacency entry, before which new entries have
286  * to be inserted.
287  * \param delta_u the distance from the second adjacent face of the reference edge
288  * except the external face to the external face of G.
289  * \param delta_d the distance from the external face to the external face of G.
290  * \param adjExternal is an adjacency entry in the external face.
291  * \param n is only set, if ExpandEdge is called for the first time, because
292  * then there is no virtual edge which has to be expanded, but the max face
293  * has to contain a certain node \p n.
294  */
295  static void expandEdge(
296  const StaticSPQRTree& spqrTree,
297  NodeArray<bool>& treeNodeTreated,
298  const node& mu,
299  const node& leftNode,
300  const NodeArray<T>& nodeLength,
301  const NodeArray< EdgeArray<T> >& edgeLength,
302  const NodeArray<T>& thickness,
303  NodeArray< List<adjEntry> >& newOrder,
304  NodeArray< ListIterator<adjEntry> >& adjBeforeNodeArraySource,
305  NodeArray< ListIterator<adjEntry> >& adjBeforeNodeArrayTarget,
306  const T& delta_u,
307  const T& delta_d,
308  adjEntry& adjExternal,
309  const node& n = nullptr);
310 
311  /* \brief Embeds all edges in the skeleton graph \a S of an S-node of the
312  * SPQR-tree into an existing embedding and calls recursively itself for
313  * all virtual edges in S.
314  *
315  * \param spqrTree The SPQR-tree of the treated graph.
316  * \param treeNodeTreated is an array saving for each SPQR-tree node \p mu
317  * whether it was already treated by any call of ExpandEdge or not. Every
318  * \p mu should only be treated once.
319  * \param mu is a node in the SPQR-tree.
320  * \param leftNode is the node adjacent to referenceEdge, which should be "left"
321  * in the embedding
322  * \param nodeLength is an array saving the lengths of the nodes of \p G.
323  * \param edgeLength is saving the edge lengths of all edges in each skeleton
324  * graph of all tree nodes.
325  * \param thickness of each skeleton graph.
326  * \param newOrder is saving for each node \p n in \p G the new adjacency
327  * list. This is an output parameter.
328  * \param adjBeforeNodeArraySource is saving for the source of the reference edge
329  * of the skeleton of mu the adjacency entry, before which new entries have
330  * to be inserted.
331  * \param adjBeforeNodeArrayTarget is saving for the target of the reference edge
332  * of the skeleton of mu the adjacency entry, before which new entries have
333  * to be inserted.
334  * \param delta_u the distance from the second adjacent face of the reference edge
335  * except the external face to the external face of G.
336  * \param delta_d the distance from the external face to the external face of G.
337  * \param adjExternal is an adjacency entry in the external face.
338  */
339  static void expandEdgeSNode(
340  const StaticSPQRTree& spqrTree,
341  NodeArray<bool>& treeNodeTreated,
342  const node& mu,
343  const node& leftNode,
344  const NodeArray<T>& nodeLength,
345  const NodeArray< EdgeArray<T> >& edgeLength,
346  const NodeArray<T>& thickness,
347  NodeArray< List<adjEntry> >& newOrder,
348  NodeArray< ListIterator<adjEntry> >& adjBeforeNodeArraySource,
349  NodeArray< ListIterator<adjEntry> >& adjBeforeNodeArrayTarget,
350  const T& delta_u,
351  const T& delta_d,
352  adjEntry& adjExternal);
353 
354  /* \brief Embeds all edges in the skeleton graph \a S of an P-node of the
355  * SPQR-tree into an existing embedding and calls recursively itself for
356  * all virtual edges in S.
357  *
358  * \param spqrTree The SPQR-tree of the treated graph.
359  * \param treeNodeTreated is an array saving for each SPQR-tree node \p mu
360  * whether it was already treated by any call of ExpandEdge or not. Every
361  * \p mu should only be treated once.
362  * \param mu is a node in the SPQR-tree.
363  * \param leftNode is the node adjacent to referenceEdge, which should be "left"
364  * in the embedding
365  * \param nodeLength is an array saving the lengths of the nodes of \p G.
366  * \param edgeLength is saving the edge lengths of all edges in each skeleton
367  * graph of all tree nodes.
368  * \param thickness of each skeleton graph.
369  * \param newOrder is saving for each node \p n in \p G the new adjacency
370  * list. This is an output parameter.
371  * \param adjBeforeNodeArraySource is saving for the source of the reference edge
372  * of the skeleton of mu the adjacency entry, before which new entries have
373  * to be inserted.
374  * \param adjBeforeNodeArrayTarget is saving for the target of the reference edge
375  * of the skeleton of mu the adjacency entry, before which new entries have
376  * to be inserted.
377  * \param delta_u the distance from the second adjacent face of the reference edge
378  * except the external face to the external face of G.
379  * \param delta_d the distance from the external face to the external face of G.
380  * \param adjExternal is an adjacency entry in the external face.
381  */
382  static void expandEdgePNode(
383  const StaticSPQRTree& spqrTree,
384  NodeArray<bool>& treeNodeTreated,
385  const node& mu,
386  const node& leftNode,
387  const NodeArray<T>& nodeLength,
388  const NodeArray< EdgeArray<T> >& edgeLength,
389  const NodeArray<T>& thickness,
390  NodeArray< List<adjEntry> >& newOrder,
391  NodeArray< ListIterator<adjEntry> >& adjBeforeNodeArraySource,
392  NodeArray< ListIterator<adjEntry> >& adjBeforeNodeArrayTarget,
393  const T& delta_u,
394  const T& delta_d,
395  adjEntry& adjExternal);
396 
397  /* \brief Embeds all edges in the skeleton graph \a S of an R-node of the
398  * SPQR-tree into an existing embedding and calls recursively itself for
399  * all virtual edges in S.
400  *
401  * \param spqrTree The SPQR-tree of the treated graph.
402  * \param treeNodeTreated is an array saving for each SPQR-tree node \p mu
403  * whether it was already treated by any call of ExpandEdge or not. Every
404  * \p mu should only be treated once.
405  * \param mu is a node in the SPQR-tree.
406  * \param leftNode is the node adjacent to referenceEdge, which should be "left"
407  * in the embedding
408  * \param nodeLength is an array saving the lengths of the nodes of \p G.
409  * \param edgeLength is saving the edge lengths of all edges in each skeleton
410  * graph of all tree nodes.
411  * \param thickness of each skeleton graph.
412  * \param newOrder is saving for each node \p n in \p G the new adjacency
413  * list. This is an output parameter.
414  * \param adjBeforeNodeArraySource is saving for the source of the reference edge
415  * of the skeleton of mu the adjacency entry, before which new entries have
416  * to be inserted.
417  * \param adjBeforeNodeArrayTarget is saving for the target of the reference edge
418  * of the skeleton of mu the adjacency entry, before which new entries have
419  * to be inserted.
420  * \param delta_u the distance from the second adjacent face of the reference edge
421  * except the external face to the external face of G.
422  * \param delta_d the distance from the external face to the external face of G.
423  * \param adjExternal is an adjacency entry in the external face.
424  * \param n is only set, if ExpandEdge is called for the first time, because
425  * then there is no virtual edge which has to be expanded, but the max face
426  * has to contain a certain node \p n.
427  */
428  static void expandEdgeRNode(
429  const StaticSPQRTree& spqrTree,
430  NodeArray<bool>& treeNodeTreated,
431  const node& mu,
432  const node& leftNode,
433  const NodeArray<T>& nodeLength,
434  const NodeArray< EdgeArray<T> >& edgeLength,
435  const NodeArray<T>& thickness,
436  NodeArray< List<adjEntry> >& newOrder,
437  NodeArray< ListIterator<adjEntry> >& adjBeforeNodeArraySource,
438  NodeArray< ListIterator<adjEntry> >& adjBeforeNodeArrayTarget,
439  const T& delta_u,
440  const T& delta_d,
441  adjEntry& adjExternal,
442  const node& n = nullptr);
443 
444  /* \brief Writes a given adjacency entry into the newOrder. If the edge
445  * belonging to ae is a virtual edge, it is expanded.
446  *
447  * \param ae is the adjacency entry which has to be expanded.
448  * \param before is the adjacency entry of the node in \p G, before
449  * which ae has to be inserted.
450  * \param spqrTree The SPQR-tree of the treated graph.
451  * \param treeNodeTreated is an array saving for each SPQR-tree node \p mu
452  * whether it was already treated by any call of ExpandEdge or not. Every
453  * \p mu should only be treated once.
454  * \param mu is a node in the SPQR-tree.
455  * \param leftNode is the node adjacent to referenceEdge, which should be "left"
456  * in the embedding
457  * \param nodeLength is an array saving the lengths of the nodes of \p G.
458  * \param edgeLength is saving the edge lengths of all edges in each skeleton
459  * graph of all tree nodes.
460  * \param thickness of each skeleton graph.
461  * \param newOrder is saving for each node \p n in \p G the new adjacency
462  * list. This is an output parameter.
463  * \param adjBeforeNodeArraySource is saving for the source of the reference edge
464  * of the skeleton of mu the adjacency entry, before which new entries have
465  * to be inserted.
466  * \param adjBeforeNodeArrayTarget is saving for the target of the reference edge
467  * of the skeleton of mu the adjacency entry, before which new entries have
468  * to be inserted.
469  * \param delta_u the distance from the second adjacent face of the reference edge
470  * except the external face to the external face of G.
471  * \param delta_d the distance from the external face to the external face of G.
472  * \param adjExternal is an adjacency entry in the external face.
473  */
474  static void adjEntryForNode(
475  adjEntry& ae,
477  const StaticSPQRTree& spqrTree,
478  NodeArray<bool>& treeNodeTreated,
479  const node& mu,
480  const node& leftNode,
481  const NodeArray<T>& nodeLength,
482  const NodeArray< EdgeArray<T> >& edgeLength,
483  const NodeArray<T>& thickness,
484  NodeArray< List<adjEntry> >& newOrder,
485  NodeArray< ListIterator<adjEntry> >& adjBeforeNodeArraySource,
486  NodeArray< ListIterator<adjEntry> >& adjBeforeNodeArrayTarget,
487  const T& delta_u,
488  const T& delta_d,
489  adjEntry& adjExternal);
490 
491  /* \brief Single source shortest path.
492  *
493  * \param G directed graph
494  * \param s source node
495  * \param length length of an edge
496  * \param d contains shortest path distances after call
497  */
498  static bool sssp(
499  const Graph& G,
500  const node& s,
501  const EdgeArray<T>& length,
502  NodeArray<T>& d);
503 };
504 
505 
506 template<class T>
508  Graph& G,
509  adjEntry& adjExternal,
510  const NodeArray<T>& nodeLength,
511  const EdgeArray<T>& edgeLength,
512  const node& n /* = 0*/)
513 {
514  //Base cases (SPQR-Tree-implementatioin would crash with these inputs):
515  OGDF_ASSERT(G.numberOfNodes() >= 2);
516  if (G.numberOfEdges() <= 2)
517  {
518  edge e = G.firstEdge();
519  adjExternal = e->adjSource();
520  return;
521  }
522 
523  //First step: calculate maximum face and edge lengths for virtual edges
524  StaticSPQRTree spqrTree(G);
525  NodeArray< EdgeArray<T> > edgeLengthSkel;
526  compute(G, nodeLength, edgeLength, &spqrTree, edgeLengthSkel);
527 
528  //Second step: Embed G
529  T biggestFace = -1;
530  node bigFaceMu;
531  if (n == nullptr)
532  {
533  for(node mu : spqrTree.tree().nodes)
534  {
535  //Expand all faces in skeleton(mu) and get size of the largest of them:
536  T sizeMu = largestFaceInSkeleton(spqrTree, mu, nodeLength, edgeLengthSkel);
537  if (sizeMu > biggestFace)
538  {
539  biggestFace = sizeMu;
540  bigFaceMu = mu;
541  }
542  }
543  }
544  else
545  {
546  node* mus = new node[n->degree()];
547  int i = 0;
548  for(adjEntry adj : n->adjEntries) {
549  mus[i] = spqrTree.skeletonOfReal(adj->theEdge()).treeNode();
550  bool alreadySeenMu = false;
551  for (int j = 0; j < i && !alreadySeenMu; j++)
552  {
553  if (mus[i] == mus[j])
554  alreadySeenMu = true;
555  }
556  if (alreadySeenMu)
557  {
558  i++;
559  continue;
560  }
561  else
562  {
563  //Expand all faces in skeleton(mu) containing n and get size of
564  //the largest of them:
565  T sizeInMu = largestFaceContainingNode(spqrTree, mus[i], n, nodeLength, edgeLengthSkel);
566  if (sizeInMu > biggestFace)
567  {
568  biggestFace = sizeInMu;
569  bigFaceMu = mus[i];
570  }
571 
572  i++;
573  }
574  }
575  delete[] mus;
576  }
577 
578  bigFaceMu = spqrTree.rootTreeAt(bigFaceMu);
579 
580  NodeArray<T> thickness(spqrTree.tree());
581  bottomUpThickness(spqrTree, bigFaceMu, thickness, nodeLength, edgeLengthSkel);
582 
583  NodeArray< List<adjEntry> > newOrder(G);
584  NodeArray<bool> treeNodeTreated(spqrTree.tree(), false);
586  adjExternal = nullptr;
587  NodeArray< ListIterator<adjEntry> > adjBeforeNodeArraySource(spqrTree.tree());
588  NodeArray< ListIterator<adjEntry> > adjBeforeNodeArrayTarget(spqrTree.tree());
589  expandEdge(spqrTree, treeNodeTreated, bigFaceMu, nullptr, nodeLength,
590  edgeLengthSkel, thickness, newOrder, adjBeforeNodeArraySource,
591  adjBeforeNodeArrayTarget, 0, 0, adjExternal, n);
592 
593  for(node v : G.nodes)
594  G.sort(v, newOrder[v]);
595 }
596 
597 
598 template<class T>
600  adjEntry& ae,
602  const StaticSPQRTree& spqrTree,
603  NodeArray<bool>& treeNodeTreated,
604  const node& mu,
605  const node& leftNode,
606  const NodeArray<T>& nodeLength,
607  const NodeArray< EdgeArray<T> >& edgeLength,
608  const NodeArray<T>& thickness,
609  NodeArray< List<adjEntry> >& newOrder,
610  NodeArray< ListIterator<adjEntry> >& adjBeforeNodeArraySource,
611  NodeArray< ListIterator<adjEntry> >& adjBeforeNodeArrayTarget,
612  const T& delta_u,
613  const T& delta_d,
614  adjEntry& adjExternal)
615 {
616  Skeleton& S = spqrTree.skeleton(mu);
617  edge referenceEdge = S.referenceEdge();
618  if (S.isVirtual(ae->theEdge()))
619  {
620  edge twinE = S.twinEdge(ae->theEdge());
621  node twinNT = S.twinTreeNode(ae->theEdge());
622 #if 0
623  Skeleton& twinS = spqrTree.skeleton(twinNT);
624 #endif
625 
626  if (!treeNodeTreated[twinNT])
627  {
628  node m_leftNode;
629  if (ae->theEdge()->source() == leftNode)
630  m_leftNode = twinE->source();
631  else
632  m_leftNode = twinE->target();
633 
634  if (ae->theEdge()->source() == ae->theNode())
635  adjBeforeNodeArraySource[twinNT] = before;
636  else
637  adjBeforeNodeArrayTarget[twinNT] = before;
638 
639  //recursion call:
640  expandEdge(spqrTree, treeNodeTreated, twinNT, m_leftNode,
641  nodeLength, edgeLength, thickness, newOrder,
642  adjBeforeNodeArraySource, adjBeforeNodeArrayTarget,
643  delta_u, delta_d, adjExternal);
644  } //if (!treeNodeTreated[twinNT])
645 
646  if (ae->theEdge() == referenceEdge)
647  {
648  if (ae->theNode() == ae->theEdge()->source())
649  {
650  ListIterator<adjEntry> tmpBefore = adjBeforeNodeArraySource[mu];
651  adjBeforeNodeArraySource[mu] = before;
652  before = tmpBefore;
653  }
654  else
655  {
656  ListIterator<adjEntry> tmpBefore = adjBeforeNodeArrayTarget[mu];
657  adjBeforeNodeArrayTarget[mu] = before;
658  before = tmpBefore;
659  }
660  }
661  else
662  {
663  if (ae->theNode() == ae->theEdge()->source())
664  before = adjBeforeNodeArraySource[twinNT];
665  else
666  before = adjBeforeNodeArrayTarget[twinNT];
667  }
668  }
669  else
670  {
671  node origNode = S.original(ae->theNode());
672  edge origEdge = S.realEdge(ae->theEdge());
673 
674  if (origNode == origEdge->source())
675  {
676  if (!before.valid())
677  before = newOrder[origNode].pushBack(origEdge->adjSource());
678  else
679  before = newOrder[origNode].insertBefore(origEdge->adjSource(), before);
680  }
681  else
682  {
683  if (!before.valid())
684  before = newOrder[origNode].pushBack(origEdge->adjTarget());
685  else
686  before = newOrder[origNode].insertBefore(origEdge->adjTarget(), before);
687  }
688  } //else //!(S.isVirtual(ae->theEdge()))
689 }
690 
691 
692 template<class T>
694  const StaticSPQRTree& spqrTree,
695  NodeArray<bool>& treeNodeTreated,
696  const node& mu,
697  const node& leftNode,
698  const NodeArray<T>& nodeLength,
699  const NodeArray< EdgeArray<T> >& edgeLength,
700  const NodeArray<T>& thickness,
701  NodeArray< List<adjEntry> >& newOrder,
702  NodeArray< ListIterator<adjEntry> >& adjBeforeNodeArraySource,
703  NodeArray< ListIterator<adjEntry> >& adjBeforeNodeArrayTarget,
704  const T& delta_u,
705  const T& delta_d,
706  adjEntry& adjExternal,
707  const node& n /*= 0*/)
708 {
709  treeNodeTreated[mu] = true;
710 
711  switch(spqrTree.typeOf(mu))
712  {
714  expandEdgeSNode(spqrTree, treeNodeTreated, mu, leftNode,
715  nodeLength, edgeLength, thickness, newOrder, adjBeforeNodeArraySource,
716  adjBeforeNodeArrayTarget, delta_u, delta_d, adjExternal);
717  break;
719  expandEdgePNode(spqrTree, treeNodeTreated, mu, leftNode,
720  nodeLength, edgeLength, thickness, newOrder, adjBeforeNodeArraySource,
721  adjBeforeNodeArrayTarget, delta_u, delta_d, adjExternal);
722  break;
724  expandEdgeRNode(spqrTree, treeNodeTreated, mu, leftNode,
725  nodeLength, edgeLength, thickness, newOrder, adjBeforeNodeArraySource,
726  adjBeforeNodeArrayTarget, delta_u, delta_d, adjExternal, n);
727  break;
728  default:
729  OGDF_ASSERT(false);
730  }
731 }
732 
733 
734 template<class T>
736  const StaticSPQRTree& spqrTree,
737  NodeArray<bool>& treeNodeTreated,
738  const node& mu,
739  const node& leftNode,
740  const NodeArray<T>& nodeLength,
741  const NodeArray< EdgeArray<T> >& edgeLength,
742  const NodeArray<T>& thickness,
743  NodeArray< List<adjEntry> >& newOrder,
744  NodeArray< ListIterator<adjEntry> >& adjBeforeNodeArraySource,
745  NodeArray< ListIterator<adjEntry> >& adjBeforeNodeArrayTarget,
746  const T& delta_u,
747  const T& delta_d,
748  adjEntry& adjExternal)
749 {
750  Skeleton& S = spqrTree.skeleton(mu);
751  edge referenceEdge = S.referenceEdge();
752  adjEntry startAdjEntry = nullptr;
753  if (leftNode == nullptr)
754  {
755  for(edge e : S.getGraph().edges)
756  {
757  if (!S.isVirtual(e))
758  {
759  startAdjEntry = e->adjSource();
760  break;
761  }
762  }
763  OGDF_ASSERT(startAdjEntry != nullptr);
764  }
765  else if (leftNode->firstAdj()->theEdge() == referenceEdge)
766  startAdjEntry = leftNode->lastAdj();
767  else
768  startAdjEntry = leftNode->firstAdj();
769 
770  adjEntry ae = startAdjEntry;
771  if (adjExternal == nullptr)
772  {
773  edge orgEdge = S.realEdge(ae->theEdge());
774  if (orgEdge->source() == S.original(ae->theNode()))
775  adjExternal = orgEdge->adjSource()->twin();
776  else
777  adjExternal = orgEdge->adjTarget()->twin();
778  }
779 
781  if (referenceEdge && leftNode == referenceEdge->source())
782  before = adjBeforeNodeArraySource[mu];
783  else if (referenceEdge)
784  before = adjBeforeNodeArrayTarget[mu];
785  ListIterator<adjEntry> beforeSource;
786 
787  bool firstStep = true;
788  while (firstStep || ae != startAdjEntry)
789  {
790  //first treat ae with ae->theNode() is left node, then treat its twin:
791  node m_leftNode = ae->theNode();
792 
793  if (ae->theEdge() == referenceEdge)
794  {
795  if (ae->theNode() == referenceEdge->source())
796  adjBeforeNodeArraySource[mu] = before;
797  else
798  adjBeforeNodeArrayTarget[mu] = before;
799  }
800  else
801  {
802  if (S.isVirtual(ae->theEdge()) && referenceEdge)
803  {
804  node twinTN = S.twinTreeNode(ae->theEdge());
805  if (ae->theEdge()->source() == ae->theNode())
806  {
807  if (ae->theEdge()->target() == referenceEdge->source())
808  adjBeforeNodeArrayTarget[twinTN] = adjBeforeNodeArraySource[mu];
809  else if (ae->theEdge()->target() == referenceEdge->target())
810  adjBeforeNodeArrayTarget[twinTN] = adjBeforeNodeArrayTarget[mu];
811  }
812  else
813  {
814  if (ae->theEdge()->source() == referenceEdge->source())
815  adjBeforeNodeArraySource[twinTN] = adjBeforeNodeArraySource[mu];
816  else if (ae->theEdge()->source() == referenceEdge->target())
817  adjBeforeNodeArraySource[twinTN] = adjBeforeNodeArrayTarget[mu];
818  }
819  }
820 
821  adjEntryForNode(ae, before, spqrTree, treeNodeTreated, mu,
822  m_leftNode, nodeLength, edgeLength, thickness, newOrder,
823  adjBeforeNodeArraySource, adjBeforeNodeArrayTarget,
824  delta_u, delta_d, adjExternal);
825  }
826 
827  if (firstStep) {
828  beforeSource = before;
829  firstStep = false;
830  }
831 
832  ae = ae->twin();
833  if (!referenceEdge)
834  before = nullptr;
835  else if (ae->theNode() == referenceEdge->source())
836  before = adjBeforeNodeArraySource[mu];
837  else if (ae->theNode() == referenceEdge->target())
838  before = adjBeforeNodeArrayTarget[mu];
839  else
840  before = nullptr;
841  if (ae->theEdge() == referenceEdge)
842  {
843  if (ae->theNode() == referenceEdge->source())
844  adjBeforeNodeArraySource[mu] = beforeSource;
845  else
846  adjBeforeNodeArrayTarget[mu] = beforeSource;
847  }
848  else
849  adjEntryForNode(ae, before, spqrTree, treeNodeTreated, mu,
850  m_leftNode, nodeLength, edgeLength, thickness, newOrder,
851  adjBeforeNodeArraySource, adjBeforeNodeArrayTarget,
852  delta_u, delta_d, adjExternal);
853 
854  //set new adjacency entry pair (ae and its twin):
855  if (ae->theNode()->firstAdj() == ae)
856  ae = ae->theNode()->lastAdj();
857  else
858  ae = ae->theNode()->firstAdj();
859  }
860 }
861 
862 
863 template<class T>
865  const StaticSPQRTree& spqrTree,
866  NodeArray<bool>& treeNodeTreated,
867  const node& mu,
868  const node& leftNode,
869  const NodeArray<T>& nodeLength,
870  const NodeArray< EdgeArray<T> >& edgeLength,
871  const NodeArray<T>& thickness,
872  NodeArray< List<adjEntry> >& newOrder,
873  NodeArray< ListIterator<adjEntry> >& adjBeforeNodeArraySource,
874  NodeArray< ListIterator<adjEntry> >& adjBeforeNodeArrayTarget,
875  const T& delta_u,
876  const T& delta_d,
877  adjEntry& adjExternal)
878 {
879  //Choose face defined by virtual edge and the longest edge different from it.
880  Skeleton& S = spqrTree.skeleton(mu);
881  edge referenceEdge = S.referenceEdge();
882  edge altReferenceEdge = nullptr;
883 
884  node m_leftNode = leftNode;
885  if (!m_leftNode) {
886  List<node> nodeList;
887  S.getGraph().allNodes(nodeList);
888  m_leftNode = *(nodeList.begin());
889  }
890  node m_rightNode = m_leftNode->firstAdj()->twinNode();
891 
892  if (referenceEdge == nullptr)
893  {
894  for(edge e : S.getGraph().edges)
895  {
896  if (!S.isVirtual(e))
897  {
898  altReferenceEdge = e;
899  edge orgEdge = S.realEdge(e);
900  if (orgEdge->source() == S.original(m_leftNode))
901  adjExternal = orgEdge->adjSource();
902  else
903  adjExternal = orgEdge->adjTarget();
904  break;
905  }
906  }
907  }
908 
909  //sort edges by length:
910  List<edge> graphEdges;
911  for(edge e : S.getGraph().edges)
912  {
913  if (e == referenceEdge || e == altReferenceEdge)
914  continue;
915 
916  if (!graphEdges.begin().valid())
917  graphEdges.pushBack(e);
918  else
919  {
920  for (ListIterator<edge> it = graphEdges.begin(); it.valid(); ++it)
921  {
922  if (edgeLength[mu][e] > edgeLength[mu][*it])
923  {
924  graphEdges.insertBefore(e, it);
925  break;
926  }
927  ListIterator<edge> next = it;
928  ++next;
929  if (!next.valid())
930  {
931  graphEdges.pushBack(e);
932  break;
933  }
934  }
935  }
936  }
937 
938  List<edge> rightEdgeOrder;
939  ListIterator<adjEntry> beforeAltRefEdge;
940  ListIterator<adjEntry> beforeLeft;
941 
942  //begin with left node and longest edge:
943  for (int i = 0; i < 2; ++i) {
945  node n;
946  if (i == 0)
947  n = m_leftNode;
948  else {
949  n = m_rightNode;
950  before = beforeAltRefEdge;
951  }
952 
953  if (referenceEdge) {
954  if (n == referenceEdge->source())
955  before = adjBeforeNodeArraySource[mu];
956  else
957  before = adjBeforeNodeArrayTarget[mu];
958  }
959 
960  adjEntry ae;
961 
962  //all edges except reference edge:
963  if (i == 0) {
964  ListIterator<edge> lastPos;
965  ListIterator<adjEntry> beforeRight;
966  if (referenceEdge) {
967  if (referenceEdge->source() == m_rightNode)
968  beforeRight = adjBeforeNodeArraySource[mu];
969  else //referenceEdge->target() == rightnode
970  beforeRight = adjBeforeNodeArrayTarget[mu];
971  }
972  bool insertBeforeLast = false;
973  bool oneEdgeInE_a = false;
974  T sum_E_a = 0;
975  T sum_E_b = 0;
976 
977  for (int looper = 0; looper < graphEdges.size(); looper++)
978  {
979  edge e = *(graphEdges.get(looper));
980 
981  if (!lastPos.valid())
982  lastPos = rightEdgeOrder.pushBack(e);
983  else if (insertBeforeLast)
984  lastPos = rightEdgeOrder.insertBefore(e, lastPos);
985  else
986  lastPos = rightEdgeOrder.insertAfter(e, lastPos);
987 
988  //decide whether to choose face f_a or f_b as f_{mu, mu'}:
989  if (delta_u + sum_E_a < delta_d + sum_E_b)
990  {
991  ListIterator<adjEntry> beforeU = before;
992 
993  if (e->source() == n)
994  ae = e->adjSource();
995  else
996  ae = e->adjTarget();
997 
998  if (S.isVirtual(e))
999  {
1000  node nu = S.twinTreeNode(e);
1001 
1002  T delta_u_nu = delta_u + sum_E_a;
1003  T delta_d_nu = delta_d + sum_E_b;
1004 
1005  //buffer computed embedding:
1006  NodeArray< List<adjEntry> > tmp_newOrder(spqrTree.originalGraph());
1007  ListIterator<adjEntry> tmp_before;
1008 
1009  adjEntryForNode(ae, tmp_before, spqrTree, treeNodeTreated, mu,
1010  m_leftNode, nodeLength, edgeLength, thickness,
1011  tmp_newOrder, adjBeforeNodeArraySource,
1012  adjBeforeNodeArrayTarget, delta_d_nu, delta_u_nu, adjExternal);
1013 
1014  //copy buffered embedding reversed into newOrder:
1015  node leftOrg = S.original(m_leftNode);
1016  node rightOrg = S.original(m_rightNode);
1017  for(node nOG : spqrTree.originalGraph().nodes)
1018  {
1019  List<adjEntry> nOG_tmp_adjList = tmp_newOrder[nOG];
1020  if (nOG_tmp_adjList.size() == 0)
1021  continue;
1022 
1023  ListIterator<adjEntry>* m_before;
1024  if (nOG == leftOrg)
1025  m_before = &beforeU;
1026  else if (nOG == rightOrg && referenceEdge)
1027  m_before = &beforeRight;
1028  else
1029  m_before = new ListIterator<adjEntry>();
1030 
1031  for (ListIterator<adjEntry> ae_it = nOG_tmp_adjList.begin(); ae_it.valid(); ++ae_it) {
1032  adjEntry adjaEnt = *ae_it;
1033  if (!m_before->valid())
1034  *m_before = newOrder[nOG].pushBack(adjaEnt);
1035  else
1036  *m_before = newOrder[nOG].insertBefore(adjaEnt, *m_before);
1037 
1038  if (nOG == leftOrg || nOG == rightOrg)
1039  {
1040  if (S.original(e->source()) == nOG)
1041  adjBeforeNodeArraySource[nu] = *m_before;
1042  else
1043  adjBeforeNodeArrayTarget[nu] = *m_before;
1044  }
1045  }
1046 
1047  if (nOG != leftOrg && (nOG != rightOrg || !referenceEdge))
1048  delete m_before;
1049  }
1050 
1051  sum_E_a += thickness[nu];
1052  }
1053  else
1054  {
1055  adjEntryForNode(ae, beforeU, spqrTree, treeNodeTreated, mu,
1056  m_leftNode, nodeLength, edgeLength, thickness,
1057  newOrder, adjBeforeNodeArraySource,
1058  adjBeforeNodeArrayTarget, 0, 0, adjExternal);
1059 
1060  sum_E_a += 1;
1061  }
1062 
1063  insertBeforeLast = false;
1064  if (!oneEdgeInE_a)
1065  {
1066  beforeLeft = beforeU;
1067  oneEdgeInE_a = true;
1068  }
1069  }
1070  else
1071  {
1072  if (S.isVirtual(e)) {
1073  node nu = S.twinTreeNode(e);
1074  if (referenceEdge) {
1075  if (e->source() == n)
1076  adjBeforeNodeArrayTarget[nu] = beforeRight;
1077  else
1078  adjBeforeNodeArraySource[nu] = beforeRight;
1079  }
1080  }
1081 
1082  T delta_u_nu = delta_u + sum_E_a;
1083  T delta_d_nu = delta_d + sum_E_b;
1084 
1085  if (e->source() == n)
1086  ae = e->adjSource();
1087  else
1088  ae = e->adjTarget();
1089 
1090  adjEntryForNode(ae, before, spqrTree, treeNodeTreated, mu,
1091  m_leftNode, nodeLength, edgeLength, thickness, newOrder,
1092  adjBeforeNodeArraySource, adjBeforeNodeArrayTarget,
1093  delta_u_nu, delta_d_nu, adjExternal);
1094 
1095  if (S.isVirtual(e))
1096  sum_E_b += thickness[S.twinTreeNode(e)];
1097  else
1098  sum_E_b += 1;
1099 
1100  insertBeforeLast = true;
1101  if (!oneEdgeInE_a)
1102  beforeLeft = before;
1103  }
1104  }
1105  }
1106  else
1107  {
1108  for (ListIterator<edge> it = rightEdgeOrder.begin(); it.valid(); ++it)
1109  {
1110  if ((*it)->source() == n)
1111  ae = (*it)->adjSource();
1112  else
1113  ae = (*it)->adjTarget();
1114 
1115  adjEntryForNode(ae, before, spqrTree, treeNodeTreated, mu,
1116  m_leftNode, nodeLength, edgeLength, thickness, newOrder,
1117  adjBeforeNodeArraySource, adjBeforeNodeArrayTarget,
1118  0, 0, adjExternal);
1119  }
1120  }
1121 
1122  //(alternative) reference edge at last:
1123  if (referenceEdge) {
1124  if (i == 0) {
1125  if (n == referenceEdge->source())
1126  adjBeforeNodeArraySource[mu] = beforeLeft;
1127  else
1128  adjBeforeNodeArrayTarget[mu] = beforeLeft;
1129  }
1130  else
1131  {
1132  if (n == referenceEdge->source())
1133  adjBeforeNodeArraySource[mu] = before;
1134  else
1135  adjBeforeNodeArrayTarget[mu] = before;
1136  }
1137  }
1138  else
1139  {
1140  if (altReferenceEdge->source() == n)
1141  ae = altReferenceEdge->adjSource();
1142  else
1143  ae = altReferenceEdge->adjTarget();
1144 
1145  adjEntryForNode(ae, before, spqrTree, treeNodeTreated, mu,
1146  m_leftNode, nodeLength, edgeLength, thickness, newOrder,
1147  adjBeforeNodeArraySource, adjBeforeNodeArrayTarget,
1148  0, 0, adjExternal);
1149  }
1150  }
1151 }
1152 
1153 
1154 template<class T>
1156  const StaticSPQRTree& spqrTree,
1157  NodeArray<bool>& treeNodeTreated,
1158  const node& mu,
1159  const node& leftNode,
1160  const NodeArray<T>& nodeLength,
1161  const NodeArray< EdgeArray<T> >& edgeLength,
1162  const NodeArray<T>& thickness,
1163  NodeArray< List<adjEntry> >& newOrder,
1164  NodeArray< ListIterator<adjEntry> >& adjBeforeNodeArraySource,
1165  NodeArray< ListIterator<adjEntry> >& adjBeforeNodeArrayTarget,
1166  const T& delta_u,
1167  const T& delta_d,
1168  adjEntry& adjExternal,
1169  const node& n /* = 0 */)
1170 {
1171  Skeleton& S = spqrTree.skeleton(mu);
1172  edge referenceEdge = S.referenceEdge();
1173 
1174  //compute biggest face containing the reference edge:
1175  face maxFaceContEdge = nullptr;
1176  List<node> maxFaceNodes;
1177  planarEmbed(S.getGraph());
1178  CombinatorialEmbedding combinatorialEmbedding(S.getGraph());
1179  T bigFaceSize = -1;
1180  adjEntry m_adjExternal = nullptr;
1181  for(face f : combinatorialEmbedding.faces)
1182  {
1183  bool containsVirtualEdgeOrN = false;
1184  adjEntry this_m_adjExternal = nullptr;
1185  T sizeOfFace = 0;
1186  List<node> faceNodes;
1187  for(adjEntry ae : f->entries)
1188  {
1189  faceNodes.pushBack(ae->theNode());
1190  if ((n == nullptr && (ae->theEdge() == referenceEdge || !referenceEdge))
1191  || S.original(ae->theNode()) == n) {
1192  containsVirtualEdgeOrN = true;
1193  if (referenceEdge)
1194  this_m_adjExternal = ae;
1195  }
1196 
1197  if (!referenceEdge && !S.isVirtual(ae->theEdge()))
1198  this_m_adjExternal = ae;
1199 
1200  sizeOfFace += edgeLength[mu][ae->theEdge()]
1201  + nodeLength[S.original(ae->theNode())];
1202  }
1203 
1204  if (containsVirtualEdgeOrN && this_m_adjExternal && sizeOfFace > bigFaceSize) {
1205  maxFaceNodes = faceNodes;
1206  bigFaceSize = sizeOfFace;
1207  maxFaceContEdge = f;
1208  m_adjExternal = this_m_adjExternal;
1209  }
1210  }
1211  OGDF_ASSERT(maxFaceContEdge);
1212 
1213  if (!adjExternal) {
1214  edge orgEdge = S.realEdge(m_adjExternal->theEdge());
1215  if (orgEdge->source() == S.original(m_adjExternal->theNode()))
1216  adjExternal = orgEdge->adjSource();
1217  else
1218  adjExternal = orgEdge->adjTarget();
1219  }
1220 
1221  adjEntry adjMaxFace = m_adjExternal;
1222 
1223  //if embedding is mirror symmetrical embedding of desired embedding,
1224  //invert adjacency list of all nodes:
1225  if (referenceEdge) {
1226  //successor of adjEntry of virtual edge in adjacency list of leftNode:
1227  adjEntry succ_virtualEdge_leftNode;
1228  if (leftNode == referenceEdge->source())
1229  succ_virtualEdge_leftNode = referenceEdge->adjSource()->succ();
1230  else
1231  succ_virtualEdge_leftNode = referenceEdge->adjTarget()->succ();
1232  if (!succ_virtualEdge_leftNode)
1233  succ_virtualEdge_leftNode = leftNode->firstAdj();
1234 
1235  bool succVELNAEInExtFace = false;
1236  for(adjEntry aeExtFace : maxFaceContEdge->entries)
1237  {
1238  if (aeExtFace->theEdge() == succ_virtualEdge_leftNode->theEdge())
1239  {
1240  succVELNAEInExtFace = true;
1241  break;
1242  }
1243  }
1244 
1245  if (!succVELNAEInExtFace)
1246  {
1247  for(node v : S.getGraph().nodes)
1248  {
1249  List<adjEntry> newAdjOrder;
1250  for (adjEntry ae = v->firstAdj(); ae; ae = ae->succ())
1251  newAdjOrder.pushFront(ae);
1252  S.getGraph().sort(v, newAdjOrder);
1253  }
1254  adjMaxFace = adjMaxFace->twin();
1255  }
1256  }
1257 
1258  NodeArray<bool> nodeTreated(S.getGraph(), false);
1259  adjEntry start_ae;
1260  if (referenceEdge) {
1261  start_ae = adjMaxFace;
1262  do
1263  {
1264  if (start_ae->theEdge() == referenceEdge) {
1265  start_ae = start_ae->faceCycleSucc();
1266  break;
1267  }
1268  start_ae = start_ae->faceCycleSucc();
1269  } while(start_ae != adjMaxFace);
1270  }
1271  else
1272  start_ae = adjMaxFace;
1273 
1274  //For every edge a buffer saving adjacency entries written in embedding step
1275  //for nodes on the maximum face, needed in step for other nodes.
1276  EdgeArray< List<adjEntry> > buffer(S.getGraph());
1277 
1278  bool firstStep = true;
1279  bool after_start_ae = true;
1280  for (adjEntry ae = start_ae;
1281  firstStep || ae != start_ae;
1282  after_start_ae = after_start_ae && ae->succ(),
1283  ae = after_start_ae ? ae->faceCycleSucc()
1284  : (!ae->faceCycleSucc() ? adjMaxFace : ae->faceCycleSucc()))
1285  {
1286  firstStep = false;
1287 #if 0
1288  node nodeG = S.original(ae->theNode());
1289 #endif
1290  nodeTreated[ae->theNode()] = true;
1291 
1292  //copy adjacency list of nodes into newOrder:
1294  edge vE = (ae->theEdge() == referenceEdge) ? referenceEdge : ae->theEdge();
1295  node nu = (ae->theEdge() == referenceEdge) ? mu : S.twinTreeNode(ae->theEdge());
1296  if (S.isVirtual(vE)) {
1297  if (ae->theNode() == vE->source())
1298  before = adjBeforeNodeArraySource[nu];
1299  else
1300  before = adjBeforeNodeArrayTarget[nu];
1301  }
1302 
1303  bool after_ae = true;
1304  adjEntry m_start_ae;
1305  if (referenceEdge) {
1306  if (ae->theNode() == referenceEdge->source())
1307  m_start_ae = referenceEdge->adjSource();
1308  else if (ae->theNode() == referenceEdge->target())
1309  m_start_ae = referenceEdge->adjTarget();
1310  else
1311  m_start_ae = ae;
1312  }
1313  else
1314  m_start_ae = ae;
1315 
1316  adjEntry m_stop_ae;
1317  bool hit_stop_twice = false;
1318  int numOfHits = 0;
1319  if (referenceEdge
1320  && (ae->theNode() == referenceEdge->source()
1321  || ae->theNode() == referenceEdge->target())) {
1322  if (m_start_ae->succ())
1323  m_stop_ae = m_start_ae->succ();
1324  else {
1325  m_stop_ae = m_start_ae->theNode()->firstAdj();
1326  hit_stop_twice = true;
1327  }
1328  }
1329  else
1330  m_stop_ae = m_start_ae;
1331 
1332  for (adjEntry aeN = m_start_ae;
1333  after_ae || (hit_stop_twice && numOfHits != 2) || aeN != m_stop_ae;
1334  after_ae = after_ae && aeN->succ(),
1335  aeN = after_ae ? aeN->succ()
1336  : (!aeN->succ() ? ae->theNode()->firstAdj() : aeN->succ()),
1337  numOfHits = (aeN == m_stop_ae) ? numOfHits + 1 : numOfHits) {
1338  node m_leftNode = nullptr;
1339  if (S.isVirtual(aeN->theEdge()) && aeN->theEdge() != referenceEdge)
1340  {
1341  //Compute left node of aeN->theNode(). First get adjacency entry in ext. face
1342  //(if edge is in ext. face) and compare face cycle successor with successor
1343  //in node adjacency list. If it is the same, it is the right node, otherwise
1344  //the left.
1345  adjEntry aeExtFace = nullptr;
1346  bool succInExtFace = false;
1347  bool aeNInExtFace = false;
1348  adjEntry aeNSucc = (aeN->succ()) ? aeN->succ() : ae->theNode()->firstAdj();
1349  aeExtFace = adjMaxFace;
1350  do
1351  {
1352  if (aeExtFace->theEdge() == aeNSucc->theEdge())
1353  {
1354  succInExtFace = true;
1355  if (aeNInExtFace)
1356  break;
1357  }
1358  if (aeExtFace->theEdge() == aeN->theEdge())
1359  {
1360  aeNInExtFace = true;
1361  if (succInExtFace)
1362  break;
1363  }
1364  aeExtFace = aeExtFace->faceCycleSucc();
1365  } while(aeExtFace != adjMaxFace);
1366  if (aeNInExtFace && succInExtFace)
1367  m_leftNode = aeN->twinNode();
1368  else
1369  m_leftNode = aeN->theNode();
1370 
1371  node twinTN = S.twinTreeNode(aeN->theEdge());
1372  if (referenceEdge) {
1373  if (aeN->theEdge()->source() == aeN->theNode()) {
1374  if (aeN->theEdge()->target() == referenceEdge->source())
1375  adjBeforeNodeArrayTarget[twinTN] = adjBeforeNodeArraySource[mu];
1376  else if (aeN->theEdge()->target() == referenceEdge->target())
1377  adjBeforeNodeArrayTarget[twinTN] = adjBeforeNodeArrayTarget[mu];
1378  }
1379  else
1380  {
1381  if (aeN->theEdge()->source() == referenceEdge->source())
1382  adjBeforeNodeArraySource[twinTN] = adjBeforeNodeArraySource[mu];
1383  else if (aeN->theEdge()->source() == referenceEdge->target())
1384  adjBeforeNodeArraySource[twinTN] = adjBeforeNodeArrayTarget[mu];
1385  }
1386  }
1387  }
1388 
1389  adjEntryForNode(aeN, before, spqrTree, treeNodeTreated, mu,
1390  m_leftNode, nodeLength, edgeLength, thickness, newOrder,
1391  adjBeforeNodeArraySource, adjBeforeNodeArrayTarget,
1392  0, 0, adjExternal);
1393 
1394  //if the other node adjacent to the current treated edge is not in the
1395  //max face, put written edges into an buffer and clear the adjacency
1396  //list of that node.
1397  if (!maxFaceNodes.search(aeN->twinNode()).valid())
1398  {
1399  node orig_aeN_twin_theNode = S.original(aeN->twinNode());
1400  buffer[aeN->theEdge()] = newOrder[orig_aeN_twin_theNode];
1401  newOrder[orig_aeN_twin_theNode].clear();
1402  }
1403  } //for (adjEntry aeN = m_start_ae; [...]
1404  } //for (adjEntry ae = start_ae; [...]
1405 
1406  //Copy of not treated node's adjacency lists (internal nodes). Setting
1407  //of left node depending on minimal distance to external face of the
1408  //face defined by left node.
1409  bool DGcomputed = false;
1410  int f_ext_id = 0;
1411  int f_ref_id = 0;
1412  Graph DG;
1413  ArrayBuffer<node> fPG_to_nDG;
1414  NodeArray< List<adjEntry> > adjacencyList;
1415  List< List<adjEntry> > faces;
1416  NodeArray<T> dist_f_ref;
1417  NodeArray<T> dist_f_ext;
1418  AdjEntryArray<int> ae_to_face;
1419 
1420  for(node v : S.getGraph().nodes)
1421  {
1422  if (nodeTreated[v])
1423  continue;
1424 
1425  node v_original = S.original(v);
1426  nodeTreated[v] = true;
1428  for (adjEntry ae = v->firstAdj(); ae; ae = ae->succ())
1429  {
1430  if (buffer[ae->theEdge()].empty())
1431  {
1432  T delta_u_nu = 0;
1433  T delta_d_nu = 0;
1434  bool frauenlinks = false;
1435  if (S.isVirtual(ae->theEdge()))
1436  {
1437  if (!DGcomputed) {
1438  ae_to_face.init(S.getGraph());
1439  EdgeArray<T> edgeLengthDG(DG);
1440  DGcomputed = true;
1441 
1442  //compute dual graph of skeleton graph:
1443  adjacencyList.init(S.getGraph());
1444  for(node nBG : S.getGraph().nodes)
1445  {
1446  for(adjEntry ae_nBG : nBG->adjEntries)
1447  adjacencyList[nBG].pushBack(ae_nBG);
1448  }
1449 
1450  NodeArray< List<adjEntry> > adjEntryTreated(S.getGraph());
1451  for(node nBG : S.getGraph().nodes)
1452  {
1453  for(adjEntry adj : nBG->adjEntries)
1454  {
1455  if (adjEntryTreated[nBG].search(adj).valid())
1456  continue;
1457 
1458  List<adjEntry> newFace;
1459  adjEntry adj2 = adj;
1460  do {
1461  newFace.pushBack(adj2);
1462  ae_to_face[adj2] = faces.size();
1463  adjEntryTreated[adj2->theNode()].pushBack(adj2);
1464  List<adjEntry> &ladj = adjacencyList[adj2->twinNode()];
1465  adj2 = *ladj.cyclicPred(ladj.search(adj2->twin()));
1466  } while (adj2 != adj);
1467  faces.pushBack(newFace);
1468  }
1469  }
1470 
1471  for (ListIterator< List<adjEntry> > it = faces.begin(); it.valid(); ++it) {
1472  fPG_to_nDG.push(DG.newNode());
1473  }
1474 
1475  NodeArray< List<node> > adjFaces(DG);
1476  int i = 0;
1477  for (ListIterator< List<adjEntry> > it = faces.begin(); it.valid(); ++it) {
1478  int f1_id = i;
1479  for (ListIterator<adjEntry> it2 = (*it).begin(); it2.valid(); ++it2) {
1480  int f2_id = 0;
1481  int j = 0;
1482  for (ListIterator< List<adjEntry> > it3 = faces.begin(); it3.valid(); ++it3)
1483  {
1484  bool do_break = false;
1485  for (ListIterator<adjEntry> it4 = (*it3).begin(); it4.valid(); ++it4)
1486  {
1487  if ((*it4) == (*it2)->twin())
1488  {
1489  f2_id = j;
1490  do_break = true;
1491  break;
1492  }
1493  }
1494  if (do_break)
1495  break;
1496  j++;
1497  }
1498 
1499  if (f1_id != f2_id
1500  && !adjFaces[fPG_to_nDG[f1_id]].search(fPG_to_nDG[f2_id]).valid()
1501  && !adjFaces[fPG_to_nDG[f2_id]].search(fPG_to_nDG[f1_id]).valid())
1502  {
1503  adjFaces[fPG_to_nDG[f1_id]].pushBack(fPG_to_nDG[f2_id]);
1504  edge e1 = DG.newEdge(fPG_to_nDG[f1_id], fPG_to_nDG[f2_id]);
1505  edge e2 = DG.newEdge(fPG_to_nDG[f2_id], fPG_to_nDG[f1_id]);
1506 
1507  //set edge length:
1508  T e_length = -1;
1509  for (auto f1 : *it) {
1510  edge e = f1->theEdge();
1511  for (auto f2 : *faces.get(f2_id)) {
1512  if (f2->theEdge() == e
1513  && (e_length == -1
1514  || edgeLength[mu][e] < e_length)) {
1515  e_length = edgeLength[mu][e];
1516  }
1517  }
1518  }
1519  edgeLengthDG[e1] = e_length;
1520  edgeLengthDG[e2] = e_length;
1521  }
1522 
1523  if (*it2 == adjMaxFace)
1524  f_ext_id = f1_id;
1525  if (referenceEdge && *it2 == adjMaxFace->twin())
1526  f_ref_id = f1_id;
1527  }
1528  i++;
1529  } //for (ListIterator< List<adjEntry> > it = faces.begin(); it.valid(); it++)
1530 
1531  //compute shortest path from every face to the external face:
1532  node f_ext_DG = fPG_to_nDG[f_ext_id];
1533  dist_f_ext.init(DG);
1534  sssp(DG, f_ext_DG, edgeLengthDG, dist_f_ext);
1535  if (referenceEdge) {
1536  node f_ref_DG = fPG_to_nDG[f_ref_id];
1537  dist_f_ref.init(DG);
1538  sssp(DG, f_ref_DG, edgeLengthDG, dist_f_ref);
1539  }
1540  } //if (!DGcomputed)
1541 
1542  //choose face with minimal shortest path:
1543  T min1, min2;
1544  T pi_f_0_f_ext = dist_f_ext[fPG_to_nDG[ae_to_face[ae]]];
1545  T pi_f_1_f_ext = dist_f_ext[fPG_to_nDG[ae_to_face[ae->twin()]]];
1546  if (referenceEdge) {
1547  T pi_f_0_f_ref = dist_f_ref[fPG_to_nDG[ae_to_face[ae]]];
1548  T pi_f_1_f_ref = dist_f_ref[fPG_to_nDG[ae_to_face[ae->twin()]]];
1549 
1550  if (delta_u + pi_f_0_f_ref < delta_d + pi_f_0_f_ext)
1551  min1 = delta_u + pi_f_0_f_ref;
1552  else
1553  min1 = delta_d + pi_f_0_f_ext;
1554 
1555  if (delta_u + pi_f_1_f_ref < delta_d + pi_f_1_f_ext)
1556  min2 = delta_u + pi_f_1_f_ref;
1557  else
1558  min2 = delta_d + pi_f_1_f_ext;
1559 
1560  if (min1 > min2)
1561  {
1562  delta_u_nu = delta_u;
1563  if (pi_f_0_f_ref < pi_f_0_f_ext)
1564  delta_u_nu += pi_f_0_f_ref;
1565  else
1566  delta_u_nu += pi_f_0_f_ext;
1567  delta_d_nu = delta_d;
1568  if (pi_f_1_f_ref < pi_f_1_f_ext)
1569  delta_d_nu += pi_f_1_f_ref;
1570  else
1571  delta_d_nu += pi_f_1_f_ext;
1572  }
1573  else
1574  {
1575  frauenlinks = true;
1576  delta_u_nu = delta_u;
1577  if (pi_f_1_f_ref < pi_f_1_f_ext)
1578  delta_u_nu += pi_f_1_f_ref;
1579  else
1580  delta_u_nu += pi_f_1_f_ext;
1581  delta_d_nu = delta_d;
1582  if (pi_f_0_f_ref < pi_f_0_f_ext)
1583  delta_d_nu += pi_f_0_f_ref;
1584  else
1585  delta_d_nu += pi_f_0_f_ext;
1586  }
1587  }
1588  else
1589  {
1590  min1 = delta_d + pi_f_0_f_ext;
1591  min2 = delta_d + pi_f_1_f_ext;
1592 
1593  if (min1 > min2)
1594  {
1595  delta_u_nu = delta_u + pi_f_0_f_ext;
1596  delta_d_nu = delta_d + pi_f_1_f_ext;
1597  }
1598  else
1599  {
1600  frauenlinks = true;
1601  delta_u_nu = delta_u + pi_f_1_f_ext;
1602  delta_d_nu = delta_d + pi_f_0_f_ext;
1603  }
1604  }
1605  }
1606 
1607  if (frauenlinks)
1608  {
1609  node nu = S.twinTreeNode(ae->theEdge());
1610 
1611  //buffer computed embedding:
1612  NodeArray< List<adjEntry> > tmp_newOrder(spqrTree.originalGraph());
1613  ListIterator<adjEntry> tmp_before;
1614 
1616  ae, tmp_before, spqrTree, treeNodeTreated, mu,
1617  v, nodeLength, edgeLength, thickness, tmp_newOrder,
1618  adjBeforeNodeArraySource, adjBeforeNodeArrayTarget,
1619  delta_u_nu, delta_d_nu, adjExternal);
1620 
1621  //copy buffered embedding reversed into newOrder:
1622 #if 0
1623  node m_leftNode = v;
1624 #endif
1625  node m_rightNode = ae->twinNode();
1626  node leftOrg = v_original;
1627  node rightOrg = S.original(m_rightNode);
1628  for(node nOG : spqrTree.originalGraph().nodes)
1629  {
1630  List<adjEntry> nOG_tmp_adjList = tmp_newOrder[nOG];
1631  if (nOG_tmp_adjList.size() == 0)
1632  continue;
1633 
1634  ListIterator<adjEntry>* m_before;
1635  if (nOG == leftOrg)
1636  m_before = &before;
1637  else
1638  m_before = new ListIterator<adjEntry>();
1639 
1640  for (ListIterator<adjEntry> ae_it = nOG_tmp_adjList.begin(); ae_it.valid(); ++ae_it)
1641  {
1642  adjEntry adjaEnt = *ae_it;
1643  if (!m_before->valid())
1644  *m_before = newOrder[nOG].pushBack(adjaEnt);
1645  else
1646  *m_before = newOrder[nOG].insertBefore(adjaEnt, *m_before);
1647 
1648  if (nOG == leftOrg || nOG == rightOrg)
1649  {
1650  if (S.original(ae->theEdge()->source()) == nOG)
1651  adjBeforeNodeArraySource[nu] = *m_before;
1652  else
1653  adjBeforeNodeArrayTarget[nu] = *m_before;
1654  }
1655  }
1656 
1657  if (nOG != leftOrg)
1658  delete m_before;
1659  }
1660  }
1661  else
1662  adjEntryForNode(ae, before, spqrTree, treeNodeTreated, mu,
1663  v, nodeLength, edgeLength, thickness, newOrder,
1664  adjBeforeNodeArraySource, adjBeforeNodeArrayTarget,
1665  delta_u_nu, delta_d_nu, adjExternal);
1666 
1667  if (!nodeTreated[ae->twinNode()])
1668  {
1669  node orig_ae_twin_theNode = S.original(ae->twinNode());
1670  buffer[ae->theEdge()] = newOrder[orig_ae_twin_theNode];
1671  newOrder[orig_ae_twin_theNode].clear();
1672  }
1673  }
1674  else
1675  {
1676  buffer[ae->theEdge()].reverse();
1677  for (ListIterator<adjEntry> it = buffer[ae->theEdge()].begin(); it.valid(); ++it)
1678  {
1679  if (!before.valid())
1680  before = newOrder[v_original].pushFront(*it);
1681  else
1682  before = newOrder[v_original].insertBefore(*it, before);
1683  }
1684  }
1685  }
1686  }
1687 }
1688 
1689 
1690 template<class T>
1692  const Graph& G,
1693  const NodeArray<T>& nodeLength,
1694  const EdgeArray<T>& edgeLength,
1695  StaticSPQRTree *spqrTree,
1696  NodeArray< EdgeArray<T> >& edgeLengthSkel)
1697 {
1698  //base cases (SPQR-tree implementation would crash for such graphs):
1699  if (G.numberOfNodes() <= 1 || G.numberOfEdges() <= 2)
1700  return;
1701 
1702  //set length for all real edges in skeletons to length of the original edge
1703  //and initialize edge lengths for virtual edges with 0:
1704  edgeLengthSkel.init(spqrTree->tree());
1705  for(node v : spqrTree->tree().nodes)
1706  {
1707  edgeLengthSkel[v].init(spqrTree->skeleton(v).getGraph());
1708  for(edge e : spqrTree->skeleton(v).getGraph().edges)
1709  {
1710  if (spqrTree->skeleton(v).isVirtual(e))
1711  edgeLengthSkel[v][e] = 0;
1712  else
1713  edgeLengthSkel[v][e] = edgeLength[spqrTree->skeleton(v).realEdge(e)];
1714  }
1715  }
1716 
1717  //set component-length for all non-reference edges:
1718  bottomUpTraversal(*spqrTree, spqrTree->rootNode(), nodeLength, edgeLengthSkel);
1719  //set component length for all reference edges:
1720  topDownTraversal(*spqrTree, spqrTree->rootNode(), nodeLength, edgeLengthSkel);
1721 }
1722 
1723 template<class T>
1725  const Graph& G,
1726  const NodeArray<T>& nodeLength,
1727  const EdgeArray<T>& edgeLength)
1728 {
1729  //base cases (SPQR-tree implementation would crash for such graphs):
1730  OGDF_ASSERT(G.numberOfNodes() >= 2);
1731  if (G.numberOfEdges() == 1)
1732  {
1733  edge e = G.firstEdge();
1734  return edgeLength[e] + nodeLength[e->source()]+ nodeLength[e->target()];
1735  }
1736  else if (G.numberOfEdges() == 2)
1737  {
1738  edge e1 = G.firstEdge();
1739  edge e2 = e1->succ();
1740  return edgeLength[e1] + edgeLength[e2] + nodeLength[e1->source()] + \
1741  nodeLength[e1->target()];
1742  }
1743  StaticSPQRTree spqrTree(G);
1744  NodeArray< EdgeArray<T> > edgeLengthSkel;
1745  return computeSize(G, nodeLength, edgeLength, spqrTree, edgeLengthSkel);
1746 }
1747 
1748 
1749 template<class T>
1751  const Graph& G,
1752  const NodeArray<T>& nodeLength,
1753  const EdgeArray<T>& edgeLength,
1754  StaticSPQRTree *spqrTree,
1755  NodeArray< EdgeArray<T> >& edgeLengthSkel)
1756 {
1757  //base cases (SPQR-tree implementation would crash for such graphs):
1758  OGDF_ASSERT(G.numberOfNodes() >= 2);
1759  if (G.numberOfEdges() == 1)
1760  {
1761  edge e = G.firstEdge();
1762  return edgeLength[e] + nodeLength[e->source()]+ nodeLength[e->target()];
1763  }
1764  else if (G.numberOfEdges() == 2)
1765  {
1766  edge e1 = G.firstEdge();
1767  edge e2 = e1->succ();
1768  return edgeLength[e1] + edgeLength[e2] + nodeLength[e1->source()] + \
1769  nodeLength[e1->target()];
1770  }
1771 
1772  //set length for all real edges in skeletons to length of the original edge
1773  //and initialize edge lengths for virtual edges with 0:
1774  edgeLengthSkel.init(spqrTree->tree());
1775  for(node v : spqrTree->tree().nodes)
1776  {
1777  edgeLengthSkel[v].init(spqrTree->skeleton(v).getGraph());
1778  for(edge e : spqrTree->skeleton(v).getGraph().edges)
1779  {
1780  if (spqrTree->skeleton(v).isVirtual(e))
1781  edgeLengthSkel[v][e] = 0;
1782  else
1783  edgeLengthSkel[v][e] = edgeLength[spqrTree->skeleton(v).realEdge(e)];
1784  }
1785  }
1786 
1787  //set component-length for all non-reference edges:
1788  bottomUpTraversal(*spqrTree, spqrTree->rootNode(), nodeLength, edgeLengthSkel);
1789  //set component length for all reference edges:
1790  topDownTraversal(*spqrTree, spqrTree->rootNode(), nodeLength, edgeLengthSkel);
1791 
1792  T biggestFace = -1;
1793  for(node mu : spqrTree->tree().nodes)
1794  {
1795  //Expand all faces in skeleton(mu) and get size of the largest of them:
1796  T sizeMu = largestFaceInSkeleton(*spqrTree, mu, nodeLength, edgeLengthSkel);
1797  if (sizeMu > biggestFace)
1798  biggestFace = sizeMu;
1799  }
1800 
1801  return biggestFace;
1802 }
1803 
1804 
1805 template<class T>
1807  const Graph& G,
1808  const node& n,
1809  const NodeArray<T>& nodeLength,
1810  const EdgeArray<T>& edgeLength)
1811 {
1812  //base cases (SPQR-tree implementation would crash for such graphs):
1813  OGDF_ASSERT(G.numberOfNodes() >= 2);
1814  if (G.numberOfEdges() == 1)
1815  {
1816  edge e = G.firstEdge();
1817  return edgeLength[e] + nodeLength[e->source()] + nodeLength[e->target()];
1818  }
1819  else if (G.numberOfEdges() == 2)
1820  {
1821  edge e1 = G.firstEdge();
1822  edge e2 = e1->succ();
1823  return edgeLength[e1] + edgeLength[e2] + nodeLength[e1->source()] + \
1824  nodeLength[e1->target()];
1825  }
1826 
1827  StaticSPQRTree spqrTree(G);
1828  NodeArray< EdgeArray<T> > edgeLengthSkel;
1829  compute(G, nodeLength, edgeLength, &spqrTree, edgeLengthSkel);
1830  return computeSize(G, n, nodeLength, edgeLength, &spqrTree, edgeLengthSkel);
1831 }
1832 
1833 
1834 template<class T>
1836  const Graph& G,
1837  const node& n,
1838  const NodeArray<T>& nodeLength,
1839  const EdgeArray<T>& edgeLength,
1840  StaticSPQRTree *spqrTree)
1841 {
1842  NodeArray< EdgeArray<T> > edgeLengthSkel;
1843  compute(G, nodeLength, edgeLength, spqrTree, edgeLengthSkel);
1844  return computeSize(G, n, nodeLength, edgeLength, spqrTree, edgeLengthSkel);
1845 }
1846 
1847 
1848 template<class T>
1850  const Graph& G,
1851  const node& n,
1852  const NodeArray<T>& nodeLength,
1853  const EdgeArray<T>& edgeLength,
1854  StaticSPQRTree *spqrTree,
1855  const NodeArray< EdgeArray<T> >& edgeLengthSkel)
1856 {
1857  //base cases (SPQR-tree implementation would crash for such graphs):
1858  OGDF_ASSERT(G.numberOfNodes() >= 2);
1859  if (G.numberOfEdges() == 1)
1860  {
1861  edge e = G.firstEdge();
1862  return edgeLength[e] + nodeLength[e->source()] + nodeLength[e->target()];
1863  }
1864  else if (G.numberOfEdges() == 2)
1865  {
1866  edge e1 = G.firstEdge();
1867  edge e2 = e1->succ();
1868  return edgeLength[e1] + edgeLength[e2] + nodeLength[e1->source()] + \
1869  nodeLength[e1->target()];
1870  }
1871 
1872  node* mus = new node[n->degree()];
1873  int i = 0;
1874  T biggestFace = -1;
1875  for(adjEntry adj : n->adjEntries) {
1876  mus[i] = spqrTree->skeletonOfReal(adj->theEdge()).treeNode();
1877  bool alreadySeenMu = false;
1878  for (int j = 0; j < i && !alreadySeenMu; j++)
1879  {
1880  if (mus[i] == mus[j])
1881  alreadySeenMu = true;
1882  }
1883  if (alreadySeenMu)
1884  {
1885  i++;
1886  continue;
1887  }
1888  else
1889  {
1890  //Expand all faces in skeleton(mu) containing n and get size of the largest of them:
1891  T sizeInMu = largestFaceContainingNode(*spqrTree, mus[i], n, nodeLength, edgeLengthSkel);
1892  if (sizeInMu > biggestFace)
1893  biggestFace = sizeInMu;
1894 
1895  i++;
1896  }
1897  }
1898  delete[] mus;
1899 
1900  return biggestFace;
1901 }
1902 
1903 
1904 template<class T>
1906  StaticSPQRTree& spqrTree,
1907  const node& mu,
1908  const NodeArray<T>& nodeLength,
1909  NodeArray< EdgeArray<T> >& edgeLength)
1910 {
1911  //Recursion:
1912  for(adjEntry adj : mu->adjEntries)
1913  {
1914  edge ed = adj->theEdge();
1915  if (ed->source() == mu)
1916  bottomUpTraversal(spqrTree, ed->target(), nodeLength, edgeLength);
1917  }
1918 
1919  for(edge e : spqrTree.skeleton(mu).getGraph().edges)
1920  {
1921  //do not treat real edges here and do not treat reference edges:
1922  if (!spqrTree.skeleton(mu).isVirtual(e) || e == spqrTree.skeleton(mu).referenceEdge())
1923  continue;
1924 
1925  //pertinent node of e in the SPQR-tree:
1926  node nu = spqrTree.skeleton(mu).twinTreeNode(e);
1927  //reference edge of nu (virtual edge in nu associated with mu):
1928  edge er = spqrTree.skeleton(nu).referenceEdge();
1929  //sum of the lengths of the two poles of mu:
1930  node refEdgeSource = spqrTree.skeleton(nu).referenceEdge()->source();
1931  node origRefEdgeSource = spqrTree.skeleton(nu).original(refEdgeSource);
1932  node refEdgeTarget = spqrTree.skeleton(nu).referenceEdge()->target();
1933  node origRefEdgeTarget = spqrTree.skeleton(nu).original(refEdgeTarget);
1934  T ell = nodeLength[origRefEdgeSource] + nodeLength[origRefEdgeTarget];
1935 
1936  if (spqrTree.typeOf(nu) == SPQRTree::NodeType::SNode)
1937  {
1938  //size of a face in skeleton(nu) minus ell
1939  T sizeOfFace = 0;
1940  for(node nS : spqrTree.skeleton(nu).getGraph().nodes)
1941  sizeOfFace += nodeLength[spqrTree.skeleton(nu).original(nS)];
1942 
1943  for(edge eS : spqrTree.skeleton(nu).getGraph().edges)
1944  sizeOfFace += edgeLength[nu][eS];
1945 
1946  edgeLength[mu][e] = sizeOfFace - ell;
1947  }
1948  else if (spqrTree.typeOf(nu) == SPQRTree::NodeType::PNode)
1949  {
1950  //length of the longest edge different from er in skeleton(nu)
1951  edge longestEdge = nullptr;
1952  for(edge ed : spqrTree.skeleton(nu).getGraph().edges)
1953  {
1954  if (ed != er && ( longestEdge == nullptr || edgeLength[nu][ed] > edgeLength[nu][longestEdge]))
1955  {
1956  longestEdge = ed;
1957  }
1958  }
1959  edgeLength[mu][e] = edgeLength[nu][longestEdge];
1960  }
1961  else if (spqrTree.typeOf(nu) == SPQRTree::NodeType::RNode)
1962  {
1963  //size of the largest face containing er in skeleton(nu) minus ell
1964  //Calculate an embedding of the graph (it exists only two which are
1965  //mirror-symmetrical):
1966  planarEmbed(spqrTree.skeleton(nu).getGraph());
1967  CombinatorialEmbedding combinatorialEmbedding(spqrTree.skeleton(nu).getGraph());
1968  T biggestFaceSize = -1;
1969  for(face f : combinatorialEmbedding.faces)
1970  {
1971  T sizeOfFace = 0;
1972  bool containsEr = false;
1973  for(adjEntry ae : f->entries)
1974  {
1975  if (ae->theEdge() == er)
1976  containsEr = true;
1977  sizeOfFace += edgeLength[nu][ae->theEdge()]
1978  + nodeLength[spqrTree.skeleton(nu).original(ae->theNode())];
1979  }
1980 
1981  if (containsEr && sizeOfFace > biggestFaceSize)
1982  biggestFaceSize = sizeOfFace;
1983  }
1984 
1985  edgeLength[mu][e] = biggestFaceSize - ell;
1986  }
1987  else //should never happen
1988  edgeLength[mu][e] = 1;
1989  }
1990 }
1991 
1992 
1993 template<class T>
1995  StaticSPQRTree& spqrTree,
1996  const node& mu,
1997  const NodeArray<T>& nodeLength,
1998  NodeArray< EdgeArray<T> >& edgeLength)
1999 {
2000  //S: skeleton of mu
2001  Skeleton& S = spqrTree.skeleton(mu);
2002 
2003  //Get all reference edges of the children nu of mu and set their component length:
2004  for(adjEntry adj : mu->adjEntries) {
2005  edge ed = adj->theEdge();
2006  if (ed->source() != mu)
2007  continue;
2008 
2009  node nu = ed->target();
2010  edge referenceEdgeOfNu = spqrTree.skeleton(nu).referenceEdge();
2011  edge eSnu = spqrTree.skeleton(nu).twinEdge(referenceEdgeOfNu);
2012  if (spqrTree.typeOf(mu) == SPQRTree::NodeType::SNode)
2013  {
2014  //Let L be the sum of the length of all vertices and edges in S. The component
2015  //length of the reference edge of nu is L minus the length of e_{S, nu} minus
2016  //the lengths of the two vertices incident to e_{S, nu}.
2017  T L = 0;
2018  for(edge ed2 : S.getGraph().edges)
2019  L += edgeLength[mu][ed2];
2020  for(node no : S.getGraph().nodes)
2021  L += nodeLength[S.original(no)];
2022 
2023  edgeLength[nu][referenceEdgeOfNu] = L - edgeLength[mu][eSnu]
2024  - nodeLength[S.original(eSnu->source())]
2025  - nodeLength[S.original(eSnu->target())];
2026  }
2027  else if (spqrTree.typeOf(mu) == SPQRTree::NodeType::PNode)
2028  {
2029  //The component length of the reference edge of nu is the length of the longest
2030  //edge in S different from e_{S, nu}.
2031  edge longestEdge = nullptr;
2032  for(edge ed2 : S.getGraph().edges)
2033  {
2034  if (ed2 != eSnu
2035  && (!longestEdge || edgeLength[mu][ed2] > edgeLength[mu][longestEdge])) {
2036  longestEdge = ed2;
2037  }
2038  }
2039  edgeLength[nu][referenceEdgeOfNu] = edgeLength[mu][longestEdge];
2040  }
2041  else if (spqrTree.typeOf(mu) == SPQRTree::NodeType::RNode)
2042  {
2043  //Let f be the largest face in S containing e_{S, nu}. The component length of
2044  //the reference edge of nu is the size of f minus the length of e_{S, nu} minus
2045  //the lengths of the two vertices incident to e_{S, nu}.
2046 
2047  //Calculate an embedding of the graph (it exists only two which are
2048  //mirror-symmetrical):
2049  planarEmbed(S.getGraph());
2050  CombinatorialEmbedding combinatorialEmbedding(S.getGraph());
2051  T biggestFaceSize = -1;
2052  for(face f : combinatorialEmbedding.faces)
2053  {
2054  T sizeOfFace = 0;
2055  bool containsESnu = false;
2056  for(adjEntry ae : f->entries)
2057  {
2058  if (ae->theEdge() == eSnu)
2059  containsESnu = true;
2060  sizeOfFace += edgeLength[mu][ae->theEdge()]
2061  + nodeLength[S.original(ae->theNode())];
2062  }
2063  if (containsESnu && sizeOfFace > biggestFaceSize)
2064  biggestFaceSize = sizeOfFace;
2065  }
2066  edgeLength[nu][referenceEdgeOfNu] = biggestFaceSize - edgeLength[mu][eSnu]
2067  - nodeLength[S.original(eSnu->source())]
2068  - nodeLength[S.original(eSnu->target())];
2069  }
2070  else //should never happen
2071  edgeLength[nu][referenceEdgeOfNu] = 0;
2072 
2073  //Recursion:
2074  topDownTraversal(spqrTree, ed->target(), nodeLength, edgeLength);
2075  }
2076 }
2077 
2078 
2079 template<class T>
2081  const StaticSPQRTree& spqrTree,
2082  const node& mu,
2083  const node& n,
2084  const NodeArray<T>& nodeLength,
2085  const NodeArray< EdgeArray<T> >& edgeLength)
2086 {
2087  bool containsARealEdge = false;
2088  if (spqrTree.typeOf(mu) == SPQRTree::NodeType::RNode)
2089  {
2090  //The largest face containing n is the largest face containg n in any embedding of S.
2091  planarEmbed(spqrTree.skeleton(mu).getGraph());
2092  CombinatorialEmbedding combinatorialEmbedding(spqrTree.skeleton(mu).getGraph());
2093  T biggestFaceSize = -1;
2094  for(face f : combinatorialEmbedding.faces)
2095  {
2096  T sizeOfFace = 0;
2097  bool containingN = false;
2098  bool m_containsARealEdge = false;
2099  for(adjEntry ae : f->entries)
2100  {
2101  if (spqrTree.skeleton(mu).original(ae->theNode()) == n)
2102  containingN = true;
2103  if (!spqrTree.skeleton(mu).isVirtual(ae->theEdge()))
2104  m_containsARealEdge = true;
2105  sizeOfFace += edgeLength[mu][ae->theEdge()];
2106  sizeOfFace += nodeLength[spqrTree.skeleton(mu).original(ae->theNode())];
2107  }
2108  if (containingN && sizeOfFace > biggestFaceSize)
2109  {
2110  biggestFaceSize = sizeOfFace;
2111  containsARealEdge = m_containsARealEdge;
2112  }
2113  }
2114 
2115  if (!containsARealEdge)
2116  return -1;
2117  return biggestFaceSize;
2118  }
2119  else if (spqrTree.typeOf(mu) == SPQRTree::NodeType::PNode)
2120  {
2121  //Find the two longest edges, they define the largest face containg n.
2122  edge longestEdges[2] = {nullptr, nullptr};
2123  for(edge edgeWalker : spqrTree.skeleton(mu).getGraph().edges)
2124  {
2125  if ( longestEdges[1] == nullptr
2126  || edgeLength[mu][edgeWalker] > edgeLength[mu][longestEdges[1]])
2127  {
2128  if ( longestEdges[0] == nullptr
2129  || edgeLength[mu][edgeWalker] > edgeLength[mu][longestEdges[0]])
2130  {
2131  longestEdges[1] = longestEdges[0];
2132  longestEdges[0] = edgeWalker;
2133  }
2134  else
2135  longestEdges[1] = edgeWalker;
2136  }
2137  }
2138 
2139  if (!spqrTree.skeleton(mu).isVirtual(longestEdges[0])
2140  || !spqrTree.skeleton(mu).isVirtual(longestEdges[1])) {
2141  containsARealEdge = true;
2142  }
2143 
2144  if (!containsARealEdge)
2145  return -1;
2146 
2147  return edgeLength[mu][longestEdges[0]] + edgeLength[mu][longestEdges[1]];
2148  }
2149  else if (spqrTree.typeOf(mu) == SPQRTree::NodeType::SNode)
2150  {
2151  //The largest face containing n is any face in the single existing embedding of S.
2152  T sizeOfFace = 0;
2153  for(node nS : spqrTree.skeleton(mu).getGraph().nodes)
2154  sizeOfFace += nodeLength[spqrTree.skeleton(mu).original(nS)];
2155 
2156  for(edge eS : spqrTree.skeleton(mu).getGraph().edges)
2157  {
2158  if (!spqrTree.skeleton(mu).isVirtual(eS))
2159  containsARealEdge = true;
2160  sizeOfFace += edgeLength[mu][eS];
2161  }
2162 
2163  if (!containsARealEdge)
2164  return -1;
2165 
2166  return sizeOfFace;
2167  }
2168 
2169  //should never end here...
2170  return 42;
2171 }
2172 
2173 
2174 template<class T>
2176  (const StaticSPQRTree& spqrTree,
2177  const node& mu,
2178  const NodeArray<T>& nodeLength,
2179  const NodeArray< EdgeArray<T> >& edgeLength)
2180 {
2181  bool containsARealEdge = false;
2182  if (spqrTree.typeOf(mu) == SPQRTree::NodeType::RNode)
2183  {
2184  //The largest face is a largest face in any embedding of S.
2185  planarEmbed(spqrTree.skeleton(mu).getGraph());
2186  CombinatorialEmbedding combinatorialEmbedding(spqrTree.skeleton(mu).getGraph());
2187  T biggestFaceSize = -1;
2188  for(face f : combinatorialEmbedding.faces)
2189  {
2190  bool m_containsARealEdge = false;
2191  T sizeOfFace = 0;
2192  for(adjEntry ae : f->entries)
2193  {
2194 #if 0
2195  node originalNode = spqrTree.skeleton(mu).original(ae->theNode());
2196 #endif
2197  if (!spqrTree.skeleton(mu).isVirtual(ae->theEdge()))
2198  m_containsARealEdge = true;
2199  sizeOfFace += edgeLength[mu][ae->theEdge()]
2200  + nodeLength[spqrTree.skeleton(mu).original(ae->theNode())];
2201  }
2202 
2203  if (sizeOfFace > biggestFaceSize)
2204  {
2205  biggestFaceSize = sizeOfFace;
2206  containsARealEdge = m_containsARealEdge;
2207  }
2208  }
2209 
2210  if (!containsARealEdge)
2211  return -1;
2212 
2213  return biggestFaceSize;
2214  }
2215  else if (spqrTree.typeOf(mu) == SPQRTree::NodeType::PNode)
2216  {
2217  //Find the two longest edges, they define the largest face.
2218  edge longestEdges[2] = {nullptr, nullptr};
2219  for(edge edgeWalker : spqrTree.skeleton(mu).getGraph().edges)
2220  {
2221  if ( longestEdges[1] == nullptr
2222  || edgeLength[mu][edgeWalker] > edgeLength[mu][longestEdges[1]])
2223  {
2224  if ( longestEdges[0] == nullptr
2225  || edgeLength[mu][edgeWalker] > edgeLength[mu][longestEdges[0]])
2226  {
2227  longestEdges[1] = longestEdges[0];
2228  longestEdges[0] = edgeWalker;
2229  }
2230  else
2231  longestEdges[1] = edgeWalker;
2232  }
2233  }
2234 
2235  if (!spqrTree.skeleton(mu).isVirtual(longestEdges[0])
2236  || !spqrTree.skeleton(mu).isVirtual(longestEdges[1])) {
2237  containsARealEdge = true;
2238  }
2239 
2240  if (!containsARealEdge)
2241  return -1;
2242 
2243  return edgeLength[mu][longestEdges[0]] + edgeLength[mu][longestEdges[1]];
2244  }
2245  else if (spqrTree.typeOf(mu) == SPQRTree::NodeType::SNode)
2246  {
2247  //The largest face is any face in the single existing embedding of S.
2248  T sizeOfFace = 0;
2249  for(node nS : spqrTree.skeleton(mu).getGraph().nodes)
2250  sizeOfFace += nodeLength[spqrTree.skeleton(mu).original(nS)];
2251 
2252  for(edge eS : spqrTree.skeleton(mu).getGraph().edges)
2253  {
2254  if (!spqrTree.skeleton(mu).isVirtual(eS))
2255  containsARealEdge = true;
2256  sizeOfFace += edgeLength[mu][eS];
2257  }
2258 
2259  if (!containsARealEdge)
2260  return -1;
2261 
2262  return sizeOfFace;
2263  }
2264 
2265  //should never end here...
2266  return 42;
2267 }
2268 
2269 
2270 template<class T>
2272  const StaticSPQRTree& spqrTree,
2273  const node& mu,
2274  NodeArray<T>& thickness,
2275  const NodeArray<T>& nodeLength,
2276  const NodeArray< EdgeArray<T> >& edgeLength)
2277 {
2278  //recursion:
2279  for(adjEntry adj : mu->adjEntries) {
2280  edge e_mu_to_nu = adj->theEdge();
2281  if (e_mu_to_nu->source() != mu)
2282  continue;
2283  else
2284  {
2285  node nu = e_mu_to_nu->target();
2286  bottomUpThickness(spqrTree, nu, thickness, nodeLength, edgeLength);
2287  }
2288  }
2289 
2290  Skeleton& S = spqrTree.skeleton(mu);
2291  edge referenceEdge = S.referenceEdge();
2292 
2293  if (!referenceEdge) { //root of SPQR-tree
2294  thickness[mu] = 0;
2295  return;
2296  }
2297 
2298  //set dLengths for all edges in skeleton graph:
2299  EdgeArray<T> dLength(S.getGraph());
2300  for(edge eSG : S.getGraph().edges)
2301  {
2302  if (eSG == referenceEdge)
2303  continue;
2304 
2305  if (S.isVirtual(eSG))
2306  {
2307  node twinTN = S.twinTreeNode(eSG);
2308  dLength[eSG] = thickness[twinTN];
2309  }
2310  else
2311  dLength[eSG] = edgeLength[mu][eSG];
2312  }
2313 
2314  //compute thickness of skeleton(mu):
2315  switch (spqrTree.typeOf(mu))
2316  {
2318  {
2319  //thickness(mu) = min_{edges e != referenceEdge} dLength(e)
2320  T min_dLength = -1;
2321  for(edge eSG : S.getGraph().edges)
2322  {
2323  if (eSG == referenceEdge)
2324  continue;
2325  if (min_dLength == -1 || dLength[eSG] < min_dLength)
2326  min_dLength = dLength[eSG];
2327  }
2328  thickness[mu] = min_dLength;
2329  } break;
2331  {
2332  //thickness(mu) = sum_{edges e != referenceEdge} dLength(e)
2333  T sumof_dLength = 0;
2334  for(edge eSG : S.getGraph().edges)
2335  {
2336  if (eSG == referenceEdge)
2337  continue;
2338  sumof_dLength += dLength[eSG];
2339  }
2340  thickness[mu] = sumof_dLength;
2341  } break;
2343  {
2344  /* Let f^ref_0, ... , f^ref_k be the faces sharing at least one edge with
2345  * f_ref - the face adjacent to the reference edge not equal to the
2346  * external face f_ext. Compute the dual graph and set edge lengths for
2347  * two faces f_i, f_j, i != j, with at least one shared edge, to the
2348  * minimal dLength of the shared edges of f_i and f_j. Remove the node
2349  * related to face f_ref. thickness(mu) is then the length of the shortest
2350  * path from any of the faces f^ref_0, ... , f^ref_k to f_ext plus 1.
2351  */
2353  adjEntry ae_f_ext = referenceEdge->adjSource();
2354  adjEntry ae_f_ref = referenceEdge->adjTarget();
2355  T faceSize_f_ext = 0;
2356  adjEntry ae_f_ext_walker = ae_f_ext;
2357  do
2358  {
2359  faceSize_f_ext += nodeLength[S.original(ae_f_ext_walker->theNode())]
2360  + edgeLength[mu][ae_f_ext_walker->theEdge()];
2361  ae_f_ext_walker = ae_f_ext_walker->faceCycleSucc();
2362  } while (ae_f_ext_walker != ae_f_ext);
2363  T faceSize_f_ref = 0;
2364  adjEntry ae_f_ref_walker = ae_f_ref;
2365  do
2366  {
2367  faceSize_f_ref += nodeLength[S.original(ae_f_ref_walker->theNode())]
2368  + edgeLength[mu][ae_f_ref_walker->theEdge()];
2369  ae_f_ref_walker = ae_f_ref_walker->faceCycleSucc();
2370  } while (ae_f_ref_walker != ae_f_ref);
2371  if (faceSize_f_ext < faceSize_f_ref)
2372  {
2373  adjEntry ae_tmp = ae_f_ext;
2374  ae_f_ext = ae_f_ref;
2375  ae_f_ref = ae_tmp;
2376  }
2377 
2378  //compute dual graph:
2379  Graph DG;
2380  ArrayBuffer<node> fPG_to_nDG;
2381  NodeArray< List<adjEntry> > adjacencyList(S.getGraph());
2382  List< List<adjEntry> > faces;
2383  NodeArray<int> distances;
2384  EdgeArray<T> edgeLengthDG(DG);
2385  int f_ref_id = -1;
2386  int f_ext_id = -1;
2387 
2388  for(node nBG : S.getGraph().nodes)
2389  {
2390  for(adjEntry ae_nBG : nBG->adjEntries)
2391  adjacencyList[nBG].pushBack(ae_nBG);
2392  }
2393 
2394  NodeArray< List<adjEntry> > adjEntryTreated(S.getGraph());
2395  for(node nBG : S.getGraph().nodes)
2396  {
2397  for(adjEntry adj : nBG->adjEntries)
2398  {
2399  if (adjEntryTreated[nBG].search(adj).valid())
2400  continue;
2401 
2402  List<adjEntry> newFace;
2403  adjEntry adj2 = adj;
2404  do {
2405  newFace.pushBack(adj2);
2406  adjEntryTreated[adj2->theNode()].pushBack(adj2);
2407  List<adjEntry> &ladj = adjacencyList[adj2->twinNode()];
2408  adj2 = *ladj.cyclicPred(ladj.search(adj2->twin()));
2409  } while (adj2 != adj);
2410  faces.pushBack(newFace);
2411  }
2412  }
2413 
2414  for (ListIterator< List<adjEntry> > it = faces.begin(); it.valid(); ++it) {
2415  fPG_to_nDG.push(DG.newNode());
2416  }
2417 
2418  NodeArray< List<node> > adjFaces(DG);
2419  int i = 0;
2420  for (ListIterator< List<adjEntry> > it = faces.begin(); it.valid(); ++it)
2421  {
2422  int f1_id = i;
2423  for (ListIterator<adjEntry> it2 = (*it).begin(); it2.valid(); ++it2)
2424  {
2425  int f2_id = 0;
2426  int j = 0;
2427  for (ListIterator< List<adjEntry> > it3 = faces.begin(); it3.valid(); ++it3)
2428  {
2429  bool do_break = false;
2430  for (ListIterator<adjEntry> it4 = (*it3).begin(); it4.valid(); ++it4)
2431  {
2432  if ((*it4) == (*it2)->twin())
2433  {
2434  f2_id = j;
2435  do_break = true;
2436  break;
2437  }
2438  }
2439  if (do_break)
2440  break;
2441  j++;
2442  }
2443 
2444  if (f1_id != f2_id
2445  && !adjFaces[fPG_to_nDG[f1_id]].search(fPG_to_nDG[f2_id]).valid()
2446  && !adjFaces[fPG_to_nDG[f2_id]].search(fPG_to_nDG[f1_id]).valid())
2447  {
2448  adjFaces[fPG_to_nDG[f1_id]].pushBack(fPG_to_nDG[f2_id]);
2449  adjFaces[fPG_to_nDG[f2_id]].pushBack(fPG_to_nDG[f1_id]);
2450  edge e1 = DG.newEdge(fPG_to_nDG[f1_id], fPG_to_nDG[f2_id]);
2451  edge e2 = DG.newEdge(fPG_to_nDG[f2_id], fPG_to_nDG[f1_id]);
2452 
2453  //set edge length:
2454  T e_length = -1;
2455  for (ListIterator<adjEntry> it_f1 = (*it).begin(); it_f1.valid(); ++it_f1)
2456  {
2457  edge e = (*it_f1)->theEdge();
2458  for (ListIterator<adjEntry> it_f2 = (*(faces.get(f2_id))).begin();
2459  it_f2.valid();
2460  ++it_f2)
2461  {
2462  if ((*it_f2)->theEdge() == e
2463  && (e_length == -1
2464  || edgeLength[mu][e] < e_length)) {
2465  e_length = edgeLength[mu][e];
2466  }
2467  }
2468  }
2469  edgeLengthDG[e1] = e_length;
2470  edgeLengthDG[e2] = e_length;
2471  }
2472 
2473  if (*it2 == ae_f_ext)
2474  f_ext_id = f1_id;
2475  if (*it2 == ae_f_ref)
2476  f_ref_id = f1_id;
2477  } //for (ListIterator<adjEntry> it2 = (*it).begin(); it2.valid(); it2++)
2478  i++;
2479  } //for (ListIterator< List<adjEntry> > it = faces.begin(); it.valid(); it++)
2480 
2481  //the faces sharing at least one edge with f_ref:
2482  node nDG_f_ref = fPG_to_nDG[f_ref_id];
2483  List<node>& f_ref_adj_faces = adjFaces[nDG_f_ref];
2484 
2485  //remove node related to f_ref from dual graph:
2486  DG.delNode(fPG_to_nDG[f_ref_id]);
2487 
2488  //compute shortest path and set thickness:
2489  NodeArray<T> dist(DG);
2490  node nDG_f_ext = fPG_to_nDG[f_ext_id];
2491  sssp(DG, nDG_f_ext, edgeLengthDG, dist);
2492  T minDist = -1;
2493  for (ListIterator<node> it_adj_faces = f_ref_adj_faces.begin();
2494  it_adj_faces.valid();
2495  ++it_adj_faces)
2496  {
2497  node fDG = *it_adj_faces;
2498  if (fDG != nDG_f_ext)
2499  {
2500  T d = dist[fDG];
2501  if (minDist == -1 || d < minDist)
2502  minDist = d;
2503  }
2504  }
2505  thickness[mu] = minDist + 1;
2506  } break;
2507  default:
2508  OGDF_ASSERT(false);
2509  }
2510 }
2511 
2512 
2513 template<class T>
2515  const Graph& G,
2516  const node& s,
2517  const EdgeArray<T>& length,
2518  NodeArray<T>& d)
2519 {
2520  const T infinity = 20000000; // big number. danger. think about it.
2521 
2522  //Initialize-Single-Source(G, s):
2523  d.init(G);
2524  for(node v : G.nodes)
2525  d[v] = infinity;
2526 
2527  d[s] = 0;
2528  for (int i = 1; i < G.numberOfNodes(); ++i)
2529  {
2530  for(edge e : G.edges)
2531  {
2532  //relax(u, v, w): // e == (u, v), length == w
2533  if (d[e->target()] > d[e->source()] + length[e])
2534  d[e->target()] = d[e->source()] + length[e];
2535  }
2536  }
2537 
2538  //check for negative cycle:
2539  for(edge e : G.edges)
2540  {
2541  if (d[e->target()] > d[e->source()] + length[e])
2542  return false;
2543  }
2544 
2545  return true;
2546 }
2547 
2548 
2549 } // end namespace ogdf
node target() const
Returns the target node of the edge.
Definition: Graph_d.h:327
virtual edge realEdge(edge e) const =0
Returns the real edge that corresponds to skeleton edge e.
virtual node twinTreeNode(edge e) const =0
Returns the tree node in T containing the twin edge of skeleton edge e.
static void bottomUpTraversal(StaticSPQRTree &spqrTree, const node &mu, const NodeArray< T > &nodeLength, NodeArray< EdgeArray< T > > &edgeLength)
Bottom up traversal of SPQR-tree computing the component length of all non-reference edges...
edge theEdge() const
Returns the edge associated with this adjacency entry.
Definition: Graph_d.h:95
iterator pushBack(const E &x)
Adds element x at the end of the list.
Definition: List.h:1316
Data type for general directed graphs (adjacency list representation).
Definition: Graph_d.h:472
virtual void delNode(node v)
Removes node v and all incident edges from the graph.
adjEntry adjSource() const
Returns the corresponding adjacancy entry at source node.
Definition: Graph_d.h:330
void sort(node v, const ADJ_ENTRY_LIST &newOrder)
Sorts the adjacency list of node v according to newOrder.
Definition: Graph_d.h:1019
void init()
Reinitializes the array. Associates the array with no graph.
Definition: NodeArray.h:292
const Graph & getGraph() const
Returns a reference to the skeleton graph M.
Definition: Skeleton.h:99
int degree() const
Returns the degree of the node (indegree + outdegree).
Definition: Graph_d.h:208
const Skeleton & skeletonOfReal(edge e) const override
Returns the skeleton that contains the real edge e.
iterator begin()
Returns an iterator to the first element of the list.
Definition: List.h:332
const Graph & originalGraph() const override
Returns a reference to the original graph G.
iterator insertAfter(const E &x, iterator it)
Inserts element x after it.
Definition: List.h:1341
void push(E e)
Puts a new element in the buffer.
Definition: ArrayBuffer.h:95
virtual node original(node v) const =0
Returns the vertex in the original graph G that corresponds to v.
node rootTreeAt(edge e) override
Roots T at edge e and returns the new root node of T.
static bool sssp(const Graph &G, const node &s, const EdgeArray< T > &length, NodeArray< T > &d)
An array that keeps track of the number of inserted elements; also usable as an efficient stack...
Definition: Array.h:44
const_iterator cyclicPred(const_iterator it) const
Returns a const iterator to the cyclic predecessor of it.
Definition: List.h:424
Computes an embedding of a biconnected graph with maximum external face (plus layers approach)...
Declaration of CombinatorialEmbedding and face.
Dynamic arrays indexed with edges.
Definition: EdgeArray.h:112
static void expandEdgePNode(const StaticSPQRTree &spqrTree, NodeArray< bool > &treeNodeTreated, const node &mu, const node &leftNode, const NodeArray< T > &nodeLength, const NodeArray< EdgeArray< T > > &edgeLength, const NodeArray< T > &thickness, NodeArray< List< adjEntry > > &newOrder, NodeArray< ListIterator< adjEntry > > &adjBeforeNodeArraySource, NodeArray< ListIterator< adjEntry > > &adjBeforeNodeArrayTarget, const T &delta_u, const T &delta_d, adjEntry &adjExternal)
edge referenceEdge() const
Returns the reference edge of S in M.
Definition: Skeleton.h:94
Skeleton graphs of nodes in an SPQR-tree.
Definition: Skeleton.h:61
adjEntry faceCycleSucc() const
Returns the cyclic successor in face.
Definition: Graph_d.h:139
static T largestFaceInSkeleton(const StaticSPQRTree &spqrTree, const node &mu, const NodeArray< T > &nodeLength, const NodeArray< EdgeArray< T > > &edgeLength)
Computes the size of a maximum face in the skeleton graph of mu.
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
Dynamic arrays indexed with nodes.
Definition: Graph_d.h:423
bool planarEmbed(Graph &G)
Returns true, if G is planar, false otherwise. If true is returned, G will be planarly embedded...
iterator pushFront(const E &x)
Adds element x at the beginning of the list.
Definition: List.h:1303
NodeType typeOf(node v) const override
Returns the type of node v.
Declaration of class StaticSPQRTree.
static void compute(const Graph &G, const NodeArray< T > &nodeLength, const EdgeArray< T > &edgeLength, StaticSPQRTree *spqrTree, NodeArray< EdgeArray< T > > &edgeLengthSkel)
Computes the component lengths of all virtual edges in spqrTree.
edge firstEdge() const
Returns the first edge in the list of all edges.
Definition: Graph_d.h:603
Doubly linked lists (maintaining the length of the list).
Definition: List.h:39
edge newEdge(node v, node w)
Creates a new edge (v,w) and returns it.
internal::FaceAdjContainer entries
Container maintaining the adjacency entries in the face.
Faces in a combinatorial embedding.
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
adjEntry twin() const
Returns the corresponding adjacency element associated with the same edge.
Definition: Graph_d.h:102
const_iterator get(int pos) const
Returns a const iterator pointing to the element at position pos.
Definition: List.h:290
adjEntry lastAdj() const
Returns the last entry in the adjacency list.
Definition: Graph_d.h:213
Class for the representation of nodes.
Definition: Graph_d.h:167
static void adjEntryForNode(adjEntry &ae, ListIterator< adjEntry > &before, const StaticSPQRTree &spqrTree, NodeArray< bool > &treeNodeTreated, const node &mu, const node &leftNode, const NodeArray< T > &nodeLength, const NodeArray< EdgeArray< T > > &edgeLength, const NodeArray< T > &thickness, NodeArray< List< adjEntry > > &newOrder, NodeArray< ListIterator< adjEntry > > &adjBeforeNodeArraySource, NodeArray< ListIterator< adjEntry > > &adjBeforeNodeArrayTarget, const T &delta_u, const T &delta_d, adjEntry &adjExternal)
bool valid() const
Returns true iff the array is associated with a graph.
Definition: NodeArray.h:157
Encapsulates a pointer to a list element.
Definition: List.h:41
virtual edge twinEdge(edge e) const =0
Returns the twin edge of skeleton edge e.
Skeleton & skeleton(node v) const override
Returns the skeleton of node v.
static void bottomUpThickness(const StaticSPQRTree &spqrTree, const node &mu, NodeArray< T > &thickness, const NodeArray< T > &nodeLength, const NodeArray< EdgeArray< T > > &edgeLength)
Linear-time implementation of static SPQR-trees.
static void expandEdgeSNode(const StaticSPQRTree &spqrTree, NodeArray< bool > &treeNodeTreated, const node &mu, const node &leftNode, const NodeArray< T > &nodeLength, const NodeArray< EdgeArray< T > > &edgeLength, const NodeArray< T > &thickness, NodeArray< List< adjEntry > > &newOrder, NodeArray< ListIterator< adjEntry > > &adjBeforeNodeArraySource, NodeArray< ListIterator< adjEntry > > &adjBeforeNodeArrayTarget, const T &delta_u, const T &delta_d, adjEntry &adjExternal)
edge succ() const
Returns the successor in the list of all edges.
Definition: Graph_d.h:340
static void topDownTraversal(StaticSPQRTree &spqrTree, const node &mu, const NodeArray< T > &nodeLength, NodeArray< EdgeArray< T > > &edgeLength)
Top down traversal of SPQR-tree computing the component length of all reference edges.
adjEntry succ() const
Returns the successor in the adjacency list.
Definition: Graph_d.h:145
static void expandEdgeRNode(const StaticSPQRTree &spqrTree, NodeArray< bool > &treeNodeTreated, const node &mu, const node &leftNode, const NodeArray< T > &nodeLength, const NodeArray< EdgeArray< T > > &edgeLength, const NodeArray< T > &thickness, NodeArray< List< adjEntry > > &newOrder, NodeArray< ListIterator< adjEntry > > &adjBeforeNodeArraySource, NodeArray< ListIterator< adjEntry > > &adjBeforeNodeArrayTarget, const T &delta_u, const T &delta_d, adjEntry &adjExternal, const node &n=nullptr)
int size() const
Returns the number of elements in the list.
Definition: List.h:1255
iterator begin()
Returns an iterator to the first entry in the node array.
Definition: NodeArray.h:215
void allNodes(NODELIST &nodeList) const
Returns a list with all nodes of the graph.
Definition: Graph_d.h:631
node rootNode() const override
Returns the root node of T.
void init()
Reinitializes the array. Associates the array with no graph.
static void embed(Graph &G, adjEntry &adjExternal, const NodeArray< T > &nodeLength, const EdgeArray< T > &edgeLength, const node &n=nullptr)
Embeds G by computing and extending a maximum face in G containg n.
node source() const
Returns the source node of the edge.
Definition: Graph_d.h:325
iterator insertBefore(const E &x, iterator it)
Inserts element x before it.
Definition: List.h:1335
The namespace for all OGDF objects.
static T computeSize(const Graph &G, const node &n, const NodeArray< T > &nodeLength, const EdgeArray< T > &edgeLength)
Returns the size of a maximum external face in G containing the node n.
Declaration of extended graph algorithms.
Declaration of class ShortestPathWithBFM which computes shortest paths via Bellman-Ford-Moore.
int numberOfNodes() const
Returns the number of nodes in the graph.
Definition: Graph_d.h:578
node newNode()
Creates a new node and returns it.
internal::GraphObjectContainer< NodeElement > nodes
The container containing all node objects.
Definition: Graph_d.h:545
adjEntry firstAdj() const
Returns the first entry in the adjaceny list.
Definition: Graph_d.h:211
static void expandEdge(const StaticSPQRTree &spqrTree, NodeArray< bool > &treeNodeTreated, const node &mu, const node &leftNode, const NodeArray< T > &nodeLength, const NodeArray< EdgeArray< T > > &edgeLength, const NodeArray< T > &thickness, NodeArray< List< adjEntry > > &newOrder, NodeArray< ListIterator< adjEntry > > &adjBeforeNodeArraySource, NodeArray< ListIterator< adjEntry > > &adjBeforeNodeArrayTarget, const T &delta_u, const T &delta_d, adjEntry &adjExternal, const node &n=nullptr)
Combinatorial embeddings of planar graphs with modification functionality.
ListConstIterator< E > search(const E &e) const
Scans the list for the specified element and returns an iterator to the first occurrence in the list...
Definition: List.h:1063
adjEntry adjTarget() const
Returns the corresponding adjacancy entry at target node.
Definition: Graph_d.h:332
static T largestFaceContainingNode(const StaticSPQRTree &spqrTree, const node &mu, const node &n, const NodeArray< T > &nodeLength, const NodeArray< EdgeArray< T > > &edgeLength)
Computes the size of a maximum face in the skeleton graph of mu containing n.
bool valid() const
Returns true iff the iterator points to an element.
Definition: List.h:112
node theNode() const
Returns the node whose adjacency list contains this element.
Definition: Graph_d.h:99
Class for adjacency list elements.
Definition: Graph_d.h:78
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition: basic.h:41
const Graph & tree() const override
Returns a reference to the tree T.
virtual bool isVirtual(edge e) const =0
Returns true iff e is a virtual edge.
internal::GraphObjectContainer< AdjElement > adjEntries
The container containing all entries in the adjacency list of this node.
Definition: Graph_d.h:198