/* * SDependenceCalculator.cpp * * Created on: January 2010 * Author: Ronald A.J. van Elburg * Email: Ronald A J (at) vanelburg (dot) eu */ #include "SDependenceCalculator.h" #include #include SDependenceCalculator::~SDependenceCalculator(){ //std::cout << "... SDependenceCalculator::~SDependenceCalculator" << std::endl; for (int n=NMax-1;n>=0;n--){ if(n=NMax for (n=NMax;n< _NTerminals;n++){ indicesArray[n]=new int[n+1]; // Calculate number of trees in this TreeSet TreeSets[n].NoOfTrees=0; for(n1=n-1 ; 2*n1 >= n-1;n1--){ TreeSets[n].NoOfTrees+=TreeSets[n1].NoOfTrees*TreeSets[n-n1-1].NoOfTrees; } n1++; // undo last n1-- to get back into the last step to allow correction of this last step if(n1==n-n1-1){TreeSets[n].NoOfTrees-=((TreeSets[n1].NoOfTrees-1)*TreeSets[n1].NoOfTrees)/2;} // End of Calculation of the number of trees in this TreeSet TreeSets[n].NoOfLeaves=n+1; TreeSets[n].historiesArray =new double[TreeSets[n].NoOfTrees]; TreeSets[n].multiplicityArray =new double[TreeSets[n].NoOfTrees]; TreeSets[n].child1IndexArray =new int[TreeSets[n].NoOfTrees]; TreeSets[n].child1NTerminalArray=new int[TreeSets[n].NoOfTrees]; TreeSets[n].child2IndexArray =new int[TreeSets[n].NoOfTrees]; TreeSets[n].child2NTerminalArray=new int[TreeSets[n].NoOfTrees]; TreeSets[n].SEPArray =new double[TreeSets[n].NoOfTrees]; TreeSets[n].SPAArray =new double[TreeSets[n].NoOfTrees]; TreeSets[n].cofArray =new int*[TreeSets[n].NoOfTrees]; for(int i=0;i= n-1;n1--){ indicesArray[n][n1]=ti; n2=n-n1-1; logCF=logCombinatorialFactor(n-1, n1, n2); for(ti1=0;ti11){ TreeSets[n].SPAArray[ti]= fabs(n1-n2)/(n1+n2) + TreeSets[n1].SPAArray[ti1]+ TreeSets[n2].SPAArray[ti2]; }else{ TreeSets[n].SPAArray[ti]=0; } for(int j=0;j<=n1;j++){ TreeSets[n].cofArray[ti][j]=1+TreeSets[n1].cofArray[ti1][j]; } for(int j=0;j<=n2;j++){ TreeSets[n].cofArray[ti][j+n1+1]=TreeSets[n2].cofArray[ti2][j]+1; } ti++; } } } } // end for n NMax=_NTerminals; return NMax; }; inline int SDependenceCalculator::getIndex(int _n1, int _ti1 , int _n2, int _ti2 ){ int _nswap, _tiswap, index, N2; if(_n2 > _n1 ){ _nswap=_n1; _n1=_n2; _n2=_nswap; _tiswap=_ti1; _ti1=_ti2; _ti2=_tiswap; }else if(_n2 ==_n1){ if(_ti1 >_ti2){ _tiswap=_ti1; _ti1=_ti2; _ti2=_tiswap; } } //Calculate index index = indicesArray[_n1+_n2+1][_n1]; N2=TreeSets[_n2].NoOfTrees; if(_n1 > _n2 ){ index+=_ti1*N2 +_ti2; }else if(_n2 ==_n1){ index+=(_ti1*(N2*2-_ti1+1))/2 +(_ti2-_ti1); } return index; }; int SDependenceCalculator::updateSPaths(){ int n, n1, n2; int ti, ti1, ti2; int pre, ipre, ipre2, preCount; if (NMaxS ==NMax) return -1; for (n=NMaxS;n