Open
Graph Drawing
Framework

 v.2012.05
 

ClustererModule.h
Go to the documentation of this file.
00001 /*
00002  * $Revision: 2299 $
00003  * 
00004  * last checkin:
00005  *   $Author: gutwenger $ 
00006  *   $Date: 2012-05-07 15:57:08 +0200 (Mon, 07 May 2012) $ 
00007  ***************************************************************/
00008  
00048 #ifdef _MSC_VER
00049 #pragma once
00050 #endif
00051 
00052 #ifndef OGDF_CLUSTERER_MODULE_H
00053 #define OGDF_CLUSTERER_MODULE_H
00054 
00055 #include <ogdf/basic/Graph.h>
00056 #include <ogdf/cluster/ClusterGraph.h>
00057 #include <ogdf/basic/simple_graph_alg.h>
00058 
00059 
00060 #include <iostream>
00061 
00062 namespace ogdf {
00063     
00064     //Helper classes to code a clustering, used as an interface to applications that
00065     //need to build the clustergraph structure themselves
00066     class SimpleCluster
00067     {
00068         public: 
00069         SimpleCluster(SimpleCluster* parent = 0) : m_size(0), m_parent(parent), m_index(-1) { }
00070         
00071         //insert vertices and children
00072         void pushBackVertex(node v) {m_nodes.pushBack(v);}
00073         void pushBackChild(SimpleCluster* s) {m_children.pushBack(s);}
00074                      
00075         void setParent(SimpleCluster* parent) {m_parent = parent;}
00076         SimpleCluster* getParent() {return m_parent;}
00077         
00078         void setIndex(int index) {m_index = index;}
00079         int getIndex() {return m_index;}
00080         
00081         SList<node> &nodes() {return m_nodes;}
00082         SList<SimpleCluster*> &children() {return m_children;}
00083         
00084         int m_size; //preliminary: allowed to be inconsistent with real vertex number to
00085                     //allow lazy vertex addition (should therefore be local Array?)
00086         
00087         
00088         private:
00089         SList<node> m_nodes;
00090         SList<SimpleCluster*> m_children;
00091         SimpleCluster* m_parent;
00092         int m_index; //index of the constructed cluster
00093         
00094     };//class SimpleCluster
00095     
00103     class OGDF_EXPORT ClustererModule 
00104     {
00105         
00106         public:
00107         //Constructor taking a graph G to be clustered 
00108         explicit ClustererModule(const Graph &G) : m_pGraph(&G) {OGDF_ASSERT(isConnected(G));}
00110         // Allows to cluster multiple
00111         // graphs with the same instance of the Clusterer  
00112         ClustererModule() {}
00113         
00120         void setGraph(const Graph &G) {OGDF_ASSERT(isConnected(G));m_pGraph = &G;}
00122         const Graph& getGraph() const {return *m_pGraph;} 
00123         
00131         virtual void computeClustering(SList<SimpleCluster*> &sl) = 0;
00132         
00134         virtual void createClusterGraph(ClusterGraph &C) = 0;
00135         
00137         virtual double computeCIndex(const Graph & G, node v) = 0;
00139         virtual double computeCIndex(node v) = 0;
00141         virtual double averageCIndex()
00142         {
00143             return averageCIndex(*m_pGraph);
00144         }
00145         virtual double averageCIndex(const Graph &G) 
00146         {
00147             node v;
00148             double ciSum = 0.0;
00149             forall_nodes(v, G)
00150             {
00151                 ciSum += computeCIndex(G, v);
00152             }
00153             return ciSum / (G.numberOfNodes());
00154         }
00155         
00156         
00157         protected:
00158         const Graph* m_pGraph; //the graph to be clustered
00159           
00160         OGDF_MALLOC_NEW_DELETE
00161         
00162     };//class ClustererModule
00163     
00164     
00165     
00166 } //end namespace ogdf
00167 
00168 
00169 #endif /*CLUSTERERMODULE_H_*/