Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

StarInserter.h
Go to the documentation of this file.
1 
32 #pragma once
33 
35 #include <ogdf/basic/DualGraph.h>
36 #include <ogdf/basic/Graph.h>
37 #include <ogdf/basic/GraphCopy.h>
38 #include <ogdf/basic/basic.h>
39 #include <ogdf/basic/comparer.h>
40 
41 #include <memory>
42 #include <unordered_map>
43 
44 namespace ogdf {
45 template<class E>
46 class List;
47 template<class E>
48 class SList;
49 
50 using PredecessorMap = std::unordered_map<node, std::unique_ptr<NodeArray<edge>>>;
51 
64 private:
66 
68 
70 
77 
79 
81 
82 public:
92  EdgeOrderComparer(node origNode, node rootDualNode, const PredecessorMap& predecessors,
93  const GraphCopy& graphCopy, const DynamicDualGraph* dualGraph)
94  : m_origNode(origNode)
95  , m_rootDualNode(rootDualNode)
96  , m_predecessors(predecessors)
97  , m_graphCopy(graphCopy)
98  , m_dualGraph(dualGraph) { }
99 
111  node findLCAInInsertionPathTree(node w1, node w2, edge& parentOfLCA) const {
112  const NodeArray<edge>& preds1 {*m_predecessors.at(w1)};
113  const NodeArray<edge>& preds2 {*m_predecessors.at(w2)};
114 
115  // Go backwards from root until predecessor path diverges.
116  node lastDualNode1 {m_rootDualNode};
117  node lastDualNode2 {m_rootDualNode};
118  edge edgeToChild {nullptr};
119  node lca {nullptr};
120  while (lastDualNode1 == lastDualNode2) {
121  // Remember current lca.
122  parentOfLCA = edgeToChild;
123  lca = lastDualNode1;
124 
125  // Go further down.
126  edgeToChild = preds1[lastDualNode1];
127  if (preds1[lastDualNode1] == nullptr || preds2[lastDualNode2] == nullptr) {
128  // If either node has no child in the insertion path tree,
129  // the lca cannot be lower.
130  break;
131  } else {
132  lastDualNode1 = preds1[lastDualNode1]->opposite(lastDualNode1);
133  lastDualNode2 = preds2[lastDualNode2]->opposite(lastDualNode2);
134  }
135  }
136 
137  return lca;
138  }
139 
146  int compare(const edge& e1, const edge& e2) const {
149  if (w1 == w2) {
150  return 0;
151  }
152 
153  // Find lowest common ancestor in predecessor tree.
154  edge parentOfLCA {nullptr};
155  node lcaDualNode {findLCAInInsertionPathTree(w1, w2, parentOfLCA)};
156 
157  // w1 and w2 must have a common ancestor.
158  OGDF_ASSERT(lcaDualNode != nullptr);
159 
160  // Get the adjEntry of the primal edge of parentOfLCA which is incident
161  // to the face corresponding to lcaDualNode.
162  // This adjEntry marks the start of the cyclic order around lcaDualNode.
163  face lcaFace {m_dualGraph->primalFace(lcaDualNode)};
164  adjEntry parentAdj {nullptr};
165  if (parentOfLCA == nullptr) {
166  OGDF_ASSERT(lcaDualNode == m_rootDualNode);
167  // The lca is the root of the insertion path tree, hence it has no
168  // predecessor. Just use any adjEntry to start the cyclic order.
169  parentAdj = lcaFace->firstAdj();
170  } else {
171  // The lca is not the root of the insertion path tree.
172  // Determine the correct adjEntry of the primal of its parent-edge.
173  edge primalParentOfLCA {m_dualGraph->primalEdge(parentOfLCA)};
174  adjEntry sourceAdj {primalParentOfLCA->adjSource()};
175  adjEntry targetAdj {primalParentOfLCA->adjTarget()};
176 
178  if (embedding.rightFace(sourceAdj) == lcaFace) {
179  parentAdj = sourceAdj;
180  } else {
181  OGDF_ASSERT(embedding.rightFace(targetAdj) == lcaFace);
182  parentAdj = targetAdj;
183  }
184  }
185 
186  // Traverse adjEntries of face corrsponding to lcaDualNode clockwise,
187  // starting at parent edge of lcaDualNode in the insertion path tree.
188  auto cyclicNextAdj = [&parentAdj](adjEntry adj) {
189  adjEntry nextAdj = adj->faceCycleSucc();
190  return nextAdj == parentAdj ? nullptr : nextAdj;
191  };
192 
193  edge pred1 {(*m_predecessors.at(w1))[lcaDualNode]};
194  edge pred2 {(*m_predecessors.at(w2))[lcaDualNode]};
195  for (adjEntry adj {parentAdj}; adj != nullptr; adj = cyclicNextAdj(adj)) {
196  edge primalEdge {adj->theEdge()};
197  node primalNode {adj->theNode()};
198  // First, if lcaFace has no pred in the insertion path of w1/w2,
199  // w1/w2 is adjacent to lcaFace.
200  // Check whether the node of the current adj is w1/w2.
201  if (pred1 == nullptr && primalNode == w1) {
202  return -1;
203  }
204  if (pred2 == nullptr && primalNode == w2) {
205  return 1;
206  }
207 
208  // If w1/w2 is not adjacent to lcaFace, check whether the insertion
209  // path from lcaFace to the face adjacent to w1/w2 crosses the
210  // current edge.
211  edge dualEdge = m_dualGraph->dualEdge(primalEdge);
212  if (dualEdge == pred1) {
213  OGDF_ASSERT(dualEdge != pred2);
214  return -1;
215  }
216  if (dualEdge == pred2) {
217  OGDF_ASSERT(dualEdge != pred1);
218  return 1;
219  }
220  }
221 
222  // Something went terribly wrong: The LCA of the insertion paths of w1
223  // and w2 is not actually part of the insertion paths of w1 and w2?
224  OGDF_ASSERT(false);
225  return 0;
226  }
227 
229 };
230 
238 private:
240 
242 
244 
248 
253 
257 
260  inline face oldPrimalFace(node dualNode) {
261  return (*m_newToOldFace)[m_dual->primalFace(dualNode)];
262  }
263 
279  node getOptimalDualNode(node origNode, const EdgeArray<int>* pCostOrig,
280  PredecessorMap& predecessors);
281 
292  void makePredsConsistent(node origNode, node optimalDualNode, PredecessorMap& predecessors);
293 
304  adjEntry getCrossedAdjEntry(edge primalEdgeToSplit, node leftDualNode);
305 
327  adjEntry getAdjEntry(node primalNode, node rightDualNode, node otherPrimalNode);
328 
347  adjEntry getAdjEntry(node primalNode, node rightDualNode, edge primalEdge, bool first);
348 
368  edge collectAdjEntries(node w, node insertedNode, node optimalDualNode,
369  const PredecessorMap& predecessors, List<adjEntry>& crossedEdges);
370 
387  void transferCrossedEdges(const List<adjEntry>& crossedEdges,
388  SList<adjEntry>& finalCrossedEdges, bool startAtSource);
389 
396  void initMemberData(GraphCopy& graphCopy, DynamicDualGraph& dualGraph);
397 
406  void updateMemberData(edge origEdge, bool startAtSource);
407 
408 public:
410  StarInserter() : m_combEmbedding {nullptr}, m_dual {nullptr} { }
411 
413 
416  StarInserter(const StarInserter& inserter) { }
417 
420 
422  StarInserter& operator=(const StarInserter& inserter);
423 
425 
435  virtual void call(GraphCopy& graphCopy, DynamicDualGraph& dualGraph, node origNode,
436  const EdgeArray<int>* pCostOrig);
437 };
438 
439 }
ogdf
The namespace for all OGDF objects.
Definition: multilevelmixer.cpp:39
Graph.h
Includes declaration of graph class.
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:168
OGDF_ASSERT
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition: basic.h:66
ogdf::EdgeOrderComparer
Orders edges such that they do not cross each other when embeddded as insertion paths.
Definition: StarInserter.h:63
ogdf::StarInserter::StarInserter
StarInserter()
Creates a StarInserter instance with default settings.
Definition: StarInserter.h:410
ogdf::DualGraphBase
A dual graph including its combinatorial embedding of an embedded graph.
Definition: DualGraph.h:47
ogdf::EdgeOrderComparer::m_graphCopy
const GraphCopy & m_graphCopy
Planarization.
Definition: StarInserter.h:78
OGDF_AUGMENT_COMPARER
#define OGDF_AUGMENT_COMPARER(type)
Add this macro to your class to turn it into a full comparer.
Definition: comparer.h:183
ogdf::EdgeOrderComparer::m_dualGraph
const DynamicDualGraph * m_dualGraph
Dual graph of m_graphCopy.
Definition: StarInserter.h:80
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:279
ogdf::SList
Singly linked lists (maintaining the length of the list).
Definition: SList.h:845
ogdf::GraphCopy
Copies of graphs supporting edge splitting.
Definition: GraphCopy.h:391
ogdf::PredecessorMap
std::unordered_map< node, std::unique_ptr< NodeArray< edge > >> PredecessorMap
Definition: StarInserter.h:50
ogdf::StarInserter::m_dual
DynamicDualGraph * m_dual
Dual graph of m_combEmbedding.
Definition: StarInserter.h:243
ogdf::StarInserter
Definition: StarInserter.h:237
ogdf::AdjElement
Class for adjacency list elements.
Definition: Graph_d.h:142
ogdf::EdgeOrderComparer::m_rootDualNode
node m_rootDualNode
Dual node, root of the insertion path tree.
Definition: StarInserter.h:67
ogdf::EdgeOrderComparer::m_origNode
node m_origNode
Common (original) node of compared edges.
Definition: StarInserter.h:65
ogdf::StarInserter::~StarInserter
~StarInserter()
Destructor.
Definition: StarInserter.h:419
ogdf::EdgeOrderComparer::m_predecessors
const PredecessorMap & m_predecessors
Insertion path tree, given by several insertion paths.
Definition: StarInserter.h:76
ogdf::StarInserter::oldPrimalFace
face oldPrimalFace(node dualNode)
Returns the primal face of dualNode which existed before any new edges were inserted.
Definition: StarInserter.h:260
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:247
ogdf::StarInserter::StarInserter
StarInserter(const StarInserter &inserter)
Creates a StarInserter instance with the same settings as inserter.
Definition: StarInserter.h:416
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: DfsMakeBiconnected.h:40
ogdf::internal::GraphRegisteredArray
RegisteredArray for nodes, edges and adjEntries of a graph.
Definition: Graph_d.h:658
ogdf::FaceArrayBase
RegisteredArray for labeling the faces of a CombinatorialEmbedding.
Definition: CombinatorialEmbedding.h:181
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:464
ogdf::EdgeOrderComparer::compare
int compare(const edge &e1, const edge &e2) const
Compares two edges as described for EdgeOrderComparer.
Definition: StarInserter.h:146
ogdf::ConstCombinatorialEmbedding
Combinatorial embeddings of planar graphs.
Definition: CombinatorialEmbedding.h:216
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:256
ogdf::DualGraphBase::getPrimalEmbedding
Embedding & getPrimalEmbedding() const
Returns a reference to the combinatorial embedding of the primal graph.
Definition: DualGraph.h:141
ogdf::DualGraphBase::dualEdge
const edge & dualEdge(edge e) const
Returns the edge in the dual graph corresponding to e.
Definition: DualGraph.h:182
ogdf::StarInserter::m_combEmbedding
CombinatorialEmbedding * m_combEmbedding
Embedding of m_graphCopy.
Definition: StarInserter.h:241
basic.h
Basic declarations, included by all source files.
CombinatorialEmbedding.h
Declaration of CombinatorialEmbedding and face.
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:161
ogdf::CombinatorialEmbedding
Combinatorial embeddings of planar graphs with modification functionality.
Definition: CombinatorialEmbedding.h:406
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:111
ogdf::AdjElement::faceCycleSucc
adjEntry faceCycleSucc() const
Returns the cyclic successor in face.
Definition: Graph_d.h:212
ogdf::EdgeElement::opposite
node opposite(node v) const
Returns the adjacent node different from v.
Definition: Graph_d.h:413
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:252
ogdf::EdgeElement
Class for the representation of edges.
Definition: Graph_d.h:363
ogdf::EdgeOrderComparer::EdgeOrderComparer
EdgeOrderComparer(node origNode, node rootDualNode, const PredecessorMap &predecessors, const GraphCopy &graphCopy, const DynamicDualGraph *dualGraph)
Creates a new EdgeOrderComparer.
Definition: StarInserter.h:92
ogdf::StarInserter::m_graphCopy
GraphCopy * m_graphCopy
Planarization.
Definition: StarInserter.h:239
comparer.h
Declarations for Comparer objects.
ogdf::NodeElement
Class for the representation of nodes.
Definition: Graph_d.h:240
ogdf::internal::EdgeArrayBase2
RegisteredArray for edges of a graph, specialized for EdgeArray<edge>.
Definition: Graph_d.h:716
ogdf::FaceElement
Faces in a combinatorial embedding.
Definition: CombinatorialEmbedding.h:118