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>
40 #include <ogdf/basic/GraphList.h>
41 #include <ogdf/basic/SList.h>
42 #include <ogdf/basic/basic.h>
43 #include <ogdf/basic/memory.h>
45 
46 namespace ogdf {
47 class ClusterGraph;
48 
49 //Helper classes to code a clustering, used as an interface to applications that
50 //need to build the clustergraph structure themselves
52 public:
53  SimpleCluster(SimpleCluster* parent = nullptr) : m_size(0), m_parent(parent), m_index(-1) { }
54 
55  //insert vertices and children
56  void pushBackVertex(node v) { m_nodes.pushBack(v); }
57 
58  void pushBackChild(SimpleCluster* s) { m_children.pushBack(s); }
59 
60  void setParent(SimpleCluster* parent) { m_parent = parent; }
61 
63 
64  void setIndex(int index) { m_index = index; }
65 
66  int getIndex() { return m_index; }
67 
68  SList<node>& nodes() { return m_nodes; }
69 
71 
72  int m_size; //preliminary: allowed to be inconsistent with real vertex number to
73  //allow lazy vertex addition (should therefore be local Array?)
74 
75 private:
79  int m_index; //index of the constructed cluster
80 };
81 
90 public:
91  //Constructor taking a graph G to be clustered
92  explicit ClustererModule(const Graph& G) : m_pGraph(&G) { OGDF_ASSERT(isConnected(G)); }
93 
95  // Allows to cluster multiple
96  // graphs with the same instance of the Clusterer
98 
105  void setGraph(const Graph& G) {
107  m_pGraph = &G;
108  }
109 
111  const Graph& getGraph() const { return *m_pGraph; }
112 
120  virtual void computeClustering(SList<SimpleCluster*>& sl) = 0;
121 
123  virtual void createClusterGraph(ClusterGraph& C) = 0;
124 
126  virtual double computeCIndex(const Graph& G, node v) = 0;
127 
129  virtual double computeCIndex(node v) = 0;
130 
132  virtual double averageCIndex() { return averageCIndex(*m_pGraph); }
133 
134  virtual double averageCIndex(const Graph& G) {
135  double ciSum = 0.0;
136  for (node v : G.nodes) {
137  ciSum += computeCIndex(G, v);
138  }
139  return ciSum / (G.numberOfNodes());
140  }
141 
142 protected:
143  const Graph* m_pGraph; //the graph to be clustered
144 
146 };
147 
148 }
ogdf
The namespace for all OGDF objects.
Definition: multilevelmixer.cpp:39
Graph.h
Includes declaration of graph class.
ogdf::SimpleCluster::m_nodes
SList< node > m_nodes
Definition: ClustererModule.h:76
OGDF_ASSERT
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition: basic.h:66
ogdf::SimpleCluster::children
SList< SimpleCluster * > & children()
Definition: ClustererModule.h:70
ogdf::SimpleCluster::m_parent
SimpleCluster * m_parent
Definition: ClustererModule.h:78
ogdf::ClustererModule::ClustererModule
ClustererModule(const Graph &G)
Definition: ClustererModule.h:92
ogdf::SList
Singly linked lists (maintaining the length of the list).
Definition: SList.h:845
ogdf::SimpleCluster::setIndex
void setIndex(int index)
Definition: ClustererModule.h:64
ogdf::SimpleCluster::m_size
int m_size
Definition: ClustererModule.h:72
ogdf::SimpleCluster::pushBackVertex
void pushBackVertex(node v)
Definition: ClustererModule.h:56
ogdf::isConnected
bool isConnected(const Graph &G)
Returns true iff G is connected.
ogdf::SimpleCluster::getIndex
int getIndex()
Definition: ClustererModule.h:66
ogdf::SimpleCluster::pushBackChild
void pushBackChild(SimpleCluster *s)
Definition: ClustererModule.h:58
ogdf::SimpleCluster::nodes
SList< node > & nodes()
Definition: ClustererModule.h:68
OGDF_MALLOC_NEW_DELETE
#define OGDF_MALLOC_NEW_DELETE
Makes the class use malloc for memory allocation.
Definition: memory.h:92
SList.h
Declaration of singly linked lists and iterators.
GraphList.h
Decralation of GraphElement and GraphList classes.
ogdf::SimpleCluster::SimpleCluster
SimpleCluster(SimpleCluster *parent=nullptr)
Definition: ClustererModule.h:53
ogdf::Graph
Data type for general directed graphs (adjacency list representation).
Definition: Graph_d.h:869
ogdf::ClustererModule::m_pGraph
const Graph * m_pGraph
Definition: ClustererModule.h:143
ogdf::ClustererModule::setGraph
void setGraph(const Graph &G)
Sets the graph to be clustered.
Definition: ClustererModule.h:105
ogdf::ClustererModule::getGraph
const Graph & getGraph() const
Returns the graph to be clustered.
Definition: ClustererModule.h:111
ogdf::SimpleCluster::getParent
SimpleCluster * getParent()
Definition: ClustererModule.h:62
ogdf::SimpleCluster::m_index
int m_index
Definition: ClustererModule.h:79
ogdf::SimpleCluster
Definition: ClustererModule.h:51
basic.h
Basic declarations, included by all source files.
ogdf::SimpleCluster::m_children
SList< SimpleCluster * > m_children
Definition: ClustererModule.h:77
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:134
ogdf::ClustererModule::ClustererModule
ClustererModule()
Default constructor, initializes a clustering module.
Definition: ClustererModule.h:97
ogdf::ClustererModule
Interface for algorithms that compute a clustering for a given graph.
Definition: ClustererModule.h:89
ogdf::ClusterGraph
Representation of clustered graphs.
Definition: ClusterGraph.h:346
ogdf::NodeElement
Class for the representation of nodes.
Definition: Graph_d.h:240
ogdf::SimpleCluster::setParent
void setParent(SimpleCluster *parent)
Definition: ClustererModule.h:60
memory.h
Declaration of memory manager for allocating small pieces of memory.
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:132