Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Loading...
Searching...
No Matches
precondition.h
Go to the documentation of this file.
1
36#pragma once
37
38#include <ogdf/basic/Graph.h>
40#include <ogdf/basic/List.h>
41#include <ogdf/basic/basic.h>
43#include <ogdf/uml/UMLGraph.h>
44
45namespace 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
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 }
105#if 0
106 OGDF_ASSERT(!used[e]);
107#endif
108 return e;
109 } else {
110 continue;
111 }
112 }
113 return nullptr;
114}
115
116bool 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}
Includes declaration of graph class.
Decralation of GraphElement and GraphList classes.
Declaration of doubly linked lists and iterators.
Declaration of class UMLGraph.
Basic declarations, included by all source files.
Class for adjacency list elements.
Definition Graph_d.h:143
Class for the representation of edges.
Definition Graph_d.h:364
node opposite(node v) const
Returns the adjacent node different from v.
Definition Graph_d.h:414
node target() const
Returns the target node of the edge.
Definition Graph_d.h:402
node source() const
Returns the source node of the edge.
Definition Graph_d.h:399
const Graph & constGraph() const
Returns a reference to the associated graph.
Graph::NodeType type(node v) const
Returns the type of node v.
Data type for general directed graphs (adjacency list representation).
Definition Graph_d.h:866
Doubly linked lists (maintaining the length of the list).
Definition List.h:1451
iterator pushBack(const E &x)
Adds element x at the end of the list.
Definition List.h:1547
Class for the representation of nodes.
Definition Graph_d.h:241
internal::GraphObjectContainer< AdjElement > adjEntries
The container containing all entries in the adjacency list of this node.
Definition Graph_d.h:272
RegisteredArray for edges of a graph, specialized for EdgeArray<edge>.
Definition Graph_d.h:717
RegisteredArray for nodes, edges and adjEntries of a graph.
Definition Graph_d.h:659
Decralation of graph iterators.
bool isTree(const Graph &G)
Returns true iff G is a tree, i.e. contains no undirected cycle and is connected.
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition basic.h:52
The namespace for all OGDF objects.
bool dfsGenTree(UMLGraph &UG, List< edge > &fakedGens, bool fakeTree)
bool dfsGenTreeRec(UMLGraph &UG, EdgeArray< bool > &used, NodeArray< int > &hierNumber, int hierNum, node v, List< edge > &fakedGens, bool fakeTree)
edge firstOutGen(UMLGraph &UG, node v, EdgeArray< bool > &)