#include #include #include "StrahlerAllMetric.h" #include METRICPLUGIN(StrahlerAllMetric,"StrahlerAllGeneral","David Auber","06/04/2000","Alpha","0","1"); using namespace std; namespace std { struct couple { int p,r; bool operator ==(const couple&d) { if ((p==d.p) && (r==d.r)) return true; return false; } }; template <> struct equal_to { bool operator()(const couple &c,const couple &d) { if ((c.r==d.r) && (c.p==d.p)) return true; return false; } }; template <> struct less { bool operator()(const couple &c,const couple &d) { if (c.rd.r) return false; if (c.pd.p) return false; return false; } }; }; static int returnEdge=0; static int crossEdge=0; static int descentEdge=0; static int normalEdge=0; int max(int i1,int i2) { if (i1>i2) return i1; else return i2; } int min(int i1,int i2) { if (i1e2.freeS); } }; Strahler StrahlerAllMetric::topSortStrahler(node n, int &curPref, STL_EXT_NS::hash_map &tofree, STL_EXT_NS::hash_map &prefix, STL_EXT_NS::hash_map &visited, STL_EXT_NS::hash_map &finished, STL_EXT_NS::hash_map &cachedValues) { visited[n]=true; Strahler result; prefix[n]=curPref; curPref++; if (superGraph->outdeg(n)==0) {finished[n]=true;return(result);} list strahlerResult; // cerr << "."; list tmpEval; //Construction des ensembles pour evaluer le strahler Iterator *itN=superGraph->getOutNodes(n); for (;itN->hasNext();) { node tmpN=itN->next(); if (!visited[tmpN]) { normalEdge++; //Arc Normal tofree[n]=0; Strahler tmpValue=topSortStrahler(tmpN,curPref,tofree,prefix,visited,finished,cachedValues); //Data for strahler evaluation on the spanning Dag. strahlerResult.push_front(tmpValue.strahler); //Counting current used stacks. //old result.usedStack+=tmpValue.usedStack; //old result.usedStack-=tofree[n]; tmpEval.push_back(StackEval(tmpValue.stacks-tmpValue.usedStack+tofree[n],tmpValue.usedStack-tofree[n])); //Looking if we need more stacks to evaluate this node. //old freeStacks=max(freeStacks,tmpValue.stacks-tmpValue.usedStack+tofree[n]); } else { if (finished[tmpN]) { if(prefix[tmpN]::iterator it=tmpEval.begin();it!=tmpEval.end();++it) { result.usedStack+=it->usedS; result.stacks=max(result.stacks,it->freeS+it->usedS);//tmpValue.stacks-tmpValue.usedStack+tofree[n]); result.stacks-=it->usedS; } result.stacks=result.stacks+result.usedStack; //evaluation du strahler simple int tmpDbl; int additional=0; int available=0; strahlerResult.sort(); while (!strahlerResult.empty()) { tmpDbl=strahlerResult.back(); strahlerResult.pop_back(); if (tmpDbl>available) { additional+=tmpDbl - available; available=tmpDbl - 1; } else available -=1; } result.strahler=additional; strahlerResult.clear(); finished [n]=true; cachedValues[n]=result; return result; } StrahlerAllMetric::StrahlerAllMetric(PropertyContext *context):Metric(context) {} StrahlerAllMetric::~StrahlerAllMetric() {} bool StrahlerAllMetric::run() { STL_EXT_NS::hash_map visited; STL_EXT_NS::hash_map finished; STL_EXT_NS::hash_map prefix; STL_EXT_NS::hash_map tofree; STL_EXT_NS::hash_map cachedValues; int curPref=0; Iterator *it=superGraph->getNodes(); for (int i=0;it->hasNext();++i) { if (!pluginProgress->progress(i,superGraph->numberOfNodes())) break; visited.clear(); finished.clear(); prefix.clear(); tofree.clear(); cachedValues.clear(); curPref=0; node itn=it->next(); tofree[itn]=0; topSortStrahler(itn,curPref,tofree,prefix,visited,finished,cachedValues); metricProxy->setNodeValue(itn,sqrt((double)cachedValues[itn].strahler*(double)cachedValues[itn].strahler +(double)cachedValues[itn].stacks*(double)cachedValues[itn].stacks)); } delete it; return pluginProgress->progress(100,100); } bool StrahlerAllMetric::check(string &erreurMsg) { erreurMsg=""; return true; } void StrahlerAllMetric::reset(){}