Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

QPartitioning.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 
36 namespace ogdf::sync_plan {
37 class QPartitioning; // IWYU pragma: keep
38 
39 #define OGDF_DECL_REG_ARRAY_TYPE(v, c) RegisteredArray<QPartitioning, v, c>
42 #undef OGDF_DECL_REG_ARRAY_TYPE
43 
46  public RegistryBase<int, QPartitioning, int> {
47 private:
50  int q_vertex_count = 0;
51  int partition_next_id = 0;
52 
53 public:
54  static inline int NO_PARTITION = -1;
55 
56  explicit QPartitioning(const Graph* G) : GraphObserver(G), partitions(*G, NO_PARTITION) {
57  partitioned_nodes.init(*this);
58  }
59 
60  bool isQVertex(node n) const;
61 
62  int getPartitionOf(node n) const;
63 
66  int makeQVertex(node n, int p = NO_PARTITION);
67 
68  void releaseQVertex(node n);
69 
70  int partitionCount() const { return partition_next_id; }
71 
72  int qVertexCount() const { return q_vertex_count; }
73 
74  const List<node>& nodesInPartition(int partition) const { return partitioned_nodes[partition]; }
75 
77  static inline int keyToIndex(int key) { return key; }
78 
80  bool isKeyAssociated(int key) const { return 0 <= key && key <= maxKeyIndex(); }
81 
83  int maxKeyIndex() const { return partition_next_id - 1; }
84 
86  int calculateArraySize(int add) const { return calculateTableSize(partition_next_id + add); }
87 
88  int begin() const { return 0; }
89 
90  int end() const { return partition_next_id; }
91 
92 protected:
93  void nodeDeleted(node v) override;
94 
95  void nodeAdded(node v) override {};
96 
97  void edgeDeleted(edge e) override {};
98 
99  void edgeAdded(edge e) override {};
100 
101  void cleared() override {
102  partitioned_nodes.fillWithDefault();
103  partitions.fill(NO_PARTITION);
104  q_vertex_count = 0;
105  partition_next_id = 0;
106  };
107 };
108 }
ogdf::RegistryBase
Abstract base class for registries.
Definition: RegisteredArray.h:95
ogdf::RegisteredArray
Dynamic arrays indexed with arbitrary keys.
Definition: RegisteredArray.h:808
OGDF_DECL_REG_ARRAY
#define OGDF_DECL_REG_ARRAY(NAME)
Definition: RegisteredArray.h:960
ogdf::sync_plan::QPartitioning::edgeAdded
void edgeAdded(edge e) override
Called by watched graph after an edge has been added.
Definition: QPartitioning.h:99
Graph.h
Includes declaration of graph class.
ogdf::sync_plan
Definition: clustering.h:44
ogdf::sync_plan::QPartitioning::partitioned_nodes
PartitionArray< List< node > > partitioned_nodes
Definition: QPartitioning.h:48
ogdf::sync_plan::QPartitioning::edgeDeleted
void edgeDeleted(edge e) override
Called by watched graph just before an edge is deleted.
Definition: QPartitioning.h:97
ogdf::sync_plan::QPartitioning
Manages the partitioning of Q-nodes in an instance of SyncPlan.
Definition: QPartitioning.h:45
ogdf::sync_plan::QPartitioning::partitions
NodeArray< int > partitions
Definition: QPartitioning.h:49
ogdf::sync_plan::QPartitioning::maxKeyIndex
int maxKeyIndex() const
Returns the maximum index of all keys managed by this registry.
Definition: QPartitioning.h:83
ogdf::sync_plan::QPartitioning::begin
int begin() const
Definition: QPartitioning.h:88
ogdf::sync_plan::PartitionArray
RegisteredArray< QPartitioning, Value, WithDefault > PartitionArray
RegisteredArray for labeling the partitions in a QPartitioning with an arbitrary Value.
Definition: QPartitioning.h:41
ogdf::sync_plan::QPartitioning::isKeyAssociated
bool isKeyAssociated(int key) const
Returns whether key is associated with this registry.
Definition: QPartitioning.h:80
ogdf::calculateTableSize
int calculateTableSize(int actualCount)
The default growth function for registered arrays.
Definition: RegisteredArray.h:58
ogdf::GraphObserver
Abstract Base class for graph observers.
Definition: Graph_d.h:770
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::Graph
Data type for general directed graphs (adjacency list representation).
Definition: Graph_d.h:862
ogdf::sync_plan::QPartitioning::partitionCount
int partitionCount() const
Definition: QPartitioning.h:70
ogdf::sync_plan::QPartitioning::nodeAdded
void nodeAdded(node v) override
Called by watched graph after a node has been added.
Definition: QPartitioning.h:95
ogdf::sync_plan::QPartitioning::calculateArraySize
int calculateArraySize(int add) const
Returns the array size currently requested by this registry.
Definition: QPartitioning.h:86
ogdf::sync_plan::QPartitioning::QPartitioning
QPartitioning(const Graph *G)
Definition: QPartitioning.h:56
ogdf::sync_plan::QPartitioning::qVertexCount
int qVertexCount() const
Definition: QPartitioning.h:72
OGDF_EXPORT
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF DLL.
Definition: config.h:101
ogdf::sync_plan::QPartitioning::end
int end() const
Definition: QPartitioning.h:90
ogdf::sync_plan::QPartitioning::keyToIndex
static int keyToIndex(int key)
Returns the index of key.
Definition: QPartitioning.h:77
ogdf::EdgeElement
Class for the representation of edges.
Definition: Graph_d.h:356
List.h
Declaration of doubly linked lists and iterators.
ogdf::RegisteredArray::init
void init(const Base *base=nullptr)
Reinitializes the array. Associates the array with the matching registry of base.
Definition: RegisteredArray.h:849
ogdf::sync_plan::QPartitioning::cleared
void cleared() override
Called by watched graph when its clear function is called, just before things are removed.
Definition: QPartitioning.h:101
ogdf::NodeElement
Class for the representation of nodes.
Definition: Graph_d.h:233
ogdf::sync_plan::QPartitioning::nodesInPartition
const List< node > & nodesInPartition(int partition) const
Definition: QPartitioning.h:74