#include #include #include #include #include #include #include "HierarchicalClustering.h" using namespace std; CLUSTERINGPLUGIN(HierarchicalClustering,"Hierarchical","David Auber","27/01/2000","Alpha","0","1"); //================================================================================ HierarchicalClustering::HierarchicalClustering(ClusterContext context):Clustering(context) {} //================================================================================ HierarchicalClustering::~HierarchicalClustering() {} //================================================================================ class LessThan { public: MetricProxy *metric; bool operator() (node n1,node n2) { return (metric->getNodeValue(n1) < metric->getNodeValue(n2)); } }; bool HierarchicalClustering::split(MetricProxy *metric,list &orderedNode) { Iterator *itN=superGraph->getNodes(); for (;itN->hasNext();) orderedNode.push_back(itN->next()); delete itN; LessThan comp; comp.metric=metric; orderedNode.sort(comp); list::iterator itListNode; double tmpDbl; //on coupe en deux la liste trié int nbElement=orderedNode.size(); nbElement/=2; if (nbElement<10) return (true); itListNode=orderedNode.begin(); double tmpDblStart; tmpDbl=metric->getNodeValue(*itListNode); tmpDblStart=tmpDbl; int n=0; ++itListNode; nbElement--; while ((itListNode!=orderedNode.end()) && ((nbElement>0) || (tmpDbl==metric->getNodeValue(*itListNode))) ) { tmpDbl=metric->getNodeValue(*itListNode); ++itListNode; n++; nbElement--; } orderedNode.erase(itListNode,orderedNode.end()); return false; } //================================================================================ bool HierarchicalClustering::run() { string tmp1,tmp2; PropertyProxyContainer *ppC=superGraph->getPropertyProxyContainer(); MetricProxy *metric=getProxy(superGraph,"viewMetric"); tmp1="Hierar Sup"; tmp2="Hierar Inf"; bool result=false; while (!result) { list badNodeList; result = split(metric,badNodeList); if (!result) { SelectionProxy *sel1 =getLocalProxy(superGraph,"good select"); SelectionProxy *sel2 =getLocalProxy(superGraph,"bad select"); SelectionProxy *splitRes =getLocalProxy(superGraph,"split result"); sel1->setAllNodeValue(true); sel1->setAllEdgeValue(true); sel2->setAllNodeValue(true); sel2->setAllEdgeValue(true); splitRes->setAllNodeValue(true); splitRes->setAllEdgeValue(true); list::iterator itl; for (itl=badNodeList.begin();itl!=badNodeList.end();++itl) splitRes->setNodeValue(*itl,false); Iterator *itN=superGraph->getNodes(); for (;itN->hasNext();) { node nit=itN->next(); if (splitRes->getNodeValue(nit)) { sel2->setNodeValue(nit,false); Iterator *itE=superGraph->getInOutEdges(nit); for (;itE->hasNext();) { edge ite=itE->next(); sel2->setEdgeValue(ite,false); }delete itE; } else { sel1->setNodeValue(nit,false); Iterator *itE=superGraph->getInOutEdges(nit); for (;itE->hasNext();) { edge ite=itE->next(); sel1->setEdgeValue(ite,false); } delete itE; } }delete itN; SubGraph * tmpSubGraph; tmpSubGraph = superGraph->addView(tmp1,sel1); superGraph->addView(tmp2,sel2); ppC->delLocalProxy("good select"); ppC->delLocalProxy("bad select"); ppC->delLocalProxy("split result"); superGraph=tmpSubGraph->getAssociatedSuperGraph(); } } return true; } //================================================================================ bool HierarchicalClustering::check(string &erreurMsg) { erreurMsg=""; return true; } //================================================================================ void HierarchicalClustering::reset() { } //================================================================================