Open
Graph Drawing
Framework

 v.2010.10
 

Clusterer.h

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