Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Loading...
Searching...
No Matches
EmbedderMaxFace.h
Go to the documentation of this file.
1
32#pragma once
33
35#include <ogdf/basic/Graph.h>
37#include <ogdf/basic/List.h>
38#include <ogdf/basic/Observer.h>
39#include <ogdf/basic/basic.h>
43
44#include <functional>
45
46namespace ogdf {
47class StaticSPQRTree;
48
50
57public:
63 virtual void doCall(Graph& G, adjEntry& adjExternal) override;
64
65 EmbedderMaxFace() = default;
66
67 /* needs to be deleted explicitly for MSVC<=16 and classes containing a NodeArrayP */
69
70protected:
72 void forEachIngoingNeighbor(node v, std::function<void(node)> fun) {
73 for (adjEntry adj : v->adjEntries) {
74 if (adj->theEdge()->target() == v) {
75 fun(adj->twinNode());
76 }
77 }
78 }
79
80 void computeNodeLength(node bT, std::function<int&(node)> setter) {
81 forEachIngoingNeighbor(bT, [&](node vT) {
82 node vH = pBCTree->cutVertex(vT, bT);
83 int length_v_in_block = 0;
84
85 // set length of vertex v in block graph of bT:
86 forEachIngoingNeighbor(vT, [&](node bT2) {
87 node cutVertex = pBCTree->cutVertex(vT, bT2);
88 length_v_in_block += constraintMaxFace(bT2, cutVertex);
89 });
90
91 setter(vH) = length_v_in_block;
92 });
93 }
94
95 void internalMaximumFaceRec(const node& bT, node& bT_opt, int& ell_opt, Graph& blockGraph,
96 NodeArray<int>& paramNodeLength, StaticSPQRTree* spqrTree,
97 std::function<node&(node)> getBENode, std::function<int&(node, node)> getCstrLength,
98 std::function<int&(node, node)> getNodeLength, int* const maxFaceSizeToUpdate = nullptr) {
99 node tmp_bT_opt = bT;
100 NodeArray<EdgeArray<int>> edgeLengthSkel;
101 EdgeArray<int> edgeLengthForEllOpt(blockGraph, 1);
102
103 int tmp_ell_opt = EmbedderMaxFaceBiconnectedGraphs<int>::computeSize(blockGraph,
104 paramNodeLength, edgeLengthForEllOpt, spqrTree, edgeLengthSkel);
105
106 if (maxFaceSizeToUpdate != nullptr) {
107 *maxFaceSizeToUpdate = tmp_ell_opt;
108 }
109
110 forEachIngoingNeighbor(bT, [&](node cT) {
111 node cH = pBCTree->cutVertex(cT, bT);
112
113 EdgeArray<int> uniformLengths;
114
115 if (maxFaceSizeToUpdate == nullptr) {
116 uniformLengths.init(blockGraph, 1);
117 }
118
119 getCstrLength(bT, cH) = EmbedderMaxFaceBiconnectedGraphs<int>::computeSize(blockGraph,
120 getBENode(cH), paramNodeLength,
121 maxFaceSizeToUpdate == nullptr ? uniformLengths : edgeLengthForEllOpt, spqrTree,
122 edgeLengthSkel);
123
124 int L = 0;
125
126 // L := \sum_{(B', c) \in bcTree} cstrLength(B', c)
127 forEachIngoingNeighbor(cT, [&](node bT2) {
128 // get partner vertex of c in the block graph of B'=e->target() and add cstrLength(B', c) to L:
129 L += getCstrLength(bT2, pBCTree->cutVertex(cT, bT2));
130 });
131
132 forEachIngoingNeighbor(cT, [&](node pT) {
133 if (pT != bT) {
134 // get partner vertex of c in the block graph of B'=e->source():
135 node partnerV = pBCTree->cutVertex(cT, pT);
136 getNodeLength(pT, partnerV) = L - getCstrLength(pT, partnerV);
137
138 // pBCTree->originalGraph().chooseNode() just to get rid of warning:
139 node thisbT_opt = pBCTree->originalGraph().chooseNode();
140 int thisell_opt = 0;
141 maximumFaceRec(pT, thisbT_opt, thisell_opt);
142
143 if (thisell_opt > tmp_ell_opt) {
144 tmp_bT_opt = thisbT_opt;
145 tmp_ell_opt = thisell_opt;
146 }
147 }
148 });
149 });
150
151 // return (B*, \ell*):
152 bT_opt = tmp_bT_opt;
153 ell_opt = tmp_ell_opt;
154 }
155
156 template<typename T>
157 void internalEmbedBlock(const node bT, const node cT, ListIterator<adjEntry>& after,
158 Graph& blockGraph, NodeArray<T>& paramNodeLength, EdgeArray<T>& paramEdgeLength,
159 NodeArray<node>& mapNodeToH, EdgeArray<edge>& mapEdgeToH, const node nodeInBlock) {
160 // 1. Compute embedding of block
161 adjEntry m_adjExternal = nullptr;
162 EmbedderMaxFaceBiconnectedGraphs<T>::embed(blockGraph, m_adjExternal, paramNodeLength,
163 paramEdgeLength, nodeInBlock);
164
165 // 2. Copy block embedding into graph embedding and call recursively
166 // embedBlock for all cut vertices in bT
167 CombinatorialEmbedding CE(blockGraph);
168 face f = CE.leftFace(m_adjExternal);
169
170 if (*pAdjExternal == nullptr) {
171 node on = pBCTree->original(mapNodeToH[m_adjExternal->theNode()]);
172
173 for (adjEntry ae : on->adjEntries) {
174 if (ae->theEdge() == pBCTree->original(mapEdgeToH[m_adjExternal->theEdge()])) {
175 *pAdjExternal = ae->twin();
176 break;
177 }
178 }
179 }
180
181 for (node nSG : blockGraph.nodes) {
182 node nH = mapNodeToH[nSG];
183 node nG = pBCTree->original(nH);
184 adjEntry ae = nSG->firstAdj();
185 ListIterator<adjEntry>* pAfter =
186 pBCTree->bcproper(nG) == cT ? &after : new ListIterator<adjEntry>;
187
188 if (pBCTree->typeOfGNode(nG) == BCTree::GNodeType::CutVertex) {
189 node cT2 = pBCTree->bcproper(nG);
190 OGDF_ASSERT(cT2 != nullptr);
191 bool doRecurse = true;
192
193 if (cT2 == cT) {
194 node parent_bT_of_cT2 = nullptr;
195
196 for (adjEntry adj : cT2->adjEntries) {
197 if (adj->theEdge()->source() == cT2) {
198 parent_bT_of_cT2 = adj->twinNode();
199 break;
200 }
201 }
202
203 OGDF_ASSERT(parent_bT_of_cT2 != nullptr);
204
205 if (treeNodeTreated[parent_bT_of_cT2]) {
206 doRecurse = false;
207 }
208 }
209
210 // (if exists) find adjacency entry of nSG which lies on external face f:
211 for (adjEntry aeFace : f->entries) {
212 if (aeFace->theNode() == nSG) {
213 ae = aeFace->succ() == nullptr ? nSG->firstAdj() : aeFace->succ();
214 break;
215 }
216 }
217
218 if (doRecurse) {
219 for (adjEntry adj : cT2->adjEntries) {
220 node bT2 = adj->theEdge()->opposite(cT2);
221
222 if (!treeNodeTreated[bT2]) {
223 embedBlock(bT2, cT2, *pAfter);
224 }
225 }
226 }
227 }
228
229 // embed all edges of block bT:
230 bool after_ae = true;
231 for (adjEntry aeNode = ae; after_ae || aeNode != ae;
232 aeNode = aeNode->succ() == nullptr ? nSG->firstAdj() : aeNode->succ()) {
233 edge e = pBCTree->original(mapEdgeToH[aeNode->theEdge()]);
234 if (nG == e->source()) {
235 if (pAfter->valid()) {
236 *pAfter = newOrder[nG].insertAfter(e->adjSource(), *pAfter);
237 } else {
238 *pAfter = newOrder[nG].pushBack(e->adjSource());
239 }
240 } else {
241 if (pAfter->valid()) {
242 *pAfter = newOrder[nG].insertAfter(e->adjTarget(), *pAfter);
243 } else {
244 *pAfter = newOrder[nG].pushBack(e->adjTarget());
245 }
246 }
247
248 after_ae &= aeNode->succ() != nullptr;
249 }
250
251 if (*pAfter != after) {
252 delete pAfter;
253 }
254 }
255 }
256
263 void computeBlockGraphs(const node& bT, const node& cH);
264
272 virtual int constraintMaxFace(const node& bT, const node& cH);
273
282 virtual void maximumFaceRec(const node& bT, node& bT_opt, int& ell_opt);
283
290 void embedBlock(const node& bT);
291
302 virtual void embedBlock(const node& bT, const node& cT, ListIterator<adjEntry>& after);
303
306
309
312
315
318
321
324
327
331
334};
335
336}
Declaration of class BCTree.
Declaration of CombinatorialEmbedding and face.
Definition of ogdf::EmbedderBCTreeBase.
Declares ogdf::EmbedderMaxFaceBiconnectedGraphs.
Includes declaration of graph class.
Decralation of GraphElement and GraphList classes.
Declaration of doubly linked lists and iterators.
Simple, safe base classes for C++ observables and observers.
Basic declarations, included by all source files.
Class for adjacency list elements.
Definition Graph_d.h:143
adjEntry succ() const
Returns the successor in the adjacency list.
Definition Graph_d.h:219
edge theEdge() const
Returns the edge associated with this adjacency entry.
Definition Graph_d.h:161
node theNode() const
Returns the node whose adjacency list contains this element.
Definition Graph_d.h:167
Combinatorial embeddings of planar graphs with modification functionality.
face leftFace(adjEntry adj) const
Returns the face to the left of adj, i.e., the face containing the twin of adj.
Class for the representation of edges.
Definition Graph_d.h:364
adjEntry adjSource() const
Returns the corresponding adjacancy entry at source node.
Definition Graph_d.h:408
adjEntry adjTarget() const
Returns the corresponding adjacancy entry at target node.
Definition Graph_d.h:411
node source() const
Returns the source node of the edge.
Definition Graph_d.h:399
Embedder that maximizing the external face.
Embedder that maximizes the external face.
void embedBlock(const node &bT)
Computes the adjacency list for all nodes in a block and calls recursively the function for all block...
void computeBlockGraphs(const node &bT, const node &cH)
Computes recursively the block graph for every block.
NodeArray< NodeArray< int > > nodeLength
saving for each node in the block graphs its length
NodeArray< NodeArray< int > > cstrLength
is saving for each node in the block graphs its cstrLength
void forEachIngoingNeighbor(node v, std::function< void(node)> fun)
Calls fun for every ingoing edge (w,v).
virtual void maximumFaceRec(const node &bT, node &bT_opt, int &ell_opt)
Top down traversal of BC-tree.
NodeArray< NodeArray< node > > nBlockEmbedding_to_nH
a mapping of nodes in blockG to the auxiliaryGraph of the BC-tree
NodeArray< EdgeArray< edge > > eBlockEmbedding_to_eH
a mapping of edges in blockG to the auxiliaryGraph of the BC-tree
NodeArray< bool > treeNodeTreated
treeNodeTreated saves for all block nodes in the BC-tree if it has already been treated or not.
void internalEmbedBlock(const node bT, const node cT, ListIterator< adjEntry > &after, Graph &blockGraph, NodeArray< T > &paramNodeLength, EdgeArray< T > &paramEdgeLength, NodeArray< node > &mapNodeToH, EdgeArray< edge > &mapEdgeToH, const node nodeInBlock)
NodeArray< EdgeArray< edge > > eH_to_eBlockEmbedding
a mapping of edges in the auxiliaryGraph of the BC-tree to blockG
NodeArray< NodeArray< node > > nH_to_nBlockEmbedding
a mapping of nodes in the auxiliaryGraph of the BC-tree to blockG
NodeArrayP< Graph > blockG
all blocks
void computeNodeLength(node bT, std::function< int &(node)> setter)
virtual int constraintMaxFace(const node &bT, const node &cH)
Bottom up traversal of BC-tree.
NodeArray< List< adjEntry > > newOrder
saves for every node of PG the new adjacency list
virtual void doCall(Graph &G, adjEntry &adjExternal) override
Computes an embedding of G with maximum external face.
virtual void embedBlock(const node &bT, const node &cT, ListIterator< adjEntry > &after)
Computes the adjacency list for all nodes in a block and calls recursively the function for all block...
void internalMaximumFaceRec(const node &bT, node &bT_opt, int &ell_opt, Graph &blockGraph, NodeArray< int > &paramNodeLength, StaticSPQRTree *spqrTree, std::function< node &(node)> getBENode, std::function< int &(node, node)> getCstrLength, std::function< int &(node, node)> getNodeLength, int *const maxFaceSizeToUpdate=nullptr)
NodeArray< StaticSPQRTree * > spqrTrees
The SPQR-trees of the blocks.
Faces in a combinatorial embedding.
internal::FaceAdjContainer entries
Container maintaining the adjacency entries in the face.
Data type for general directed graphs (adjacency list representation).
Definition Graph_d.h:866
internal::GraphObjectContainer< NodeElement > nodes
The container containing all node objects.
Definition Graph_d.h:929
Encapsulates a pointer to a list element.
Definition List.h:113
bool valid() const
Returns true iff the iterator points to an element.
Definition List.h:153
ListIteratorBase< E, isConst, isReverse > succ() const
Returns successor iterator.
Definition List.h:174
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
void init(const Base *base=nullptr)
Reinitializes the array. Associates the array with the matching registry of base.
Linear-time implementation of static SPQR-trees.
Common base for embedder algorithms based on BC trees.
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
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF dynamic library (shared object / DLL),...
Definition config.h:117
#define OGDF_NO_COPY(cls)
Explicitly disables (deletes) copy construction and assignment for class cls.
Definition copy_move.h:37
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition basic.h:52
The namespace for all OGDF objects.