Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Clusterer.h
Go to the documentation of this file.
1 
36 #pragma once
37 
38 #include <ogdf/basic/Graph.h>
39 #include <ogdf/basic/GraphList.h>
40 #include <ogdf/basic/List.h>
41 #include <ogdf/basic/basic.h>
43 
44 namespace ogdf {
45 class ClusterGraph;
46 template<class E>
47 class SList;
48 
59 public:
61  explicit Clusterer(const Graph& G);
62 
66  Clusterer();
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
78  void setClusteringThresholds(const List<double>& threshs);
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
90  void computeEdgeStrengths(EdgeArray<double>& strength);
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 
123 protected:
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 }
ogdf
The namespace for all OGDF objects.
Definition: multilevelmixer.cpp:39
Graph.h
Includes declaration of graph class.
ogdf::Clusterer::m_edgeValue
EdgeArray< double > m_edgeValue
Definition: Clusterer.h:124
ogdf::Clusterer::computeCIndex
virtual double computeCIndex(const Graph &G, node v) override
compute a clustering index for each vertex
Definition: Clusterer.h:101
OGDF_ASSERT
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition: basic.h:66
ogdf::Clusterer::setAutomaticThresholds
void setAutomaticThresholds(int numValues)
Definition: Clusterer.h:84
ogdf::Clusterer::m_autoThreshNum
int m_autoThreshNum
Definition: Clusterer.h:135
ogdf::SList
Singly linked lists (maintaining the length of the list).
Definition: SList.h:845
ogdf::Clusterer::~Clusterer
virtual ~Clusterer()
Definition: Clusterer.h:68
ogdf::Clusterer::m_autoThresholds
List< double > m_autoThresholds
Definition: Clusterer.h:127
ogdf::Clusterer::m_stopIndex
double m_stopIndex
Definition: Clusterer.h:129
ogdf::AdjElement
Class for adjacency list elements.
Definition: Graph_d.h:142
ogdf::NodeElement::degree
int degree() const
Returns the degree of the node (indegree + outdegree).
Definition: Graph_d.h:283
ogdf::Clusterer::computeCIndex
virtual double computeCIndex(node v) override
compute a clustering index for each vertex
Definition: Clusterer.h:99
GraphList.h
Decralation of GraphElement and GraphList classes.
ogdf::NodeElement::adjEntries
internal::GraphObjectContainer< AdjElement > adjEntries
The container containing all entries in the adjacency list of this node.
Definition: Graph_d.h:271
ogdf::Clusterer::m_thresholds
List< double > m_thresholds
Definition: Clusterer.h:126
ogdf::Clusterer::m_defaultThresholds
List< double > m_defaultThresholds
Definition: Clusterer.h:128
ogdf::List< double >
ogdf::internal::GraphRegisteredArray
RegisteredArray for nodes, edges and adjEntries of a graph.
Definition: Graph_d.h:658
ogdf::Graph
Data type for general directed graphs (adjacency list representation).
Definition: Graph_d.h:869
ogdf::Clusterer::m_recursive
bool m_recursive
Definition: Clusterer.h:131
ogdf::Clusterer::setStopIndex
void setStopIndex(double stop)
Definition: Clusterer.h:95
ogdf::AdjElement::twinNode
node twinNode() const
Returns the associated node of the corresponding adjacency entry (shorthand for twin()->theNode()).
Definition: Graph_d.h:175
basic.h
Basic declarations, included by all source files.
ClustererModule.h
Declaration of interface for clustering algorithms that compute a clustering for a given graph based ...
OGDF_EXPORT
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF DLL.
Definition: config.h:101
List.h
Declaration of doubly linked lists and iterators.
ogdf::NodeElement::graphOf
const Graph * graphOf() const
Returns the graph containing this node (debug only).
Definition: Graph_d.h:344
ogdf::ClustererModule
Interface for algorithms that compute a clustering for a given graph.
Definition: ClustererModule.h:89
ogdf::Clusterer::setRecursive
void setRecursive(bool b)
Definition: Clusterer.h:87
ogdf::Clusterer
Definition: Clusterer.h:58
ogdf::ClusterGraph
Representation of clustered graphs.
Definition: ClusterGraph.h:346
ogdf::NodeElement
Class for the representation of nodes.
Definition: Graph_d.h:240
ogdf::Clusterer::m_vertexValue
NodeArray< double > m_vertexValue
Definition: Clusterer.h:125
ogdf::internal::EdgeArrayBase2
RegisteredArray for edges of a graph, specialized for EdgeArray<edge>.
Definition: Graph_d.h:716