src/ell/StateAcceptor.cc
Go to the documentation of this file.00001 #include "ell/StateAcceptor.hh" 00002 #include "biu/RandomNumberFactory.hh" // for SA_Metropolis 00003 #include <math.h> // exp for SA_Metropolis 00004 00005 00006 using namespace ell; 00007 00008 bool 00009 SA_All::accept(const StateCollector* const sc, const State& succ) const 00010 { 00011 return true; 00012 } 00013 00014 bool 00015 SA_E_Eq::accept(const StateCollector* const sc, const State& succ) const 00016 { 00017 if ( succ.getEnergy() == sc->getLastAdded()->getEnergy()) 00018 return true; 00019 else 00020 return false; 00021 } 00022 00023 bool 00024 SA_E_Gr::accept(const StateCollector* const sc, const State& succ) const 00025 { 00026 if ( succ.getEnergy() > sc->getLastAdded()->getEnergy()) 00027 return true; 00028 else 00029 return false; 00030 } 00031 00032 bool 00033 SA_E_GrEq::accept(const StateCollector* const sc, const State& succ) const 00034 { 00035 if ( succ.getEnergy() >= sc->getLastAdded()->getEnergy()) 00036 return true; 00037 else 00038 return false; 00039 } 00040 00041 bool 00042 SA_E_Le::accept(const StateCollector* const sc, const State& succ) const 00043 { 00044 if ( succ.getEnergy() < sc->getLastAdded()->getEnergy()) 00045 return true; 00046 else 00047 return false; 00048 } 00049 00050 bool 00051 SA_E_LeEq::accept(const StateCollector* const sc, const State& succ) const 00052 { 00053 if ( succ.getEnergy() <= sc->getLastAdded()->getEnergy()) 00054 return true; 00055 else 00056 return false; 00057 } 00058 00059 bool 00060 SA_EC_Le::accept(const StateCollector* const sc, const State& succ) const 00061 { 00062 if ( succ.getEnergy() < sc->getLastAdded()->getEnergy()) { 00063 return true; 00064 } else if ( succ.getEnergy() == sc->getLastAdded()->getEnergy() 00065 && succ.compress() < sc->getLastAdded()->compress() ) 00066 { 00067 return true; 00068 } else { 00069 return false; 00070 } 00071 } 00072 00073 SA_Metropolis::SA_Metropolis(const double _beta) :beta(_beta) {} 00074 00075 bool 00076 SA_Metropolis::accept(const StateCollector* const sc, const State& succ) const 00077 { 00078 // compute energy difference 00079 double deltaE = succ.getEnergy() - sc->getLastAdded()->getEnergy(); 00080 // compute probability for accepting state -> Metropolis 00081 double p = exp((-1)*beta*deltaE); 00082 00083 // compute random number 0 <= r <= 1 00084 double r = (((double) biu::RNF::getRN()) / ((double) biu::RNF::getMaxRN())); 00085 00086 // return true with probability p 00087 if (p>r) return true; 00088 else return false; 00089 }