Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

EmbedderMaxFace.h
Go to the documentation of this file.
1 
32 #pragma once
33 
37 
38 namespace ogdf {
39 
41 
48 public:
54  virtual void doCall(Graph& G, adjEntry& adjExternal) override;
55 
56  EmbedderMaxFace() = default;
57 
58  /* needs to be deleted explicitly for MSVC<=16 and classes containing a NodeArrayP */
60 
61 protected:
63  void forEachIngoingNeighbor(node v, std::function<void(node)> fun) {
64  for (adjEntry adj : v->adjEntries) {
65  if (adj->theEdge()->target() == v) {
66  fun(adj->twinNode());
67  }
68  }
69  }
70 
71  void computeNodeLength(node bT, std::function<int&(node)> setter) {
72  forEachIngoingNeighbor(bT, [&](node vT) {
73  node vH = pBCTree->cutVertex(vT, bT);
74  int length_v_in_block = 0;
75 
76  // set length of vertex v in block graph of bT:
77  forEachIngoingNeighbor(vT, [&](node bT2) {
78  node cutVertex = pBCTree->cutVertex(vT, bT2);
79  length_v_in_block += constraintMaxFace(bT2, cutVertex);
80  });
81 
82  setter(vH) = length_v_in_block;
83  });
84  }
85 
86  void internalMaximumFaceRec(const node& bT, node& bT_opt, int& ell_opt, Graph& blockGraph,
87  NodeArray<int>& paramNodeLength, StaticSPQRTree* spqrTree,
88  std::function<node&(node)> getBENode, std::function<int&(node, node)> getCstrLength,
89  std::function<int&(node, node)> getNodeLength, int* const maxFaceSizeToUpdate = nullptr) {
90  node tmp_bT_opt = bT;
91  NodeArray<EdgeArray<int>> edgeLengthSkel;
92  EdgeArray<int> edgeLengthForEllOpt(blockGraph, 1);
93 
94  int tmp_ell_opt = EmbedderMaxFaceBiconnectedGraphs<int>::computeSize(blockGraph,
95  paramNodeLength, edgeLengthForEllOpt, spqrTree, edgeLengthSkel);
96 
97  if (maxFaceSizeToUpdate != nullptr) {
98  *maxFaceSizeToUpdate = tmp_ell_opt;
99  }
100 
101  forEachIngoingNeighbor(bT, [&](node cT) {
102  node cH = pBCTree->cutVertex(cT, bT);
103 
104  EdgeArray<int> uniformLengths;
105 
106  if (maxFaceSizeToUpdate == nullptr) {
107  uniformLengths.init(blockGraph, 1);
108  }
109 
110  getCstrLength(bT, cH) = EmbedderMaxFaceBiconnectedGraphs<int>::computeSize(blockGraph,
111  getBENode(cH), paramNodeLength,
112  maxFaceSizeToUpdate == nullptr ? uniformLengths : edgeLengthForEllOpt, spqrTree,
113  edgeLengthSkel);
114 
115  int L = 0;
116 
117  // L := \sum_{(B', c) \in bcTree} cstrLength(B', c)
118  forEachIngoingNeighbor(cT, [&](node bT2) {
119  // get partner vertex of c in the block graph of B'=e->target() and add cstrLength(B', c) to L:
120  L += getCstrLength(bT2, pBCTree->cutVertex(cT, bT2));
121  });
122 
123  forEachIngoingNeighbor(cT, [&](node pT) {
124  if (pT != bT) {
125  // get partner vertex of c in the block graph of B'=e->source():
126  node partnerV = pBCTree->cutVertex(cT, pT);
127  getNodeLength(pT, partnerV) = L - getCstrLength(pT, partnerV);
128 
129  // pBCTree->originalGraph().chooseNode() just to get rid of warning:
130  node thisbT_opt = pBCTree->originalGraph().chooseNode();
131  int thisell_opt = 0;
132  maximumFaceRec(pT, thisbT_opt, thisell_opt);
133 
134  if (thisell_opt > tmp_ell_opt) {
135  tmp_bT_opt = thisbT_opt;
136  tmp_ell_opt = thisell_opt;
137  }
138  }
139  });
140  });
141 
142  // return (B*, \ell*):
143  bT_opt = tmp_bT_opt;
144  ell_opt = tmp_ell_opt;
145  }
146 
147  template<typename T>
148  void internalEmbedBlock(const node bT, const node cT, ListIterator<adjEntry>& after,
149  Graph& blockGraph, NodeArray<T>& paramNodeLength, EdgeArray<T>& paramEdgeLength,
150  NodeArray<node>& mapNodeToH, EdgeArray<edge>& mapEdgeToH, const node nodeInBlock) {
151  // 1. Compute embedding of block
152  adjEntry m_adjExternal = nullptr;
153  EmbedderMaxFaceBiconnectedGraphs<T>::embed(blockGraph, m_adjExternal, paramNodeLength,
154  paramEdgeLength, nodeInBlock);
155 
156  // 2. Copy block embedding into graph embedding and call recursively
157  // embedBlock for all cut vertices in bT
158  CombinatorialEmbedding CE(blockGraph);
159  face f = CE.leftFace(m_adjExternal);
160 
161  if (*pAdjExternal == nullptr) {
162  node on = pBCTree->original(mapNodeToH[m_adjExternal->theNode()]);
163 
164  for (adjEntry ae : on->adjEntries) {
165  if (ae->theEdge() == pBCTree->original(mapEdgeToH[m_adjExternal->theEdge()])) {
166  *pAdjExternal = ae->twin();
167  break;
168  }
169  }
170  }
171 
172  for (node nSG : blockGraph.nodes) {
173  node nH = mapNodeToH[nSG];
174  node nG = pBCTree->original(nH);
175  adjEntry ae = nSG->firstAdj();
176  ListIterator<adjEntry>* pAfter =
177  pBCTree->bcproper(nG) == cT ? &after : new ListIterator<adjEntry>;
178 
179  if (pBCTree->typeOfGNode(nG) == BCTree::GNodeType::CutVertex) {
180  node cT2 = pBCTree->bcproper(nG);
181  OGDF_ASSERT(cT2 != nullptr);
182  bool doRecurse = true;
183 
184  if (cT2 == cT) {
185  node parent_bT_of_cT2 = nullptr;
186 
187  for (adjEntry adj : cT2->adjEntries) {
188  if (adj->theEdge()->source() == cT2) {
189  parent_bT_of_cT2 = adj->twinNode();
190  break;
191  }
192  }
193 
194  OGDF_ASSERT(parent_bT_of_cT2 != nullptr);
195 
196  if (treeNodeTreated[parent_bT_of_cT2]) {
197  doRecurse = false;
198  }
199  }
200 
201  // (if exists) find adjacency entry of nSG which lies on external face f:
202  for (adjEntry aeFace : f->entries) {
203  if (aeFace->theNode() == nSG) {
204  ae = aeFace->succ() == nullptr ? nSG->firstAdj() : aeFace->succ();
205  break;
206  }
207  }
208 
209  if (doRecurse) {
210  for (adjEntry adj : cT2->adjEntries) {
211  node bT2 = adj->theEdge()->opposite(cT2);
212 
213  if (!treeNodeTreated[bT2]) {
214  embedBlock(bT2, cT2, *pAfter);
215  }
216  }
217  }
218  }
219 
220  // embed all edges of block bT:
221  bool after_ae = true;
222  for (adjEntry aeNode = ae; after_ae || aeNode != ae;
223  aeNode = aeNode->succ() == nullptr ? nSG->firstAdj() : aeNode->succ()) {
224  edge e = pBCTree->original(mapEdgeToH[aeNode->theEdge()]);
225  if (nG == e->source()) {
226  if (pAfter->valid()) {
227  *pAfter = newOrder[nG].insertAfter(e->adjSource(), *pAfter);
228  } else {
229  *pAfter = newOrder[nG].pushBack(e->adjSource());
230  }
231  } else {
232  if (pAfter->valid()) {
233  *pAfter = newOrder[nG].insertAfter(e->adjTarget(), *pAfter);
234  } else {
235  *pAfter = newOrder[nG].pushBack(e->adjTarget());
236  }
237  }
238 
239  after_ae &= aeNode->succ() != nullptr;
240  }
241 
242  if (*pAfter != after) {
243  delete pAfter;
244  }
245  }
246  }
247 
254  void computeBlockGraphs(const node& bT, const node& cH);
255 
263  virtual int constraintMaxFace(const node& bT, const node& cH);
264 
273  virtual void maximumFaceRec(const node& bT, node& bT_opt, int& ell_opt);
274 
281  void embedBlock(const node& bT);
282 
293  virtual void embedBlock(const node& bT, const node& cT, ListIterator<adjEntry>& after);
294 
297 
300 
303 
306 
309 
312 
315 
318 
322 
325 };
326 
327 }
ogdf
The namespace for all OGDF objects.
Definition: AugmentationModule.h:36
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:321
ogdf::StaticSPQRTree
Linear-time implementation of static SPQR-trees.
Definition: StaticSPQRTree.h:73
OGDF_ASSERT
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition: basic.h:54
ogdf::AdjElement::theNode
node theNode() const
Returns the node whose adjacency list contains this element.
Definition: Graph_d.h:159
ogdf::EmbedderMaxFace
Embedder that maximizes the external face.
Definition: EmbedderMaxFace.h:47
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:276
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:299
StaticSPQRTree.h
Declaration of class StaticSPQRTree.
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:305
ogdf::FaceElement::entries
internal::FaceAdjContainer entries
Container maintaining the adjacency entries in the face.
Definition: CombinatorialEmbedding.h:133
ogdf::embedder::EmbedderBCTreeBase
Common base for embedder algorithms based on BC trees.
Definition: EmbedderBCTreeBase.h:44
ogdf::ListIteratorBase::valid
bool valid() const
Returns true iff the iterator points to an element.
Definition: List.h:143
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:148
ogdf::AdjElement::twin
adjEntry twin() const
Returns the corresponding adjacency element associated with the same edge.
Definition: Graph_d.h:165
ogdf::BCTree::GNodeType::CutVertex
@ CutVertex
a cut-vertex
ogdf::AdjElement
Class for adjacency list elements.
Definition: Graph_d.h:135
ogdf::ListIteratorBase::succ
ListIteratorBase< E, isConst, isReverse > succ() const
Returns successor iterator.
Definition: List.h:164
ogdf::AdjElement::theEdge
edge theEdge() const
Returns the edge associated with this adjacency entry.
Definition: Graph_d.h:153
ogdf::EmbedderMaxFace::blockG
NodeArrayP< Graph > blockG
all blocks
Definition: EmbedderMaxFace.h:296
ogdf::EmbedderMaxFace::computeNodeLength
void computeNodeLength(node bT, std::function< int &(node)> setter)
Definition: EmbedderMaxFace.h:71
ogdf::Direction::after
@ after
ogdf::Graph::nodes
internal::GraphObjectContainer< NodeElement > nodes
The container containing all node objects.
Definition: Graph_d.h:924
ogdf::AdjElement::succ
adjEntry succ() const
Returns the successor in the adjacency list.
Definition: Graph_d.h:211
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::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:361
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:391
ogdf::EmbedderMaxFace::newOrder
NodeArray< List< adjEntry > > newOrder
saves for every node of PG the new adjacency list
Definition: EmbedderMaxFace.h:317
ogdf::internal::GraphRegisteredArray
RegisteredArray for nodes, edges and adjEntries of a graph.
Definition: Graph_d.h:651
ogdf::EdgeElement::adjSource
adjEntry adjSource() const
Returns the corresponding adjacancy entry at source node.
Definition: Graph_d.h:400
ogdf::Graph
Data type for general directed graphs (adjacency list representation).
Definition: Graph_d.h:862
ogdf::EmbedderMaxFace::nodeLength
NodeArray< NodeArray< int > > nodeLength
saving for each node in the block graphs its length
Definition: EmbedderMaxFace.h:311
ogdf::AdjElement::twinNode
node twinNode() const
Returns the associated node of the corresponding adjacency entry (shorthand for twin()->theNode()).
Definition: Graph_d.h:168
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:86
ogdf::EdgeElement::adjTarget
adjEntry adjTarget() const
Returns the corresponding adjacancy entry at target node.
Definition: Graph_d.h:403
ogdf::EmbedderMaxFace::forEachIngoingNeighbor
void forEachIngoingNeighbor(node v, std::function< void(node)> fun)
Calls fun for every ingoing edge (w,v).
Definition: EmbedderMaxFace.h:63
EmbedderBCTreeBase.h
Definition of ogdf::EmbedderBCTreeBase.
EmbedderMaxFaceBiconnectedGraphs.h
Declares ogdf::EmbedderMaxFaceBiconnectedGraphs.
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:1199
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:397
ogdf::NodeElement::firstAdj
adjEntry firstAdj() const
Returns the first entry in the adjaceny list.
Definition: Graph_d.h:279
ogdf::EdgeElement::opposite
node opposite(node v) const
Returns the adjacent node different from v.
Definition: Graph_d.h:406
ogdf::EmbedderMaxFace::cstrLength
NodeArray< NodeArray< int > > cstrLength
is saving for each node in the block graphs its cstrLength
Definition: EmbedderMaxFace.h:314
ogdf::EdgeElement
Class for the representation of edges.
Definition: Graph_d.h:356
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:849
ogdf::ListIteratorBase
Encapsulates a pointer to a list element.
Definition: List.h:46
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:308
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::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:302
ogdf::internal::EdgeArrayBase2
RegisteredArray for edges of a graph, specialized for EdgeArray<edge>.
Definition: Graph_d.h:709
ogdf::EmbedderMaxFace::spqrTrees
NodeArray< StaticSPQRTree * > spqrTrees
The SPQR-trees of the blocks.
Definition: EmbedderMaxFace.h:324
ogdf::FaceElement
Faces in a combinatorial embedding.
Definition: CombinatorialEmbedding.h:109