Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Loading...
Searching...
No Matches
ClustererModule.h
Go to the documentation of this file.
1
37#pragma once
38
39#include <ogdf/basic/Graph.h>
42
43namespace ogdf {
44
45//Helper classes to code a clustering, used as an interface to applications that
46//need to build the clustergraph structure themselves
48public:
49 SimpleCluster(SimpleCluster* parent = nullptr) : m_size(0), m_parent(parent), m_index(-1) { }
50
51 //insert vertices and children
52 void pushBackVertex(node v) { m_nodes.pushBack(v); }
53
54 void pushBackChild(SimpleCluster* s) { m_children.pushBack(s); }
55
56 void setParent(SimpleCluster* parent) { m_parent = parent; }
57
59
60 void setIndex(int index) { m_index = index; }
61
62 int getIndex() { return m_index; }
63
64 SList<node>& nodes() { return m_nodes; }
65
67
68 int m_size; //preliminary: allowed to be inconsistent with real vertex number to
69 //allow lazy vertex addition (should therefore be local Array?)
70
71private:
75 int m_index; //index of the constructed cluster
76};
77
86public:
87 //Constructor taking a graph G to be clustered
88 explicit ClustererModule(const Graph& G) : m_pGraph(&G) { OGDF_ASSERT(isConnected(G)); }
89
91 // Allows to cluster multiple
92 // graphs with the same instance of the Clusterer
94
101 void setGraph(const Graph& G) {
103 m_pGraph = &G;
104 }
105
107 const Graph& getGraph() const { return *m_pGraph; }
108
117
119 virtual void createClusterGraph(ClusterGraph& C) = 0;
120
122 virtual double computeCIndex(const Graph& G, node v) = 0;
123
125 virtual double computeCIndex(node v) = 0;
126
128 virtual double averageCIndex() { return averageCIndex(*m_pGraph); }
129
130 virtual double averageCIndex(const Graph& G) {
131 double ciSum = 0.0;
132 for (node v : G.nodes) {
133 ciSum += computeCIndex(G, v);
134 }
135 return ciSum / (G.numberOfNodes());
136 }
137
138protected:
139 const Graph* m_pGraph; //the graph to be clustered
140
142};
143
144}
Derived class of GraphObserver providing additional functionality to handle clustered graphs.
Includes declaration of graph class.
Representation of clustered graphs.
Interface for algorithms that compute a clustering for a given graph.
virtual double averageCIndex()
compute the average clustering index for the given graph
ClustererModule(const Graph &G)
ClustererModule()
Default constructor, initializes a clustering module.
void setGraph(const Graph &G)
Sets the graph to be clustered.
const Graph & getGraph() const
Returns the graph to be clustered.
virtual double averageCIndex(const Graph &G)
virtual double computeCIndex(node v)=0
compute a clustering index for each vertex
virtual void computeClustering(SList< SimpleCluster * > &sl)=0
compute some kind of clustering on the graph m_pGraph
virtual double computeCIndex(const Graph &G, node v)=0
compute a clustering index for each vertex
virtual void createClusterGraph(ClusterGraph &C)=0
translate computed clustering into cluster hierarchy in cluster graph C
Data type for general directed graphs (adjacency list representation).
Definition Graph_d.h:521
Class for the representation of nodes.
Definition Graph_d.h:177
Singly linked lists (maintaining the length of the list).
Definition SList.h:833
SimpleCluster * getParent()
SList< SimpleCluster * > & children()
SimpleCluster * m_parent
SList< SimpleCluster * > m_children
SList< node > m_nodes
void pushBackChild(SimpleCluster *s)
void pushBackVertex(node v)
SimpleCluster(SimpleCluster *parent=nullptr)
void setIndex(int index)
SList< node > & nodes()
void setParent(SimpleCluster *parent)
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF DLL.
Definition config.h:101
bool isConnected(const Graph &G)
Returns true iff G is connected.
#define OGDF_MALLOC_NEW_DELETE
Makes the class use malloc for memory allocation.
Definition memory.h:91
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition basic.h:41
static MultilevelBuilder * getDoubleFactoredZeroAdjustedMerger()
The namespace for all OGDF objects.
Declaration of simple graph algorithms.