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>
41#include <ogdf/basic/SList.h>
42#include <ogdf/basic/basic.h>
43#include <ogdf/basic/memory.h>
45
46namespace ogdf {
47class ClusterGraph;
48
49//Helper classes to code a clustering, used as an interface to applications that
50//need to build the clustergraph structure themselves
52public:
53 SimpleCluster(SimpleCluster* parent = nullptr) : m_size(0), m_parent(parent), m_index(-1) { }
54
55 //insert vertices and children
56 void pushBackVertex(node v) { m_nodes.pushBack(v); }
57
58 void pushBackChild(SimpleCluster* s) { m_children.pushBack(s); }
59
60 void setParent(SimpleCluster* parent) { m_parent = parent; }
61
63
64 void setIndex(int index) { m_index = index; }
65
66 int getIndex() { return m_index; }
67
68 SList<node>& nodes() { return m_nodes; }
69
71
72 int m_size; //preliminary: allowed to be inconsistent with real vertex number to
73 //allow lazy vertex addition (should therefore be local Array?)
74
75private:
79 int m_index; //index of the constructed cluster
80};
81
90public:
91 //Constructor taking a graph G to be clustered
92 explicit ClustererModule(const Graph& G) : m_pGraph(&G) { OGDF_ASSERT(isConnected(G)); }
93
95 // Allows to cluster multiple
96 // graphs with the same instance of the Clusterer
98
105 void setGraph(const Graph& G) {
107 m_pGraph = &G;
108 }
109
111 const Graph& getGraph() const { return *m_pGraph; }
112
121
123 virtual void createClusterGraph(ClusterGraph& C) = 0;
124
126 virtual double computeCIndex(const Graph& G, node v) = 0;
127
129 virtual double computeCIndex(node v) = 0;
130
132 virtual double averageCIndex() { return averageCIndex(*m_pGraph); }
133
134 virtual double averageCIndex(const Graph& G) {
135 double ciSum = 0.0;
136 for (node v : G.nodes) {
137 ciSum += computeCIndex(G, v);
138 }
139 return ciSum / (G.numberOfNodes());
140 }
141
142protected:
143 const Graph* m_pGraph; //the graph to be clustered
144
146};
147
148}
Includes declaration of graph class.
Decralation of GraphElement and GraphList classes.
Declaration of singly linked lists and iterators.
Basic declarations, included by all source files.
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:866
Class for the representation of nodes.
Definition Graph_d.h:241
Singly linked lists (maintaining the length of the list).
Definition SList.h:845
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 dynamic library (shared object / DLL),...
Definition config.h:117
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:92
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition basic.h:52
Declaration of memory manager for allocating small pieces of memory.
The namespace for all OGDF objects.
Declaration of simple graph algorithms.