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