Open
Graph Drawing
Framework

 v. 2020.02 (Catalpa)
 

precondition.h
Go to the documentation of this file.
1 
36 #pragma once
37 
39 #include <ogdf/uml/UMLGraph.h>
40 
41 
42 namespace ogdf {
43 
44 //descent the hierarchy tree at "sink" v recursively
46  UMLGraph& UG,
47  EdgeArray<bool> &used,
48  NodeArray<int> &hierNumber, //number of hierarchy tree
49  // A node is visited if its hierNumber != 0
50  int hierNum,
51  node v,
52  List<edge>& fakedGens, //temporary
53  bool fakeTree)
54 {
55  OGDF_ASSERT(hierNumber[v] == 0);
56  hierNumber[v] = hierNum;
57 
58  bool returnValue = true;
59 
60  for(adjEntry adj : v->adjEntries) {
61  edge e = adj->theEdge();
62  if (e->source() == v) continue;
63  if (!(UG.type(e) == Graph::EdgeType::generalization)) continue;
64  if (used[e]) continue; //error ??
65  used[e] = true;
66 
67  node w = e->opposite(v);
68 
69  if (hierNumber[w]) {
70  //temporarily fake trees
71 #if 0
72  if (hierNumber[w] == hierNum) //forward search edge
73 #endif
74  if (fakeTree)
75  {
76 #if 0
77  UG.type(e) = Graph::association;
78 #endif
79  fakedGens.pushBack(e);
80  continue;
81  }
82  else return false;//reached w over unused edge => no tree
83  }
84 
85  returnValue = dfsGenTreeRec(UG, used, hierNumber, hierNum, w, fakedGens, fakeTree);
86  //shortcut
87  if (!returnValue) return false;
88  }
89 
90  return returnValue;
91 }
92 
94 {
95  for(adjEntry adj : v->adjEntries) {
96  edge e = adj->theEdge();
97  if (e->target() == v) continue;
99  {
100 #if 0
101  OGDF_ASSERT(!used[e]);
102 #endif
103  return e;
104  }
105  else continue;
106  }
107  return nullptr;
108 }
109 
111  UMLGraph& UG,
112  List<edge>& fakedGens,
113  bool fakeTree)
114 {
115  EdgeArray<bool> used(UG.constGraph(), false);
116 #if 0
117  NodeArray<bool> visited(UG,false);
118 #endif
119  NodeArray<int> hierNumber(UG.constGraph(), 0);
120 
121  int hierNum = 0; //number of hierarchy tree
122 
123  const Graph& G = UG.constGraph();
124  for(edge e : G.edges)
125  {
126  //descent in the hierarchy containing e
127  if (!used[e] && UG.type(e) == Graph::EdgeType::generalization)
128  {
129  hierNum++; //current hierarchy tree
130  //first we search for the sink
131  node sink = e->target();
132  edge sinkPath = firstOutGen(UG, e->target(), used);
133  int cycleCounter = 0;
134  while (sinkPath)
135  {
136  sink = sinkPath->target();
137  sinkPath = firstOutGen(UG, sinkPath->target(), used);
138  cycleCounter++;
139  //if there is no sink, convert Generalizations to Associations and draw
140  if (cycleCounter > G.numberOfEdges())
141  {
142  UG.type(sinkPath) = Graph::EdgeType::association;
143  fakedGens.pushBack(sinkPath);
144  sink = sinkPath->source();
145  sinkPath = nullptr;
146  }
147  }
148 
149  //now sink is the hierarchy sink
150 
151  //used is set in dfsGenTreeRec
152  bool isTree = dfsGenTreeRec(UG, used, hierNumber, hierNum, sink, fakedGens, fakeTree);
153  if (!isTree) return false;
154  }
155 
156  }
157 
158  return true;
159 }
160 
161 }
node target() const
Returns the target node of the edge.
Definition: Graph_d.h:328
edge theEdge() const
Returns the edge associated with this adjacency entry.
Definition: Graph_d.h:96
iterator pushBack(const E &x)
Adds element x at the end of the list.
Definition: List.h:1373
Data type for general directed graphs (adjacency list representation).
Definition: Graph_d.h:492
bool dfsGenTree(UMLGraph &UG, List< edge > &fakedGens, bool fakeTree)
Definition: precondition.h:110
Declaration of class UMLGraph.
internal::GraphObjectContainer< EdgeElement > edges
The container containing all edge objects.
Definition: Graph_d.h:568
int numberOfEdges() const
Returns the number of edges in the graph.
Definition: Graph_d.h:601
Declaration of EdgeRouter...
edge firstOutGen(UMLGraph &UG, node v, EdgeArray< bool > &)
Definition: precondition.h:93
bool dfsGenTreeRec(UMLGraph &UG, EdgeArray< bool > &used, NodeArray< int > &hierNumber, int hierNum, node v, List< edge > &fakedGens, bool fakeTree)
Definition: precondition.h:45
Class for the representation of edges.
Definition: Graph_d.h:292
Class for the representation of nodes.
Definition: Graph_d.h:169
const Graph & constGraph() const
Returns a reference to the associated graph.
Graph::NodeType type(node v) const
Returns the type of node v.
bool isTree(const Graph &G)
Returns true iff G is a tree, i.e. contains no undirected cycle and is connected. ...
node source() const
Returns the source node of the edge.
Definition: Graph_d.h:326
The namespace for all OGDF objects.
Class for adjacency list elements.
Definition: Graph_d.h:79
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition: basic.h:41
internal::GraphObjectContainer< AdjElement > adjEntries
The container containing all entries in the adjacency list of this node.
Definition: Graph_d.h:200