ECF 1.5
TermStagnationOp.cpp
1#include "ECF_base.h"
2#include "TermStagnationOp.h"
3#include <cmath>
4
5
7{
8 uint *value = new uint(50);
9 state->getRegistry()->registerEntry("term.stagnation", (voidP) value, ECF::UINT,
10 "max number of consecutive generations without improvement (default: 5000 / pop_size)");
11}
12
13
15{
16 voidP sptr = state->getRegistry()->getEntry("term.stagnation");
17 termStagnation_ = *((uint*) sptr.get());
18
19 // define the default criterion
20 if(termStagnation_ == 0) {
21 voidP sptr = state->getRegistry()->getEntry("population.size");
22 uint demeSize = *((uint*) sptr.get());
23 termStagnation_ = 5000 / demeSize;
24 if(termStagnation_ < 10)
25 termStagnation_ = 5;
26 if(termStagnation_ > 200)
27 termStagnation_ = 200;
28 }
29
30 if(!state->getRegistry()->isModified("term.stagnation"))
31 return false;
32
33 return true;
34}
35
36
37bool TermStagnationOp::operate(StateP state)
38{
39 uint currentGen = state->getGenerationNo();
40 if(currentGen - state->getPopulation()->getHof()->getLastChange() > termStagnation_) {
41 state->setTerminateCond();
42 ECF_LOG(state, 1, "Termination: maximum number of generations without improvement ("
43 + uint2str(termStagnation_) + ") reached");
44 }
45
46 return true;
47}
void registerParameters(StateP)
Register parameters with the Registry. Called before Operator::initialize.
bool operate(StateP)
perform the designated operation
bool initialize(StateP)
Perform initialization. Called before Operator::operate. By default, if the return value is false,...