2#include "TermStagnationOp.h"
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)");
16 voidP sptr = state->getRegistry()->getEntry(
"term.stagnation");
17 termStagnation_ = *((uint*) sptr.get());
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)
26 if(termStagnation_ > 200)
27 termStagnation_ = 200;
30 if(!state->getRegistry()->isModified(
"term.stagnation"))
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");
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,...