Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Loading...
Searching...
No Matches
ClusterGraph.h
Go to the documentation of this file.
1
33#pragma once
34
35#include <ogdf/basic/Graph.h>
37#include <ogdf/basic/List.h>
38#include <ogdf/basic/Observer.h>
40#include <ogdf/basic/SList.h>
41#include <ogdf/basic/basic.h>
42#include <ogdf/basic/comparer.h>
43#include <ogdf/basic/memory.h>
44
45#include <functional>
46#include <iosfwd>
47#include <memory>
48#include <utility>
49
50namespace ogdf {
51
52class ClusterElement; // IWYU pragma: keep
53class ClusterGraph; // IWYU pragma: keep
54class ClusterGraphObserver; // IWYU pragma: keep
55
57
59
63 friend class ClusterGraph;
65
66 int m_id;
67 int m_depth;
68
69public:
76
79
82
84
88
90
91private:
96
97#ifdef OGDF_DEBUG
98 // we store the graph containing this cluster for debugging purposes only
100#endif
101
102
104 List<cluster>& getChildren() { return children; }
105
107 List<node>& getNodes() { return nodes; }
108
110 List<adjEntry>& getAdjEntries() { return adjEntries; }
111
113
117
118 void getClusterInducedNodes(NodeArray<bool>& clusterNode, int& num);
119
120public:
122#ifdef OGDF_DEBUG
123 ClusterElement(const ClusterGraph* pClusterGraph, int id)
124 : m_id(id)
125 , m_depth(0)
126 , m_parent(nullptr)
127 , m_pPrev(nullptr)
128 , m_pNext(nullptr)
129 , m_pClusterGraph(pClusterGraph) { }
130#else
131 explicit ClusterElement(int id)
132 : m_id(id), m_depth(0), m_parent(nullptr), m_pPrev(nullptr), m_pNext(nullptr) { }
133#endif
134
135
140
141#ifdef OGDF_DEBUG
142 const ClusterGraph* graphOf() const { return m_pClusterGraph; }
143#endif
144
145
147 int index() const { return m_id; }
148
150 int depth() const { return m_depth; }
151
153 cluster parent() { return m_parent; }
154
156 cluster succ() const { return static_cast<cluster>(m_next); }
157
159 cluster pred() const { return static_cast<cluster>(m_prev); }
160
162 cluster pSucc() const { return m_pNext; }
163
165 cluster pPred() const { return m_pPrev; }
166
168
171 void getClusterNodes(List<node>& clusterNodes) {
172 clusterNodes.clear();
173 getClusterInducedNodes(clusterNodes);
174 }
175
177
183 int num = 0;
184 getClusterInducedNodes(clusterNode, num);
185 return num;
186 }
187
189
194 bool isDescendant(ClusterElement* child, bool allow_equal = false) {
195 OGDF_ASSERT(child != nullptr);
196 if (!allow_equal) {
197 child = child->parent();
198 }
199 while (child != this) {
200 if (child == nullptr) {
201 return false;
202 }
203 child = child->parent();
204 }
205 return true;
206 }
207
209
214
216 ListConstIterator<ClusterElement*> cBegin() const { return children.begin(); }
217
219 ListConstIterator<ClusterElement*> crBegin() const { return children.rbegin(); }
220
222 int cCount() { return children.size(); }
223
225 ListConstIterator<node> nBegin() const { return nodes.begin(); }
226
228 int nCount() { return nodes.size(); }
229
231 ListConstIterator<adjEntry> firstAdj() const { return adjEntries.begin(); }
232
234 ListConstIterator<adjEntry> lastAdj() const { return adjEntries.rbegin(); }
235
237
239 static int compare(const ClusterElement& x, const ClusterElement& y) { return x.m_id - y.m_id; }
241
243};
244
247
250#define forall_cluster_adj(adj, c) \
251 for (ogdf::ListConstIterator<adjEntry> ogdf_loop_var = (c)->firstAdj(); \
252 ogdf::test_forall_adj_entries_of_cluster(ogdf_loop_var, (adj)); \
253 ogdf_loop_var = ogdf_loop_var.succ())
254
257#define forall_cluster_rev_adj(adj, c) \
258 for (ogdf::ListConstIterator<adjEntry> ogdf_loop_var = (c)->lastAdj(); \
259 ogdf::test_forall_adj_entries_of_cluster(ogdf_loop_var, (adj)); \
260 ogdf_loop_var = ogdf_loop_var.pred())
261
264#define forall_cluster_adj_edges(e, c) \
265 for (ogdf::ListConstIterator<adjEntry> ogdf_loop_var = (c)->firstAdj(); \
266 ogdf::test_forall_adj_edges_of_cluster(ogdf_loop_var, (e)); \
267 ogdf_loop_var = ogdf_loop_var.succ())
268
270 if (it.valid()) {
271 adj = (*it);
272 return true;
273 } else {
274 return false;
275 }
276}
277
279 adjEntry adj = (*it);
280 if (adj) {
281 e = adj->theEdge();
282 return true;
283 } else {
284 return false;
285 }
286}
287
289 if (adj) {
290 e = adj->theEdge();
291 return true;
292 } else {
293 return false;
294 }
295}
296
299#define forall_clusters(c, C) for ((c) = (C).firstCluster(); (c); (c) = (c)->succ())
300
303#define forall_postOrderClusters(c, C) \
304 for ((c) = (C).firstPostOrderCluster(); (c); (c) = (c)->pSucc())
305
307
309
310template<typename Value, bool WithDefault>
311class ClusterArrayBase; // IWYU pragma: keep
312
313#define OGDF_DECL_REG_ARRAY_TYPE(v, c) ClusterArrayBase<v, c>
315#undef OGDF_DECL_REG_ARRAY_TYPE
316
326class OGDF_EXPORT ClusterGraphObserver : public Observer<ClusterGraph, ClusterGraphObserver> {
327public:
329
330 OGDF_DEPRECATED("calls registrationChanged with only partially-constructed child classes, "
331 "see copy constructor of Observer for fix")
332
333 explicit ClusterGraphObserver(const ClusterGraph* CG) { reregister(CG); }
334
335 virtual void clusterDeleted(cluster v) = 0;
336 virtual void clusterAdded(cluster v) = 0;
337 virtual void clustersCleared() = 0;
338
339 const ClusterGraph* getGraph() const { return getObserved(); }
340};
341
343
350 : private GraphObserver, // to get updates when graph nodes/edges added/removed
351 public Observable<ClusterGraphObserver, ClusterGraph>, // to publish updates when clusters added/removed
352 public ClusterGraphRegistry // for ClusterArrays
353{
355
356 int m_clusterIdCount = 0;
357
358 mutable cluster m_postOrderStart = nullptr;
359 cluster m_rootCluster = nullptr;
360
361 bool m_adjAvailable = false;
362 bool m_allowEmptyClusters =
363 true;
364
368
369public:
376
379
381
387
390
392
393
395
399
401
404 explicit ClusterGraph(const Graph& G);
405
407
412
414
418
420
424 ClusterGraph(const ClusterGraph& C, Graph& G, ClusterArray<cluster>& originalClusterTable,
425 NodeArray<node>& originalNodeTable);
426
428
433 ClusterGraph(const ClusterGraph& C, Graph& G, ClusterArray<cluster>& originalClusterTable,
434 NodeArray<node>& originalNodeTable, EdgeArray<edge>& edgeCopy);
435
437 virtual ~ClusterGraph();
438
443
444 using GraphObserver::getGraph;
445
447 cluster rootCluster() const { return m_rootCluster; }
448
450 int numberOfClusters() const { return clusters.size(); }
451
453 int maxClusterIndex() const { return m_clusterIdCount - 1; }
454
456 inline cluster clusterOf(node v) const { return m_nodeMap[v]; }
457
459 //should be called instead of direct c->depth call to assure
460 //valid depth
461 int& clusterDepth(cluster c) const {
462 // updateDepth must be set to true if depth info shall be used
463 OGDF_ASSERT(m_updateDepth);
464
465 //initialize depth at first call
466 if (!m_depthUpToDate) {
467 computeSubTreeDepth(rootCluster());
468 }
469 OGDF_ASSERT(c->depth() != 0);
470 return c->m_depth;
471 }
472
474 cluster firstCluster() const { return clusters.head(); }
475
477 cluster lastCluster() const { return clusters.tail(); }
478
481 if (!m_postOrderStart) {
482 postOrder();
483 }
484 return m_postOrderStart;
485 }
486
488 template<class CLUSTERLIST>
489 void allClusters(CLUSTERLIST& clusterList) const {
490 clusterList.clear();
491 for (cluster c : clusters) {
492 clusterList.pushBack(c);
493 }
494 }
495
497
501
503 void clear();
504
506 void init(const Graph& G);
507
510
512 cluster newCluster(cluster parent, int id = -1);
513
515 cluster createEmptyCluster(const cluster parent = nullptr, int clusterId = -1);
516
518
526 cluster createCluster(const SList<node>& nodes, const cluster parent = nullptr);
527
529
534
536 void moveCluster(cluster c, cluster newParent);
537
538
541
543 //inserted mainly for use in gmlparser.
544 void reInit(Graph& G) { reinitGraph(G); }
545
548 const ClusterGraph& C, const Graph& G, ClusterArray<cluster>& originalClusterTable,
549 std::function<node(node)> nodeMap = [](node v) { return v; });
550
552 template<class NODELIST>
553 void collapse(NODELIST& nodes, Graph& G) {
554 OGDF_ASSERT(&G == &constGraph());
555 m_adjAvailable = false;
556
557 m_postOrderStart = nullptr;
558 node v = nodes.popFrontRet();
559 while (!nodes.empty()) {
560 node w = nodes.popFrontRet();
561 adjEntry adj = w->firstAdj();
562 while (adj != nullptr) {
563 adjEntry succ = adj->succ();
564 edge e = adj->theEdge();
565 if (e->source() == v || e->target() == v) {
566 G.delEdge(e);
567 } else if (e->source() == w) {
568 G.moveSource(e, v);
569 } else {
570 G.moveTarget(e, v);
571 }
572 adj = succ;
573 }
574 //because nodes can already be unassigned (they are always
575 //unassigned if deleted), we have to check this
576#if 0
577 if (m_nodeMap[w])
578 {
579 cluster c = m_nodeMap[w];
580 c->m_entries.del(m_itMap[w]);
581 }
582 removeNodeAssignment(w);
583#endif
584 G.delNode(w);
585 }
586 }
587
589
590
595
604 std::function<bool(cluster)> includeCluster = [](cluster) { return true; },
605 bool isFastTest = true) const;
606
608 void setUpdateDepth(bool b) const {
609 m_updateDepth = b;
610 //make sure that depth cant be used anymore
611 //(even if it may still be valid a little while)
612 if (!b) {
613 m_depthUpToDate = false;
614 }
615 }
616
619
621 //maybe later we should provide a permanent depth member update
622 int treeDepth() const;
623
626
629
631
635 cluster c1, c2;
636 return commonClusterLastAncestors(v, w, c1, c2);
637 }
638
641 List<cluster> eL;
642 return commonClusterAncestorsPath(v, w, c1, c2, eL);
643 }
644
646
650 cluster c1, c2;
651 return commonClusterAncestorsPath(v, w, c1, c2, eL);
652 }
653
656 List<cluster>& eL) const;
657
659
666 void emptyClusters(SList<cluster>& emptyCluster, SList<cluster>* checkCluster = nullptr);
667
669 inline bool emptyOnNodeDelete(cluster c) //virtual?
670 {
671#if 0
672 if (!c) {
673 return false; //Allows easy use in loops
674 }
675#endif
676 return c->nCount() == 1 && c->cCount() == 0;
677 }
678
680 inline bool emptyOnClusterDelete(cluster c) //virtual?
681 {
682#if 0
683 if (!c) {
684 return false; //Allows easy use in loops
685 }
686#endif
687 return c->nCount() == 0 && c->cCount() == 1;
688 }
689
691
695
697 template<class EDGELIST>
698 void adjEdges(cluster c, EDGELIST& edges) const {
699 edges.clear();
700
701 if (m_adjAvailable) {
702 edge e;
704 edges.pushBack(e);
705 }
706 }
707 }
708
710 template<class ADJLIST>
711 void adjEntries(cluster c, ADJLIST& entries) const {
712 entries.clear();
713 if (m_adjAvailable) {
714 for (adjEntry adj : c->adjEntries) {
715 entries.pushBack(adj);
716 }
717 }
718 }
719
721 template<class LISTITERATOR>
722 void makeAdjEntries(cluster c, LISTITERATOR start) {
723 c->adjEntries.clear();
724 LISTITERATOR its;
725 for (its = start; its.valid(); its++) {
726 adjEntry adj = (*its);
727 c->adjEntries.pushBack(adj);
728 }
729 }
730
732 bool adjAvailable() const { return m_adjAvailable; }
733
735 void adjAvailable(bool val) { m_adjAvailable = val; }
736
738
742
744
750
752
761
762#ifdef OGDF_DEBUG
764 void consistencyCheck() const;
765#endif
766
768
774
775 static inline int keyToIndex(cluster key) { return key->index(); }
776
777 bool isKeyAssociated(cluster key) const {
778 if (key == nullptr) {
779 return false;
780 }
781#ifdef OGDF_DEBUG
782 if (key->graphOf() == this) {
783 OGDF_ASSERT(keyToIndex(key) < this->getArraySize());
784 return true;
785 } else {
786 return false;
787 }
788#else
789 return true;
790#endif
791 }
792
793 int calculateArraySize(int add) const { return calculateTableSize(m_clusterIdCount + add); }
794
795 int maxKeyIndex() const { return (m_clusterIdCount)-1; }
796
797 cluster_iterator begin() const { return clusters.begin(); }
798
799 cluster_iterator end() const { return clusters.end(); }
800
802
806
808 operator const Graph&() const { return *getGraph(); }
809
811 const Graph& constGraph() const { return *getGraph(); }
812
815
817
818protected:
819 mutable std::unique_ptr<ClusterArray<int>> m_lcaSearch;
820 mutable int m_lcaNumber = 0;
821 mutable std::unique_ptr<ClusterArray<cluster>> m_vAncestor;
822 mutable std::unique_ptr<ClusterArray<cluster>> m_wAncestor;
823
824 mutable bool m_updateDepth = false;
825 mutable bool m_depthUpToDate = false;
826
829 cluster doCreateCluster(const SList<node>& nodes, const cluster parent, int clusterId = -1);
830
834 const cluster parent, int clusterId = -1);
835
837 void doClear();
838
840 void copyLCA(const ClusterGraph& C);
841 //int m_treeDepth; //should be implemented and updated in operations?
842
844 //we assume that c is inserted via pushback in newparent->children
845 void updatePostOrder(cluster c, cluster oldParent, cluster newParent);
846
849
852
855
857 void nodeDeleted(node v) override;
858
860 void nodeAdded(node v) override { assignNode(v, rootCluster()); }
861
863 void edgeDeleted(edge /* e */) override { }
864
866 void edgeAdded(edge /* e */) override { }
867
869 void cleared() override {
870 //we don't want a complete clear, as the graph still exists
871 //and can be updated from input stream
872 clear();
873 }
874
875 void registrationChanged(const Graph* newG) override;
876
877 // need to re-export both to allow parameter-type-based overload in the same namespace
880 using ClusterGraphRegistry::registerObserver;
881 using ClusterGraphRegistry::unregisterObserver;
882 using Obs::registerObserver;
883 using Obs::unregisterObserver;
884
886
887private:
889 template<typename T>
890 inline void fillEmptyClusters(SList<cluster>& emptyCluster, const T& clusterList) const {
891 emptyCluster.clear();
892
893 for (cluster cc : clusterList) {
894 if (cc->cCount() + cc->nCount() == 0 && cc != rootCluster()) { // we dont add rootcluster
895 emptyCluster.pushBack(cc);
896 }
897 }
898 }
899
902 m_adjAvailable = false;
903 for (auto child : c->getChildren()) {
904 clearClusterTree(child, attached);
905 }
906 }
907
910
913
917 if (m_nodeMap[v]) //iff == 0, itmap == 0 !!?
918 {
919 cluster c2 = m_nodeMap[v];
920 c2->nodes.del(m_itMap[v]);
921 m_nodeMap[v] = nullptr;
922 m_itMap[v] = ListIterator<node>();
923 }
924 }
925
928 void shallowCopy(const ClusterGraph& C);
929
932 void deepCopy(const ClusterGraph& C, Graph& G);
933
936 void deepCopy(const ClusterGraph& C, Graph& G, ClusterArray<cluster>& originalClusterTable,
937 NodeArray<node>& originalNodeTable);
938
942 void deepCopy(const ClusterGraph& C, Graph& G, ClusterArray<cluster>& originalClusterTable,
943 NodeArray<node>& originalNodeTable, EdgeArray<edge>& edgeCopy);
944
945
947
948 void initGraph(const Graph& G);
949
951 void reinitGraph(const Graph& G);
952
955
958
960 void postOrder() const;
961
962#ifdef OGDF_DEBUG
964 void checkPostOrder() const;
965#endif
966
968};
969
971template<class Value, bool WithDefault>
972class ClusterArrayBase : public RegisteredArray<ClusterGraph, Value, WithDefault> {
974
975public:
976 using RA::RA;
977
979 ClusterArrayBase() = default;
980
982 ClusterArrayBase(const ClusterGraph& C, const Value& def, int size) : RA(C, def) {
983 RA::resize(size, true);
984 };
985
987 ClusterGraph* graphOf() const { return RA::registeredAt(); }
988};
989
990OGDF_EXPORT std::ostream& operator<<(std::ostream& os, cluster c);
991
993
1006 EdgeArray<List<std::pair<adjEntry, cluster>>>* subdivisions,
1007 const std::function<edge(edge)>& translate);
1008
1009}
Includes declaration of graph class.
Decralation of GraphElement and GraphList classes.
Declaration of doubly linked lists and iterators.
Simple, safe base classes for C++ observables and observers.
Declaration and implementation of RegisteredArray class.
#define OGDF_DECL_REG_ARRAY(NAME)
Declaration of singly linked lists and iterators.
Basic declarations, included by all source files.
Class for adjacency list elements.
Definition Graph_d.h:143
adjEntry succ() const
Returns the successor in the adjacency list.
Definition Graph_d.h:219
edge theEdge() const
Returns the edge associated with this adjacency entry.
Definition Graph_d.h:161
RegisteredArray for labeling the clusters of a ClusterGraph.
ClusterArrayBase()=default
Default Constructor.
ClusterArrayBase(const ClusterGraph &C, const Value &def, int size)
Creates a new cluster array with initial capacity size.
ClusterGraph * graphOf() const
Returns a pointer to the associated cluster graph.
Representation of clusters in a clustered graph.
void getClusterInducedNodes(NodeArray< bool > &clusterNode, int &num)
cluster m_parent
The parent of this cluster.
void getClusterNodes(List< node > &clusterNodes)
Returns the list of nodes in the cluster, i.e., all nodes in the subtree rooted at this cluster.
const ClusterGraph * m_pClusterGraph
ListConstIterator< adjEntry > lastAdj() const
Returns the last adjacency entry in the list of outgoing edges.
ListConstIterator< ClusterElement * > crBegin() const
Returns the last element in the list of child clusters.
int m_depth
The depth of this cluster in the cluster tree.
int depth() const
Returns the depth of the cluster in the cluster tree.
List< adjEntry > & getAdjEntries()
Provides access to the encapsulated list of adjacency entries (for friends of ClusterElement).
int cCount()
Returns the number of child clusters.
ListContainer< node, ClusterElement > nodes
The container containing the nodes lying (directly) in this cluster.
static int compare(const ClusterElement &x, const ClusterElement &y)
Standard Comparer (uses cluster indices).
cluster pPred() const
Returns the postorder predecessor of the cluster in the list of all clusters.
ListContainer< cluster, ClusterElement > children
The container containing the child clusters (children in the cluster tree) of this cluster.
ClusterElement(const ClusterGraph *pClusterGraph, int id)
Creates a new cluster element.
int m_id
The index of this cluster.
List< node > & getNodes()
Provides access to the encapsulated list of nodes (for friends of ClusterElement).
int index() const
Returns the (unique) index of the cluster.
ListIterator< cluster > m_it
The position of this cluster within the children list of its parent.
cluster parent()
Returns the parent of the cluster.
ListContainer< adjEntry, ClusterElement > adjEntries
The container containing the sorted list of adjacency entries of edges leaving this cluster.
bool isDescendant(ClusterElement *child, bool allow_equal=false)
Checks whether a cluster child is a descendant (i.e. child, child of a child, ...) of this cluster.
int getClusterNodes(NodeArray< bool > &clusterNode)
Sets the entry for each node v to true if v is a member of the subgraph induced by the ClusterElement...
cluster pred() const
Returns the predecessor of the cluster in the list of all clusters.
const ClusterGraph * graphOf() const
cluster m_pNext
The postorder successor of this cluster.
cluster pSucc() const
Returns the postorder successor of the cluster in the list of all clusters.
int nCount()
Returns the number of child nodes.
void getClusterInducedNodes(List< node > &clusterNodes)
Traverses the inclusion tree and adds nodes to clusterNodes.
cluster m_pPrev
The postorder predecessor of this cluster.
cluster succ() const
Returns the successor of the cluster in the list of all clusters.
ListConstIterator< ClusterElement * > cBegin() const
Returns the first element in the list of child clusters.
ListConstIterator< adjEntry > firstAdj() const
Returns the first adjacency entry in the list of outgoing edges.
ListConstIterator< node > nBegin() const
Returns the first element in list of child nodes.
List< cluster > & getChildren()
Provides access to the encapsulated list of children (for friends of ClusterElement).
Representation of clustered graphs.
void pullUpSubTree(cluster c)
Updates depth information in subtree after delCluster.
std::unique_ptr< ClusterArray< cluster > > m_vAncestor
Used to save last search run number for commoncluster.
cluster newCluster(cluster parent, int id=-1)
Inserts a new cluster; makes it a child of the cluster parent.
NodeArray< ListIterator< node > > m_itMap
void edgeDeleted(edge) override
Implementation of inherited method: Updates data if edge deleted.
void shallowCopy(const ClusterGraph &C)
Performs a copy of the cluster structure of C, the underlying graph stays the same.
void postOrder(cluster c, SListPure< cluster > &S) const
void recurseClearClusterTreeOnChildren(cluster c, List< node > &attached)
Clears children of a cluster, used by recursive clearClusterTree.
void setUpdateDepth(bool b) const
Turns automatic update of node depth values on or off.
cluster firstPostOrderCluster() const
Returns the first cluster in the list of post ordered clusters.
ClusterGraph & operator=(const ClusterGraph &C)
Assignment operator.
cluster commonCluster(node v, node w) const
Returns the lowest common cluster of v and w in the cluster tree.
cluster commonCluster(SList< node > &nodes)
Returns lowest common cluster of nodes in list nodes.
void adjEdges(cluster c, EDGELIST &edges) const
Returns the list of all edges adjacent to cluster c in edges.
void checkPostOrder() const
Check postorder information in cluster tree.
void initGraph(const Graph &G)
void adjAvailable(bool val)
Sets the availability status of the adjacency entries.
void emptyClusters(SList< cluster > &emptyCluster, SList< cluster > *checkCluster=nullptr)
Returns the list of clusters that are empty or only contain empty clusters.
void nodeDeleted(node v) override
Implementation of inherited method: Updates data if node deleted.
void computeSubTreeDepth(cluster c) const
Computes depth of cluster tree hanging at c.
void reassignNode(node v, cluster c)
Reassigns node v to cluster c.
cluster firstCluster() const
Returns the first cluster in the list of all clusters.
void copyLCA(const ClusterGraph &C)
Copies lowest common ancestor info to copy of clustered graph.
cluster chooseCluster(std::function< bool(cluster)> includeCluster=[](cluster) { return true;}, bool isFastTest=true) const
Returns a random cluster.
cluster postOrderPredecessor(cluster c) const
Computes new predecessor for subtree at moved cluster c (nullptr if c is the root).
void allClusters(CLUSTERLIST &clusterList) const
Returns the list of all clusters in clusterList.
int & clusterDepth(cluster c) const
Returns depth of cluster c in cluster tree, starting with root depth 1.
int calculateArraySize(int add) const
int maxClusterIndex() const
Returns the maximal used cluster index.
ClusterGraph(const ClusterGraph &C, Graph &G)
Copies the underlying graph of C into G and constructs a copy of C associated with G.
bool emptyOnClusterDelete(cluster c)
Returns true if cluster c has only one child and no nodes.
cluster clusterOf(node v) const
Returns the cluster to which a node belongs.
cluster doCreateCluster(const SList< node > &nodes, const cluster parent, int clusterId=-1)
Creates new cluster containing nodes in parameter list with index clusterId.
cluster rootCluster() const
Returns the root cluster.
void reInit(Graph &G)
Clear cluster info structure, reinitializes with underlying graph G.
void updatePostOrder(cluster c, cluster oldParent, cluster newParent)
Adjusts the post order structure for moved clusters.
ClusterGraph(const ClusterGraph &C, Graph &G, ClusterArray< cluster > &originalClusterTable, NodeArray< node > &originalNodeTable, EdgeArray< edge > &edgeCopy)
Copies the underlying graph of C into G and constructs a copy of C associated with G.
cluster leftMostCluster(cluster c) const
Leftmost cluster in subtree rooted at c, gets predecessor of subtree.
void unassignNode(node v)
Unassigns node v from its cluster.
void deepCopy(const ClusterGraph &C, Graph &G)
Perform a deep copy on C, C's underlying graph is copied into G.
cluster_iterator begin() const
ClusterGraph(const Graph &G)
Creates a cluster graph associated with graph G.
void makeAdjEntries(cluster c, LISTITERATOR start)
Computes the adjacency entry list for cluster c.
cluster createCluster(const SList< node > &nodes, const cluster parent=nullptr)
Creates a new cluster containing the nodes given by nodes; makes it a child of the cluster parent.
void postOrder() const
Create postorder information in cluster tree.
cluster createEmptyCluster(const cluster parent=nullptr, int clusterId=-1)
Creates an empty cluster with index clusterId and parent parent.
void removeNodeAssignment(node v)
Remove the assignment entries for nodes. Checks if node v is currently not assigned.
bool isKeyAssociated(cluster key) const
void reinitGraph(const Graph &G)
Reinitializes instance with graph G.
NodeArray< cluster > m_nodeMap
Defines if empty clusters are deleted immediately if generated by operations.
bool adjAvailable() const
Gets the availability status of the adjacency entries.
bool emptyOnNodeDelete(cluster c)
Returns true if cluster c has only one node and no children.
ClusterGraph(const ClusterGraph &C, Graph &G, ClusterArray< cluster > &originalClusterTable, NodeArray< node > &originalNodeTable)
Copies the underlying graph of C into G and constructs a copy of C associated with G.
cluster newCluster()
Creates new cluster.
void adjEntries(cluster c, ADJLIST &entries) const
Returns the list of all adjacency entries adjacent to cluster c in entries.
static int keyToIndex(cluster key)
void registrationChanged(const Graph *newG) override
Called after reregister() changed the observed instance.
void doClear()
Clears all cluster data.
const Graph & constGraph() const
Returns a reference to the underlying graph.
cluster commonClusterAncestorsPath(node v, node w, cluster &c1, cluster &c2, List< cluster > &eL) const
Returns lca of v and w, stores corresponding path in eL and ancestors in c1, c2.
int numberOfClusters() const
Returns the number of clusters.
void cleared() override
Clears cluster data without deleting root when underlying graphs' clear method is called.
void collapse(NODELIST &nodes, Graph &G)
Collapses all nodes in the list nodes to the first node; multi-edges are removed.
std::unique_ptr< ClusterArray< cluster > > m_wAncestor
Used to save last search run number for commoncluster.
void delCluster(cluster c)
Deletes cluster c.
virtual ~ClusterGraph()
Destructor.
void init(const Graph &G)
Clears all cluster data and then reinitializes the instance with underlying graph G.
cluster commonClusterLastAncestors(node v, node w, cluster &c1, cluster &c2) const
Returns the lowest common cluster lca and the highest ancestors on the path to lca.
cluster doCreateCluster(const SList< node > &nodes, SList< cluster > &emptyCluster, const cluster parent, int clusterId=-1)
Creates new cluster containing nodes in parameter list and stores resulting empty clusters in list,...
bool representsCombEmbedding() const
Checks the combinatorial cluster planar embedding.
cluster commonClusterPath(node v, node w, List< cluster > &eL) const
Returns lca of v and w and stores corresponding path in eL.
void clearClusterTree(cluster C)
Removes all clusters from the cluster subtree rooted at cluster C except for cluster C itself.
void moveCluster(cluster c, cluster newParent)
Moves cluster c to a new parent newParent.
void fillEmptyClusters(SList< cluster > &emptyCluster, const T &clusterList) const
Fills emptyCluster with empty, non-root clusters from clusterList.
void deepCopy(const ClusterGraph &C, Graph &G, ClusterArray< cluster > &originalClusterTable, NodeArray< node > &originalNodeTable, EdgeArray< edge > &edgeCopy)
Perform a deep copy on C, C's underlying graph is copied into G. Stores associated nodes in originalN...
cluster newCluster(int id)
Creates new cluster with given id, precondition: id not used.
ClusterGraph()
Creates a cluster graph associated with no graph.
cluster lastCluster() const
Returns the last cluster in the list of all cluster.
void consistencyCheck() const
Asserts consistency of this cluster graph.
internal::GraphObjectContainer< ClusterElement > clusters
The container containing all cluster objects.
ClusterGraph(const ClusterGraph &C)
Copy constructor.
void nodeAdded(node v) override
Implementation of inherited method: Updates data if node added.
void edgeAdded(edge) override
Implementation of inherited method: Updates data if edge added.
void copyClusterTree(const ClusterGraph &C, const Graph &G, ClusterArray< cluster > &originalClusterTable, std::function< node(node)> nodeMap=[](node v) { return v;})
Constructs a cluster tree.
int maxKeyIndex() const
cluster_iterator end() const
std::unique_ptr< ClusterArray< int > > m_lcaSearch
Used to save last search run number for commoncluster.
void clearClusterTree(cluster c, List< node > &attached)
void clear()
Removes all clusters except for the root cluster.
bool representsConnectedCombEmbedding() const
Checks the combinatorial cluster planar embedding.
void deepCopy(const ClusterGraph &C, Graph &G, ClusterArray< cluster > &originalClusterTable, NodeArray< node > &originalNodeTable)
Perform a deep copy on C, C's underlying graph is copied into G. Stores associated nodes in originalN...
void assignNode(node v, cluster C)
Assigns node v to cluster C (v not yet assigned!).
int treeDepth() const
Computes depth of cluster tree, running time O(C).
Abstract base class for cluster graph observers.
virtual void clusterAdded(cluster v)=0
virtual void clustersCleared()=0
const ClusterGraph * getGraph() const
virtual void clusterDeleted(cluster v)=0
Class for the representation of edges.
Definition Graph_d.h:364
node target() const
Returns the target node of the edge.
Definition Graph_d.h:402
node source() const
Returns the source node of the edge.
Definition Graph_d.h:399
Data type for general directed graphs (adjacency list representation).
Definition Graph_d.h:866
Abstract Base class for graph observers.
Definition Graph_d.h:775
iterator begin() const
Returns an iterator to the first element in the container.
Definition List.h:1838
reverse_iterator rbegin() const
Returns a reverse iterator to the last element in the container.
Definition List.h:1844
int size() const
Returns the number of elements in the container.
Definition List.h:1850
Doubly linked lists (maintaining the length of the list).
Definition List.h:1451
void clear()
Removes all elements from the list.
Definition List.h:1626
Encapsulates a pointer to a list element.
Definition List.h:113
bool valid() const
Returns true iff the iterator points to an element.
Definition List.h:153
Class for the representation of nodes.
Definition Graph_d.h:241
adjEntry firstAdj() const
Returns the first entry in the adjaceny list.
Definition Graph_d.h:287
Base class for an observable object that can be tracked by multiple Observer objects.
Definition Observer.h:127
Base class for an observer for a single Observable object.
Definition Observer.h:53
Dynamic arrays indexed with arbitrary keys.
typename std::conditional< WithDefault, internal::RegisteredArrayWithDefault< ClusterGraph, Value >, internal::RegisteredArrayWithoutDefault< ClusterGraph, Value > >::type RA
Abstract base class for registries.
Singly linked lists (maintaining the length of the list).
Definition SList.h:845
void clear()
Removes all elements from the list.
Definition SList.h:984
SListIterator< E > pushBack(const E &x)
Adds element x at the end of the list.
Definition SList.h:939
Singly linked lists.
Definition SList.h:191
RegisteredArray for edges of a graph, specialized for EdgeArray<edge>.
Definition Graph_d.h:717
The base class for objects used by (hyper)graphs.
Definition GraphList.h:60
Lists of graph objects (like nodes, edges, etc.).
Definition GraphList.h:301
T * head() const
Returns the first element in the list.
Definition GraphList.h:324
T * tail() const
Returns the last element in the list.
Definition GraphList.h:327
iterator begin() const
Returns an iterator to the first element in the container.
Definition GraphList.h:385
iterator end() const
Returns an iterator to the one-past-last element in the container.
Definition GraphList.h:388
int size() const
Returns the size of the list.
Definition GraphList.h:89
Public read-only interface for lists of graph objects.
Definition GraphList.h:410
RegisteredArray for nodes, edges and adjEntries of a graph.
Definition Graph_d.h:659
Declarations for Comparer objects.
#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_AUGMENT_COMPARER(type)
Add this macro to your class to turn it into a full comparer.
Definition comparer.h:183
#define forall_cluster_adj_edges(e, c)
Iterates over all outgoing edges.
bool test_forall_adj_edges_of_cluster(ListConstIterator< adjEntry > &it, edge &e)
EdgeElement * edge
The type of edges.
Definition Graph_d.h:75
bool test_forall_adj_entries_of_cluster(ListConstIterator< adjEntry > &it, adjEntry &adj)
#define OGDF_DEPRECATED(reason)
Mark a class / member / function as deprecated.
Definition config.h:206
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition basic.h:52
#define OGDF_NEW_DELETE
Makes the class use OGDF's memory allocator.
Definition memory.h:85
Declaration of memory manager for allocating small pieces of memory.
The namespace for all OGDF objects.
std::ostream & operator<<(std::ostream &os, const ogdf::Array< E, INDEX > &a)
Prints array a to output stream os.
Definition Array.h:983
int calculateTableSize(int actualCount)
The default growth function for registered arrays.
void planarizeClusterBorderCrossings(const ClusterGraph &CG, Graph &G, EdgeArray< List< std::pair< adjEntry, cluster > > > *subdivisions, const std::function< edge(edge)> &translate)
Turn cluster borders into cycles of edges and cluster-border-edge-crossings into vertices.