Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

StarInserter.h
Go to the documentation of this file.
1 
32 #pragma once
33 
34 #include <ogdf/basic/DualGraph.h>
35 #include <ogdf/basic/GraphCopy.h>
36 #include <ogdf/basic/comparer.h>
37 
38 #include <memory>
39 #include <unordered_map>
40 
41 namespace ogdf {
42 
43 using PredecessorMap = std::unordered_map<node, std::unique_ptr<NodeArray<edge>>>;
44 
57 private:
59 
61 
63 
70 
72 
74 
75 public:
85  EdgeOrderComparer(node origNode, node rootDualNode, const PredecessorMap& predecessors,
86  const GraphCopy& graphCopy, const DynamicDualGraph* dualGraph)
87  : m_origNode(origNode)
88  , m_rootDualNode(rootDualNode)
89  , m_predecessors(predecessors)
90  , m_graphCopy(graphCopy)
91  , m_dualGraph(dualGraph) { }
92 
104  node findLCAInInsertionPathTree(node w1, node w2, edge& parentOfLCA) const {
105  const NodeArray<edge>& preds1 {*m_predecessors.at(w1)};
106  const NodeArray<edge>& preds2 {*m_predecessors.at(w2)};
107 
108  // Go backwards from root until predecessor path diverges.
109  node lastDualNode1 {m_rootDualNode};
110  node lastDualNode2 {m_rootDualNode};
111  edge edgeToChild {nullptr};
112  node lca {nullptr};
113  while (lastDualNode1 == lastDualNode2) {
114  // Remember current lca.
115  parentOfLCA = edgeToChild;
116  lca = lastDualNode1;
117 
118  // Go further down.
119  edgeToChild = preds1[lastDualNode1];
120  if (preds1[lastDualNode1] == nullptr || preds2[lastDualNode2] == nullptr) {
121  // If either node has no child in the insertion path tree,
122  // the lca cannot be lower.
123  break;
124  } else {
125  lastDualNode1 = preds1[lastDualNode1]->opposite(lastDualNode1);
126  lastDualNode2 = preds2[lastDualNode2]->opposite(lastDualNode2);
127  }
128  }
129 
130  return lca;
131  }
132 
139  int compare(const edge& e1, const edge& e2) const {
142  if (w1 == w2) {
143  return 0;
144  }
145 
146  // Find lowest common ancestor in predecessor tree.
147  edge parentOfLCA {nullptr};
148  node lcaDualNode {findLCAInInsertionPathTree(w1, w2, parentOfLCA)};
149 
150  // w1 and w2 must have a common ancestor.
151  OGDF_ASSERT(lcaDualNode != nullptr);
152 
153  // Get the adjEntry of the primal edge of parentOfLCA which is incident
154  // to the face corresponding to lcaDualNode.
155  // This adjEntry marks the start of the cyclic order around lcaDualNode.
156  face lcaFace {m_dualGraph->primalFace(lcaDualNode)};
157  adjEntry parentAdj {nullptr};
158  if (parentOfLCA == nullptr) {
159  OGDF_ASSERT(lcaDualNode == m_rootDualNode);
160  // The lca is the root of the insertion path tree, hence it has no
161  // predecessor. Just use any adjEntry to start the cyclic order.
162  parentAdj = lcaFace->firstAdj();
163  } else {
164  // The lca is not the root of the insertion path tree.
165  // Determine the correct adjEntry of the primal of its parent-edge.
166  edge primalParentOfLCA {m_dualGraph->primalEdge(parentOfLCA)};
167  adjEntry sourceAdj {primalParentOfLCA->adjSource()};
168  adjEntry targetAdj {primalParentOfLCA->adjTarget()};
169 
171  if (embedding.rightFace(sourceAdj) == lcaFace) {
172  parentAdj = sourceAdj;
173  } else {
174  OGDF_ASSERT(embedding.rightFace(targetAdj) == lcaFace);
175  parentAdj = targetAdj;
176  }
177  }
178 
179  // Traverse adjEntries of face corrsponding to lcaDualNode clockwise,
180  // starting at parent edge of lcaDualNode in the insertion path tree.
181  auto cyclicNextAdj = [&parentAdj](adjEntry adj) {
182  adjEntry nextAdj = adj->faceCycleSucc();
183  return nextAdj == parentAdj ? nullptr : nextAdj;
184  };
185 
186  edge pred1 {(*m_predecessors.at(w1))[lcaDualNode]};
187  edge pred2 {(*m_predecessors.at(w2))[lcaDualNode]};
188  for (adjEntry adj {parentAdj}; adj != nullptr; adj = cyclicNextAdj(adj)) {
189  edge primalEdge {adj->theEdge()};
190  node primalNode {adj->theNode()};
191  // First, if lcaFace has no pred in the insertion path of w1/w2,
192  // w1/w2 is adjacent to lcaFace.
193  // Check whether the node of the current adj is w1/w2.
194  if (pred1 == nullptr && primalNode == w1) {
195  return -1;
196  }
197  if (pred2 == nullptr && primalNode == w2) {
198  return 1;
199  }
200 
201  // If w1/w2 is not adjacent to lcaFace, check whether the insertion
202  // path from lcaFace to the face adjacent to w1/w2 crosses the
203  // current edge.
204  edge dualEdge = m_dualGraph->dualEdge(primalEdge);
205  if (dualEdge == pred1) {
206  OGDF_ASSERT(dualEdge != pred2);
207  return -1;
208  }
209  if (dualEdge == pred2) {
210  OGDF_ASSERT(dualEdge != pred1);
211  return 1;
212  }
213  }
214 
215  // Something went terribly wrong: The LCA of the insertion paths of w1
216  // and w2 is not actually part of the insertion paths of w1 and w2?
217  OGDF_ASSERT(false);
218  return 0;
219  }
220 
222 };
223 
231 private:
233 
235 
237 
241 
246 
250 
253  inline face oldPrimalFace(node dualNode) {
254  return (*m_newToOldFace)[m_dual->primalFace(dualNode)];
255  }
256 
272  node getOptimalDualNode(node origNode, const EdgeArray<int>* pCostOrig,
273  PredecessorMap& predecessors);
274 
285  void makePredsConsistent(node origNode, node optimalDualNode, PredecessorMap& predecessors);
286 
297  adjEntry getCrossedAdjEntry(edge primalEdgeToSplit, node leftDualNode);
298 
320  adjEntry getAdjEntry(node primalNode, node rightDualNode, node otherPrimalNode);
321 
340  adjEntry getAdjEntry(node primalNode, node rightDualNode, edge primalEdge, bool first);
341 
361  edge collectAdjEntries(node w, node insertedNode, node optimalDualNode,
362  const PredecessorMap& predecessors, List<adjEntry>& crossedEdges);
363 
380  void transferCrossedEdges(const List<adjEntry>& crossedEdges,
381  SList<adjEntry>& finalCrossedEdges, bool startAtSource);
382 
389  void initMemberData(GraphCopy& graphCopy, DynamicDualGraph& dualGraph);
390 
399  void updateMemberData(edge origEdge, bool startAtSource);
400 
401 public:
403  StarInserter() : m_combEmbedding {nullptr}, m_dual {nullptr} { }
404 
406 
409  StarInserter(const StarInserter& inserter) { }
410 
413 
415  StarInserter& operator=(const StarInserter& inserter);
416 
418 
428  virtual void call(GraphCopy& graphCopy, DynamicDualGraph& dualGraph, node origNode,
429  const EdgeArray<int>* pCostOrig);
430 };
431 
432 }
ogdf
The namespace for all OGDF objects.
Definition: AugmentationModule.h:36
ogdf::DualGraphBase::primalFace
const face & primalFace(node v) const
Returns the face in the embedding of the primal graph corresponding to v.
Definition: DualGraph.h:163
OGDF_ASSERT
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition: basic.h:54
ogdf::EdgeOrderComparer
Orders edges such that they do not cross each other when embeddded as insertion paths.
Definition: StarInserter.h:56
ogdf::StarInserter::StarInserter
StarInserter()
Creates a StarInserter instance with default settings.
Definition: StarInserter.h:403
ogdf::DualGraphBase
A dual graph including its combinatorial embedding of an embedded graph.
Definition: DualGraph.h:42
ogdf::EdgeOrderComparer::m_graphCopy
const GraphCopy & m_graphCopy
Planarization.
Definition: StarInserter.h:71
OGDF_AUGMENT_COMPARER
#define OGDF_AUGMENT_COMPARER(type)
Add this macro to your class to turn it into a full comparer.
Definition: comparer.h:179
ogdf::EdgeOrderComparer::m_dualGraph
const DynamicDualGraph * m_dualGraph
Dual graph of m_graphCopy.
Definition: StarInserter.h:73
ogdf::ConstCombinatorialEmbedding::rightFace
face rightFace(adjEntry adj) const
Returns the face to the right of adj, i.e., the face containing adj.
Definition: CombinatorialEmbedding.h:270
ogdf::SList
Singly linked lists (maintaining the length of the list).
Definition: SList.h:833
ogdf::GraphCopy
Copies of graphs supporting edge splitting.
Definition: GraphCopy.h:384
ogdf::PredecessorMap
std::unordered_map< node, std::unique_ptr< NodeArray< edge > >> PredecessorMap
Definition: StarInserter.h:43
ogdf::StarInserter::m_dual
DynamicDualGraph * m_dual
Dual graph of m_combEmbedding.
Definition: StarInserter.h:236
ogdf::StarInserter
Definition: StarInserter.h:230
ogdf::AdjElement
Class for adjacency list elements.
Definition: Graph_d.h:135
ogdf::EdgeOrderComparer::m_rootDualNode
node m_rootDualNode
Dual node, root of the insertion path tree.
Definition: StarInserter.h:60
ogdf::EdgeOrderComparer::m_origNode
node m_origNode
Common (original) node of compared edges.
Definition: StarInserter.h:58
ogdf::StarInserter::~StarInserter
~StarInserter()
Destructor.
Definition: StarInserter.h:412
ogdf::EdgeOrderComparer::m_predecessors
const PredecessorMap & m_predecessors
Insertion path tree, given by several insertion paths.
Definition: StarInserter.h:69
ogdf::StarInserter::oldPrimalFace
face oldPrimalFace(node dualNode)
Returns the primal face of dualNode which existed before any new edges were inserted.
Definition: StarInserter.h:253
ogdf::StarInserter::m_newToOldFace
FaceArray< face > * m_newToOldFace
Maps new faces (created after the insertion of edge paths) to old (non-split) faces....
Definition: StarInserter.h:240
ogdf::StarInserter::StarInserter
StarInserter(const StarInserter &inserter)
Creates a StarInserter instance with the same settings as inserter.
Definition: StarInserter.h:409
DualGraph.h
Includes declaration of dual graph class.
GraphCopy.h
Declaration of graph copy classes.
ogdf::List
Doubly linked lists (maintaining the length of the list).
Definition: List.h:42
ogdf::internal::GraphRegisteredArray
RegisteredArray for nodes, edges and adjEntries of a graph.
Definition: Graph_d.h:651
ogdf::FaceArrayBase
RegisteredArray for labeling the faces of a CombinatorialEmbedding.
Definition: CombinatorialEmbedding.h:172
ogdf::GraphCopy::copy
edge copy(edge e) const override
Returns the first edge in the list of edges corresponding to edge e.
Definition: GraphCopy.h:457
ogdf::EdgeOrderComparer::compare
int compare(const edge &e1, const edge &e2) const
Compares two edges as described for EdgeOrderComparer.
Definition: StarInserter.h:139
ogdf::ConstCombinatorialEmbedding
Combinatorial embeddings of planar graphs.
Definition: CombinatorialEmbedding.h:207
ogdf::StarInserter::m_originalEdge
EdgeArray< edge > * m_originalEdge
Maps the parts of a chain in m_graphCopy to the respective copy edge contained in m_graphCopy before ...
Definition: StarInserter.h:249
ogdf::DualGraphBase::getPrimalEmbedding
Embedding & getPrimalEmbedding() const
Returns a reference to the combinatorial embedding of the primal graph.
Definition: DualGraph.h:136
ogdf::DualGraphBase::dualEdge
const edge & dualEdge(edge e) const
Returns the edge in the dual graph corresponding to e.
Definition: DualGraph.h:177
ogdf::StarInserter::m_combEmbedding
CombinatorialEmbedding * m_combEmbedding
Embedding of m_graphCopy.
Definition: StarInserter.h:234
OGDF_EXPORT
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF DLL.
Definition: config.h:101
ogdf::DualGraphBase::primalEdge
const edge & primalEdge(edge e) const
Returns the edge in the primal graph corresponding to e.
Definition: DualGraph.h:156
ogdf::CombinatorialEmbedding
Combinatorial embeddings of planar graphs with modification functionality.
Definition: CombinatorialEmbedding.h:397
ogdf::EdgeOrderComparer::findLCAInInsertionPathTree
node findLCAInInsertionPathTree(node w1, node w2, edge &parentOfLCA) const
Returns the lowest common ancestor of w1 and w2 in the insertion path tree given by m_predecessors.
Definition: StarInserter.h:104
ogdf::AdjElement::faceCycleSucc
adjEntry faceCycleSucc() const
Returns the cyclic successor in face.
Definition: Graph_d.h:205
ogdf::EdgeElement::opposite
node opposite(node v) const
Returns the adjacent node different from v.
Definition: Graph_d.h:406
ogdf::StarInserter::m_edgeInChainToSplit
EdgeArray< edge > * m_edgeInChainToSplit
Maps each edge e originally contained in m_graphCopy to the edge in the same chain which should be sp...
Definition: StarInserter.h:245
ogdf::EdgeElement
Class for the representation of edges.
Definition: Graph_d.h:356
ogdf::EdgeOrderComparer::EdgeOrderComparer
EdgeOrderComparer(node origNode, node rootDualNode, const PredecessorMap &predecessors, const GraphCopy &graphCopy, const DynamicDualGraph *dualGraph)
Creates a new EdgeOrderComparer.
Definition: StarInserter.h:85
ogdf::StarInserter::m_graphCopy
GraphCopy * m_graphCopy
Planarization.
Definition: StarInserter.h:232
comparer.h
Declarations for Comparer objects.
ogdf::NodeElement
Class for the representation of nodes.
Definition: Graph_d.h:233
ogdf::internal::EdgeArrayBase2
RegisteredArray for edges of a graph, specialized for EdgeArray<edge>.
Definition: Graph_d.h:709
ogdf::FaceElement
Faces in a combinatorial embedding.
Definition: CombinatorialEmbedding.h:109