Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

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