Open
Graph Drawing
Framework

 v.2012.05
 

CliqueFinder.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  
00043 #ifdef _MSC_VER
00044 #pragma once
00045 #endif
00046 
00047 #ifndef OGDF_CLIQUEFINDER_H
00048 #define OGDF_CLIQUEFINDER_H
00049 
00050 
00051 #include <ogdf/basic/NodeArray.h>
00052 #include <ogdf/basic/EdgeArray.h>
00053 #include <ogdf/basic/List.h>
00054 #include <ogdf/basic/GraphCopy.h>
00055 
00056 namespace ogdf{
00057 
00058 
00060 
00074 class OGDF_EXPORT CliqueFinder {
00075 
00076 public:
00077     //constructor
00078     CliqueFinder(const Graph &G);
00079     ~CliqueFinder();
00080     
00081     //Calls
00082     //We first make G biconnected, this keeps the triconnected 
00083     //components. then the triconnected components are computed
00084     //within these components, we search for cliques
00085     
00087 
00091     void call(NodeArray<int> &cliqueNumber);
00093 
00097     void call(List< List<node> > &cliqueLists);
00098 
00100     void setMinSize(int i) { m_minDegree = max(2, i-1);}
00101     enum postProcess {ppNone, ppSimple};
00102 
00104 
00107     void setDensity(int density)
00108     {
00109         if (density < 0) m_density = 0;
00110         else if (density > 100) m_density = 100;
00111         else m_density = density;
00112     }
00113 
00114 protected:
00120     void doCall(int minDegree = 2);
00121 
00122     //------------------------------------------------------
00123     //sets the results of doCall depending on call signature
00124 
00125     //clique nodes get numbers from >=0, all other nodes -1
00126     void setResults(NodeArray<int> &cliqueNumber);
00127     void setResults(List< List<node> > &cliqueLists);
00128     void setResults(List< List<node>* > &cliqueLists);
00129 
00130     //work on the result of the first phase (heuristic), e.g.
00131     //by dropping, splitting or joining some of the found subgraphs
00132     void postProcessCliques(List< List<node>* > &cliqueList,
00133         EdgeArray<bool> &usableEdge);
00134 
00135     //check if node v is adjacent to all nodes in node list
00136     bool allAdjacent(node v, List<node>* vList);
00137     void writeGraph(Graph &G, NodeArray<int> &cliqueNumber,
00138         const String &fileName);
00139 
00140     //does a heuristic evaluation of node v (in m_pCopy)
00141     //concerning its qualification as a cluster start node
00142     //the higher the return value, the better the node
00143     //uses only edges with usableEdge == true
00144     int evaluate(node v, EdgeArray<bool> &usableEdge);
00145     void checkCliques(List< List<node>* > &cliqueList, bool sizeCheck = true);
00146     bool cliqueOK(List<node> *clique);
00147     void findClique(node v, List<node> &neighbours,
00148                         int numRandom = 0);
00149 
00150 private:
00151     const Graph* m_pGraph;
00152     GraphCopy* m_pCopy;
00153     NodeArray<int> m_copyCliqueNumber;
00154     NodeArray<bool> m_usedNode; //node is assigned to clique
00155     //List< List<node>* > m_cliqueList;
00156     int m_minDegree;
00157     int m_numberOfCliques; //stores the number of found cliques
00158     postProcess m_postProcess;
00159     bool m_callByList; //stores information on type of call for result setting
00160     List< List<node> > *m_pList; //stores pointer on list given as call parameter
00161 
00162     int m_density; //an abstract value from 0..100 definin how dense the
00163                    //subgraphs need to be, is not directly related to any
00164                    //measure (degree, ...) but translated into a constraint
00165                    //based on the heuristical search of the subgraphs
00166 };//CliqueFinder
00167 
00168 }//end namespace ogdf
00169 
00170 #endif