Open
Graph Drawing
Framework

 v. 2020.02 (Catalpa)
 

EmbedderMaxFace.h
Go to the documentation of this file.
1 
32 #pragma once
33 
37 
38 namespace ogdf {
39 
41 
48 {
49 public:
55  virtual void doCall(Graph& G, adjEntry& adjExternal) override;
56 
57 protected:
59  void forEachIngoingNeighbor(node v, std::function<void(node)> fun) {
60  for (adjEntry adj : v->adjEntries) {
61  if (adj->theEdge()->target() == v) {
62  fun(adj->twinNode());
63  }
64  }
65  }
66 
67  void computeNodeLength(node bT, std::function<int &(node)> setter) {
68  forEachIngoingNeighbor(bT, [&](node vT) {
69  node vH = pBCTree->cutVertex(vT, bT);
70  int length_v_in_block = 0;
71 
72  // set length of vertex v in block graph of bT:
73  forEachIngoingNeighbor(vT, [&](node bT2) {
74  node cutVertex = pBCTree->cutVertex(vT, bT2);
75  length_v_in_block += constraintMaxFace(bT2, cutVertex);
76  });
77 
78  setter(vH) = length_v_in_block;
79  });
80  }
81 
83  const node& bT,
84  node& bT_opt,
85  int& ell_opt,
86  Graph &blockGraph,
87  NodeArray<int> &paramNodeLength,
88  StaticSPQRTree *spqrTree,
89  std::function<node &(node)> getBENode,
90  std::function<int &(node, node)> getCstrLength,
91  std::function<int &(node, node)> getNodeLength,
92  int * const maxFaceSizeToUpdate = nullptr) {
93  node tmp_bT_opt = bT;
94  NodeArray<EdgeArray<int>> edgeLengthSkel;
95  EdgeArray<int> edgeLengthForEllOpt(blockGraph, 1);
96 
98  blockGraph,
99  paramNodeLength,
100  edgeLengthForEllOpt,
101  spqrTree,
102  edgeLengthSkel);
103 
104  if (maxFaceSizeToUpdate != nullptr) {
105  *maxFaceSizeToUpdate = tmp_ell_opt;
106  }
107 
108  forEachIngoingNeighbor(bT, [&](node cT) {
109  node cH = pBCTree->cutVertex(cT, bT);
110 
111  EdgeArray<int> uniformLengths;
112 
113  if (maxFaceSizeToUpdate == nullptr) {
114  uniformLengths.init(blockGraph, 1);
115  }
116 
118  blockGraph,
119  getBENode(cH),
120  paramNodeLength,
121  maxFaceSizeToUpdate == nullptr ? uniformLengths : edgeLengthForEllOpt,
122  spqrTree,
123  edgeLengthSkel);
124 
125  int L = 0;
126 
127  // L := \sum_{(B', c) \in bcTree} cstrLength(B', c)
128  forEachIngoingNeighbor(cT, [&](node bT2) {
129  // get partner vertex of c in the block graph of B'=e->target() and add cstrLength(B', c) to L:
130  L += getCstrLength(bT2, pBCTree->cutVertex(cT, bT2));
131  });
132 
133  forEachIngoingNeighbor(cT, [&](node pT) {
134  if (pT != bT) {
135  // get partner vertex of c in the block graph of B'=e->source():
136  node partnerV = pBCTree->cutVertex(cT, pT);
137  getNodeLength(pT, partnerV) = L - getCstrLength(pT, partnerV);
138 
139  // pBCTree->originalGraph().chooseNode() just to get rid of warning:
140  node thisbT_opt = pBCTree->originalGraph().chooseNode();
141  int thisell_opt = 0;
142  maximumFaceRec(pT, thisbT_opt, thisell_opt);
143 
144  if (thisell_opt > tmp_ell_opt) {
145  tmp_bT_opt = thisbT_opt;
146  tmp_ell_opt = thisell_opt;
147  }
148  }
149  });
150  });
151 
152  // return (B*, \ell*):
153  bT_opt = tmp_bT_opt;
154  ell_opt = tmp_ell_opt;
155  }
156 
157  template<typename T>
159  const node bT,
160  const node cT,
162  Graph &blockGraph,
163  NodeArray<T> &paramNodeLength,
164  EdgeArray<T> &paramEdgeLength,
165  NodeArray<node> &mapNodeToH,
166  EdgeArray<edge> &mapEdgeToH,
167  const node nodeInBlock) {
168  // 1. Compute embedding of block
169  adjEntry m_adjExternal = nullptr;
170  EmbedderMaxFaceBiconnectedGraphs<T>::embed(blockGraph, m_adjExternal, paramNodeLength, paramEdgeLength, nodeInBlock);
171 
172  // 2. Copy block embedding into graph embedding and call recursively
173  // embedBlock for all cut vertices in bT
174  CombinatorialEmbedding CE(blockGraph);
175  face f = CE.leftFace(m_adjExternal);
176 
177  if (*pAdjExternal == nullptr) {
178  node on = pBCTree->original(mapNodeToH[m_adjExternal->theNode()]);
179 
180  for (adjEntry ae : on->adjEntries) {
181  if (ae->theEdge() == pBCTree->original(mapEdgeToH[m_adjExternal->theEdge()])) {
182  *pAdjExternal = ae->twin();
183  break;
184  }
185  }
186  }
187 
188  for (node nSG : blockGraph.nodes) {
189  node nH = mapNodeToH[nSG];
190  node nG = pBCTree->original(nH);
191  adjEntry ae = nSG->firstAdj();
192  ListIterator<adjEntry>* pAfter = pBCTree->bcproper(nG) == cT ? &after : new ListIterator<adjEntry>;
193 
194  if (pBCTree->typeOfGNode(nG) == BCTree::GNodeType::CutVertex) {
195  node cT2 = pBCTree->bcproper(nG);
196  bool doRecurse = true;
197 
198  if (cT2 == cT) {
199  node parent_bT_of_cT2 = nullptr;
200 
201  for (adjEntry adj : cT2->adjEntries) {
202  if (adj->theEdge()->source() == cT2) {
203  parent_bT_of_cT2 = adj->twinNode();
204  break;
205  }
206  }
207 
208  OGDF_ASSERT(parent_bT_of_cT2 != nullptr);
209 
210  if (treeNodeTreated[parent_bT_of_cT2]) {
211  doRecurse = false;
212  }
213  }
214 
215  // (if exists) find adjacency entry of nSG which lies on external face f:
216  for (adjEntry aeFace : f->entries) {
217  if (aeFace->theNode() == nSG) {
218  ae = aeFace->succ() == nullptr ? nSG->firstAdj() : aeFace->succ();
219  break;
220  }
221 
222  }
223 
224  if (doRecurse) {
225  for (adjEntry adj : cT2->adjEntries) {
226  node bT2 = adj->theEdge()->opposite(cT2);
227 
228  if (!treeNodeTreated[bT2]) {
229  embedBlock(bT2, cT2, *pAfter);
230  }
231  }
232  }
233  }
234 
235  // embed all edges of block bT:
236  bool after_ae = true;
237  for (adjEntry aeNode = ae; after_ae || aeNode != ae; aeNode = aeNode->succ() == nullptr ? nSG->firstAdj() : aeNode->succ()) {
238  edge e = pBCTree->original(mapEdgeToH[aeNode->theEdge()]);
239  if (nG == e->source()) {
240  if (pAfter->valid()) {
241  *pAfter = newOrder[nG].insertAfter(e->adjSource(), *pAfter);
242  } else {
243  *pAfter = newOrder[nG].pushBack(e->adjSource());
244  }
245  } else {
246  if (pAfter->valid()) {
247  *pAfter = newOrder[nG].insertAfter(e->adjTarget(), *pAfter);
248  } else {
249  *pAfter = newOrder[nG].pushBack(e->adjTarget());
250  }
251  }
252 
253  after_ae &= aeNode->succ() != nullptr;
254  }
255 
256  if (*pAfter != after) {
257  delete pAfter;
258  }
259  }
260  }
261 
268  void computeBlockGraphs(const node& bT, const node& cH);
269 
277  virtual int constraintMaxFace(const node& bT, const node& cH);
278 
287  virtual void maximumFaceRec(const node& bT, node& bT_opt, int& ell_opt);
288 
295  void embedBlock(const node& bT);
296 
307  virtual void embedBlock(const node& bT, const node& cT, ListIterator<adjEntry>& after);
308 
311 
314 
317 
320 
323 
326 
329 
332 
336 
339 };
340 
341 }
node target() const
Returns the target node of the edge.
Definition: Graph_d.h:328
NodeArray< NodeArray< node > > nBlockEmbedding_to_nH
a mapping of nodes in blockG to the auxiliaryGraph of the BC-tree
NodeArray< StaticSPQRTree * > spqrTrees
The SPQR-trees of the blocks.
edge theEdge() const
Returns the edge associated with this adjacency entry.
Definition: Graph_d.h:96
NodeArray< NodeArray< int > > nodeLength
saving for each node in the block graphs its length
ListIteratorBase< E, isConst, isReverse > succ() const
Returns successor iterator.
Definition: List.h:145
void init()
Reinitializes the array. Associates the array with no graph.
Definition: EdgeArray.h:283
Data type for general directed graphs (adjacency list representation).
Definition: Graph_d.h:492
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF DLL.
Definition: config.h:99
adjEntry adjSource() const
Returns the corresponding adjacancy entry at source node.
Definition: Graph_d.h:333
NodeArray< List< adjEntry > > newOrder
saves for every node of PG the new adjacency list
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.
NodeArray< EdgeArray< edge > > eH_to_eBlockEmbedding
a mapping of edges in the auxiliaryGraph of the BC-tree to blockG
void computeNodeLength(node bT, std::function< int &(node)> setter)
bool valid() const
Returns true iff the iterator points to an element.
Definition: List.h:124
NodeArray< bool > treeNodeTreated
treeNodeTreated saves for all block nodes in the BC-tree if it has already been treated or not...
Declaration of class StaticSPQRTree.
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.
NodeArray< NodeArray< int > > cstrLength
is saving for each node in the block graphs its cstrLength
internal::FaceAdjContainer entries
Container maintaining the adjacency entries in the face.
Faces in a combinatorial embedding.
node twinNode() const
Returns the associated node of the corresponding adjacency entry (shorthand for twin()->theNode()).
Definition: Graph_d.h:108
Class for the representation of edges.
Definition: Graph_d.h:292
adjEntry twin() const
Returns the corresponding adjacency element associated with the same edge.
Definition: Graph_d.h:105
Class for the representation of nodes.
Definition: Graph_d.h:169
Encapsulates a pointer to a list element.
Definition: List.h:42
Embedder that maximizes the external face.
node opposite(node v) const
Returns the adjacent node different from v.
Definition: Graph_d.h:338
NodeArray< NodeArray< node > > nH_to_nBlockEmbedding
a mapping of nodes in the auxiliaryGraph of the BC-tree to blockG
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)
void forEachIngoingNeighbor(node v, std::function< void(node)> fun)
Calls fun for every ingoing edge (w,v).
Linear-time implementation of static SPQR-trees.
Declares ogdf::EmbedderMaxFaceBiconnectedGraphs.
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)
adjEntry succ() const
Returns the successor in the adjacency list.
Definition: Graph_d.h:148
face leftFace(adjEntry adj) const
Returns the face to the left of adj, i.e., the face containing the twin of adj.
NodeArray< Graph > blockG
all blocks
node source() const
Returns the source node of the edge.
Definition: Graph_d.h:326
Common base for embedder algorithms based on BC trees.
The namespace for all OGDF objects.
Definition of ogdf::EmbedderBCTreeBase.
internal::GraphObjectContainer< NodeElement > nodes
The container containing all node objects.
Definition: Graph_d.h:565
adjEntry firstAdj() const
Returns the first entry in the adjaceny list.
Definition: Graph_d.h:213
Combinatorial embeddings of planar graphs with modification functionality.
adjEntry adjTarget() const
Returns the corresponding adjacancy entry at target node.
Definition: Graph_d.h:335
node theNode() const
Returns the node whose adjacency list contains this element.
Definition: Graph_d.h:100
Class for adjacency list elements.
Definition: Graph_d.h:79
NodeArray< EdgeArray< edge > > eBlockEmbedding_to_eH
a mapping of edges in blockG to the auxiliaryGraph of the BC-tree
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition: basic.h:41
internal::GraphObjectContainer< AdjElement > adjEntries
The container containing all entries in the adjacency list of this node.
Definition: Graph_d.h:200