Open
Graph Drawing
Framework

 v. snapshot-2017-02-16
 

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