Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

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