Open
Graph Drawing
Framework

 v. snapshot-2017-02-16
 

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