Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef __RD_UTILS_H__
00012 #define __RD_UTILS_H__
00013
00014 #include "types.h"
00015 #include <RDGeneral/Invariant.h>
00016
00017 #include <boost/random.hpp>
00018
00019 namespace RDKit{
00020 const int NUM_PRIMES_AVAIL = 1000;
00021 extern int firstThousandPrimes[NUM_PRIMES_AVAIL];
00022
00023 const int FILE_MAXLINE=256;
00024
00025
00026
00027 double computeIntVectPrimesProduct(const INT_VECT &ring);
00028
00029
00030 bool feq(double v1,double v2,double tol=1e-4);
00031
00032 typedef boost::minstd_rand rng_type;
00033 typedef boost::uniform_int<> uniform_int;
00034 typedef boost::uniform_real<> uniform_double;
00035 typedef boost::variate_generator<rng_type &,uniform_int> int_source_type;
00036 typedef boost::variate_generator<rng_type &,uniform_double> double_source_type;
00037
00038
00039 rng_type &getRandomGenerator(int seed=-1);
00040
00041
00042
00043 double getRandomVal(int seed = -1);
00044
00045
00046 template <class T>
00047 unsigned int countSwapsToInterconvert(const T &ref,T probe){
00048 PRECONDITION(ref.size()==probe.size(),"size mismatch");
00049 typename T::const_iterator refIt=ref.begin();
00050 typename T::iterator probeIt=probe.begin();
00051 typename T::iterator probeIt2;
00052
00053 unsigned int nSwaps = 0;
00054 while(refIt!=ref.end()){
00055 if((*probeIt)!=(*refIt)){
00056 bool foundIt=false;
00057 probeIt2=probeIt;
00058 while((*probeIt2)!=(*refIt) && probeIt2!=probe.end()){
00059 ++probeIt2;
00060 }
00061 if(probeIt2 != probe.end()){
00062 foundIt=true;
00063 }
00064 CHECK_INVARIANT(foundIt,"could not find probe element");
00065
00066 std::swap(*probeIt,*probeIt2);
00067 nSwaps++;
00068 }
00069 ++probeIt;
00070 ++refIt;
00071 }
00072 return nSwaps;
00073 }
00074
00075
00076
00077 }
00078
00079
00080
00081 #endif