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 <chrono>
46 #include <cstdint>
47 #include <functional>
48 #include <ostream>
49 #include <string>
50 #include <tuple>
51 #include <utility>
52 #include <vector>
53 
54 namespace ogdf::pc_tree {
55 class NodePCRotation;
56 class PCTree;
57 } // namespace ogdf::pc_tree
58 
59 namespace ogdf {
60 class ClusterGraph;
61 class ClusterGraphAttributes;
62 class GraphAttributes;
63 } // namespace ogdf
64 
66 
67 // // Profiling with LIKWID
68 // #ifdef LIKWID_PERFMON
69 // include <likwid.h>
70 // define SYNCPLAN_PROFILE_START(regionTag) likwid_markerStartRegion(regionTag);
71 // define SYNCPLAN_PROFILE_STOP(regionTag) likwid_markerStopRegion(regionTag);
72 // #else
73 // define SYNCPLAN_PROFILE_START(regionTag)
74 // define SYNCPLAN_PROFILE_STOP(regionTag)
75 // #endif
76 
77 // // Collection of JSON Operation Statistics
78 // define SYNCPLAN_OPSTATS
79 
80 namespace ogdf::sync_plan {
81 
82 namespace internal {
83 using tpc = std::chrono::high_resolution_clock;
84 using tp = const std::chrono::time_point<std::chrono::high_resolution_clock>;
85 
86 inline int64_t dur_ms(const tp::duration& d) {
87  return std::chrono::duration_cast<std::chrono::milliseconds>(d).count();
88 }
89 
90 inline int64_t dur_ns(const tp::duration& d) {
91  return std::chrono::duration_cast<std::chrono::nanoseconds>(d).count();
92 }
93 
95 
96 class UndoSimplify;
97 }
98 
100 enum class Operation {
108  BATCH_SPQR
109 };
110 
111 OGDF_EXPORT std::ostream& operator<<(std::ostream& os, Operation op);
112 
114 
125  friend class SyncPlanConsistency;
126 
127  friend class SyncPlanDrawer;
128 
129  friend class SyncPlanOptions;
130 
131  friend std::ostream& operator<<(std::ostream& os, const SyncPlan& pq);
132 
133  friend class UndoContract;
134 
135  friend class UndoConvertSmall;
136 
137  friend class UndoEncapsulate;
138 
139  friend class UndoInitCluster;
140 
141  friend class UndoPropagate;
142 
144 
145  friend class UndoSimplifyToroidal;
146 
147  friend class UndoMakeWheel;
148 
149  friend class EmbeddingTrees;
150 
151  // Inner Classes //////////////////////////////////////////////////////////////////////////////////////////////////
152 
153 public:
156  public:
157 #ifdef OGDF_DEBUG
158  int consistency_nr = -1;
159 #endif
160 
161  virtual ~UndoOperation() = default;
162 
163  virtual void undo(SyncPlan& pq) = 0;
164 
165  virtual std::ostream& print(std::ostream& os) const = 0;
166 
167  virtual std::string name() const;
168 
169  friend std::ostream& operator<<(std::ostream& os, const SyncPlan::UndoOperation& undo_op);
170  };
171 
174 
175  public:
176  explicit VerifyPipeBijections(SyncPlan& pq);
177 
178  void undo(SyncPlan& pq) override;
179 
180  std::ostream& print(std::ostream& os) const override;
181  };
182 
183  class ResetIndices : public UndoOperation {
184  int max_node, max_edge, count_node, count_edge;
185 
186  public:
187  explicit ResetIndices(SyncPlan& pq);
188 
189  void undo(SyncPlan& pq) override;
190 
191  std::ostream& print(std::ostream& os) const override;
192  };
193 
195  enum class Result { SUCCESS, NOT_APPLICABLE, INVALID_INSTANCE };
196 
197  // Members ////////////////////////////////////////////////////////////////////////////////////////////////////////
198 
199 public:
201  Graph* const G;
206 
207 #ifdef SYNCPLAN_OPSTATS
208  std::ofstream stats_out;
210  uint64_t stats_pc_time = 0;
211  bool stats_first_in_array = true;
212 #endif
213 
214 private:
221 #ifdef OGDF_DEBUG
222  NodeSet<> deletedNodes;
224 #endif
225  GraphAttributes* GA;
236  bool indices_saved = false;
238  bool allow_contract_bb_pipe = false;
240  bool intersect_trees = true;
242  bool batch_spqr = true;
244  int longestSimplifyToroidalCycle = 0;
245 
246 #ifdef OGDF_DEBUG
247  SyncPlanConsistency consistency;
249 #endif
250 
251  // Constructors ///////////////////////////////////////////////////////////////////////////////////////////////////
252 
253 public:
255 
281  explicit SyncPlan(Graph* g, GraphAttributes* ga = nullptr);
282 
284 
307  explicit SyncPlan(Graph* g, ClusterGraph* cg,
308  std::vector<std::pair<adjEntry, adjEntry>>* augmentation = nullptr,
309  ClusterGraphAttributes* ga = nullptr);
310 
312 
317  explicit SyncPlan(Graph* sefe, Graph* work, EdgeArray<uint8_t>& edge_types);
318 
319  virtual ~SyncPlan() {
320  while (!undo_stack.empty()) {
321  delete undo_stack.popBackRet();
322  }
323  }
324 
325  // Graph Utils /////////////////////////////////////////////////////////////////////////////////////////////////////
326 
327 private:
328  void formatNode(node n) const;
329 
330  std::function<std::ostream&(std::ostream&)> fmtPQNode(node n, bool include_comp = true) const;
331 
332  node nodeFromIndex(int idx) const;
333 
334  edge edgeFromIndex(int idx) const;
335 
336  void thawPipeBijection(node u, node v, const FrozenPipeBij& in, PipeBij& out) const;
337 
338  bool verifyPipeBijection(node u, node v, const FrozenPipeBij& bij) const;
339 
341  // room for improvement: don't generate UndoOps if we are never going to embed
342 #ifdef OGDF_DEBUG
343  operation->consistency_nr = consistency.getCheckCounter() - 1;
344 #endif
345  undo_stack.pushBack(operation);
346  OGDF_ASSERT(consistency.consistencyCheck());
347  }
348 
349  void pushUndoOperation(UndoOperation* operation) { undo_stack.pushBack(operation); }
350 
351  // Operations //////////////////////////////////////////////////////////////////////////////////////////////////////
352 
353 public:
356  void makeWheel(node centre, bool update_cuts = true);
357 
358  void contractWheel(node centre);
359 
360  Result convertSmall(node small);
361 
362  Result encapsulate(node g_cut);
363 
364  Result contract(node u);
365 
366  Result propagatePQ(node u, NodePCRotation* pct, NodePCRotation* pct_v = nullptr);
367 
368  Result simplify(node u, const NodePCRotation* pc);
369 
371  Result checkPCTree(node u);
372 
373  Result batchSPQR();
375 
376 public:
380  void initComponents();
381 
383  bool makeReduced(int check_planarity_every = 0);
384 
386  bool solveReduced(bool fail_fast = false);
387 
389  void embed();
390 
392 
393  // Statistics /////////////////////////////////////////////////////////////////////////////////////////////////////
396 
398  int undoOperations() const { return undo_stack.size(); }
399 
401  int getLongestSimplifyToroidalCycle() const { return longestSimplifyToroidalCycle; }
402 
404  const SyncPlanComponents& getComponents() const { return components; }
405 
406 #ifdef SYNCPLAN_OPSTATS
407 
408  void printOPStatsStart(const Pipe* p, Operation op, const NodePCRotation* pct = nullptr);
409 
410  void printOPStatsEnd(bool success, int64_t time_ns);
411 
412 #endif
413 
414  PipeType getPipeType(const Pipe* p) const;
415 
418  bool canContract(const Pipe* p) const;
419 
421 
423 
426 
427  bool isAllowContractBBPipe() const { return allow_contract_bb_pipe; }
428 
430  void setAllowContractBBPipe(bool allowContractBbPipe) {
431  allow_contract_bb_pipe = allowContractBbPipe;
432  }
433 
434  bool isIntersectTrees() const { return intersect_trees; }
435 
437  void setIntersectTrees(bool intersectTrees) { intersect_trees = intersectTrees; }
438 
439  bool isBatchSpqr() const { return batch_spqr; }
440 
442  void setBatchSpqr(bool batchSpqr) { batch_spqr = batchSpqr; }
443 
445 };
446 
447 }
ogdf
The namespace for all OGDF objects.
Definition: multilevelmixer.cpp:39
ogdf::GraphAttributes
Stores additional attributes of a graph (like layout information).
Definition: GraphAttributes.h:72
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:66
ogdf::sync_plan::SyncPlan::pushUndoOperationAndCheck
void pushUndoOperationAndCheck(UndoOperation *operation)
Definition: SyncPlan.h:340
ogdf::sync_plan::Operation::PROPAGATE_BICON
@ PROPAGATE_BICON
ogdf::sync_plan::SyncPlan::Result
Result
The result of applying a single operation.
Definition: SyncPlan.h:195
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:220
ogdf::sync_plan::SyncPlanConsistency::getCheckCounter
int getCheckCounter() const
Definition: SyncPlanConsistency.h:58
ogdf::Graph::HiddenEdgeSet
Functionality for temporarily hiding edges in constant time.
Definition: Graph_d.h:1224
ogdf::pc_tree
Definition: NodePCRotation.h:47
ogdf::sync_plan::QPartitioning
Manages the partitioning of Q-nodes in an instance of SyncPlan.
Definition: QPartitioning.h:46
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:118
ogdf::pc_tree::NodePCRotation
This class represents the embedding tree of a single node in a biconnected component.
Definition: NodePCRotation.h:54
ogdf::sync_plan::internal::tp
const std::chrono::time_point< std::chrono::high_resolution_clock > tp
Definition: SyncPlan.h:84
ogdf::NodeSet
Node sets.
Definition: GraphSets.h:57
ogdf::sync_plan::SyncPlanDrawer
Utilities by dumping a drawing of the current state of a SyncPlan instance.
Definition: SyncPlanDrawer.h:67
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:401
ogdf::sync_plan::Operation::SIMPLIFY_TOROIDAL
@ SIMPLIFY_TOROIDAL
ogdf::sync_plan::SyncPlan
A class for modelling and solving Synchronized Planarity instances.
Definition: SyncPlan.h:124
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:430
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:172
Logger.h
Contains logging functionality.
ogdf::sync_plan::SyncPlan::getComponents
const SyncPlanComponents & getComponents() const
The maintained (bi)connected components information.
Definition: SyncPlan.h:404
ogdf::sync_plan::SyncPlan::undo_stack
List< UndoOperation * > undo_stack
Stack of all operations that should be undone when embedding.
Definition: SyncPlan.h:216
ogdf::ClusterGraphAttributes
Stores additional attributes of a clustered graph (like layout information).
Definition: ClusterGraphAttributes.h:52
ogdf::sync_plan::internal::dur_ns
int64_t dur_ns(const tp::duration &d)
Definition: SyncPlan.h:90
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:437
ogdf::sync_plan::SyncPlan::matchings
PMatching matchings
Collection of all matched P-nodes and their pipes.
Definition: SyncPlan.h:203
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:86
ogdf::sync_plan::Operation
Operation
The reduction operations (and their distinct cases) implemented by SyncPlan.
Definition: SyncPlan.h:100
ogdf::sync_plan::SyncPlan::~SyncPlan
virtual ~SyncPlan()
Definition: SyncPlan.h:319
ogdf::sync_plan::internal::tpc
std::chrono::high_resolution_clock tpc
Definition: SyncPlan.h:83
ogdf::sync_plan::SyncPlanConsistency
Consistency checks for debugging the SyncPlan algorithm.
Definition: SyncPlanConsistency.h:42
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::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:869
ogdf::sync_plan::SyncPlan::components
SyncPlanComponents components
Data structure maintaining (bi)connected components information.
Definition: SyncPlan.h:218
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:1604
ogdf::sync_plan::SyncPlan::UndoOperation
The information needed for undoing the changes a specific operation made to the graph while maintaini...
Definition: SyncPlan.h:155
ogdf::sync_plan::SyncPlan::pushUndoOperation
void pushUndoOperation(UndoOperation *operation)
Definition: SyncPlan.h:349
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:398
basic.h
Basic declarations, included by all source files.
ogdf::sync_plan::SyncPlan::isAllowContractBBPipe
bool isAllowContractBBPipe() const
Definition: SyncPlan.h:427
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:232
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:205
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:183
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:972
ogdf::EdgeElement
Class for the representation of edges.
Definition: Graph_d.h:363
ogdf::sync_plan::SyncPlan::VerifyPipeBijections::pipes
List< std::tuple< int, int, FrozenPipeBij > > pipes
Definition: SyncPlan.h:173
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:228
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:1488
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:442
ogdf::sync_plan::Operation::SIMPLIFY_TRANSITIVE
@ SIMPLIFY_TRANSITIVE
ogdf::sync_plan::SyncPlanComponents
(Bi)Connected components information maintained during the SyncPlan algorithm.
Definition: SyncPlanComponents.h:58
ogdf::Logger
Centralized global and local logging facility working on streams like std::cout.
Definition: Logger.h:102
ogdf::sync_plan::internal::UndoSimplify
Definition: Simplify.h:75
ogdf::sync_plan::SyncPlan::G
Graph *const G
The underlying graph.
Definition: SyncPlan.h:201
QPartitioning.h
Manages the partitioning of Q-nodes in an instance of SyncPlan.
ogdf::sync_plan::SyncPlan::isIntersectTrees
bool isIntersectTrees() const
Definition: SyncPlan.h:434
ogdf::sync_plan::SyncPlan::ResetIndices::max_node
int max_node
Definition: SyncPlan.h:184
ogdf::ClusterGraph
Representation of clustered graphs.
Definition: ClusterGraph.h:346
ogdf::NodeElement
Class for the representation of nodes.
Definition: Graph_d.h:240
ogdf::sync_plan::SyncPlan::UndoOperation::consistency_nr
int consistency_nr
Definition: SyncPlan.h:158
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:1547
ogdf::sync_plan::SyncPlan::isBatchSpqr
bool isBatchSpqr() const
Definition: SyncPlan.h:439
ogdf::internal::EdgeArrayBase2
RegisteredArray for edges of a graph, specialized for EdgeArray<edge>.
Definition: Graph_d.h:716
ogdf::sync_plan::SyncPlan::log
Logger log
The logger to use.
Definition: SyncPlan.h:234
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:230