Open
Graph Drawing
Framework

 v. snapshot-2017-02-16
 

CompactionConstraintGraph.h
Go to the documentation of this file.
1 
35 #pragma once
36 
40 #include <ogdf/planarity/PlanRep.h>
41 
42 namespace ogdf {
43 
45 enum class ConstraintEdgeType {
46  BasicArc,
49  FixToZeroArc,
50  ReducibleArc,
51  MedianArc
52 };
53 
56 {
57 public:
60  void writeGML(const char *fileName) const ;
61  void writeGML(ostream &os) const;
62  //output edges on external face
63  void writeGML(const char *fileName, NodeArray<bool> one) const ;
64  void writeGML(ostream &os, NodeArray<bool> one) const;
65  // @}
66 
68  edge basicArc(edge e) const {
69  return m_edgeToBasicArc[e];
70  }
71 
74 
76  bool verticalGen(edge e) const {return m_verticalGen[e];}
77 
80  bool verticalArc(edge e) const {return m_verticalArc[e];}
81 
83  bool onBorder(edge e) const {return m_border[e]>0;}
84 
86  bool fixOnBorder(edge e) const {return m_border[e] == 2;}
87 
89 
91  void align(bool b) {m_align = b;}
92 
95  bool alignmentArc(edge e) const {return m_alignmentArc[e];}
96 
97  const PlanRep& getPlanRep() const {return *m_pPR;}
98 
99  edge pathToOriginal(node v) {return m_pathToEdge[v];}
100 
101 protected:
104  const PlanRep &PG,
105  OrthoDir arcDir,
106  int costGen = 1,
107  int costAssoc = 1, bool align = false);
108 
110  void computeTopologicalSegmentNum(NodeArray<int> &topNum);
111 
114  void removeRedundantVisibArcs(SListPure<Tuple2<node,node> > &visibArcs);
115 
116  const OrthoRep *m_pOR;
117  const PlanRep *m_pPR;
120 
121  int m_edgeCost[2];
122 
126 
129 
130  //test fuer vorkomp. der Generalisierungen
134 
137 
140 
142  void embed();
143 
144  virtual void writeLength(ostream &os, edge e) const = 0;
145 
146 private:
147  //set special costs for node to merger generalizations
148  bool m_align;
149 
150  void insertPathVertices(const PlanRep &PG);
151  void dfsInsertPathVertex(
152  node v,
153  node pathVertex,
154  NodeArray<bool> &visited,
155  const NodeArray<node> &genOpposite);
156 
157  void insertBasicArcs(const PlanRep &PG);
158 
161 };
162 
163 
174 template<class ATYPE>
176 {
177 public:
180  const PlanRep &PG,
181  OrthoDir arcDir,
182  ATYPE sep,
183  int costGen = 1,
184  int costAssoc = 1,
185  bool align = false) :
186  CompactionConstraintGraphBase(OR, PG, arcDir, costGen, costAssoc, align)
187  {
188  OGDF_ASSERT(&(const Graph &)PG == &(const Graph &)OR);
189 
190  m_length .init((Graph&)*this, sep);
191  m_extraNode.init((Graph&)*this, false);
192  m_extraOfs .init((Graph&)*this, 0);
193  m_extraRep .init((Graph&)*this, nullptr);
194 
195  m_sep = sep;
196 
197  m_centerPriority = true; //should centering of single edges have prio. to gen. length
198  m_genToMedian = true; //should outgoing merger gen. be drawn to merger median
199 
200  initializeCosts();
201  }
202 
205  void writeGML(const char *fileName) const ;
206  void writeGML(ostream &os) const;
208 
211  const Graph &getGraph() const { return (const Graph&)*this; }
212  Graph &getGraph() { return (Graph&)*this; }
214 
216  const OrthoRep &getOrthoRep() const {
217  return *m_pOR;
218  }
219 
222  const SListPure<node> &nodesIn(node v) const {
223  return m_path[v];
224  }
225 
228  node pathNodeOf(node v) const {
229  return m_pathNode[v];
230  }
231 
234  ATYPE length(edge e) const {
235  return m_length[e];
236  }
237 
240  int cost(edge e) const {
241  return m_cost[e];
242  }
243 
247  return m_type[e];
248  }
249 
251  bool extraNode(node v) const {
252  return m_extraNode[v];
253  }
254 
256  ATYPE extraOfs(node v) const {
257  return m_extraOfs[v];
258  }
259 
261  node extraRep(node v) const {
262  return m_extraRep[v];
263  }
264 
266  bool centerPriority() {return m_centerPriority;}
268  void centerPriority(bool b) { m_centerPriority = b;}
269 
272  ATYPE computeTotalCosts(const NodeArray<ATYPE> &pos) const;
273 
278  void insertVertexSizeArcs(
279  const PlanRep &PG,
280  const NodeArray<ATYPE> &sizeOrig,
281  const RoutingChannel<ATYPE> &rc);
282 
288  void insertVertexSizeArcs(
289  const PlanRep &PG,
290  const NodeArray<ATYPE> &sizeOrig,
291  const MinimumEdgeDistances<ATYPE> &minDist);
292 
296  void insertVisibilityArcs(
297  const PlanRep &PG,
298  const NodeArray<ATYPE> &posDir,
299  const NodeArray<ATYPE> &posOppDir
300  );
301 
302  void insertVisibilityArcs(
303  const PlanRep &PG,
304  const NodeArray<ATYPE> &posDir,
305  const NodeArray<ATYPE> &posOrthDir,
306  const MinimumEdgeDistances<ATYPE> &minDist);
307 
309  void setMinimumSeparation(const PlanRep &PG,
310  const NodeArray<int> &coord,
311  const MinimumEdgeDistances<ATYPE> &minDist);
312 
314  void embed() {
316  }
317 
322  bool isFeasible(const NodeArray<ATYPE> &pos);
323 
325  ATYPE separation() const {return m_sep;}
326 
328  bool areMulti(edge e1, edge e2) const;
329 
330 private:
332  struct Interval
333  {
334  Interval(node v, ATYPE low, ATYPE high) {
335  m_low = low;
336  m_high = high;
337  m_pathNode = v;
338  }
339 
340  ATYPE m_low, m_high;
342 
344  friend ostream &operator<<(ostream &os,
345  const Interval &interval)
346  {
347  os << "[" << interval.m_low << "," << interval.m_high <<
348  ";" << interval.m_pathNode << "]";
349  return os;
350  }
351 
352  };
353 
359  {
360  public:
362  const NodeArray<int> &secSort) {
363  m_pPos = &segPos;
364  m_pSec = &secSort;
365  }
366 
367  int compare(const node &x, const node &y) const {
368  ATYPE d = (*m_pPos)[x] - (*m_pPos)[y];
369  if (d < 0)
370  return -1;
371  else if (d > 0)
372  return 1;
373  else
374  return (*m_pSec)[x] - (*m_pSec)[y];
375  }
376 
378  private:
381  };
382 
383  virtual void writeLength(ostream &os, edge e) const override {
384  os << m_length[e];
385  }
386 
387  void setBasicArcsZeroLength(const PlanRep &PG);
388  void resetGenMergerLengths(const PlanRep &PG, adjEntry adjFirst);
389  void setBoundaryCosts(adjEntry cornerDir,adjEntry cornerOppDir);
390 
391  bool checkSweepLine(const List<Interval> &sweepLine);
392 
393  ATYPE m_sep;
394 
396 
402 
405 
406  // we make vertex size arcs more expensive than basic arcs in order
407  // to get small cages
408  // should be replaced by option/value dependent on e.g. degree
414  //this does not work if generalization costs are set very small by the user
415  //because there must be a minimum cost for centering
417 
418  //factor of costs relative to generalization
419  static const int c_vertexArcFactor;
420  static const int c_bungeeFactor;
421  static const int c_doubleBendFactor;
422  static const int c_MedianFactor;
423 
425 
426 protected:
428  void setExtra(node v, node rep, ATYPE ofs) {
429  m_extraNode[v] = true;
430  m_extraRep[v] = rep;
431  m_extraOfs[v] = ofs;
432  }
433 
435  {
436  // we make vertex size arcs more expensive than basic arcs in order
437  // to get small cages; not necessary if cage size fixed in improvement
438  // cost should be dependend on degree
439  // Z.B. DURCH OPTION ODER WERT; DER VON DER ZAHL ADJAZENTER KANTEN ABHAENGIG IST
440  // should be derived by number of edges times something
441  int costGen = m_edgeCost[static_cast<int>(Graph::EdgeType::generalization)];
442 
443  m_vertexArcCost = c_vertexArcFactor*costGen; //spaeter aus Kompaktierungsmodul uebergeben
444  if (m_centerPriority)
445  m_bungeeCost = c_bungeeFactor*costGen+1;//-1;//for distance to middle position,
446  else
447  m_bungeeCost = c_bungeeFactor*4+1;//-1;//for distance to middle position,
448  //addition value should be < gen cost!!!
449  m_MedianArcCost = c_MedianFactor*m_vertexArcCost;
450  m_doubleBendCost = c_doubleBendFactor*m_vertexArcCost;
451  }//initializeCosts
452 };
453 
454 //initialization of static members
455 template<class ATYPE>
457 template<class ATYPE>
459 template<class ATYPE>
460 const int CompactionConstraintGraph<ATYPE>::c_doubleBendFactor = 20; //double bends cost mxxx*vertexArcCost
461 //factor *VertexArcCost, costs for pulling generalization to median position at merger
462 template<class ATYPE>
463 const int CompactionConstraintGraph<ATYPE>::c_MedianFactor = 10*c_doubleBendFactor;
464 
465 
466 // allow 0-length for sides of generalization merger cages
467 template<class ATYPE>
469  const PlanRep &PG,
470  adjEntry adjFirst)
471 {
472  adjEntry adj = adjFirst;
473  int faceSize = 0;
474 
475  do {
476  if ((m_pOR->direction(adj) == m_arcDir ||
477  m_pOR->direction(adj) == m_oppArcDir) &&
478  (PG.typeOf(adj->theNode()) == Graph::NodeType::dummy ||
479  PG.typeOf(adj->twinNode()) == Graph::NodeType::dummy))
480  {
481  m_length[m_edgeToBasicArc[adj]] = 0;
482  }
483 
484  adj = adj->faceCycleSucc();
485  faceSize++;
486  } while(adj != adjFirst);
487 
488  //generalization position section
489  //pull upper generalization to median of merger cage's incoming lower generalizations
490 
491  if (m_genToMedian
492  && (m_pOR->direction(adjFirst) == m_arcDir
493  || m_pOR->direction(adjFirst) == m_oppArcDir)) {
494  int numIncoming = faceSize - 3;
495  int median = (numIncoming / 2) + 1;
496 
497  // if (numIncoming == 2) ... just the middle position
498  node upper = m_pathNode[adjFirst->theNode()];
499  if (PG.typeOf(adjFirst->theNode()) != Graph::NodeType::generalizationMerger) {
501  }
502 
503  node vMin;
504  if (m_pOR->direction(adjFirst) == m_arcDir) {
505  vMin = adjFirst->faceCyclePred()->theNode();
506  } else {
507  vMin = adjFirst->faceCycleSucc()->theNode();
508  }
509 
510  adj = adjFirst->faceCycleSucc(); // target right or left boundary, depending on drawing direction
511  for (int i = 0; i < median; i++) {
512  adj = adj->faceCycleSucc();
513  }
514 
515  node lower = m_pathNode[adj->theNode()];
516  node vCenter = newNode();
517  setExtra(vCenter, vMin, 0);
518 
519  // it seems we dont need the helper, as only source-adjEntries lying on
520  // the outer face are considered later, but keep it in mind
521 #if 0
522  edge helper = newEdge(m_pathNode[vMin], vCenter);
523  m_length[helper] = 0;
524  m_cost[helper] = 0;
525  m_type[helper] = ConstraintEdgeType::ReducibleArc;
526 #endif
527 
528  edge e1 = newEdge(vCenter,upper);
529  m_length[e1] = 0;
530  m_cost[e1] = m_MedianArcCost;
531  m_type[e1] = ConstraintEdgeType::MedianArc;
532 
533  edge e2 = newEdge(vCenter,lower);
534  m_length[e2] = 0;
535  m_cost[e2] = m_MedianArcCost;
536  m_type[e2] = ConstraintEdgeType::MedianArc;
537  }
538 }
539 
540 
541 // set cost of edges on the cage boundary to 0
542 template<class ATYPE>
544  adjEntry cornerDir,
545  adjEntry cornerOppDir)
546 {
547 #if 0
548  adjEntry adj;
549  for (adj = cornerDir; m_pOR->direction(adj) == m_arcDir; adj = adj->faceCycleSucc())
550  m_cost[m_edgeToBasicArc[adj]] = 0;
551  for (adj = cornerOppDir; m_pOR->direction(adj) == m_oppArcDir; adj = adj->faceCycleSucc())
552  m_cost[m_edgeToBasicArc[adj]] = 0;
553 #endif
554  //test for multi separation
555  adjEntry adj;
556  for (adj = cornerDir; m_pOR->direction(adj) == m_arcDir; adj = adj->faceCycleSucc())
557  {
558  m_cost[m_edgeToBasicArc[adj]] = 0;
559 
560  if (m_pathNode[adj->twin()->cyclicSucc()->theNode()] &&
561  (m_pOR->direction(adj->faceCycleSucc()) == m_arcDir)
562  )
563  m_originalEdge[m_pathNode[adj->twin()->cyclicSucc()->theNode()]] =
564  m_pPR->original(adj->twin()->cyclicSucc()->theEdge());
565 
566  }
567  for (adj = cornerOppDir; m_pOR->direction(adj) == m_oppArcDir; adj = adj->faceCycleSucc())
568  {
569  m_cost[m_edgeToBasicArc[adj]] = 0;
570 
571  if (m_pathNode[adj->twin()->cyclicSucc()->theNode()])
572  m_originalEdge[m_pathNode[adj->twin()->cyclicSucc()->theNode()]] =
573  m_pPR->original(adj->twin()->cyclicSucc()->theEdge());
574  }
575 }
576 
577 
578 //
579 // insert arcs required for respecting vertex sizes, sizes of routing channels
580 // and position of attached generalizations
581 // vertices are represented by variable cages
582 template<class ATYPE>
584  const PlanRep &PG,
585  const NodeArray<ATYPE> &sizeOrig,
586  const RoutingChannel<ATYPE> &rc)
587 {
588 
589  // segments in constraint graph are sides sMin and sMax; other two side
590  // are sides in which adjacency entries run in direction m_arcDir and
591  // m_oppArcDir
592  OrthoDir dirMin = OrthoRep::prevDir(m_arcDir);
593  OrthoDir dirMax = OrthoRep::nextDir(m_arcDir);
594 
595  const ATYPE overhang = rc.overhang();
596 
597  for(node v : PG.nodes)
598  {
599  if (PG.expandAdj(v) == nullptr) continue;
600 
602  {
603  resetGenMergerLengths(PG,PG.expandAdj(v));
604 
605  }
606  else // high/low-degree expander
607  {
608  ATYPE size = sizeOrig[v];
609 
610  const OrthoRep::VertexInfoUML &vi = *m_pOR->cageInfo(v);
611 
612  // determine routing channels rcMin and rcMax
613  ATYPE rcMin = overhang + rc(v,dirMin);
614  ATYPE rcMax = overhang + rc(v,dirMax);
615 
616  adjEntry cornerDir = vi.m_corner[static_cast<int>(m_arcDir)];
617  adjEntry cornerOppDir = vi.m_corner[static_cast<int>(m_oppArcDir)];
618  adjEntry cornerMin = vi.m_corner[static_cast<int>(dirMin)];
619  adjEntry cornerMax = vi.m_corner[static_cast<int>(dirMax)];
620 
621  // set cost of edges on the cage boundary to 0
622  setBoundaryCosts(cornerDir,cornerOppDir);
623 
624  const OrthoRep::SideInfoUML &sDir = vi.m_side[static_cast<int>(m_arcDir)];
625  const OrthoRep::SideInfoUML &sOppDir = vi.m_side[static_cast<int>(m_oppArcDir)];
626 
627  // correct lengths of edges within cage adjacent to corners
628  if(sDir.totalAttached() > 0) {
629  m_length[m_edgeToBasicArc[cornerDir]] = rcMin;
630  m_length[m_edgeToBasicArc[cornerMax->faceCyclePred()]] = rcMax;
631  } else {
632  // if no edges are attached at this side we need no constraint
633  m_length[m_edgeToBasicArc[cornerDir]] = 0;
634  delEdge(m_edgeToBasicArc[cornerDir]);
635  }
636 
637  if(sOppDir.totalAttached() > 0) {
638  m_length[m_edgeToBasicArc[cornerOppDir]] = rcMax;
639  m_length[m_edgeToBasicArc[cornerMin->faceCyclePred()]] = rcMin;
640  } else {
641  // if no edges are attached at this side we need no constraint
642  m_length[m_edgeToBasicArc[cornerOppDir]] = 0;
643  delEdge(m_edgeToBasicArc[cornerOppDir]);
644  }
645 
646 
647  // insert arcs for respecting vertex size / position of generalizations
648  node vMin = m_pathNode[cornerDir->theNode()];
649  node vMax = m_pathNode[cornerOppDir->theNode()];
650 
651  // any attached generalizations ?
652  if (sDir.m_adjGen == nullptr && sOppDir.m_adjGen == nullptr)
653  {
654  // no, only one arc for vertex size + routing channels
655  edge e = newEdge(vMin,vMax);
656  m_length[e] = rcMin + size + rcMax - 2*overhang;
657  m_cost [e] = 2*m_vertexArcCost;
659 
660  } else {
661  // yes, then two arcs for each side with an attached generalization
662  ATYPE minHalf = size/2;
663  ATYPE maxHalf = size - minHalf;
664  ATYPE lenMin = rcMin + minHalf - overhang;
665  ATYPE lenMax = maxHalf + rcMax - overhang;
666 
667  if (sDir.m_adjGen != nullptr) {
668  node vCenter = m_pathNode[sDir.m_adjGen->theNode()];
669  edge e1 = newEdge(vMin,vCenter);
670  m_length[e1] = lenMin;
671  m_cost [e1] = m_vertexArcCost;
672  m_type [e1] = ConstraintEdgeType::VertexSizeArc;
673  edge e2 = newEdge(vCenter,vMax);
674  m_length[e2] = lenMax;
675  m_cost [e2] = m_vertexArcCost;
676  m_type [e2] = ConstraintEdgeType::VertexSizeArc;
677  }
678 
679  if (sOppDir.m_adjGen != nullptr) {
680  node vCenter = m_pathNode[sOppDir.m_adjGen->theNode()];
681  edge e1 = newEdge(vMin,vCenter);
682  m_length[e1] = lenMin;
683  m_cost [e1] = m_vertexArcCost;
684  m_type [e1] = ConstraintEdgeType::VertexSizeArc;
685  edge e2 = newEdge(vCenter,vMax);
686  m_length[e2] = lenMax;
687  m_cost [e2] = m_vertexArcCost;
688  m_type [e2] = ConstraintEdgeType::VertexSizeArc;
689  }
690 
691  }
692 
693  } // high/lowDegreeExpander
694  }
695 }
696 
697 
698 template<class ATYPE>
700  const PlanRep &PG)
701 {
702  for(edge e : PG.edges)
703  {
704  edge arc = m_edgeToBasicArc[e];
705  if (arc == nullptr) continue;
706 
707  node v = e->source();
708  node w = e->target();
709  if ( ((PG.typeOf(v) == Graph::NodeType::dummy) && (PG.typeOf(w) == Graph::NodeType::dummy) &&
710  (v->degree() == 2) && w->degree() == 2) &&
711  (m_pOR->angle(e->adjSource()) == m_pOR->angle(e->adjTarget()) ) && //no uturns
713  )
714  {
715  m_length[arc] = 0;
716  m_type[arc] = ConstraintEdgeType::FixToZeroArc;
717  //we make fixtozero arcs as expensive as possible
718  m_cost[arc] = m_doubleBendCost;
719  }
720  }
721 }
722 
723 
724 
725 //
726 // insert arcs required for respecting vertex sizes
727 // and position of attached generalizations
728 // vertices are represented by tight cages
729 template<class ATYPE>
731  const PlanRep &PG,
732  const NodeArray<ATYPE> &sizeOrig,
733  const MinimumEdgeDistances<ATYPE> &minDist)
734 {
735  // set the length of all basic arcs corresponding to inner edge segments
736  // to 0
737  setBasicArcsZeroLength(PG);
738 
739  // segments in constraint graph are sides sMin and sMax; other two side
740  // are sides in which adjacency entries run in direction m_arcDir and
741  // m_oppArcDir
742  OrthoDir dirMin = OrthoRep::prevDir(m_arcDir);
743  OrthoDir dirMax = OrthoRep::nextDir(m_arcDir);
744 
745  for(node v : PG.nodes)
746  {
747  if (PG.expandAdj(v) == nullptr) continue;
748 
750  {
751  resetGenMergerLengths(PG,PG.expandAdj(v));
752 
753  }
754  else // high/low-degree expander
755  {
756  ATYPE size = sizeOrig[v];
757  const OrthoRep::VertexInfoUML &vi = *m_pOR->cageInfo(v);
758 
759  adjEntry cornerDir = vi.m_corner[static_cast<int>(m_arcDir)];
760  adjEntry cornerOppDir = vi.m_corner[static_cast<int>(m_oppArcDir)];
761  adjEntry cornerMin = vi.m_corner[static_cast<int>(dirMin)];
762  adjEntry cornerMax = vi.m_corner[static_cast<int>(dirMax)];
763 
764  adjEntry adj = cornerDir, last = cornerMax->faceCyclePred();
765  if(adj != last) {
766  m_length[m_edgeToBasicArc[adj]] = minDist.epsilon(v,m_arcDir,0);
767  m_length[m_edgeToBasicArc[last]] = minDist.epsilon(v,m_arcDir,1);
768  int i = 0;
769  for(adj = adj->faceCycleSucc(); adj != last; adj = adj->faceCycleSucc()) {
771  i++;
772  m_length[m_edgeToBasicArc[adj]] = minDist.delta(v,m_arcDir,i);
773  }
774  }
775 
776  adj = cornerOppDir, last = cornerMin->faceCyclePred();
777  if(adj != last) {
778  m_length[m_edgeToBasicArc[adj]] = minDist.epsilon(v,m_oppArcDir,0);
779  m_length[m_edgeToBasicArc[last]] = minDist.epsilon(v,m_oppArcDir,1);
780  int i = 0;
781  for(adj = adj->faceCycleSucc(); adj != last; adj = adj->faceCycleSucc()) {
783  i++;
784  m_length[m_edgeToBasicArc[adj]] = minDist.delta(v,m_oppArcDir,i);
785  }
786  }
787 
788 
789  // insert arcs for respecting vertex size / position of generalizations
790  node vMin = m_pathNode[cornerDir->theNode()];
791  node vMax = m_pathNode[cornerOppDir->theNode()];
792 
793  const OrthoRep::SideInfoUML &sDir = vi.m_side[static_cast<int>(m_arcDir)];
794  const OrthoRep::SideInfoUML &sOppDir = vi.m_side[static_cast<int>(m_oppArcDir)];
795 
796  // any attached generalizations ?
797  if (sDir.m_adjGen == nullptr && sOppDir.m_adjGen == nullptr)
798  {
799  //check for single edge case => special treatment
800  //generic case could handle all numbers
801 
802  if ((sDir.totalAttached() == 1) || (sOppDir.totalAttached() == 1))
803  {
804  //first, insert a new center node and connect it
805  ATYPE lenMin = size/2;
806  ATYPE lenMax = size - lenMin;
807  node vCenter = newNode();
808  setExtra(vCenter, cornerDir->theNode(), lenMin);
809 
810  edge e1 = newEdge(vMin,vCenter);
811  m_length[e1] = lenMin;
812  m_cost[e1] = m_vertexArcCost;
814  edge e2 = newEdge(vCenter,vMax);
815  m_length[e2] = lenMax;
816  m_cost[e2] = m_vertexArcCost;
818 
819  if (sDir.totalAttached() == 1)
820  {
821 
822  //then, insert a moveable node connecting center
823  //and outgoing segment
824  node vBungee = newNode();
825  //+1 should fix the fixzerolength problem
826  setExtra(vBungee, cornerDir->theNode(), minDist.epsilon(v,m_arcDir,0) );
827 
828  edge eToBungee = newEdge(vMin, vBungee);
829  m_type[eToBungee] = ConstraintEdgeType::MedianArc; //BasicArc; // XXX: is this ok?
830  m_cost[eToBungee] = 0; // XXX: what about this?
831  m_length[eToBungee] = minDist.epsilon(v,m_arcDir,0);
832 
833  edge eBungeeCenter = newEdge(vBungee, vCenter);
834  //bungee, center and outgoing segment may build column if in the middle
835  m_type[eBungeeCenter] = ConstraintEdgeType::MedianArc;
836  m_cost[eBungeeCenter] = m_bungeeCost; // XXX: what about this?
837  m_length[eBungeeCenter] = 0;
838 
839  //attention: pathnode construct works only if degree 1
840  edge eBungeeOut = newEdge(vBungee, m_pathNode[cornerDir->twinNode()]);
841  //bungee, center and outgoing segment may build column if in the middle
842  m_type[eBungeeOut] = ConstraintEdgeType::MedianArc;
843  m_cost[eBungeeOut] = m_bungeeCost; // XXX: what about this?
844  m_length[eBungeeOut] = 0;
845 #if 0
846  //connect outgoing segment and "right" segment, maybe obsolete
847  edge eFromOut = newEdge(m_pathNode[cornerDir->twinNode()], vMax);
848  m_type[eFromOut] = ConstraintEdgeType::BasicArc; // XXX
849  m_cost[eFromOut] = 0; // XXX
850  m_length[eFromOut] = minDist.epsilon(v,m_arcDir,1);
851 #endif
852  }//if sDir case
853  if ( sOppDir.totalAttached() == 1 && m_pathNode[cornerOppDir->twinNode()] != vMin )
854  {
855 
856  //then, insert a moveable node connecting center
857  //and outgoing segment
858  node vBungee = newNode();
859  //+1 for not fixzerolength
860  setExtra(vBungee, cornerDir->theNode(), minDist.epsilon(v,m_oppArcDir,0) );
861 
862  edge eToBungee = newEdge(vMin, vBungee);
863  m_type[eToBungee] = ConstraintEdgeType::MedianArc;//BasicArc; // XXX: is this ok?
864  m_cost[eToBungee] = 0; // XXX: what about this?
865  m_length[eToBungee] = minDist.epsilon(v,m_oppArcDir,0);
866 
867  edge eBungeeCenter = newEdge(vBungee, vCenter);
868  //bungee, center and outgoing segment may build column if in the middle
869  m_type[eBungeeCenter] = ConstraintEdgeType::MedianArc;
870  m_cost[eBungeeCenter] = m_bungeeCost; // XXX: what about this?
871  m_length[eBungeeCenter] = 0;
872 
873  //attention: pathnode construct works only if degree 1, sometimes not at all
874  edge eBungeeOut = newEdge(vBungee, m_pathNode[cornerOppDir->twinNode()]);
875  //bungee, center and outgoing segment may build column if in the middle
876  m_type[eBungeeOut] = ConstraintEdgeType::MedianArc;
877  m_cost[eBungeeOut] = m_bungeeCost; // XXX: what about this?
878  m_length[eBungeeOut] = 0;
879 #if 0
880  //connect outgoing segment and "right" segment, maybe obsolete
881  edge eFromOut = newEdge(m_pathNode[cornerOppDir->twinNode()], vMax);
882  m_type[eFromOut] = ConstraintEdgeType::BasicArc; // XXX
883  m_cost[eFromOut] = 0; // XXX
884  m_length[eFromOut] = minDist.epsilon(v,m_oppArcDir,0);
885 #endif
886  }//if sOppDir case
887  }//if special case
888  else
889  {
890  // no, only one arc for vertex size + routing channels
891  edge e = newEdge(vMin,vMax);
892  m_length[e] = size;
893  m_cost[e] = 2*m_vertexArcCost;
895  }//else special case
896 
897 
898  } else {
899  // yes, then two arcs for each side with an attached generalization
900  ATYPE lenMin = size/2;
901  ATYPE lenMax = size - lenMin;
902 
903 #if 0
904  ATYPE len = size/2;
905 #endif
906 
907  if (sDir.m_adjGen != nullptr) {
908  node vCenter = m_pathNode[sDir.m_adjGen->theNode()];
909  edge e1 = newEdge(vMin,vCenter);
910  m_length[e1] = lenMin;
911  m_cost [e1] = m_vertexArcCost;
912  m_type [e1] = ConstraintEdgeType::VertexSizeArc;
913  edge e2 = newEdge(vCenter,vMax);
914  m_length[e2] = lenMax;
915  m_cost [e2] = m_vertexArcCost;
916  m_type [e2] = ConstraintEdgeType::VertexSizeArc;
917  }
918  else
919  {
920  if (sDir.totalAttached() == 1)
921  {
922  node vCenter = newNode();//m_pathNode[sOppDir.m_adjGen->theNode()]; //newNode();
923  setExtra(vCenter, cornerDir->theNode(), lenMin);
924 
925  edge e1 = newEdge(vMin,vCenter);
926  m_length[e1] = lenMin;
927  m_cost[e1] = m_vertexArcCost;
929  edge e2 = newEdge(vCenter,vMax);
930  m_length[e2] = lenMax;
931  m_cost[e2] = m_vertexArcCost;
933 
934  //then, insert a moveable node connecting center
935  //and outgoing segment
936  node vBungee = newNode();
937  //+1 for not fixzerolength
938  setExtra(vBungee, cornerDir->theNode(), minDist.epsilon(v,m_arcDir,0) );
939 
940  edge eToBungee = newEdge(vMin, vBungee);
941  m_type[eToBungee] = ConstraintEdgeType::MedianArc;//BasicArc; // XXX: is this ok?
942  m_cost[eToBungee] = 0; // XXX: what about this?
943  m_length[eToBungee] = minDist.epsilon(v,m_arcDir,0);
944 
945  edge eBungeeCenter = newEdge(vBungee, vCenter);
946  //bungee, center and outgoing segment may build column if in the middle
947  m_type[eBungeeCenter] = ConstraintEdgeType::MedianArc;
948  m_cost[eBungeeCenter] = m_bungeeCost; // XXX: what about this?
949  m_length[eBungeeCenter] = 0;
950 
951  //attention: pathnode construct works only if degree 1
952  edge eBungeeOut = newEdge(vBungee, m_pathNode[cornerDir->twinNode()]);
953  //bungee, center and outgoing segment may build column if in the middle
954  m_type[eBungeeOut] = ConstraintEdgeType::MedianArc;
955  m_cost[eBungeeOut] = m_bungeeCost; // XXX: what about this?
956  m_length[eBungeeOut] = 0;
957 
958  }//if sDir case
959  }//else, only oppdir
960  if (sOppDir.m_adjGen != nullptr) {
961  node vCenter = m_pathNode[sOppDir.m_adjGen->theNode()];
962  edge e1 = newEdge(vMin,vCenter);
963  m_length[e1] = lenMin;
964  m_cost [e1] = m_vertexArcCost;
965  m_type [e1] = ConstraintEdgeType::VertexSizeArc;
966  edge e2 = newEdge(vCenter,vMax);
967  m_length[e2] = lenMax;
968  m_cost [e2] = m_vertexArcCost;
969  m_type [e2] = ConstraintEdgeType::VertexSizeArc;
970  }
971  else
972  {
973  //special case single edge to middle position
974  if ( sOppDir.totalAttached() == 1 && m_pathNode[cornerOppDir->twinNode()] != vMin )
975  {
976  node vCenter = newNode();//m_pathNode[sDir.m_adjGen->theNode()];//newNode();
977  setExtra(vCenter, cornerDir->theNode(), lenMin);
978 
979  edge e1 = newEdge(vMin,vCenter);
980  m_length[e1] = lenMin;
981  m_cost[e1] = m_vertexArcCost;
983  edge e2 = newEdge(vCenter,vMax);
984  m_length[e2] = lenMax;
985  m_cost[e2] = m_vertexArcCost;
987  //then, insert a moveable node connecting center
988  //and outgoing segment
989  node vBungee = newNode();
990  //+1 for not fixzerolength
991  setExtra(vBungee, cornerDir->theNode(), minDist.epsilon(v,m_oppArcDir,0) );
992 
993  edge eToBungee = newEdge(vMin, vBungee);
994  m_type[eToBungee] = ConstraintEdgeType::MedianArc;//BasicArc; // XXX: is this ok?
995  m_cost[eToBungee] = 0; // XXX: what about this?
996  m_length[eToBungee] = minDist.epsilon(v,m_oppArcDir,0);
997 
998  edge eBungeeCenter = newEdge(vBungee, vCenter);
999  //bungee, center and outgoing segment may build column if in the middle
1000  m_type[eBungeeCenter] = ConstraintEdgeType::MedianArc;
1001  m_cost[eBungeeCenter] = m_bungeeCost; // XXX: what about this?
1002  m_length[eBungeeCenter] = 0;
1003 
1004  //attention: pathnode construct works only if degree 1
1005  edge eBungeeOut = newEdge(vBungee, m_pathNode[cornerOppDir->twinNode()]);
1006  //bungee, center and outgoing segment may build column if in the middle
1007  m_type[eBungeeOut] = ConstraintEdgeType::MedianArc;
1008  m_cost[eBungeeOut] = m_bungeeCost; // XXX: what about this?
1009  m_length[eBungeeOut] = 0;
1010 
1011  }//if sOppDir case
1012  }//else only dir gen
1013 
1014  }
1015 
1016  // set cost of edges on the cage boundary to 0
1017  setBoundaryCosts(cornerDir,cornerOppDir);
1018 
1019  } // high/lowDegreeExpander
1020  }
1021 #if 0
1022  if (m_arcDir == OrthoDir::East) writeGML("eastvertexsizeinserted.gml");
1023  else writeGML("northvertexsizeinserted.gml");
1024 #endif
1025 }
1026 
1027 
1028 // computes the total costs for coordintes given by pos, i.e.,
1029 // the sum of the weighted lengths of edges in the constraint graph.
1030 template<class ATYPE>
1032  const NodeArray<ATYPE> &pos) const
1033 {
1034  ATYPE c = 0;
1035  for(edge e : edges) {
1036  c += cost(e) * (pos[e->target()] - pos[e->source()]);
1037  }
1038 
1039  return c;
1040 }
1041 
1042 
1043 //
1044 // insertion of visibility arcs
1045 
1046 // checks if intervals on the sweep line are in correct order
1047 template<class ATYPE>
1049 {
1050  if (sweepLine.empty())
1051  return true;
1052 
1053  ListConstIterator<Interval> it = sweepLine.begin();
1054 
1055  if((*it).m_high < (*it).m_low)
1056  return false;
1057 
1058  ATYPE x = (*it).m_low;
1059 
1060  for(++it; it.valid(); ++it) {
1061  if((*it).m_high < (*it).m_low)
1062  return false;
1063  if ((*it).m_high > x)
1064  return false;
1065  x = (*it).m_low;
1066  }
1067 
1068  return true;
1069 }
1070 
1071 
1072 template<class ATYPE>
1074  const PlanRep &PG,
1075  const NodeArray<ATYPE> &posDir,
1076  const NodeArray<ATYPE> &posOrthDir
1077  )
1078 {
1079  MinimumEdgeDistances<ATYPE> minDist(PG, m_sep);
1080 
1081  for(node v : PG.nodes)
1082  {
1083  if(PG.expandAdj(v) == nullptr) continue;
1084 
1085  for(int d = 0; d < 4; ++d) {
1086  minDist.delta(v,OrthoDir(d),0) = m_sep;//currentSeparation;
1087  minDist.delta(v,OrthoDir(d),1) = m_sep;//currentSeparation;
1088  }
1089  }
1090 
1091  insertVisibilityArcs(PG,posDir,posOrthDir,minDist);
1092 }
1093 
1094 
1095 
1096 // inserts arcs connecting segments which can see each other in a drawing
1097 // of the associated planarized representation PG which is given by
1098 // posDir and posOppDir.
1099 
1100 //ersetze mindist.delta durch min(m_sep, mindist.delta) fuer skalierung
1101 template<class ATYPE>
1103  const PlanRep &PG,
1104  const NodeArray<ATYPE> &posDir,
1105  const NodeArray<ATYPE> &posOrthDir,
1106  const MinimumEdgeDistances<ATYPE> &minDist)
1107 {
1108  OrthoDir segDir = OrthoRep::prevDir(m_arcDir);
1109  OrthoDir segOppDir = OrthoRep::nextDir(m_arcDir);
1110 
1111  // list of visibility arcs which have to be inserted
1112  SListPure<Tuple2<node,node> > visibArcs;
1113 
1114  // lower and upper bound of segments
1115  NodeArray<ATYPE> low(getGraph()), lowReal(getGraph()), high(getGraph());
1116  NodeArray<ATYPE> segPos(getGraph(), 0); // position of segments
1117  NodeArray<int> topNum(getGraph()/*,0*/); // secondary sorting criteria for segments
1118 
1119  // compute position and lower/upper bound of segments
1120  // We have to take care that segments cannot be shifted one upon the other,
1121  // e.g., if we have two segments (l1,h1) and (l2,h2) with l2 > h2 and
1122  // the distance l2-h2 is smaller than separation, the segments can see
1123  // each other. We do this by enlarging the lower bound of all segments
1124  // by separation if this lower bound is realized by a bend.
1125  //
1126  // Note: Be careful at segments attached at a vertex which are closer
1127  // than separation to each other. Possible solution: Remove visibility
1128  // arcs of segments which are connected by orthogonal segments to the
1129  // same vertex and bend in opposite directions.
1130  for(node v : nodes) {
1131 
1132  //special case nodes
1133  if (m_path[v].empty()) continue;
1134 
1135  SListConstIterator<node> it = m_path[v].begin();
1136 
1137  segPos[v] = posDir[*it];
1138  low[v] = high[v] = posOrthDir[*it];
1139  node nodeLow = *it;
1140  for(++it; it.valid(); ++it) {
1141  ATYPE x = posOrthDir[*it];
1142  if (x < low [v]) {
1143  low [v] = x;
1144  nodeLow = *it;
1145  }
1146  if (x > high[v]) high[v] = x;
1147  }
1148  lowReal[v] = low[v];
1149  Graph::NodeType typeLow = PG.typeOf(nodeLow);
1151 #if 0
1152  bool subtractSep = true;
1153  if (nodeLow->degree() == 2) {
1154  adjEntry adjFound = nullptr;
1155  for(adjEntry adj : nodeLow->adjEntries) {
1156  if(m_pOR->direction(adj) == m_arcDir || m_pOR->direction(adj) == m_oppArcDir) {
1157  adjFound = adj;
1158  break;
1159  }
1160  }
1161  if (adjFound) {
1162  for(adjEntry adj2 = adjFound->faceCycleSucc();
1163  m_pOR->direction(adj2) == m_pOR->direction(adjFound);
1164  adj2 = adj2->twin()->faceCycleSucc()) ;
1165  if(posDir[adjFound->theNode()] == posDir[adj2->twinNode()])
1166  subtractSep = false;
1167  }
1168  }
1169  if (subtractSep)
1170  low[v] -= m_sep;
1171 #else
1172  low[v] -= m_sep;
1173 #endif
1174  }
1175  }
1176 
1177  // correct "-= m_sep" ...
1178  OrthoDir dirMin = OrthoRep::prevDir(m_arcDir);
1179  OrthoDir dirMax = OrthoRep::nextDir(m_arcDir);
1180  bool isCaseA = (m_arcDir == OrthoDir::East || m_arcDir == OrthoDir::South);
1181  const int angleAtMin = (m_arcDir == OrthoDir::East || m_arcDir == OrthoDir::South) ? 3 : 1;
1182  const int angleAtMax = (m_arcDir == OrthoDir::East || m_arcDir == OrthoDir::South) ? 1 : 3;
1183 
1184  for(node v : PG.nodes)
1185  {
1186  if(PG.expandAdj(v) == nullptr) continue;
1187  const OrthoRep::VertexInfoUML &vi = *m_pOR->cageInfo(v);
1188 
1189  int i = 0;
1190  adjEntry adj;
1191 
1192  for (adj = (isCaseA) ? vi.m_corner[static_cast<int>(dirMin)]->faceCycleSucc()->faceCycleSucc() : vi.m_corner[static_cast<int>(dirMin)]->faceCycleSucc();
1193  m_pOR->direction((isCaseA) ? adj : adj->faceCycleSucc()) == dirMin; //m_pOR->direction(adj) == dirMin;
1194  adj = adj->faceCycleSucc())
1195  {
1196  adjEntry adjCross = adj->cyclicPred();
1197  adjEntry adjTwin = adjCross->twin();
1198 
1199  adjEntry adjPred = adj->faceCyclePred();
1200  ATYPE delta = (isCaseA) ?
1201  min(abs(posOrthDir[adjPred->theNode()] - posOrthDir[adjPred->twinNode()]), m_sep) :
1202  min(abs(posOrthDir[adj->theNode()] - posOrthDir[adj->twinNode()]), m_sep);
1203  ATYPE boundary = (isCaseA) ?
1204  min(posOrthDir[adjPred->theNode()], posOrthDir[adjPred->twinNode()]) :
1205  min(posOrthDir[adj->theNode()], posOrthDir[adj->twinNode()]);
1206 
1207  if (PG.typeOf(adjCross->theEdge()) == Graph::EdgeType::generalization)
1208  {
1209  if (isCaseA) {
1211  m_pOR->angle(adjTwin) == 2)
1212  {
1213  node s1 = m_pathNode[adjTwin->theNode()];
1214  node s2 = m_pathNode[adjTwin->cyclicSucc()->twinNode()];
1215  low[s1] = lowReal[s1] - delta; // minDist.delta(v,dirMin,i);
1216  low[s2] = lowReal[s2] - delta; //minDist.delta(v,dirMin,i);
1217  }
1218  ++i;
1219  } else {
1220  ++i;
1222  m_pOR->angle(adjTwin->cyclicPred()) == 2)
1223  {
1224  node s1 = m_pathNode[adjTwin->theNode()];
1225  node s2 = m_pathNode[adjTwin->cyclicPred()->twinNode()];
1226  low[s1] = lowReal[s1] - delta; //minDist.delta(v,dirMin,i);
1227  low[s2] = lowReal[s2] - delta; //minDist.delta(v,dirMin,i);
1228  }
1229  }
1230  continue;
1231  }
1232 
1233  //we save the current direction and stop if we run in opposite
1234  OrthoDir runDir = m_pOR->direction(adjCross);
1235  // if -> while
1236  while (PG.typeOf(adjTwin->theNode()) == Graph::NodeType::dummy &&
1237  adjTwin->theNode()->degree() == 2 &&
1238  m_pOR->angle(adjTwin) == angleAtMin)
1239  {
1240  // We handle the case if an edge segment adjacent to a vertex
1241  // is separated by less than separation from edge segments above.
1242  node s = m_edgeToBasicArc[adjCross]->source();
1243  if(lowReal[s] != low[s])
1244  {
1245  if(low[s] >= boundary) // nothing to do?
1246  break;
1247  low[s] = boundary;
1248 #if 0
1249  low[s] += m_sep - delta; //minDist.delta(v,dirMin,i);
1250 #endif
1251 
1252  // If the compaction has eliminated bends, we can have the situation
1253  // that segment s has length 0 and the next segment s' (following the
1254  // edge) is at the same position (the edge arc has length 0).
1255  // In this case, the low-value of s' must be lowered (low[s'] := lowReal[s']
1256  // is approproate). The same situation can appear several times in a
1257  // row.
1258  //collect chains of segments compacted to zero length
1259  for( ; ; ) { //while(true/*lowReal[s] == high[s]*/) {
1260  do {
1261  adjCross = adjCross->faceCycleSucc();
1262  } while(m_pOR->direction(adjCross) == segDir ||
1263  m_pOR->direction(adjCross) == segOppDir);
1264 
1265  if(adjCross->theNode()->degree() != 2) // no longer a bend point?
1266  break;
1267 
1268  node sNext = m_edgeToBasicArc[adjCross]->opposite(s);
1269 
1270  if(segPos[sNext] != segPos[s])
1271  break;
1272 
1273  low[sNext] = lowReal[sNext]; //?
1274  s = sNext;
1275  }//while
1276  }//if
1277 
1278  adjTwin = adjCross->twin(); // update of twin for while
1279  //check if we have to stop
1280  if (runDir != m_pOR->direction(adjCross)) break;
1281  }//while dummy bend
1282  }
1283 
1284  i = 0;
1285  for (adj = (isCaseA) ? vi.m_corner[static_cast<int>(dirMax)]->faceCycleSucc() : vi.m_corner[static_cast<int>(dirMax)]->faceCycleSucc()->faceCycleSucc();
1286  m_pOR->direction((isCaseA) ? adj->faceCycleSucc() : adj) == dirMax; // m_pOR->direction(adj) == dirMax;
1287  adj = adj->faceCycleSucc())
1288  {
1289  adjEntry adjCross = adj->cyclicPred();
1290  adjEntry adjTwin = adjCross->twin();
1291 
1292 #if 0
1293  ATYPE delta = -posOrthDir[adj->twinNode()] + posOrthDir[adj->theNode()];
1294 #endif
1295  adjEntry adjPred = adj->faceCyclePred();
1296  ATYPE delta = (isCaseA) ?
1297  min(abs(posOrthDir[adj->twinNode()] - posOrthDir[adj->theNode()]), m_sep) :
1298  min(abs(posOrthDir[adjPred->theNode()] - posOrthDir[adjPred->twinNode()]), m_sep);
1299  ATYPE boundary = (isCaseA) ?
1300  min(posOrthDir[adj->twinNode()], posOrthDir[adj->theNode()]) :
1301  min(posOrthDir[adjPred->theNode()], posOrthDir[adjPred->twinNode()]);
1302 
1303  if (PG.typeOf(adjCross->theEdge()) == Graph::EdgeType::generalization)
1304  {
1305  if (isCaseA) {
1306  ++i;
1308  m_pOR->angle(adjTwin->cyclicPred()) == 2)
1309  {
1310  node s1 = m_pathNode[adjTwin->theNode()];
1311  node s2 = m_pathNode[adjTwin->cyclicPred()->twinNode()];
1312  low[s1] = lowReal[s1] - delta; //minDist.delta(v,dirMax,i);
1313  low[s2] = lowReal[s2] - delta; //minDist.delta(v,dirMax,i);
1314  }
1315  } else {
1317  m_pOR->angle(adjTwin) == 2)
1318  {
1319  node s1 = m_pathNode[adjTwin->theNode()];
1320  node s2 = m_pathNode[adjTwin->cyclicSucc()->twinNode()];
1321  low[s1] = lowReal[s1] - delta; //minDist.delta(v,dirMax,i);
1322  low[s2] = lowReal[s2] - delta; //minDist.delta(v,dirMax,i);
1323  }
1324  ++i;
1325  }
1326  continue;
1327  }
1328 
1329 
1330  //we save the current direction and stop if we run in opposite
1331  OrthoDir runDir = m_pOR->direction(adjCross);
1332  // if -> while
1333  while (PG.typeOf(adjTwin->theNode()) == Graph::NodeType::dummy &&
1334  adjTwin->theNode()->degree() == 2 &&
1335  m_pOR->angle(adjTwin) == angleAtMax)
1336  {
1337  node s = m_edgeToBasicArc[adjCross]->target();
1338  if(lowReal[s] != low[s])
1339  {
1340  if(low[s] >= boundary) // nothing to do?
1341  break;
1342  low[s] = boundary;
1343 #if 0
1344  low[s] += m_sep - delta; //minDist.delta(v,dirMax,i);
1345 #endif
1346 
1347  // If the compaction has eliminated bends, we can have the situation
1348  // that segment s has length 0 and the next segment s' (following the
1349  // edge) is at the same position (the edge arc has length 0).
1350  // In this case, the low-value of s' must be lowered (low[s'] := lowReal[s']
1351  // is approproate). The same situation can appear several times in a
1352  // row.
1353  //collect chains of segments compacted to zero length
1354  for( ; ; ) /*lowReal[s] == high[s]*/
1355  {
1356  do
1357  {
1358  adjCross = adjCross->faceCycleSucc();
1359  } while(m_pOR->direction(adjCross) == segDir ||
1360  m_pOR->direction(adjCross) == segOppDir);
1361 
1362  if(adjCross->theNode()->degree() != 2) // no longer a bend point?
1363  break;
1364 
1365  node sNext = m_edgeToBasicArc[adjCross]->opposite(s);
1366 
1367  if(segPos[sNext] != segPos[s])
1368  break;
1369 
1370  low[sNext] = lowReal[sNext];//was: low[s]
1371  s = sNext;
1372  }
1373  }//if lowreal != low
1374 
1375  adjTwin = adjCross->twin(); // update of twin for while
1376 
1377  //check if we have to stop
1378  if (runDir != m_pOR->direction(adjCross)) break;
1379  }//while dummy
1380  }
1381  }
1382 
1383  // compute topological numbering of segments as second sorting criteria
1384  // in order to process overlapping segments in the order imposed by the
1385  // embedding
1386  computeTopologicalSegmentNum(topNum);
1387 
1388 
1389  // sort segments
1390  SegmentComparer cmpBySegPos(segPos,topNum);
1391  List<node> sortedPathNodes;
1392  allNodes(sortedPathNodes);
1393  sortedPathNodes.quicksort(cmpBySegPos);
1394 
1395  // add segments in the order given by sortedPathNodes to sweep line
1396  List<Interval> sweepLine;
1397 
1398  ListIterator<node> itV;
1399  for(itV = sortedPathNodes.begin(); itV.valid(); ++itV)
1400  {
1401  //special case nodes
1402  if (m_path[*itV].empty()) continue;
1403  OGDF_ASSERT_IF(DebugLevel::ExtendedChecking,checkSweepLine(sweepLine));
1404 
1405  node v = *itV;
1407  for(it = sweepLine.begin(); it.valid(); ++it) {
1408  if ((*it).m_low < high[v])
1409  break;
1410  }
1411 
1412  if (!it.valid()) {
1413  sweepLine.pushBack(Interval(v,low[v],high[v]));
1414  continue;
1415  }
1416 
1417  if((*it).m_high <= low[v]) {
1418  sweepLine.insertBefore(Interval(v,low[v],high[v]),it);
1419  continue;
1420  }
1421 
1422  ListIterator<Interval> itUp = it, itSucc;
1423  // we store if itUp will be deleted in order not to
1424  // access the deleted iterator later
1425  bool isItUpDel = ( ((*itUp).m_low >= low[v]) && ((*itUp).m_high <= high[v]) );
1426 
1427  for(; it.valid() && (*it).m_low >= low[v]; it = itSucc) {
1428  itSucc = it.succ();
1429  if ((*it).m_high <= high[v]) {
1430  visibArcs.pushBack(Tuple2<node,node>((*it).m_pathNode,v));
1431  sweepLine.del(it);
1432  }
1433  }
1434 
1435  if (it == itUp && (*it).m_high > high[v]) {
1436  node w = (*it).m_pathNode;
1437  sweepLine.insertAfter(Interval(w,(*it).m_low,low[v]),it);
1438  (*it).m_low = high[v];
1439  sweepLine.insertAfter(Interval(v,low[v],high[v]),it);
1440  visibArcs.pushBack(Tuple2<node,node>(w,v));
1441 
1442  } else {
1443  if ( (!isItUpDel) && itUp != it && (*itUp).m_low < high[v]) {
1444  (*itUp).m_low = high[v];
1445  visibArcs.pushBack(Tuple2<node,node>((*itUp).m_pathNode,v));
1446  }
1447  if (it.valid()) {
1448  if ((*it).m_high > low[v]) {
1449  (*it).m_high = low[v];
1450  visibArcs.pushBack(Tuple2<node,node>((*it).m_pathNode,v));
1451  }
1452  sweepLine.insertBefore(Interval(v,low[v],high[v]),it);
1453 
1454  } else {
1455  sweepLine.pushBack(Interval(v,low[v],high[v]));
1456  }
1457  }
1458 
1459  }
1460 
1461  // remove all arcs from visibArcs that are already in the constraint graph
1462  removeRedundantVisibArcs(visibArcs);
1463 
1464  // compute original adjacency entry corresponding to a segment
1465  // We use this in order to omit visibility arcs between segments which
1466  // belong to the same edge if they can see each other from the same side
1467  // of the edge; if they see each other from different sides the arc is
1468  // essential!
1469  NodeArray<adjEntry> correspEdge(getGraph(),nullptr);
1470 
1471  for(node v : PG.nodes) {
1472  node seg = m_pathNode[v];
1473  for(adjEntry adj : v->adjEntries) {
1474  if(m_pOR->direction(adj) != segDir) continue;
1475  edge eAdj = adj->theEdge();
1476  edge eOrig = PG.original(eAdj);
1477  if (eOrig == nullptr) continue;
1478  if (adj == eAdj->adjSource())
1479  correspEdge[seg] = eOrig->adjSource();
1480  else
1481  correspEdge[seg] = eOrig->adjTarget();
1482  }
1483  }
1484 
1485  // remove visibility arcs between ...
1486  SListIterator<Tuple2<node,node> > itT, itTSucc, itTPred;
1487  for(itT = visibArcs.begin(); itT.valid(); itT = itTSucc) {
1488  itTSucc = itT.succ();
1489  node v = (*itT).x1(), w = (*itT).x2();
1490 
1491  // remove arcs which connect segments belonging to the same edge
1492  if (correspEdge[v] && (correspEdge[v] == correspEdge[w]))
1493  {
1494  if (itTPred.valid())
1495  visibArcs.delSucc(itTPred);
1496  else
1497  visibArcs.popFront();
1498  }
1499 
1500  else
1501  itTPred = itT;
1502  }
1503 
1504 
1505 
1506  for(itT = visibArcs.begin(); itT.valid(); ++itT) {
1507  //CHECK if
1508  node v = (*itT).x1(), w = (*itT).x2();
1509  if (!(m_extraNode[v] || m_extraNode[w])) {
1510  //CHECK if
1511  node boundRepresentant1 = m_path[v].front();
1512  node boundRepresentant2 = m_path[w].front();
1513  node en1 = m_pPR->expandedNode(boundRepresentant1);
1514  node en2 = m_pPR->expandedNode(boundRepresentant2);
1515  //do not insert visibility in cages
1516  if (!( ( en1 && en2 ) && ( en1 == en2) ))
1517  {
1518  edge e = newEdge(v,w);
1519 
1520  //hier vielleicht multiedges abfangen: length auf max(min(sep, dists), minDist.sep)
1521 
1522  m_length[e] = max(m_sep, minDist.separation()); //m_sep;
1523  m_cost [e] = 0;
1524  m_type [e] = ConstraintEdgeType::VisibilityArc;
1525 #if 0
1526  writeGML("visibilityinserted.gml");
1527 #endif
1528  }
1529  }
1530  }
1531 
1532  OGDF_ASSERT_IF(DebugLevel::ExtendedChecking,checkSweepLine(sweepLine));
1533 
1534 }//insertvisibilityarcs
1535 
1536 
1537 
1538 // performs feasibility test for position assignment pos, i.e., checks if
1539 // the segment positions given by pos fulfill the constraints in the
1540 // compaction constraint graph
1541 template<class ATYPE>
1543  const NodeArray<ATYPE> &pos)
1544 {
1545  for(edge e : getGraph().edges) {
1546  node v = m_path[e->source()].front();
1547  node w = m_path[e->target()].front();
1548  if (pos[w] - pos[v] < length(e)) {
1549  cout << "feasibility check failed for edge " << e << endl;
1550  cout << " representatives: " << v << ", " << w << endl;
1551  cout << " length: " << length(e) << endl;
1552  cout << " actual distance: " << pos[w] - pos[v] << endl;
1553  cout << " type of " << e << ": ";
1554  switch(m_type[e]) {
1555  case ConstraintEdgeType::BasicArc: cout << "basic arc" << endl;
1556  break;
1557  case ConstraintEdgeType::VertexSizeArc: cout << "vertex-size arc" << endl;
1558  break;
1559  case ConstraintEdgeType::VisibilityArc: cout << "visibility arc" << endl;
1560  break;
1561  case ConstraintEdgeType::MedianArc: cout << "median arc" << endl;
1562  break;
1563  case ConstraintEdgeType::ReducibleArc: cout << "reducible arc" <<endl;
1564  break;
1565  case ConstraintEdgeType::FixToZeroArc: cout << "fixtozero arc" <<endl;
1566 
1567  }
1568  return false;
1569  }
1570  }
1571 
1572  return true;
1573 }
1574 
1575 //colouring for extranode
1576 template<class ATYPE>
1577 void CompactionConstraintGraph<ATYPE>::writeGML(const char *filename) const
1578 {
1579  ofstream os(filename);
1580  writeGML(os);
1581 }
1582 
1583 template<class ATYPE>
1585 {
1586  const Graph &G = *this;
1587 
1588  NodeArray<int> id(getGraph());
1589  int nextId = 0;
1590 
1591  os.setf(ios::showpoint);
1592  os.precision(10);
1593 
1594  os << "Creator \"ogdf::CompactionConstraintGraphBase::writeGML\"\n";
1595  os << "graph [\n";
1596  os << " directed 1\n";
1597 
1598  for(node v : G.nodes) {
1599  os << " node [\n";
1600  os << " id " << (id[v] = nextId++) << "\n";
1601 
1602  if (m_extraNode[v]) {
1603  os << " label \"" << "0" << "\"\n";
1604  } else {
1605  os << " label \"" << m_pPR->expandedNode(m_path[v].front()) << "\"\n";
1606  }
1607 
1608  os << " graphics [\n";
1609  os << " x 0.0\n";
1610  os << " y 0.0\n";
1611  os << " w 30.0\n";
1612  os << " h 30.0\n";
1613  if (m_extraNode[v])
1614  os << " fill \"#00FFFF\"\n";
1615  else
1616  os << " fill \"#FFFF00\"\n";
1617  os << " ]\n"; // graphics
1618 
1619  os << " ]\n"; // node
1620  }
1621 
1622  for(edge e : G.edges) {
1623  os << " edge [\n";
1624  os << " source " << id[e->source()] << "\n";
1625  os << " target " << id[e->target()] << "\n";
1626 
1627 #if 0
1628  // show edge lengths as edge lables (not yet supported)
1629  os << " label \"";
1630  writeLength(os, e);
1631  os << "\"\n";
1632 #endif
1633 
1634  os << " graphics [\n";
1635 
1636  os << " type \"line\"\n";
1637  os << " arrow \"last\"\n";
1638  switch(m_type[e])
1639  {
1640  case ConstraintEdgeType::BasicArc: // red
1641  os << " fill \"#FF0000\"\n";
1642  break;
1643  case ConstraintEdgeType::VertexSizeArc: // blue
1644  os << " fill \"#0000FF\"\n";
1645  break;
1646  case ConstraintEdgeType::VisibilityArc: // green
1647  os << " fill \"#00FF00\"\n";
1648  break;
1650  os << " fill \"#FF0000\"\n";
1651  break;
1652  case ConstraintEdgeType::FixToZeroArc: // violett
1653  os << " fill \"#AF00FF\"\n";
1654  break;
1655  case ConstraintEdgeType::MedianArc: // rose
1656  os << " fill \"#FF00FF\"\n";
1657  break;
1658  }
1659 
1660  os << " ]\n"; // graphics
1661 
1662 #if 0
1663  os << " LabelGraphics [\n";
1664  os << " type \"text\"\n";
1665  os << " fill \"#000000\"\n";
1666  os << " anchor \"w\"\n";
1667  os << " ]\n";
1668 #endif
1669 
1670  os << " ]\n"; // edge
1671  }
1672 
1673  os << "]\n"; // graph
1674 }
1675 
1676 
1677 } // end namespace ogdf
node target() const
Returns the target node of the edge.
Definition: Graph_d.h:327
node pathNodeOf(node v) const
Returns the segment (path node in constraint graph) containing v.
const Graph & getGraph() const
Returns underlying graph.
int m_MedianArcCost
draw merger gen at median of incoming generalizations
NodeArray< edge > m_originalEdge
save edge for the basic arcs
node extraRep(node v) const
Returns extraNode existing anchor representant.
#define OGDF_ASSERT_IF(minLevel, expr)
Assert condition expr if debug level is at least minLevel.
Definition: basic.h:44
int m_doubleBendCost
try to minimize double bends
void delSucc(iterator itBefore)
Removes the succesor of itBefore.
Definition: SList.h:522
edge theEdge() const
Returns the edge associated with this adjacency entry.
Definition: Graph_d.h:95
bool valid() const
Returns true iff the iterator points to an element.
Definition: SList.h:113
void centerPriority(bool b)
Sets centerPriority (center single edges?)
bool fixOnBorder(edge e) const
Returns true if edge is subject to length fixation if length < sep.
void setBoundaryCosts(adjEntry cornerDir, adjEntry cornerOppDir)
void writeGML(const char *fileName) const
Output for debugging only.
void insertVertexSizeArcs(const PlanRep &PG, const NodeArray< ATYPE > &sizeOrig, const RoutingChannel< ATYPE > &rc)
Inserts arcs for respecting sizes of vertices and achieving desired placement of generalizations if v...
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
bool extraNode(node v) const
Returns node status.
int m_bungeeCost
middle position distance penalty
#define OGDF_AUGMENT_COMPARER(type)
Add this macro to your class to turn it into a full comparer.
Definition: comparer.h:155
Declaration of orthogonal representation of planar graphs.
adjEntry adjSource() const
Returns the corresponding adjacancy entry at source node.
Definition: Graph_d.h:330
Maintains input sizes for improvement compaction (deltas and epsilons)
ATYPE extraOfs(node v) const
Returns extraNode position, change to save mem, only need some entries.
NodeArray< node > m_pathNode
segment containing a node in PG
void embed()
Embeds constraint graph such that all sources and sinks lie in a common face.
Singly linked lists.
Definition: SList.h:38
Information about a side of a vertex in UML diagrams.
Definition: OrthoRep.h:241
#define OGDF_THROW(CLASS)
Replacement for throw.
Definition: exceptions.h:60
int degree() const
Returns the degree of the node (indegree + outdegree).
Definition: Graph_d.h:208
const ATYPE & epsilon(node v, OrthoDir s, int i) const
adjEntry faceCyclePred() const
Returns the cyclic predecessor in face.
Definition: Graph_d.h:141
iterator begin()
Returns an iterator to the first element of the list.
Definition: List.h:332
Represents a constraint graph used for compaction.
EdgeArray< bool > m_alignmentArc
Basic arcs that have to be short for alignment (node to gen expander)
iterator insertAfter(const E &x, iterator it)
Inserts element x after it.
Definition: List.h:1341
Orthogonal representation of an embedded graph.
Definition: OrthoRep.h:237
ConstraintEdgeType
Types of edges in the constraint graph.
Declaration of a base class for planar representations of graphs and cluster graphs.
Further information about the cages of vertices in UML diagrams.
Definition: OrthoRep.h:279
Encapsulates a pointer to an ogdf::SList element.
Definition: SList.h:40
const OrthoRep & getOrthoRep() const
Returns underlying OrthoRep.
NodeArray< bool > m_extraNode
Node does not represent drawing node as we dont have positions we save a drawing representant and an ...
Dynamic arrays indexed with edges.
Definition: EdgeArray.h:112
SListIteratorBase< E, isConst > succ() const
Returns successor iterator.
Definition: SList.h:135
adjEntry cyclicSucc() const
Returns the cyclic successor in the adjacency list.
Definition: Graph_d.h:278
Graph::NodeType typeOf(node v) const
Returns the type of node v.
Definition: PlanRep.h:209
Singly linked lists (maintaining the length of the list).
Definition: SList.h:777
ListIteratorBase< E, isConst > succ() const
Returns successor iterator.
Definition: List.h:133
Declaration of class RoutingChannel which maintains required size of routing channels and separation...
void del(iterator it)
Removes it from the list.
Definition: List.h:1380
adjEntry faceCycleSucc() const
Returns the cyclic successor in face.
Definition: Graph_d.h:139
const SListPure< node > & nodesIn(node v) const
Returns list of nodes contained in segment v.
bool m_centerPriority
should centering be more expensive than generalizations
EdgeArray< edge > m_edgeToBasicArc
basic arc representing an edge in PG
NodeArray< edge > m_pathToEdge
save the (single!) edge (segment) for a pathNode
Represents an interval on the sweep line.
internal::GraphObjectContainer< EdgeElement > edges
The container containing all edge objects.
Definition: Graph_d.h:548
adjEntry expandAdj(node v) const
Returns the adjacency entry of a node of an expanded face.
Definition: PlanRep.h:160
ATYPE separation() const
Returns the separation value.
iterator begin()
Returns an iterator to the first element of the list.
Definition: SList.h:316
void quicksort()
Sorts the list using Quicksort.
Definition: List.h:1097
bool checkSweepLine(const List< Interval > &sweepLine)
bool m_genToMedian
draw outgoing generalization from merger above ingoing gen.
iterator pushBack(const E &x)
Adds element x at the end of the list.
Definition: SList.h:455
void embed()
Embeds constraint graph such that all sources and sinks lie in a common face.
Tuples of two elements (2-tuples).
Definition: tuples.h:46
CompactionConstraintGraph(const OrthoRep &OR, const PlanRep &PG, OrthoDir arcDir, ATYPE sep, int costGen=1, int costAssoc=1, bool align=false)
Construction.
Doubly linked lists (maintaining the length of the list).
Definition: List.h:39
bool verticalArc(edge e) const
Returns true if e is basic arc of vertical edge in PlanRepUML hierarchy.
Exception thrown when an algorithm realizes an internal bug that prevents it from continuing...
Definition: exceptions.h:308
void setBasicArcsZeroLength(const PlanRep &PG)
static const int c_doubleBendFactor
double bends cost factor*vertexArcCost
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
EdgeArray< int > m_border
only used for cage precompaction in flowcompaction computecoords
void popFront()
Removes the first element from the list.
Definition: SList.h:501
void resetGenMergerLengths(const PlanRep &PG, adjEntry adjFirst)
Maintains input sizes for constructive compaction (size of routing channels, separation, cOverhang)
Class for the representation of nodes.
Definition: Graph_d.h:167
NodeArray< SListPure< node > > m_path
list of nodes contained in a segment
Encapsulates a pointer to a list element.
Definition: List.h:41
NodeArray< node > m_extraRep
existing representant of extranodes position anchor
bool onBorder(edge e) const
Returns true if edge lies on cage border.
SegmentComparer(const NodeArray< ATYPE > &segPos, const NodeArray< int > &secSort)
ATYPE length(edge e) const
Returns length of edge e.
OrthoDir
Definition: OrthoRep.h:52
const Graph & original() const
Returns a reference to the original graph.
Definition: GraphCopy.h:287
adjEntry cyclicPred() const
Returns the cyclic predecessor in the adjacency list.
Definition: Graph_d.h:283
EdgeArray< ATYPE > m_length
length of an edge
ATYPE overhang() const
inserted to replace some reducible in fixzerolength
friend ostream & operator<<(ostream &os, const Interval &interval)
output operator
Comparer class used for sorting segments by increasing position (given by segPos) such that two overl...
static OrthoDir prevDir(OrthoDir d)
Returns the previous OrthoDir (in a clockwise manner)
Definition: OrthoRep.h:445
ATYPE computeTotalCosts(const NodeArray< ATYPE > &pos) const
Computes the total costs for coordintes given by pos, i.e., the sum of the weighted lengths of edges ...
static OrthoDir nextDir(OrthoDir d)
Returns the next OrthoDir (in a clockwise manner)
Definition: OrthoRep.h:440
bool isFeasible(const NodeArray< ATYPE > &pos)
Performs feasibility test for position assignment pos, i.e., checks if the segment positions given by...
void setExtra(node v, node rep, ATYPE ofs)
Node v has no representation in drawing, only internal representation.
static const int c_MedianFactor
median arcs cost factor*vertexArcCost
Declaration of class MinimumEdgeDistances which maintains minimum distances between attached edges at...
bool alignmentArc(edge e) const
Returns if arc is important for alignment. These are the arcs representing node to gen...
const ATYPE & delta(node v, OrthoDir s, int i) const
edge basicArc(edge e) const
Returns constraint arc representing input edge e in constraint graph.
NodeArray< ATYPE > m_extraOfs
offset of extra node to its rep, should change this
int compare(const node &x, const node &y) const
can be compacted to zero length
EdgeArray< int > m_cost
cost of an edge
can be compacted to zero length, can be fixed
void align(bool b)
Triggers alignment (=>some special edge handling to support al.)
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
Base class implementing common behaviour of ogdf::CompactionConstraintGraph.
The namespace for all OGDF objects.
EdgeArray< bool > m_verticalGen
generalization that runs vertical relative to hierarchy
EdgeArray< ConstraintEdgeType > m_type
bool centerPriority()
Gets centerPriority (center single edges?)
virtual void writeLength(ostream &os, edge e) const override
NodeType
The type of nodes.
Definition: Graph_d.h:525
EdgeArray< bool > m_verticalArc
arc corresponding to such an edge
internal::GraphObjectContainer< NodeElement > nodes
The container containing all node objects.
Definition: Graph_d.h:545
int cost(edge e) const
Returns cost of edge e.
void insertVisibilityArcs(const PlanRep &PG, const NodeArray< ATYPE > &posDir, const NodeArray< ATYPE > &posOppDir)
Inserts arcs connecting segments which can see each other in a drawing of the associated planarized r...
adjEntry adjTarget() const
Returns the corresponding adjacancy entry at target node.
Definition: Graph_d.h:332
bool empty() const
Returns true iff the list is empty.
Definition: List.h:236
bool valid() const
Returns true iff the iterator points to an element.
Definition: List.h:112
ConstraintEdgeType typeOf(edge e) const
Returns type of edge e.
node theNode() const
Returns the node whose adjacency list contains this element.
Definition: Graph_d.h:99
bool verticalGen(edge e) const
Returns true if e is vertical edge in PlanRepUML hierarchy.
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
Planarized representations (of a connected component) of a graph.
Definition: PlanRep.h:60
internal::GraphObjectContainer< AdjElement > adjEntries
The container containing all entries in the adjacency list of this node.
Definition: Graph_d.h:198