• Main Page
  • Modules
  • Classes
  • Files
  • File List

D:/Projekt/ECF_trunk/ECF/TermStagnationOp.cpp

00001 #include "ECF_base.h"
00002 #include "TermStagnationOp.h"
00003 #include <cmath>
00004 
00005 
00006 void TermStagnationOp::registerParameters(StateP state)
00007 {
00008     uint *value = new uint(50);
00009     state->getRegistry()->registerEntry("term.stagnation", (voidP) value, ECF::UINT,
00010         "max number of consecutive generations without improvement (default: 5000 / pop_size)");
00011 }
00012 
00013 
00014 bool TermStagnationOp::initialize(StateP state)
00015 {
00016     voidP sptr = state->getRegistry()->getEntry("term.stagnation");
00017     termStagnation_ = *((uint*) sptr.get());
00018 
00019     // define the default criterion
00020     if(termStagnation_ == 0) {
00021         voidP sptr = state->getRegistry()->getEntry("population.size");
00022         uint demeSize = *((uint*) sptr.get());
00023         termStagnation_ = 5000 / demeSize;
00024         if(termStagnation_ < 10)
00025             termStagnation_ = 5;
00026         if(termStagnation_ > 200)
00027             termStagnation_ = 200;
00028     }
00029 
00030     if(!state->getRegistry()->isModified("term.stagnation"))
00031         return false;
00032 
00033     return true;
00034 }
00035 
00036 
00037 bool TermStagnationOp::operate(StateP state)
00038 {
00039     uint currentGen = state->getGenerationNo();
00040     if(currentGen - state->getPopulation()->getHof()->getLastChange() > termStagnation_) {
00041         state->setTerminateCond();
00042         ECF_LOG(state, 1, "Termination: maximum number of generations without improvement ("
00043             + uint2str(termStagnation_) + ") reached");
00044     }
00045 
00046     return true;
00047 }

Generated on Tue Nov 4 2014 13:04:31 for ECF by  doxygen 1.7.1