proj home

Files   Classes   Functions   Hierarchy  

explorerand.h

Go to the documentation of this file.
00001 #ifndef EXPLORERAND_H
00002 #define EXPLORERAND_H
00003 
00014 template < typename EXP, typename RND >
00015 class explorerand : public EXP
00016 {
00017 public:
00018 
00019   RND rnd;
00020 
00021   typedef typename typeop<EXP>::Targ::FNtype FN;
00022   typedef typename typeop<EXP>::Tbare::Ttype T;
00023 
00025   explorerand
00026   (
00027     uintc N_, 
00028     T const h0step=20.0, 
00029     uintc indexmax_=500
00030   )
00031     : EXP(N_,h0step,indexmax_) {}
00032 
00034   explorerand
00035   (
00036     FN fn_,
00037     uintc N_, 
00038     T const h0step=20.0, 
00039     uintc indexmax_=500
00040   )
00041     : EXP(fn_,N_,h0step,indexmax_) {}
00042 
00044   void operator ++ ();
00045 
00046 };
00047 
00048 
00049 template < typename EXP, typename RND >
00050 void explorerand<EXP,RND>::operator ++ ()
00051 {
00052   EXP::hasStateChanged=false;
00053 
00054   if (!EXP::valid)
00055     return;
00056 
00057   if (EXP::index>EXP::indexmax)
00058   {
00059     EXP::valid=false;
00060 #ifndef NDEBUG
00061 cout << "error: indexmax reached  " << SHOW(EXP::index) << endl;
00062 #endif
00063     return;
00064   }
00065 
00066   ++EXP::index;
00067 
00068   static T tmp;
00069 
00070   for (uint i=0; i<EXP::N; ++i)
00071   {
00072     tmp = EXP::xi[i];
00073 
00074 bool flag=false;
00075 for (uint k=0; k<1; ++k)
00076 {
00077 if (flag==false)
00078 {
00079     EXP::xi[i] += EXP::hi[i]*rnd();
00080     if (EXP::evaluate())
00081     {
00082       flag=true;
00083 //      cout << "***" << endl;
00084       continue;
00085     }
00086 
00087     EXP::xi[i] = tmp - EXP::hi[i]*rnd();
00088     if (EXP::evaluate())
00089     {
00090       flag=true;
00091 //      cout << "###" << endl;
00092       continue;
00093     }
00094 }
00095 }
00096 
00097 if (flag==true)
00098   continue;
00099 
00100 
00101     EXP::xi[i] = tmp;
00102 
00103 /*
00104 
00105     EXP::xi[i] += EXP::hi[i];
00106     if (EXP::evaluate())
00107       continue;
00108 
00109     EXP::hi[i] *= -1;
00110     EXP::xi[i] += EXP::hi[i];
00111     EXP::xi[i] += EXP::hi[i];
00112     if (EXP::evaluate())
00113       continue;
00114 
00115     tmp = EXP::xi[i];
00116     
00117     // Try find a random solution with the interval. 
00118     EXP::xi[i] += EXP::hi[i]*2.0*rnd();
00119     if (EXP::evaluate())
00120     {
00121 cout << "success" << endl;
00122       continue;
00123     }
00124 
00125 cout << "fuck" << endl;
00126  
00127     EXP::xi[i] = tmp; 
00128 
00129     EXP::xi[i] -= EXP::hi[i];
00130 */
00131 
00132     EXP::hi[i] *= 0.61803398875; 
00133   }
00134 }
00135 
00136 
00137 
00138 #endif
00139 
00140 

Generated on Fri Mar 4 00:49:29 2011 for Chelton Evans Source by  doxygen 1.5.8