Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

precondition.h
Go to the documentation of this file.
1 
36 #pragma once
37 
38 #include <ogdf/basic/Graph.h>
39 #include <ogdf/basic/GraphList.h>
40 #include <ogdf/basic/List.h>
41 #include <ogdf/basic/basic.h>
43 #include <ogdf/uml/UMLGraph.h>
44 
45 namespace ogdf {
46 
47 //descent the hierarchy tree at "sink" v recursively
49  NodeArray<int>& hierNumber, //number of hierarchy tree
50  // A node is visited if its hierNumber != 0
51  int hierNum, node v,
52  List<edge>& fakedGens, //temporary
53  bool fakeTree) {
54  OGDF_ASSERT(hierNumber[v] == 0);
55  hierNumber[v] = hierNum;
56 
57  bool returnValue = true;
58 
59  for (adjEntry adj : v->adjEntries) {
60  edge e = adj->theEdge();
61  if (e->source() == v) {
62  continue;
63  }
64  if (!(UG.type(e) == Graph::EdgeType::generalization)) {
65  continue;
66  }
67  if (used[e]) {
68  continue; //error ??
69  }
70  used[e] = true;
71 
72  node w = e->opposite(v);
73 
74  if (hierNumber[w]) {
75  //temporarily fake trees
76  // if (hierNumber[w] == hierNum) //forward search edge
77  if (fakeTree) {
78 #if 0
79  UG.type(e) = Graph::association;
80 #endif
81  fakedGens.pushBack(e);
82  continue;
83  } else {
84  return false; //reached w over unused edge => no tree
85  }
86  }
87 
88  returnValue = dfsGenTreeRec(UG, used, hierNumber, hierNum, w, fakedGens, fakeTree);
89  //shortcut
90  if (!returnValue) {
91  return false;
92  }
93  }
94 
95  return returnValue;
96 }
97 
99  for (adjEntry adj : v->adjEntries) {
100  edge e = adj->theEdge();
101  if (e->target() == v) {
102  continue;
103  }
104  if (UG.type(e) == Graph::EdgeType::generalization) {
105 #if 0
106  OGDF_ASSERT(!used[e]);
107 #endif
108  return e;
109  } else {
110  continue;
111  }
112  }
113  return nullptr;
114 }
115 
116 bool dfsGenTree(UMLGraph& UG, List<edge>& fakedGens, bool fakeTree) {
117  EdgeArray<bool> used(UG.constGraph(), false);
118 #if 0
119  NodeArray<bool> visited(UG,false);
120 #endif
121  NodeArray<int> hierNumber(UG.constGraph(), 0);
122 
123  int hierNum = 0; //number of hierarchy tree
124 
125  const Graph& G = UG.constGraph();
126  for (edge e : G.edges) {
127  //descent in the hierarchy containing e
128  if (!used[e] && UG.type(e) == Graph::EdgeType::generalization) {
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  sink = sinkPath->target();
136  sinkPath = firstOutGen(UG, sinkPath->target(), used);
137  cycleCounter++;
138  //if there is no sink, convert Generalizations to Associations and draw
139  if (cycleCounter > G.numberOfEdges()) {
140  UG.type(sinkPath) = Graph::EdgeType::association;
141  fakedGens.pushBack(sinkPath);
142  sink = sinkPath->source();
143  sinkPath = nullptr;
144  }
145  }
146 
147  //now sink is the hierarchy sink
148 
149  //used is set in dfsGenTreeRec
150  bool isTree = dfsGenTreeRec(UG, used, hierNumber, hierNum, sink, fakedGens, fakeTree);
151  if (!isTree) {
152  return false;
153  }
154  }
155  }
156 
157  return true;
158 }
159 
160 }
ogdf
The namespace for all OGDF objects.
Definition: multilevelmixer.cpp:39
Graph.h
Includes declaration of graph class.
OGDF_ASSERT
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition: basic.h:66
UMLGraph.h
Declaration of class UMLGraph.
ogdf::GraphAttributes::constGraph
const Graph & constGraph() const
Returns a reference to the associated graph.
Definition: GraphAttributes.h:223
ogdf::AdjElement
Class for adjacency list elements.
Definition: Graph_d.h:142
ogdf::GraphAttributes::type
Graph::NodeType type(node v) const
Returns the type of node v.
Definition: GraphAttributes.h:609
ogdf::AdjElement::theEdge
edge theEdge() const
Returns the edge associated with this adjacency entry.
Definition: Graph_d.h:160
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:48
GraphList.h
Decralation of GraphElement and GraphList classes.
ogdf::NodeElement::adjEntries
internal::GraphObjectContainer< AdjElement > adjEntries
The container containing all entries in the adjacency list of this node.
Definition: Graph_d.h:271
ogdf::Graph::EdgeType::generalization
@ generalization
ogdf::EdgeElement::source
node source() const
Returns the source node of the edge.
Definition: Graph_d.h:398
ogdf::dfsGenTree
bool dfsGenTree(UMLGraph &UG, List< edge > &fakedGens, bool fakeTree)
Definition: precondition.h:116
ogdf::List< edge >
ogdf::internal::GraphRegisteredArray
RegisteredArray for nodes, edges and adjEntries of a graph.
Definition: Graph_d.h:658
ogdf::Graph
Data type for general directed graphs (adjacency list representation).
Definition: Graph_d.h:869
graph_iterators.h
Decralation of graph iterators.
ogdf::UMLGraph
Definition: UMLGraph.h:48
basic.h
Basic declarations, included by all source files.
ogdf::firstOutGen
edge firstOutGen(UMLGraph &UG, node v, EdgeArray< bool > &)
Definition: precondition.h:98
ogdf::EdgeElement
Class for the representation of edges.
Definition: Graph_d.h:363
List.h
Declaration of doubly linked lists and iterators.
ogdf::EdgeElement::target
node target() const
Returns the target node of the edge.
Definition: Graph_d.h:401
ogdf::NodeElement
Class for the representation of nodes.
Definition: Graph_d.h:240
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:922
ogdf::List::pushBack
iterator pushBack(const E &x)
Adds element x at the end of the list.
Definition: List.h:1547
ogdf::internal::EdgeArrayBase2
RegisteredArray for edges of a graph, specialized for EdgeArray<edge>.
Definition: Graph_d.h:716