Open
Graph Drawing
Framework

 v.2012.05
 

Clusterer.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 
00047 #ifdef _MSC_VER
00048 #pragma once
00049 #endif
00050 
00051 #ifndef OGDF_CLUSTERER_H
00052 #define OGDF_CLUSTERER_H
00053 
00054 #include <ogdf/module/ClustererModule.h>
00055 
00056 namespace ogdf {
00057     
00058     
00066     class OGDF_EXPORT Clusterer : public ClustererModule
00067     {
00068         public: 
00069         //Constructor taking a graph G to be clustered 
00070         Clusterer(const Graph &G);
00071         //Default constructor allowing to cluster multiple
00072         //graphs with the same instance of the Clusterer  
00073         //Clusterer();
00074         virtual ~Clusterer() {}
00075         
00076         //The clustering can be done recursively (use single threshold
00077         //on component to delete weak edges (recompute strengths)) or 
00078         //by applying a set of thresholds, set the behaviour in 
00079         //function setRecursive
00080         virtual void computeClustering(SList<SimpleCluster*> &sl);
00081         //set the thresholds defining the hierarchy assignment decision
00082         //should be dependent on the used metrics
00083         void setClusteringThresholds(const List<double> &threshs);
00084         //thresholds are computed from edge strengths to split off
00085         //at least some edges as long as there is a difference between 
00086         //min and max strength (progressive clustering)
00087         //set this value to 0 to use your own or the default values
00088         void setAutomaticThresholds(int numValues)
00089         {m_autoThreshNum = numValues;}
00090         //for recursive clustering, only the first threshold is used
00091         void setRecursive(bool b) {m_recursive = b;}
00092         //preliminary 
00093         void computeEdgeStrengths(EdgeArray<double> & strength);
00094         void computeEdgeStrengths(const Graph &G, EdgeArray<double> & strength);
00095         
00096         void createClusterGraph(ClusterGraph &C);
00097         
00098         void setStopIndex(double stop) {m_stopIndex = stop;} 
00099         
00100         //compute a clustering index for node v
00101         //number of connections in neighborhood compared to clique
00102         virtual double computeCIndex(node v)
00103         {
00104             return computeCIndex(*m_pGraph, v);
00105         }
00106         virtual double computeCIndex(const Graph &G, node v) 
00107         {
00108             OGDF_ASSERT(v->graphOf() == &G);
00109             if (v->degree()<2) return 1.0;
00110             int conns = 0; //connections, without v
00111             NodeArray<bool> neighbor(G, false);
00112             adjEntry adjE;
00113             forall_adj(adjE, v)
00114             {
00115                 neighbor[adjE->twinNode()] = true;
00116             }
00117             forall_adj(adjE, v)
00118             {
00119                 adjEntry adjEE;
00120                 forall_adj(adjEE, adjE->twinNode())
00121                 {
00122                     if (neighbor[adjEE->twinNode()])
00123                         conns++;
00124                 }
00125             }
00126             //connections were counted twice
00127             double index = conns / 2.0;
00128             return index / (v->degree()*(v->degree()-1));
00129         }
00130         
00131         protected:
00132         EdgeArray<double> m_edgeValue; //strength value for edge clustering index
00133         NodeArray<double> m_vertexValue; //clustering index for vertices
00134         List<double> m_thresholds; //clustering level thresholds
00135         List<double> m_autoThresholds; //automatically generated values (dep. on graph instance)
00136         List<double> m_defaultThresholds; //some default values
00137         double m_stopIndex; //average clustering index when recursive clustering stops
00138                             //between 0 and 1
00139         bool m_recursive; //recursive clustering or list of tresholds
00140         //bool m_autoThresholds; //compute thresholds according to edge strengths
00141         int m_autoThreshNum; //number of thresholds to be computed 
00142     
00143     };//class Clusterer
00144     
00145 } //end namespace ogdf
00146 
00147 #endif