54class ClusterGraphObserver;
129 , m_pClusterGraph(pClusterGraph) { }
132 : m_id(id), m_depth(0), m_parent(nullptr), m_pPrev(nullptr), m_pNext(nullptr) { }
150 int depth()
const {
return m_depth; }
172 clusterNodes.
clear();
173 getClusterInducedNodes(clusterNodes);
184 getClusterInducedNodes(clusterNode, num);
199 while (child !=
this) {
200 if (child ==
nullptr) {
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())
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())
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())
299#define forall_clusters(c, C) for ((c) = (C).firstCluster(); (c); (c) = (c)->succ())
303#define forall_postOrderClusters(c, C) \
304 for ((c) = (C).firstPostOrderCluster(); (c); (c) = (c)->pSucc())
310template<
typename Value,
bool WithDefault>
313#define OGDF_DECL_REG_ARRAY_TYPE(v, c) ClusterArrayBase<v, c>
315#undef OGDF_DECL_REG_ARRAY_TYPE
330 OGDF_DEPRECATED(
"calls registrationChanged with only partially-constructed child classes, "
331 "see copy constructor of Observer for fix")
351 public Observable<ClusterGraphObserver, ClusterGraph>,
356 int m_clusterIdCount = 0;
361 bool m_adjAvailable =
false;
362 bool m_allowEmptyClusters =
444 using GraphObserver::getGraph;
466 if (!m_depthUpToDate) {
467 computeSubTreeDepth(rootCluster());
481 if (!m_postOrderStart) {
484 return m_postOrderStart;
488 template<
class CLUSTERLIST>
492 clusterList.pushBack(c);
549 std::function<
node(
node)> nodeMap = [](
node v) {
return v; });
552 template<
class NODELIST>
555 m_adjAvailable =
false;
557 m_postOrderStart =
nullptr;
558 node v = nodes.popFrontRet();
559 while (!nodes.empty()) {
560 node w = nodes.popFrontRet();
562 while (adj !=
nullptr) {
567 }
else if (e->
source() == w) {
580 c->m_entries.del(m_itMap[w]);
582 removeNodeAssignment(w);
604 std::function<
bool(
cluster)> includeCluster = [](
cluster) {
return true; },
605 bool isFastTest =
true)
const;
613 m_depthUpToDate =
false;
636 return commonClusterLastAncestors(v, w, c1, c2);
642 return commonClusterAncestorsPath(v, w, c1, c2, eL);
651 return commonClusterAncestorsPath(v, w, c1, c2, eL);
697 template<
class EDGELIST>
701 if (m_adjAvailable) {
710 template<
class ADJLIST>
713 if (m_adjAvailable) {
715 entries.pushBack(adj);
721 template<
class LISTITERATOR>
725 for (its = start; its.valid(); its++) {
778 if (key ==
nullptr) {
783 OGDF_ASSERT(keyToIndex(key) < this->getArraySize());
808 operator const Graph&()
const {
return *getGraph(); }
820 mutable int m_lcaNumber = 0;
824 mutable bool m_updateDepth =
false;
825 mutable bool m_depthUpToDate =
false;
834 const cluster parent,
int clusterId = -1);
880 using ClusterGraphRegistry::registerObserver;
881 using ClusterGraphRegistry::unregisterObserver;
882 using Obs::registerObserver;
883 using Obs::unregisterObserver;
891 emptyCluster.
clear();
893 for (
cluster cc : clusterList) {
894 if (cc->cCount() + cc->nCount() == 0 && cc != rootCluster()) {
902 m_adjAvailable =
false;
904 clearClusterTree(child, attached);
920 c2->
nodes.del(m_itMap[v]);
921 m_nodeMap[v] =
nullptr;
971template<
class Value,
bool WithDefault>
983 RA::resize(size,
true);
1006 EdgeArray<
List<std::pair<adjEntry, cluster>>>* subdivisions,
1007 const std::function<
edge(
edge)>& translate);
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.
adjEntry succ() const
Returns the successor in the adjacency list.
edge theEdge() const
Returns the edge associated with this adjacency entry.
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.
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
ClusterGraphObserver()=default
Class for the representation of edges.
node target() const
Returns the target node of the edge.
node source() const
Returns the source node of the edge.
Data type for general directed graphs (adjacency list representation).
Abstract Base class for graph observers.
iterator begin() const
Returns an iterator to the first element in the container.
reverse_iterator rbegin() const
Returns a reverse iterator to the last element in the container.
int size() const
Returns the number of elements in the container.
Doubly linked lists (maintaining the length of the list).
void clear()
Removes all elements from the list.
Encapsulates a pointer to a list element.
bool valid() const
Returns true iff the iterator points to an element.
Class for the representation of nodes.
adjEntry firstAdj() const
Returns the first entry in the adjaceny list.
Base class for an observable object that can be tracked by multiple Observer objects.
Base class for an observer for a single Observable object.
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).
void clear()
Removes all elements from the list.
SListIterator< E > pushBack(const E &x)
Adds element x at the end of the list.
RegisteredArray for edges of a graph, specialized for EdgeArray<edge>.
The base class for objects used by (hyper)graphs.
Lists of graph objects (like nodes, edges, etc.).
T * head() const
Returns the first element in the list.
T * tail() const
Returns the last element in the list.
iterator begin() const
Returns an iterator to the first element in the container.
iterator end() const
Returns an iterator to the one-past-last element in the container.
int size() const
Returns the size of the list.
Public read-only interface for lists of graph objects.
RegisteredArray for nodes, edges and adjEntries of a graph.
Declarations for Comparer objects.
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF dynamic library (shared object / DLL),...
#define OGDF_AUGMENT_COMPARER(type)
Add this macro to your class to turn it into a full comparer.
#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.
bool test_forall_adj_entries_of_cluster(ListConstIterator< adjEntry > &it, adjEntry &adj)
#define OGDF_DEPRECATED(reason)
Mark a class / member / function as deprecated.
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
#define OGDF_NEW_DELETE
Makes the class use OGDF's memory allocator.
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.
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.