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 #include <ogdf/basic/basic.h>
36 
37 namespace ogdf::sync_plan {
38 class QPartitioning; // IWYU pragma: keep
39 
40 #define OGDF_DECL_REG_ARRAY_TYPE(v, c) RegisteredArray<QPartitioning, v, c>
43 #undef OGDF_DECL_REG_ARRAY_TYPE
44 
47  public RegistryBase<int, QPartitioning, int> {
48 private:
51  int q_vertex_count = 0;
52  int partition_next_id = 0;
53 
54 public:
55  static inline int NO_PARTITION = -1;
56 
57  explicit QPartitioning(const Graph* G) : GraphObserver(G), partitions(*G, NO_PARTITION) {
58  partitioned_nodes.init(*this);
59  }
60 
61  bool isQVertex(node n) const;
62 
63  int getPartitionOf(node n) const;
64 
67  int makeQVertex(node n, int p = NO_PARTITION);
68 
69  void releaseQVertex(node n);
70 
71  int partitionCount() const { return partition_next_id; }
72 
73  int qVertexCount() const { return q_vertex_count; }
74 
75  const List<node>& nodesInPartition(int partition) const { return partitioned_nodes[partition]; }
76 
78  static inline int keyToIndex(int key) { return key; }
79 
81  bool isKeyAssociated(int key) const { return 0 <= key && key <= maxKeyIndex(); }
82 
84  int maxKeyIndex() const { return partition_next_id - 1; }
85 
87  int calculateArraySize(int add) const { return calculateTableSize(partition_next_id + add); }
88 
89  int begin() const { return 0; }
90 
91  int end() const { return partition_next_id; }
92 
93 protected:
94  void nodeDeleted(node v) override;
95 
96  void nodeAdded(node v) override {};
97 
98  void edgeDeleted(edge e) override {};
99 
100  void edgeAdded(edge e) override {};
101 
102  void cleared() override {
103  partitioned_nodes.fillWithDefault();
104  partitions.fill(NO_PARTITION);
105  q_vertex_count = 0;
106  partition_next_id = 0;
107  };
108 };
109 }
ogdf::RegistryBase
Abstract base class for registries.
Definition: RegisteredArray.h:104
ogdf::RegisteredArray
Dynamic arrays indexed with arbitrary keys.
Definition: RegisteredArray.h:817
OGDF_DECL_REG_ARRAY
#define OGDF_DECL_REG_ARRAY(NAME)
Definition: RegisteredArray.h:969
ogdf::sync_plan::QPartitioning::edgeAdded
void edgeAdded(edge e) override
Called by watched graph after an edge has been added.
Definition: QPartitioning.h:100
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:49
ogdf::sync_plan::QPartitioning::edgeDeleted
void edgeDeleted(edge e) override
Called by watched graph just before an edge is deleted.
Definition: QPartitioning.h:98
ogdf::sync_plan::QPartitioning
Manages the partitioning of Q-nodes in an instance of SyncPlan.
Definition: QPartitioning.h:46
ogdf::sync_plan::QPartitioning::partitions
NodeArray< int > partitions
Definition: QPartitioning.h:50
ogdf::sync_plan::QPartitioning::maxKeyIndex
int maxKeyIndex() const
Returns the maximum index of all keys managed by this registry.
Definition: QPartitioning.h:84
ogdf::sync_plan::QPartitioning::begin
int begin() const
Definition: QPartitioning.h:89
ogdf::sync_plan::PartitionArray
RegisteredArray< QPartitioning, Value, WithDefault > PartitionArray
RegisteredArray for labeling the partitions in a QPartitioning with an arbitrary Value.
Definition: QPartitioning.h:42
ogdf::sync_plan::QPartitioning::isKeyAssociated
bool isKeyAssociated(int key) const
Returns whether key is associated with this registry.
Definition: QPartitioning.h:81
ogdf::calculateTableSize
int calculateTableSize(int actualCount)
The default growth function for registered arrays.
Definition: RegisteredArray.h:67
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::Graph
Data type for general directed graphs (adjacency list representation).
Definition: Graph_d.h:869
ogdf::sync_plan::QPartitioning::partitionCount
int partitionCount() const
Definition: QPartitioning.h:71
ogdf::sync_plan::QPartitioning::nodeAdded
void nodeAdded(node v) override
Called by watched graph after a node has been added.
Definition: QPartitioning.h:96
ogdf::sync_plan::QPartitioning::calculateArraySize
int calculateArraySize(int add) const
Returns the array size currently requested by this registry.
Definition: QPartitioning.h:87
ogdf::sync_plan::QPartitioning::QPartitioning
QPartitioning(const Graph *G)
Definition: QPartitioning.h:57
ogdf::sync_plan::QPartitioning::qVertexCount
int qVertexCount() const
Definition: QPartitioning.h:73
basic.h
Basic declarations, included by all source files.
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:91
ogdf::sync_plan::QPartitioning::keyToIndex
static int keyToIndex(int key)
Returns the index of key.
Definition: QPartitioning.h:78
ogdf::EdgeElement
Class for the representation of edges.
Definition: Graph_d.h:363
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:858
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:102
ogdf::NodeElement
Class for the representation of nodes.
Definition: Graph_d.h:240
ogdf::sync_plan::QPartitioning::nodesInPartition
const List< node > & nodesInPartition(int partition) const
Definition: QPartitioning.h:75