Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

EmbedderMaxFace.h
Go to the documentation of this file.
1 
32 #pragma once
33 
35 #include <ogdf/basic/Graph.h>
36 #include <ogdf/basic/GraphList.h>
37 #include <ogdf/basic/List.h>
38 #include <ogdf/basic/Observer.h>
39 #include <ogdf/basic/basic.h>
43 
44 #include <functional>
45 
46 namespace ogdf {
47 class StaticSPQRTree;
48 
50 
57 public:
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 
70 protected:
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 }
ogdf
The namespace for all OGDF objects.
Definition: multilevelmixer.cpp:39
ogdf::EmbedderMaxFace::treeNodeTreated
NodeArray< bool > treeNodeTreated
treeNodeTreated saves for all block nodes in the BC-tree if it has already been treated or not.
Definition: EmbedderMaxFace.h:330
Graph.h
Includes declaration of graph class.
ogdf::StaticSPQRTree
Linear-time implementation of static SPQR-trees.
Definition: StaticSPQRTree.h:79
OGDF_ASSERT
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition: basic.h:66
ogdf::AdjElement::theNode
node theNode() const
Returns the node whose adjacency list contains this element.
Definition: Graph_d.h:166
ogdf::EmbedderMaxFace
Embedder that maximizes the external face.
Definition: EmbedderMaxFace.h:56
ogdf::ConstCombinatorialEmbedding::leftFace
face leftFace(adjEntry adj) const
Returns the face to the left of adj, i.e., the face containing the twin of adj.
Definition: CombinatorialEmbedding.h:285
ogdf::EmbedderMaxFace::nH_to_nBlockEmbedding
NodeArray< NodeArray< node > > nH_to_nBlockEmbedding
a mapping of nodes in the auxiliaryGraph of the BC-tree to blockG
Definition: EmbedderMaxFace.h:308
ogdf::EmbedderMaxFace::nBlockEmbedding_to_nH
NodeArray< NodeArray< node > > nBlockEmbedding_to_nH
a mapping of nodes in blockG to the auxiliaryGraph of the BC-tree
Definition: EmbedderMaxFace.h:314
Observer.h
Simple, safe base classes for C++ observables and observers.
ogdf::FaceElement::entries
internal::FaceAdjContainer entries
Container maintaining the adjacency entries in the face.
Definition: CombinatorialEmbedding.h:142
ogdf::embedder::EmbedderBCTreeBase
Common base for embedder algorithms based on BC trees.
Definition: EmbedderBCTreeBase.h:49
ogdf::ListIteratorBase::valid
bool valid() const
Returns true iff the iterator points to an element.
Definition: List.h:153
ogdf::EmbedderMaxFace::internalEmbedBlock
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)
Definition: EmbedderMaxFace.h:157
ogdf::AdjElement::twin
adjEntry twin() const
Returns the corresponding adjacency element associated with the same edge.
Definition: Graph_d.h:172
ogdf::BCTree::GNodeType::CutVertex
@ CutVertex
a cut-vertex
ogdf::AdjElement
Class for adjacency list elements.
Definition: Graph_d.h:142
ogdf::ListIteratorBase::succ
ListIteratorBase< E, isConst, isReverse > succ() const
Returns successor iterator.
Definition: List.h:174
ogdf::AdjElement::theEdge
edge theEdge() const
Returns the edge associated with this adjacency entry.
Definition: Graph_d.h:160
ogdf::EmbedderMaxFace::blockG
NodeArrayP< Graph > blockG
all blocks
Definition: EmbedderMaxFace.h:305
ogdf::EmbedderMaxFace::computeNodeLength
void computeNodeLength(node bT, std::function< int &(node)> setter)
Definition: EmbedderMaxFace.h:80
BCTree.h
Declaration of class BCTree.
ogdf::Direction::after
@ after
ogdf::Graph::nodes
internal::GraphObjectContainer< NodeElement > nodes
The container containing all node objects.
Definition: Graph_d.h:932
GraphList.h
Decralation of GraphElement and GraphList classes.
ogdf::AdjElement::succ
adjEntry succ() const
Returns the successor in the adjacency list.
Definition: Graph_d.h:218
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::EmbedderMaxFaceBiconnectedGraphs::embed
static void embed(Graph &G, adjEntry &adjExternal, const NodeArray< T > &nodeLength, const EdgeArray< T > &edgeLength, const node &n=nullptr)
Embeds G by computing and extending a maximum face in G containing n.
Definition: EmbedderMaxFaceBiconnectedGraphs.h:367
OGDF_NO_COPY
#define OGDF_NO_COPY(cls)
Explicitly disables (deletes) copy construction and assignment for class cls.
Definition: copy_move.h:37
ogdf::EdgeElement::source
node source() const
Returns the source node of the edge.
Definition: Graph_d.h:398
ogdf::EmbedderMaxFace::newOrder
NodeArray< List< adjEntry > > newOrder
saves for every node of PG the new adjacency list
Definition: EmbedderMaxFace.h:326
ogdf::internal::GraphRegisteredArray
RegisteredArray for nodes, edges and adjEntries of a graph.
Definition: Graph_d.h:658
ogdf::EdgeElement::adjSource
adjEntry adjSource() const
Returns the corresponding adjacancy entry at source node.
Definition: Graph_d.h:407
ogdf::Graph
Data type for general directed graphs (adjacency list representation).
Definition: Graph_d.h:869
ogdf::EmbedderMaxFace::nodeLength
NodeArray< NodeArray< int > > nodeLength
saving for each node in the block graphs its length
Definition: EmbedderMaxFace.h:320
ogdf::AdjElement::twinNode
node twinNode() const
Returns the associated node of the corresponding adjacency entry (shorthand for twin()->theNode()).
Definition: Graph_d.h:175
ogdf::EmbedderMaxFace::internalMaximumFaceRec
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)
Definition: EmbedderMaxFace.h:95
ogdf::EdgeElement::adjTarget
adjEntry adjTarget() const
Returns the corresponding adjacancy entry at target node.
Definition: Graph_d.h:410
ogdf::EmbedderMaxFace::forEachIngoingNeighbor
void forEachIngoingNeighbor(node v, std::function< void(node)> fun)
Calls fun for every ingoing edge (w,v).
Definition: EmbedderMaxFace.h:72
EmbedderBCTreeBase.h
Definition of ogdf::EmbedderBCTreeBase.
basic.h
Basic declarations, included by all source files.
EmbedderMaxFaceBiconnectedGraphs.h
Declares ogdf::EmbedderMaxFaceBiconnectedGraphs.
CombinatorialEmbedding.h
Declaration of CombinatorialEmbedding and face.
ogdf::EmbedderMaxFaceBiconnectedGraphs::computeSize
static T computeSize(const Graph &G, const node &n, const NodeArray< T > &nodeLength, const EdgeArray< T > &edgeLength)
Returns the size of a maximum external face in G containing the node n.
Definition: EmbedderMaxFaceBiconnectedGraphs.h:1205
OGDF_EXPORT
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF DLL.
Definition: config.h:101
ogdf::CombinatorialEmbedding
Combinatorial embeddings of planar graphs with modification functionality.
Definition: CombinatorialEmbedding.h:406
ogdf::NodeElement::firstAdj
adjEntry firstAdj() const
Returns the first entry in the adjaceny list.
Definition: Graph_d.h:286
ogdf::EdgeElement::opposite
node opposite(node v) const
Returns the adjacent node different from v.
Definition: Graph_d.h:413
ogdf::EmbedderMaxFace::cstrLength
NodeArray< NodeArray< int > > cstrLength
is saving for each node in the block graphs its cstrLength
Definition: EmbedderMaxFace.h:323
ogdf::EdgeElement
Class for the representation of edges.
Definition: Graph_d.h:363
List.h
Declaration of doubly linked lists and iterators.
ogdf::RegisteredArray< GraphRegistry< EdgeElement >, Value, WithDefault, Graph >::init
void init(const Graph *base=nullptr)
Reinitializes the array. Associates the array with the matching registry of base.
Definition: RegisteredArray.h:858
ogdf::ListIteratorBase
Encapsulates a pointer to a list element.
Definition: List.h:51
ogdf::EmbedderMaxFace::eBlockEmbedding_to_eH
NodeArray< EdgeArray< edge > > eBlockEmbedding_to_eH
a mapping of edges in blockG to the auxiliaryGraph of the BC-tree
Definition: EmbedderMaxFace.h:317
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::EmbedderMaxFace::eH_to_eBlockEmbedding
NodeArray< EdgeArray< edge > > eH_to_eBlockEmbedding
a mapping of edges in the auxiliaryGraph of the BC-tree to blockG
Definition: EmbedderMaxFace.h:311
ogdf::internal::EdgeArrayBase2
RegisteredArray for edges of a graph, specialized for EdgeArray<edge>.
Definition: Graph_d.h:716
ogdf::EmbedderMaxFace::spqrTrees
NodeArray< StaticSPQRTree * > spqrTrees
The SPQR-trees of the blocks.
Definition: EmbedderMaxFace.h:333
ogdf::FaceElement
Faces in a combinatorial embedding.
Definition: CombinatorialEmbedding.h:118