Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

ClustererModule.h
Go to the documentation of this file.
1 
37 #pragma once
38 
39 #include <ogdf/basic/Graph.h>
42 
43 namespace ogdf {
44 
45 //Helper classes to code a clustering, used as an interface to applications that
46 //need to build the clustergraph structure themselves
48 public:
49  SimpleCluster(SimpleCluster* parent = nullptr) : m_size(0), m_parent(parent), m_index(-1) { }
50 
51  //insert vertices and children
52  void pushBackVertex(node v) { m_nodes.pushBack(v); }
53 
54  void pushBackChild(SimpleCluster* s) { m_children.pushBack(s); }
55 
56  void setParent(SimpleCluster* parent) { m_parent = parent; }
57 
59 
60  void setIndex(int index) { m_index = index; }
61 
62  int getIndex() { return m_index; }
63 
64  SList<node>& nodes() { return m_nodes; }
65 
67 
68  int m_size; //preliminary: allowed to be inconsistent with real vertex number to
69  //allow lazy vertex addition (should therefore be local Array?)
70 
71 private:
75  int m_index; //index of the constructed cluster
76 };
77 
86 public:
87  //Constructor taking a graph G to be clustered
88  explicit ClustererModule(const Graph& G) : m_pGraph(&G) { OGDF_ASSERT(isConnected(G)); }
89 
91  // Allows to cluster multiple
92  // graphs with the same instance of the Clusterer
94 
101  void setGraph(const Graph& G) {
103  m_pGraph = &G;
104  }
105 
107  const Graph& getGraph() const { return *m_pGraph; }
108 
116  virtual void computeClustering(SList<SimpleCluster*>& sl) = 0;
117 
119  virtual void createClusterGraph(ClusterGraph& C) = 0;
120 
122  virtual double computeCIndex(const Graph& G, node v) = 0;
123 
125  virtual double computeCIndex(node v) = 0;
126 
128  virtual double averageCIndex() { return averageCIndex(*m_pGraph); }
129 
130  virtual double averageCIndex(const Graph& G) {
131  double ciSum = 0.0;
132  for (node v : G.nodes) {
133  ciSum += computeCIndex(G, v);
134  }
135  return ciSum / (G.numberOfNodes());
136  }
137 
138 protected:
139  const Graph* m_pGraph; //the graph to be clustered
140 
142 };
143 
144 }
ogdf
The namespace for all OGDF objects.
Definition: AugmentationModule.h:36
Graph.h
Includes declaration of graph class.
ogdf::SimpleCluster::m_nodes
SList< node > m_nodes
Definition: ClustererModule.h:72
OGDF_ASSERT
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition: basic.h:54
ogdf::SimpleCluster::children
SList< SimpleCluster * > & children()
Definition: ClustererModule.h:66
ogdf::SimpleCluster::m_parent
SimpleCluster * m_parent
Definition: ClustererModule.h:74
ogdf::ClustererModule::ClustererModule
ClustererModule(const Graph &G)
Definition: ClustererModule.h:88
ogdf::SList
Singly linked lists (maintaining the length of the list).
Definition: SList.h:833
ogdf::SimpleCluster::setIndex
void setIndex(int index)
Definition: ClustererModule.h:60
ogdf::SimpleCluster::m_size
int m_size
Definition: ClustererModule.h:68
ogdf::SimpleCluster::pushBackVertex
void pushBackVertex(node v)
Definition: ClustererModule.h:52
ogdf::isConnected
bool isConnected(const Graph &G)
Returns true iff G is connected.
ogdf::SimpleCluster::getIndex
int getIndex()
Definition: ClustererModule.h:62
ogdf::SimpleCluster::pushBackChild
void pushBackChild(SimpleCluster *s)
Definition: ClustererModule.h:54
ogdf::SimpleCluster::nodes
SList< node > & nodes()
Definition: ClustererModule.h:64
OGDF_MALLOC_NEW_DELETE
#define OGDF_MALLOC_NEW_DELETE
Makes the class use malloc for memory allocation.
Definition: memory.h:91
ogdf::SimpleCluster::SimpleCluster
SimpleCluster(SimpleCluster *parent=nullptr)
Definition: ClustererModule.h:49
ogdf::Graph
Data type for general directed graphs (adjacency list representation).
Definition: Graph_d.h:862
ogdf::ClustererModule::m_pGraph
const Graph * m_pGraph
Definition: ClustererModule.h:139
ogdf::ClustererModule::setGraph
void setGraph(const Graph &G)
Sets the graph to be clustered.
Definition: ClustererModule.h:101
ogdf::ClustererModule::getGraph
const Graph & getGraph() const
Returns the graph to be clustered.
Definition: ClustererModule.h:107
ogdf::SimpleCluster::getParent
SimpleCluster * getParent()
Definition: ClustererModule.h:58
ogdf::SimpleCluster::m_index
int m_index
Definition: ClustererModule.h:75
ogdf::SimpleCluster
Definition: ClustererModule.h:47
ogdf::SimpleCluster::m_children
SList< SimpleCluster * > m_children
Definition: ClustererModule.h:73
OGDF_EXPORT
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF DLL.
Definition: config.h:101
ogdf::ClustererModule::averageCIndex
virtual double averageCIndex(const Graph &G)
Definition: ClustererModule.h:130
ClusterGraph.h
Derived class of GraphObserver providing additional functionality to handle clustered graphs.
ogdf::ClustererModule::ClustererModule
ClustererModule()
Default constructor, initializes a clustering module.
Definition: ClustererModule.h:93
ogdf::ClustererModule
Interface for algorithms that compute a clustering for a given graph.
Definition: ClustererModule.h:85
ogdf::ClusterGraph
Representation of clustered graphs.
Definition: ClusterGraph.h:339
ogdf::NodeElement
Class for the representation of nodes.
Definition: Graph_d.h:233
ogdf::SimpleCluster::setParent
void setParent(SimpleCluster *parent)
Definition: ClustererModule.h:56
simple_graph_alg.h
Declaration of simple graph algorithms.
ogdf::ClustererModule::averageCIndex
virtual double averageCIndex()
compute the average clustering index for the given graph
Definition: ClustererModule.h:128