Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Loading...
Searching...
No Matches
SyncPlan.h
Go to the documentation of this file.
1
31#pragma once
32
33
34#include <ogdf/basic/Graph.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
54namespace ogdf::pc_tree {
55class NodePCRotation;
56class PCTree;
57} // namespace ogdf::pc_tree
58
59namespace ogdf {
60class ClusterGraph;
61class ClusterGraphAttributes;
62class 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
80namespace ogdf::sync_plan {
81
82namespace internal {
83using tpc = std::chrono::high_resolution_clock;
84using tp = const std::chrono::time_point<std::chrono::high_resolution_clock>;
85
86inline int64_t dur_ms(const tp::duration& d) {
87 return std::chrono::duration_cast<std::chrono::milliseconds>(d).count();
88}
89
90inline int64_t dur_ns(const tp::duration& d) {
91 return std::chrono::duration_cast<std::chrono::nanoseconds>(d).count();
92}
93
95
96class UndoSimplify;
97}
98
110
111OGDF_EXPORT std::ostream& operator<<(std::ostream& os, Operation op);
112
114
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
153public:
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:
177
178 void undo(SyncPlan& pq) override;
179
180 std::ostream& print(std::ostream& os) const override;
181 };
182
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
199public:
201 Graph* const G;
206
207#ifdef SYNCPLAN_OPSTATS
209 std::ofstream stats_out;
210 uint64_t stats_pc_time = 0;
211 bool stats_first_in_array = true;
212#endif
213
214private:
221#ifdef OGDF_DEBUG
224#endif
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
249#endif
250
251 // Constructors ///////////////////////////////////////////////////////////////////////////////////////////////////
252
253public:
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
327private:
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
353public:
356 void makeWheel(node centre, bool update_cuts = true);
357
358 void contractWheel(node centre);
359
361
363
365
367
369
372
375
376public:
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}
Utilities for working with the bijections between the edges incident to the two endpoints of a Pipe.
Includes declaration of graph class.
Declaration and implementation of NodeSet, EdgeSet, and AdjEntrySet classes.
Declaration of doubly linked lists and iterators.
Contains logging functionality.
Manages the matching of P-nodes via pipes in an instance of SyncPlan.
Manages the partitioning of Q-nodes in an instance of SyncPlan.
(Bi)Connected components information maintained during the SyncPlan algorithm.
Consistency checks for debugging the SyncPlan algorithm.
Basic declarations, included by all source files.
Stores additional attributes of a clustered graph (like layout information).
Representation of clustered graphs.
Class for the representation of edges.
Definition Graph_d.h:364
Functionality for temporarily hiding edges in constant time.
Definition Graph_d.h:1222
Stores additional attributes of a graph (like layout information).
Data type for general directed graphs (adjacency list representation).
Definition Graph_d.h:866
Doubly linked lists (maintaining the length of the list).
Definition List.h:1451
int size() const
Returns the number of elements in the list.
Definition List.h:1488
iterator pushBack(const E &x)
Adds element x at the end of the list.
Definition List.h:1547
E popBackRet()
Removes the last element from the list and returns it.
Definition List.h:1604
bool empty() const
Returns true iff the list is empty.
Definition List.h:286
Centralized global and local logging facility working on streams like std::cout.
Definition Logger.h:102
Class for the representation of nodes.
Definition Graph_d.h:241
Node sets.
Definition GraphSets.h:54
RegisteredArray for edges of a graph, specialized for EdgeArray<edge>.
Definition Graph_d.h:717
RegisteredArray for nodes, edges and adjEntries of a graph.
Definition Graph_d.h:659
This class represents the embedding tree of a single node in a biconnected component.
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
Manages the matching of P-nodes via pipes in an instance of SyncPlan.
Definition PMatching.h:86
Manages the partitioning of Q-nodes in an instance of SyncPlan.
std::ostream & print(std::ostream &os) const override
void undo(SyncPlan &pq) override
The information needed for undoing the changes a specific operation made to the graph while maintaini...
Definition SyncPlan.h:155
friend std::ostream & operator<<(std::ostream &os, const SyncPlan::UndoOperation &undo_op)
virtual void undo(SyncPlan &pq)=0
virtual std::ostream & print(std::ostream &os) const =0
virtual std::string name() const
std::ostream & print(std::ostream &os) const override
List< std::tuple< int, int, FrozenPipeBij > > pipes
Definition SyncPlan.h:173
(Bi)Connected components information maintained during the SyncPlan algorithm.
Consistency checks for debugging the SyncPlan algorithm.
bool consistencyCheck(bool force_check_components=false)
Utilities by dumping a drawing of the current state of a SyncPlan instance.
A class for modelling and solving Synchronized Planarity instances.
Definition SyncPlan.h:124
void contractWheel(node centre)
Result simplify(node u, const NodePCRotation *pc)
Graph *const G
The underlying graph.
Definition SyncPlan.h:201
std::function< std::ostream &(std::ostream &)> fmtPQNode(node n, bool include_comp=true) const
PipeType getPipeType(const Pipe *p) const
void setBatchSpqr(bool batchSpqr)
Configure whether embedding trees should be computed in batch by deriving them from an SPQR-tree.
Definition SyncPlan.h:442
void pushUndoOperationAndCheck(UndoOperation *operation)
Definition SyncPlan.h:340
EdgeArray< edge > edge_reg
A mapping of edge-index to edge-object used while undoing operations.
Definition SyncPlan.h:230
node nodeFromIndex(int idx) const
Result propagatePQ(node u, NodePCRotation *pct, NodePCRotation *pct_v=nullptr)
bool makeReduced(int check_planarity_every=0)
Apply operations (in the order defined by the current PipeQueue) until no pipes are left.
NodeArray< node > node_reg
A mapping of node-index to node-object used while undoing operations.
Definition SyncPlan.h:228
bool verifyPipeBijection(node u, node v, const FrozenPipeBij &bij) const
SyncPlan(Graph *sefe, Graph *work, EdgeArray< uint8_t > &edge_types)
Create a new SyncPlan instance using the reduction from a 2-SEFE instance with a connected shared gra...
void formatNode(node n) const
SyncPlanConsistency consistency
Consistency checking utils.
Definition SyncPlan.h:248
edge edgeFromIndex(int idx) const
Result convertSmall(node small)
NodeArray< bool > is_wheel
Labels nodes whether they are already part of a (Q-node-replacement) wheel.
Definition SyncPlan.h:232
bool isAllowContractBBPipe() const
Definition SyncPlan.h:427
GraphAttributes * GA
If non-null, will be updated with debugging information from applied operations.
Definition SyncPlan.h:226
QPartitioning partitions
Collection of all Q-nodes and their partitions.
Definition SyncPlan.h:205
friend std::ostream & operator<<(std::ostream &os, const SyncPlan &pq)
SyncPlan(Graph *g, ClusterGraph *cg, std::vector< std::pair< adjEntry, adjEntry > > *augmentation=nullptr, ClusterGraphAttributes *ga=nullptr)
Create a new Synchronized Planarity instance by applying the reduction from some ClusteredPlanarity i...
int undoOperations() const
The number of operations that need undoing.
Definition SyncPlan.h:398
SyncPlan(Graph *g, GraphAttributes *ga=nullptr)
Create a new Synchronized Planarity instance with a given underlying graph.
void makeWheel(node centre, bool update_cuts=true)
void pushUndoOperation(UndoOperation *operation)
Definition SyncPlan.h:349
void setAllowContractBBPipe(bool allowContractBbPipe)
Configure whether block-block pipes can be contracted.
Definition SyncPlan.h:430
Graph::HiddenEdgeSet deletedEdges
Set of all edge objects deleted during the reduction, to be restored when undoing all operations.
Definition SyncPlan.h:220
bool isIntersectTrees() const
Definition SyncPlan.h:434
bool solveReduced(bool fail_fast=false)
Solve a reduced instance, creating a combinatorial embedding of the current graph that respects all Q...
Result
The result of applying a single operation.
Definition SyncPlan.h:195
NodeSet deletedNodes
Set of all node objects deleted during the reduction. Will remain as isolated nodes within G.
Definition SyncPlan.h:223
Result encapsulate(node g_cut)
bool isBatchSpqr() const
Definition SyncPlan.h:439
SyncPlanComponents components
Data structure maintaining (bi)connected components information.
Definition SyncPlan.h:218
void embed()
Undo all operations while maintaining the current embedding to obtain an embedding of the initial gra...
PMatching matchings
Collection of all matched P-nodes and their pipes.
Definition SyncPlan.h:203
void thawPipeBijection(node u, node v, const FrozenPipeBij &in, PipeBij &out) const
List< UndoOperation * > undo_stack
Stack of all operations that should be undone when embedding.
Definition SyncPlan.h:216
bool canContract(const Pipe *p) const
Check whether a Pipe can be removed by applying contract().
int getLongestSimplifyToroidalCycle() const
Return the longest cycle length encountered in simplify toroidal.
Definition SyncPlan.h:401
const SyncPlanComponents & getComponents() const
The maintained (bi)connected components information.
Definition SyncPlan.h:404
void setIntersectTrees(bool intersectTrees)
Configure whether the embedding trees of block-block pipes should be intersected before propagating.
Definition SyncPlan.h:437
Result checkPCTree(node u)
Computes an embedding tree and either applies propagatePQ() or simplify()
Logger log
The logger to use.
Definition SyncPlan.h:234
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF dynamic library (shared object / DLL),...
Definition config.h:117
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition basic.h:52
int64_t dur_ms(const tp::duration &d)
Definition SyncPlan.h:86
int sumPNodeDegrees(const ogdf::pc_tree::PCTree &pct)
const std::chrono::time_point< std::chrono::high_resolution_clock > tp
Definition SyncPlan.h:84
std::chrono::high_resolution_clock tpc
Definition SyncPlan.h:83
int64_t dur_ns(const tp::duration &d)
Definition SyncPlan.h:90
std::ostream & operator<<(std::ostream &os, Operation op)
Operation
The reduction operations (and their distinct cases) implemented by SyncPlan.
Definition SyncPlan.h:100
The namespace for all OGDF objects.
A pair of matched vertices of the same degree, whose rotation shall be synchronized.
Definition PMatching.h:47