Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

PMatching.h
Go to the documentation of this file.
1 
31 #pragma once
32 
33 #include <ogdf/basic/Graph.h>
34 #include <ogdf/basic/List.h>
35 #include <ogdf/basic/basic.h>
37 
38 #include <functional>
39 #include <memory>
40 #include <ostream>
41 #include <utility>
42 
43 namespace ogdf::sync_plan {
45 
47 struct OGDF_EXPORT Pipe {
48  node node1, node2;
49  int pipe_priority = -1;
51  void* heap_entry = nullptr;
52  int heap_data = 0;
53 #ifdef OGDF_DEBUG
55 #endif
56 
57  Pipe(node node1, node node2);
58 
59  int degree() const;
60 
61  node getTwin(node n) const;
62 
63  friend std::ostream& operator<<(std::ostream& os, const Pipe& pipe);
64 };
65 
68  virtual ~PipeQueue() = default;
69 
70  virtual bool empty() = 0;
71 
72  virtual int size() = 0;
73 
74  virtual Pipe* getTop() = 0;
75 
76  virtual void addPipe(Pipe* p) = 0;
77 
78  virtual void removePipe(Pipe* p) = 0;
79 
80  virtual void rebuild(List<Pipe>& pipes_list) = 0;
81 
82  virtual void clear() = 0;
83 };
84 
86 class OGDF_EXPORT PMatching : protected GraphObserver {
87  friend class SyncPlanConsistency;
88 
89 private:
90  int priority_pipes = 0;
93  std::unique_ptr<PipeQueue> queue;
94 
95 public:
96  explicit PMatching(const Graph* G) : GraphObserver(G), nodes(*G, nullptr) { }
97 
98  bool isMatchedPVertex(node n) const;
99 
101  node getTwin(node n) const;
102 
103  node getTwinOrNull(node n) const;
104 
105  const Pipe* getPipe(node n) const;
106 
107  const Pipe& getTopPipe() const;
108 
110 
112 
113  const List<Pipe>& getPipes() const;
114 
115  int getPipeCount() const;
116 
118  bool isReduced() const;
119 
121  PipeBijRange getIncidentEdgeBijection(node u) const;
122 
123  void getIncidentEdgeBijection(node u, PipeBij& out) const;
124 
125  void getIncidentEdgeBijection(node u, AdjEntryArray<adjEntry>& out) const;
126 
127  void getIncidentEdgeBijection(node u, EdgeArray<edge>& out) const;
128 
129  adjEntry translateIncidentEdge(adjEntry e) const;
130 
131  std::function<std::ostream&(std::ostream&)> printBijection(node u) const;
132 
133  void matchNodes(node f, node s);
134 
135  node removeMatching(node n, node t = nullptr);
136 
138  void makePriority(node n);
139 
140  int getPriorityPipeCount() const { return priority_pipes; }
141 
143  void rebuildHeap();
144 
146  queue.reset(q);
147  rebuildHeap();
148  }
149 
150  void setPipeQueue(std::unique_ptr<PipeQueue> q) {
151  queue = std::move(q);
152  rebuildHeap();
153  }
154 
155  PipeQueue* getPipeQueue() const { return queue.get(); }
156 
157 protected:
158  void nodeDeleted(node v) override;
159 
160  void nodeAdded(node v) override {};
161 
162  void edgeDeleted(edge e) override {};
163 
164  void edgeAdded(edge e) override {};
165 
166  void cleared() override {
167  pipes_list.clear();
168  if (queue) {
169  queue->clear();
170  }
171  nodes.fill(nullptr);
172  };
173 };
174 }
ogdf::sync_plan::PipeQueue
A queue of all pipes, ordered by an arbitrary comparator function.
Definition: PMatching.h:67
ogdf::sync_plan::PMatching::setPipeQueue
void setPipeQueue(PipeQueue *q)
Definition: PMatching.h:145
Graph.h
Includes declaration of graph class.
ogdf::sync_plan::PMatching::nodes
NodeArray< Pipe * > nodes
Definition: PMatching.h:92
ogdf::sync_plan
Definition: clustering.h:44
ogdf::sync_plan::Pipe::node2
node node2
Definition: PMatching.h:48
ogdf::begin
HypergraphRegistry< HypernodeElement >::iterator begin(const HypergraphRegistry< HypernodeElement > &self)
ogdf::sync_plan::PMatching::getPipeQueue
PipeQueue * getPipeQueue() const
Definition: PMatching.h:155
ogdf::sync_plan::PMatching::setPipeQueue
void setPipeQueue(std::unique_ptr< PipeQueue > q)
Definition: PMatching.h:150
Bijection.h
Utilities for working with the bijections between the edges incident to the two endpoints of a Pipe.
ogdf::sync_plan::PMatching::queue
std::unique_ptr< PipeQueue > queue
Definition: PMatching.h:93
ogdf::sync_plan::Pipe::dbg_degree
int dbg_degree
Definition: PMatching.h:54
ogdf::sync_plan::PMatching::nodeAdded
void nodeAdded(node v) override
Called by watched graph after a node has been added.
Definition: PMatching.h:160
ogdf::sync_plan::Pipe
A pair of matched vertices of the same degree, whose rotation shall be synchronized.
Definition: PMatching.h:47
ogdf::AdjElement
Class for adjacency list elements.
Definition: Graph_d.h:142
ogdf::sync_plan::Pipe::list_entry
List< Pipe >::iterator list_entry
Definition: PMatching.h:50
ogdf::sync_plan::PMatching::getPriorityPipeCount
int getPriorityPipeCount() const
Definition: PMatching.h:140
backward::details::move
const T & move(const T &v)
Definition: backward.hpp:243
ogdf::sync_plan::PMatching::cleared
void cleared() override
Called by watched graph when its clear function is called, just before things are removed.
Definition: PMatching.h:166
ogdf::sync_plan::PipeType::CutCut
@ CutCut
ogdf::sync_plan::PMatching::pipes_list
List< Pipe > pipes_list
Definition: PMatching.h:91
ogdf::sync_plan::PMatching
Manages the matching of P-nodes via pipes in an instance of SyncPlan.
Definition: PMatching.h:86
ogdf::sync_plan::SyncPlanConsistency
Consistency checks for debugging the SyncPlan algorithm.
Definition: SyncPlanConsistency.h:42
ogdf::GraphObserver
Abstract Base class for graph observers.
Definition: Graph_d.h:777
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::Range
Simple before-C++20 version for std::ranges::ref_view.
Definition: Iterators.h:41
ogdf::sync_plan::PMatching::PMatching
PMatching(const Graph *G)
Definition: PMatching.h:96
ogdf::sync_plan::PipeType::BlockBlock
@ BlockBlock
ogdf::sync_plan::PMatching::edgeAdded
void edgeAdded(edge e) override
Called by watched graph after an edge has been added.
Definition: PMatching.h:164
ogdf::sync_plan::PipeType::BlockCut
@ BlockCut
basic.h
Basic declarations, included by all source files.
ogdf::end
HypergraphRegistry< HypernodeElement >::iterator end(const HypergraphRegistry< HypernodeElement > &self)
OGDF_EXPORT
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF DLL.
Definition: config.h:101
ogdf::sync_plan::PipeType
PipeType
Definition: PMatching.h:44
ogdf::EdgeElement
Class for the representation of edges.
Definition: Graph_d.h:363
List.h
Declaration of doubly linked lists and iterators.
ogdf::sync_plan::PMatching::edgeDeleted
void edgeDeleted(edge e) override
Called by watched graph just before an edge is deleted.
Definition: PMatching.h:162
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::List::clear
void clear()
Removes all elements from the list.
Definition: List.h:1626