Open
Graph Drawing
Framework

 v. 2020.02 (Catalpa)
 

Clusterer.h
Go to the documentation of this file.
1 
36 #pragma once
37 
39 
40 namespace ogdf {
41 
52 {
53 public:
55  explicit Clusterer(const Graph &G);
56 
60  Clusterer();
61 
62  virtual ~Clusterer() {}
63 
64  //The clustering can be done recursively (use single threshold
65  //on component to delete weak edges (recompute strengths)) or
66  //by applying a set of thresholds, set the behaviour in
67  //function setRecursive
68  virtual void computeClustering(SList<SimpleCluster*> &sl) override;
69 
70  //set the thresholds defining the hierarchy assignment decision
71  //should be dependent on the used metrics
72  void setClusteringThresholds(const List<double> &threshs);
73 
74  //thresholds are computed from edge strengths to split off
75  //at least some edges as long as there is a difference between
76  //min and max strength (progressive clustering)
77  //set this value to 0 to use your own or the default values
78  void setAutomaticThresholds(int numValues)
79  {
80  m_autoThreshNum = numValues;
81  }
82 
83  //for recursive clustering, only the first threshold is used
84  void setRecursive(bool b) { m_recursive = b; }
85 
86  //preliminary
87  void computeEdgeStrengths(EdgeArray<double> & strength);
88  void computeEdgeStrengths(const Graph &G, EdgeArray<double> & strength);
89 
90  virtual void createClusterGraph(ClusterGraph &C) override;
91 
92  void setStopIndex(double stop) { m_stopIndex = stop; }
93 
94  //compute a clustering index for node v
95  //number of connections in neighborhood compared to clique
96  virtual double computeCIndex(node v) override
97  {
98  return computeCIndex(*m_pGraph, v);
99  }
100 
101  virtual double computeCIndex(const Graph &G, node v) override
102  {
103  OGDF_ASSERT(v->graphOf() == &G);
104  if (v->degree() < 2) return 1.0;
105  int conns = 0; //connections, without v
106  NodeArray<bool> neighbor(G, false);
107  for (adjEntry adjE : v->adjEntries)
108  {
109  neighbor[adjE->twinNode()] = true;
110  }
111  for (adjEntry adjE : v->adjEntries)
112  {
113  for (adjEntry adjEE : adjE->twinNode()->adjEntries)
114  {
115  if (neighbor[adjEE->twinNode()])
116  conns++;
117  }
118  }
119  //connections were counted twice
120  double index = conns / 2.0;
121  return index / (v->degree()*(v->degree() - 1));
122  }
123 
124 protected:
125  EdgeArray<double> m_edgeValue; //strength value for edge clustering index
126  NodeArray<double> m_vertexValue; //clustering index for vertices
127  List<double> m_thresholds; //clustering level thresholds
128  List<double> m_autoThresholds; //automatically generated values (dep. on graph instance)
129  List<double> m_defaultThresholds; //some default values
130  double m_stopIndex; //average clustering index when recursive clustering stops
131  //between 0 and 1
132  bool m_recursive; //recursive clustering or list of tresholds
133 #if 0
134  bool m_autoThresholds; //compute thresholds according to edge strengths
135 #endif
136  int m_autoThreshNum; //number of thresholds to be computed
137 };
138 
139 }
virtual ~Clusterer()
Definition: Clusterer.h:62
NodeArray< double > m_vertexValue
Definition: Clusterer.h:126
Data type for general directed graphs (adjacency list representation).
Definition: Graph_d.h:492
Interface for algorithms that compute a clustering for a given graph.
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF DLL.
Definition: config.h:99
int degree() const
Returns the degree of the node (indegree + outdegree).
Definition: Graph_d.h:210
Clustering is determined based on the threshold values (connectivity thresholds determine edges to be...
Definition: Clusterer.h:51
Declaration of interface for clustering algorithms that compute a clustering for a given graph based ...
List< double > m_thresholds
Definition: Clusterer.h:127
Singly linked lists (maintaining the length of the list).
Definition: SList.h:773
Representation of clustered graphs.
Definition: ClusterGraph.h:291
void setAutomaticThresholds(int numValues)
Definition: Clusterer.h:78
virtual double computeCIndex(const Graph &G, node v) override
compute a clustering index for each vertex
Definition: Clusterer.h:101
virtual double computeCIndex(node v) override
compute a clustering index for each vertex
Definition: Clusterer.h:96
EdgeArray< double > m_edgeValue
Definition: Clusterer.h:125
double m_stopIndex
Definition: Clusterer.h:130
node twinNode() const
Returns the associated node of the corresponding adjacency entry (shorthand for twin()->theNode()).
Definition: Graph_d.h:108
Class for the representation of nodes.
Definition: Graph_d.h:169
void setRecursive(bool b)
Definition: Clusterer.h:84
void setStopIndex(double stop)
Definition: Clusterer.h:92
The namespace for all OGDF objects.
List< double > m_defaultThresholds
Definition: Clusterer.h:129
Class for adjacency list elements.
Definition: Graph_d.h:79
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition: basic.h:41
List< double > m_autoThresholds
Definition: Clusterer.h:128
internal::GraphObjectContainer< AdjElement > adjEntries
The container containing all entries in the adjacency list of this node.
Definition: Graph_d.h:200