Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Loading...
Searching...
No Matches
Clusterer.h
Go to the documentation of this file.
1
36#pragma once
37
38#include <ogdf/basic/Graph.h>
40#include <ogdf/basic/List.h>
41#include <ogdf/basic/basic.h>
43
44namespace ogdf {
45class ClusterGraph;
46template<class E>
47class SList;
48
59public:
61 explicit Clusterer(const Graph& G);
62
67
68 virtual ~Clusterer() { }
69
70 //The clustering can be done recursively (use single threshold
71 //on component to delete weak edges (recompute strengths)) or
72 //by applying a set of thresholds, set the behaviour in
73 //function setRecursive
74 virtual void computeClustering(SList<SimpleCluster*>& sl) override;
75
76 //set the thresholds defining the hierarchy assignment decision
77 //should be dependent on the used metrics
79
80 //thresholds are computed from edge strengths to split off
81 //at least some edges as long as there is a difference between
82 //min and max strength (progressive clustering)
83 //set this value to 0 to use your own or the default values
84 void setAutomaticThresholds(int numValues) { m_autoThreshNum = numValues; }
85
86 //for recursive clustering, only the first threshold is used
87 void setRecursive(bool b) { m_recursive = b; }
88
89 //preliminary
91 void computeEdgeStrengths(const Graph& G, EdgeArray<double>& strength);
92
93 virtual void createClusterGraph(ClusterGraph& C) override;
94
95 void setStopIndex(double stop) { m_stopIndex = stop; }
96
97 //compute a clustering index for node v
98 //number of connections in neighborhood compared to clique
99 virtual double computeCIndex(node v) override { return computeCIndex(*m_pGraph, v); }
100
101 virtual double computeCIndex(const Graph& G, node v) override {
102 OGDF_ASSERT(v->graphOf() == &G);
103 if (v->degree() < 2) {
104 return 1.0;
105 }
106 int conns = 0; //connections, without v
107 NodeArray<bool> neighbor(G, false);
108 for (adjEntry adjE : v->adjEntries) {
109 neighbor[adjE->twinNode()] = true;
110 }
111 for (adjEntry adjE : v->adjEntries) {
112 for (adjEntry adjEE : adjE->twinNode()->adjEntries) {
113 if (neighbor[adjEE->twinNode()]) {
114 conns++;
115 }
116 }
117 }
118 //connections were counted twice
119 double index = conns / 2.0;
120 return index / (v->degree() * (v->degree() - 1));
121 }
122
123protected:
124 EdgeArray<double> m_edgeValue; //strength value for edge clustering index
125 NodeArray<double> m_vertexValue; //clustering index for vertices
126 List<double> m_thresholds; //clustering level thresholds
127 List<double> m_autoThresholds; //automatically generated values (dep. on graph instance)
128 List<double> m_defaultThresholds; //some default values
129 double m_stopIndex; //average clustering index when recursive clustering stops
130 //between 0 and 1
131 bool m_recursive; //recursive clustering or list of tresholds
132#if 0
133 bool m_autoThresholds; //compute thresholds according to edge strengths
134#endif
135 int m_autoThreshNum; //number of thresholds to be computed
136};
137
138}
Declaration of interface for clustering algorithms that compute a clustering for a given graph based ...
Includes declaration of graph class.
Decralation of GraphElement and GraphList classes.
Declaration of doubly linked lists and iterators.
Basic declarations, included by all source files.
Class for adjacency list elements.
Definition Graph_d.h:143
Representation of clustered graphs.
Clustering is determined based on the threshold values (connectivity thresholds determine edges to be...
Definition Clusterer.h:58
Clusterer(const Graph &G)
Constructor taking a graph G to be clustered.
virtual double computeCIndex(const Graph &G, node v) override
compute a clustering index for each vertex
Definition Clusterer.h:101
virtual ~Clusterer()
Definition Clusterer.h:68
void setClusteringThresholds(const List< double > &threshs)
double m_stopIndex
Definition Clusterer.h:129
List< double > m_defaultThresholds
Definition Clusterer.h:128
Clusterer()
Default constructor allowing to cluster multiple graphs with the same instance of the Clusterer graph...
void setAutomaticThresholds(int numValues)
Definition Clusterer.h:84
List< double > m_autoThresholds
Definition Clusterer.h:127
virtual double computeCIndex(node v) override
compute a clustering index for each vertex
Definition Clusterer.h:99
void setStopIndex(double stop)
Definition Clusterer.h:95
void computeEdgeStrengths(EdgeArray< double > &strength)
EdgeArray< double > m_edgeValue
Definition Clusterer.h:124
virtual void computeClustering(SList< SimpleCluster * > &sl) override
compute some kind of clustering on the graph m_pGraph
virtual void createClusterGraph(ClusterGraph &C) override
translate computed clustering into cluster hierarchy in cluster graph C
List< double > m_thresholds
Definition Clusterer.h:126
void setRecursive(bool b)
Definition Clusterer.h:87
NodeArray< double > m_vertexValue
Definition Clusterer.h:125
void computeEdgeStrengths(const Graph &G, EdgeArray< double > &strength)
Interface for algorithms that compute a clustering for a given graph.
Data type for general directed graphs (adjacency list representation).
Definition Graph_d.h:866
Doubly linked lists (maintaining the length of the list).
Definition List.h:1451
Class for the representation of nodes.
Definition Graph_d.h:241
int degree() const
Returns the degree of the node (indegree + outdegree).
Definition Graph_d.h:284
internal::GraphObjectContainer< AdjElement > adjEntries
The container containing all entries in the adjacency list of this node.
Definition Graph_d.h:272
const Graph * graphOf() const
Returns the graph containing this node (debug only).
Definition Graph_d.h:345
Singly linked lists (maintaining the length of the list).
Definition SList.h:845
RegisteredArray for edges of a graph, specialized for EdgeArray<edge>.
Definition Graph_d.h:717
RegisteredArray for nodes, edges and adjEntries of a graph.
Definition Graph_d.h:659
#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_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition basic.h:52
The namespace for all OGDF objects.