Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

SyncPlan.h
Go to the documentation of this file.
1 
31 #pragma once
32 
33 
34 #include <ogdf/basic/Graph.h>
35 #include <ogdf/basic/GraphSets.h>
36 #include <ogdf/basic/List.h>
37 #include <ogdf/basic/Logger.h>
38 #include <ogdf/basic/basic.h>
44 
45 #include <cstdint>
46 #include <functional>
47 #include <ostream>
48 #include <string>
49 #include <tuple>
50 #include <utility>
51 #include <vector>
52 
53 namespace ogdf::pc_tree {
54 class NodePCRotation;
55 class PCTree;
56 } // namespace ogdf::pc_tree
57 
58 namespace ogdf {
59 class ClusterGraph;
60 class ClusterGraphAttributes;
61 class GraphAttributes;
62 } // namespace ogdf
63 
65 
66 // // Profiling with LIKWID
67 // #ifdef LIKWID_PERFMON
68 // include <likwid.h>
69 // define SYNCPLAN_PROFILE_START(regionTag) likwid_markerStartRegion(regionTag);
70 // define SYNCPLAN_PROFILE_STOP(regionTag) likwid_markerStopRegion(regionTag);
71 // #else
72 // define SYNCPLAN_PROFILE_START(regionTag)
73 // define SYNCPLAN_PROFILE_STOP(regionTag)
74 // #endif
75 
76 // // Collection of JSON Operation Statistics
77 // define SYNCPLAN_OPSTATS
78 
79 namespace ogdf::sync_plan {
80 
81 namespace internal {
82 using tpc = std::chrono::high_resolution_clock;
83 using tp = const std::chrono::time_point<std::chrono::high_resolution_clock>;
84 
85 inline int64_t dur_ms(const tp::duration& d) {
86  return std::chrono::duration_cast<std::chrono::milliseconds>(d).count();
87 }
88 
89 inline int64_t dur_ns(const tp::duration& d) {
90  return std::chrono::duration_cast<std::chrono::nanoseconds>(d).count();
91 }
92 
94 
95 class UndoSimplify;
96 }
97 
99 enum class Operation {
107  BATCH_SPQR
108 };
109 
110 OGDF_EXPORT std::ostream& operator<<(std::ostream& os, Operation op);
111 
113 
124  friend class SyncPlanConsistency;
125 
126  friend class SyncPlanDrawer;
127 
128  friend class SyncPlanOptions;
129 
130  friend std::ostream& operator<<(std::ostream& os, const SyncPlan& pq);
131 
132  friend class UndoContract;
133 
134  friend class UndoConvertSmall;
135 
136  friend class UndoEncapsulate;
137 
138  friend class UndoInitCluster;
139 
140  friend class UndoPropagate;
141 
143 
144  friend class UndoSimplifyToroidal;
145 
146  friend class UndoMakeWheel;
147 
148  friend class EmbeddingTrees;
149 
150  // Inner Classes //////////////////////////////////////////////////////////////////////////////////////////////////
151 
152 public:
155  public:
156 #ifdef OGDF_DEBUG
157  int consistency_nr = -1;
158 #endif
159 
160  virtual ~UndoOperation() = default;
161 
162  virtual void undo(SyncPlan& pq) = 0;
163 
164  virtual std::ostream& print(std::ostream& os) const = 0;
165 
166  virtual std::string name() const;
167 
168  friend std::ostream& operator<<(std::ostream& os, const SyncPlan::UndoOperation& undo_op);
169  };
170 
173 
174  public:
175  explicit VerifyPipeBijections(SyncPlan& pq);
176 
177  void undo(SyncPlan& pq) override;
178 
179  std::ostream& print(std::ostream& os) const override;
180  };
181 
182  class ResetIndices : public UndoOperation {
183  int max_node, max_edge, count_node, count_edge;
184 
185  public:
186  explicit ResetIndices(SyncPlan& pq);
187 
188  void undo(SyncPlan& pq) override;
189 
190  std::ostream& print(std::ostream& os) const override;
191  };
192 
194  enum class Result { SUCCESS, NOT_APPLICABLE, INVALID_INSTANCE };
195 
196  // Members ////////////////////////////////////////////////////////////////////////////////////////////////////////
197 
198 public:
200  Graph* const G;
205 
206 #ifdef SYNCPLAN_OPSTATS
207  std::ofstream stats_out;
209  uint64_t stats_pc_time = 0;
210  bool stats_first_in_array = true;
211 #endif
212 
213 private:
220 #ifdef OGDF_DEBUG
221  NodeSet<> deletedNodes;
223 #endif
224  GraphAttributes* GA;
235  bool indices_saved = false;
237  bool allow_contract_bb_pipe = false;
239  bool intersect_trees = true;
241  bool batch_spqr = true;
243  int longestSimplifyToroidalCycle = 0;
244 
245 #ifdef OGDF_DEBUG
246  SyncPlanConsistency consistency;
248 #endif
249 
250  // Constructors ///////////////////////////////////////////////////////////////////////////////////////////////////
251 
252 public:
254 
280  explicit SyncPlan(Graph* g, GraphAttributes* ga = nullptr);
281 
283 
306  explicit SyncPlan(Graph* g, ClusterGraph* cg,
307  std::vector<std::pair<adjEntry, adjEntry>>* augmentation = nullptr,
308  ClusterGraphAttributes* ga = nullptr);
309 
311 
316  explicit SyncPlan(Graph* sefe, Graph* work, EdgeArray<uint8_t>& edge_types);
317 
318  virtual ~SyncPlan() {
319  while (!undo_stack.empty()) {
320  delete undo_stack.popBackRet();
321  }
322  }
323 
324  // Graph Utils /////////////////////////////////////////////////////////////////////////////////////////////////////
325 
326 private:
327  void formatNode(node n) const;
328 
329  std::function<std::ostream&(std::ostream&)> fmtPQNode(node n, bool include_comp = true) const;
330 
331  node nodeFromIndex(int idx) const;
332 
333  edge edgeFromIndex(int idx) const;
334 
335  void thawPipeBijection(node u, node v, const FrozenPipeBij& in, PipeBij& out) const;
336 
337  bool verifyPipeBijection(node u, node v, const FrozenPipeBij& bij) const;
338 
340  // room for improvement: don't generate UndoOps if we are never going to embed
341 #ifdef OGDF_DEBUG
342  operation->consistency_nr = consistency.getCheckCounter() - 1;
343 #endif
344  undo_stack.pushBack(operation);
345  OGDF_ASSERT(consistency.consistencyCheck());
346  }
347 
348  void pushUndoOperation(UndoOperation* operation) { undo_stack.pushBack(operation); }
349 
350  // Operations //////////////////////////////////////////////////////////////////////////////////////////////////////
351 
352 public:
355  void makeWheel(node centre, bool update_cuts = true);
356 
357  void contractWheel(node centre);
358 
359  Result convertSmall(node small);
360 
361  Result encapsulate(node g_cut);
362 
363  Result contract(node u);
364 
365  Result propagatePQ(node u, NodePCRotation* pct, NodePCRotation* pct_v = nullptr);
366 
367  Result simplify(node u, const NodePCRotation* pc);
368 
370  Result checkPCTree(node u);
371 
372  Result batchSPQR();
374 
375 public:
379  void initComponents();
380 
382  bool makeReduced(int check_planarity_every = 0);
383 
385  bool solveReduced(bool fail_fast = false);
386 
388  void embed();
389 
391 
392  // Statistics /////////////////////////////////////////////////////////////////////////////////////////////////////
395 
397  int undoOperations() const { return undo_stack.size(); }
398 
400  int getLongestSimplifyToroidalCycle() const { return longestSimplifyToroidalCycle; }
401 
403  const SyncPlanComponents& getComponents() const { return components; }
404 
405 #ifdef SYNCPLAN_OPSTATS
406 
407  void printOPStatsStart(const Pipe* p, Operation op, const NodePCRotation* pct = nullptr);
408 
409  void printOPStatsEnd(bool success, int64_t time_ns);
410 
411 #endif
412 
413  PipeType getPipeType(const Pipe* p) const;
414 
417  bool canContract(const Pipe* p) const;
418 
420 
422 
425 
426  bool isAllowContractBBPipe() const { return allow_contract_bb_pipe; }
427 
429  void setAllowContractBBPipe(bool allowContractBbPipe) {
430  allow_contract_bb_pipe = allowContractBbPipe;
431  }
432 
433  bool isIntersectTrees() const { return intersect_trees; }
434 
436  void setIntersectTrees(bool intersectTrees) { intersect_trees = intersectTrees; }
437 
438  bool isBatchSpqr() const { return batch_spqr; }
439 
441  void setBatchSpqr(bool batchSpqr) { batch_spqr = batchSpqr; }
442 
444 };
445 
446 }
ogdf
The namespace for all OGDF objects.
Definition: AugmentationModule.h:36
ogdf::GraphAttributes
Stores additional attributes of a graph (like layout information).
Definition: GraphAttributes.h:66
ogdf::sync_plan::SyncPlanConsistency::consistencyCheck
bool consistencyCheck(bool force_check_components=false)
PMatching.h
Manages the matching of P-nodes via pipes in an instance of SyncPlan.
Graph.h
Includes declaration of graph class.
ogdf::sync_plan::Operation::PROPAGATE_CUT
@ PROPAGATE_CUT
ogdf::sync_plan
Definition: clustering.h:44
OGDF_ASSERT
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition: basic.h:54
ogdf::sync_plan::SyncPlan::pushUndoOperationAndCheck
void pushUndoOperationAndCheck(UndoOperation *operation)
Definition: SyncPlan.h:339
ogdf::sync_plan::Operation::PROPAGATE_BICON
@ PROPAGATE_BICON
ogdf::sync_plan::SyncPlan::Result
Result
The result of applying a single operation.
Definition: SyncPlan.h:194
ogdf::sync_plan::SyncPlan::deletedEdges
Graph::HiddenEdgeSet deletedEdges
Set of all edge objects deleted during the reduction, to be restored when undoing all operations.
Definition: SyncPlan.h:219
ogdf::sync_plan::SyncPlanConsistency::getCheckCounter
int getCheckCounter() const
Definition: SyncPlanConsistency.h:57
ogdf::Graph::HiddenEdgeSet
Functionality for temporarily hiding edges in constant time.
Definition: Graph_d.h:1216
ogdf::pc_tree
Definition: NodePCRotation.h:37
ogdf::sync_plan::QPartitioning
Manages the partitioning of Q-nodes in an instance of SyncPlan.
Definition: QPartitioning.h:45
Bijection.h
Utilities for working with the bijections between the edges incident to the two endpoints of a Pipe.
ogdf::pc_tree::PCTree
A PC-tree represents a set of cyclic orders of its leaves by labeling its inner nodes as either P- or...
Definition: PCTree.h:109
ogdf::pc_tree::NodePCRotation
This class represents the embedding tree of a single node in a biconnected component.
Definition: NodePCRotation.h:44
ogdf::sync_plan::internal::tp
const std::chrono::time_point< std::chrono::high_resolution_clock > tp
Definition: SyncPlan.h:83
ogdf::NodeSet
Node sets.
Definition: GraphSets.h:52
ogdf::sync_plan::SyncPlanDrawer
Utilities by dumping a drawing of the current state of a SyncPlan instance.
Definition: SyncPlanDrawer.h:63
SyncPlanComponents.h
(Bi)Connected components information maintained during the SyncPlan algorithm.
ogdf::sync_plan::SyncPlan::getLongestSimplifyToroidalCycle
int getLongestSimplifyToroidalCycle() const
Return the longest cycle length encountered in simplify toroidal.
Definition: SyncPlan.h:400
ogdf::sync_plan::Operation::SIMPLIFY_TOROIDAL
@ SIMPLIFY_TOROIDAL
ogdf::sync_plan::SyncPlan
A class for modelling and solving Synchronized Planarity instances.
Definition: SyncPlan.h:123
GraphSets.h
Declaration and implementation of NodeSet, EdgeSet, and AdjEntrySet classes.
ogdf::sync_plan::SyncPlan::setAllowContractBBPipe
void setAllowContractBBPipe(bool allowContractBbPipe)
Configure whether block-block pipes can be contracted.
Definition: SyncPlan.h:429
ogdf::sync_plan::Pipe
A pair of matched vertices of the same degree, whose rotation shall be synchronized.
Definition: PMatching.h:47
ogdf::sync_plan::SyncPlan::VerifyPipeBijections
Definition: SyncPlan.h:171
Logger.h
Contains logging functionality.
ogdf::sync_plan::SyncPlan::getComponents
const SyncPlanComponents & getComponents() const
The maintained (bi)connected components information.
Definition: SyncPlan.h:403
ogdf::sync_plan::SyncPlan::undo_stack
List< UndoOperation * > undo_stack
Stack of all operations that should be undone when embedding.
Definition: SyncPlan.h:215
ogdf::ClusterGraphAttributes
Stores additional attributes of a clustered graph (like layout information).
Definition: ClusterGraphAttributes.h:46
ogdf::sync_plan::internal::dur_ns
int64_t dur_ns(const tp::duration &d)
Definition: SyncPlan.h:89
ogdf::sync_plan::Operation::ENCAPSULATE_CONTRACT
@ ENCAPSULATE_CONTRACT
ogdf::sync_plan::SyncPlan::setIntersectTrees
void setIntersectTrees(bool intersectTrees)
Configure whether the embedding trees of block-block pipes should be intersected before propagating.
Definition: SyncPlan.h:436
ogdf::sync_plan::SyncPlan::matchings
PMatching matchings
Collection of all matched P-nodes and their pipes.
Definition: SyncPlan.h:202
ogdf::sync_plan::PMatching
Manages the matching of P-nodes via pipes in an instance of SyncPlan.
Definition: PMatching.h:86
ogdf::sync_plan::internal::dur_ms
int64_t dur_ms(const tp::duration &d)
Definition: SyncPlan.h:85
ogdf::sync_plan::Operation
Operation
The reduction operations (and their distinct cases) implemented by SyncPlan.
Definition: SyncPlan.h:99
ogdf::sync_plan::SyncPlan::~SyncPlan
virtual ~SyncPlan()
Definition: SyncPlan.h:318
ogdf::sync_plan::internal::tpc
std::chrono::high_resolution_clock tpc
Definition: SyncPlan.h:82
ogdf::sync_plan::SyncPlanConsistency
Consistency checks for debugging the SyncPlan algorithm.
Definition: SyncPlanConsistency.h:41
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::sync_plan::operator<<
std::ostream & operator<<(std::ostream &os, Operation op)
ogdf::Graph
Data type for general directed graphs (adjacency list representation).
Definition: Graph_d.h:862
ogdf::sync_plan::SyncPlan::components
SyncPlanComponents components
Data structure maintaining (bi)connected components information.
Definition: SyncPlan.h:217
ogdf::sync_plan::Operation::CONTRACT_BICON
@ CONTRACT_BICON
ogdf::List::popBackRet
E popBackRet()
Removes the last element from the list and returns it.
Definition: List.h:1594
ogdf::sync_plan::SyncPlan::UndoOperation
The information needed for undoing the changes a specific operation made to the graph while maintaini...
Definition: SyncPlan.h:154
ogdf::sync_plan::SyncPlan::pushUndoOperation
void pushUndoOperation(UndoOperation *operation)
Definition: SyncPlan.h:348
ogdf::sync_plan::internal::sumPNodeDegrees
int sumPNodeDegrees(const ogdf::pc_tree::PCTree &pct)
ogdf::sync_plan::Operation::SIMPLIFY_TERMINAL
@ SIMPLIFY_TERMINAL
ogdf::sync_plan::SyncPlan::undoOperations
int undoOperations() const
The number of operations that need undoing.
Definition: SyncPlan.h:397
basic.h
Basic declarations, included by all source files.
ogdf::sync_plan::SyncPlan::isAllowContractBBPipe
bool isAllowContractBBPipe() const
Definition: SyncPlan.h:426
ogdf::sync_plan::SyncPlan::is_wheel
NodeArray< bool > is_wheel
Labels nodes whether they are already part of a (Q-node-replacement) wheel.
Definition: SyncPlan.h:231
OGDF_EXPORT
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF DLL.
Definition: config.h:101
ogdf::sync_plan::SyncPlan::partitions
QPartitioning partitions
Collection of all Q-nodes and their partitions.
Definition: SyncPlan.h:204
ogdf::sync_plan::formatNode
void formatNode(node n, GraphAttributes *ga, int group)
Simple util for apply a default style to nodes, including a group-based coloring.
ogdf::sync_plan::SyncPlan::ResetIndices
Definition: SyncPlan.h:182
ogdf::sync_plan::PipeType
PipeType
Definition: PMatching.h:44
ogdf::print
void print(std::ostream &os, const Array< E, INDEX > &a, char delim=' ')
Prints array a to output stream os using delimiter delim.
Definition: Array.h:967
ogdf::EdgeElement
Class for the representation of edges.
Definition: Graph_d.h:356
ogdf::sync_plan::SyncPlan::VerifyPipeBijections::pipes
List< std::tuple< int, int, FrozenPipeBij > > pipes
Definition: SyncPlan.h:172
List.h
Declaration of doubly linked lists and iterators.
ogdf::sync_plan::SyncPlan::node_reg
NodeArray< node > node_reg
A mapping of node-index to node-object used while undoing operations.
Definition: SyncPlan.h:227
SyncPlanConsistency.h
Consistency checks for debugging the SyncPlan algorithm.
ogdf::List::size
int size() const
Returns the number of elements in the list.
Definition: List.h:1478
ogdf::sync_plan::SyncPlan::setBatchSpqr
void setBatchSpqr(bool batchSpqr)
Configure whether embedding trees should be computed in batch by deriving them from an SPQR-tree.
Definition: SyncPlan.h:441
ogdf::sync_plan::Operation::SIMPLIFY_TRANSITIVE
@ SIMPLIFY_TRANSITIVE
ogdf::sync_plan::SyncPlanComponents
(Bi)Connected components information maintained during the SyncPlan algorithm.
Definition: SyncPlanComponents.h:57
ogdf::Logger
Centralized global and local logging facility working on streams like std::cout.
Definition: Logger.h:100
ogdf::sync_plan::internal::UndoSimplify
Definition: Simplify.h:76
ogdf::sync_plan::SyncPlan::G
Graph *const G
The underlying graph.
Definition: SyncPlan.h:200
QPartitioning.h
Manages the partitioning of Q-nodes in an instance of SyncPlan.
ogdf::sync_plan::SyncPlan::isIntersectTrees
bool isIntersectTrees() const
Definition: SyncPlan.h:433
ogdf::sync_plan::SyncPlan::ResetIndices::max_node
int max_node
Definition: SyncPlan.h:183
ogdf::ClusterGraph
Representation of clustered graphs.
Definition: ClusterGraph.h:339
ogdf::NodeElement
Class for the representation of nodes.
Definition: Graph_d.h:233
ogdf::sync_plan::SyncPlan::UndoOperation::consistency_nr
int consistency_nr
Definition: SyncPlan.h:157
ogdf::sync_plan::Operation::BATCH_SPQR
@ BATCH_SPQR
ogdf::List::pushBack
iterator pushBack(const E &x)
Adds element x at the end of the list.
Definition: List.h:1537
ogdf::sync_plan::SyncPlan::isBatchSpqr
bool isBatchSpqr() const
Definition: SyncPlan.h:438
ogdf::internal::EdgeArrayBase2
RegisteredArray for edges of a graph, specialized for EdgeArray<edge>.
Definition: Graph_d.h:709
ogdf::sync_plan::SyncPlan::log
Logger log
The logger to use.
Definition: SyncPlan.h:233
ogdf::sync_plan::SyncPlan::edge_reg
EdgeArray< edge > edge_reg
A mapping of edge-index to edge-object used while undoing operations.
Definition: SyncPlan.h:229