ECF 1.5
EvaluateAlternate.h
1//
2// pomocni operator za ispitivanje trenutnih rjesenja iz HoF-a na skupu za evaluaciju
3//
5{
6private:
7 StateP state_;
8 std::string logfilename;
9 SchedulingEvalOpP testEvalOp;
10public:
11 void registerParameters(StateP state)
12 {
13 state->getRegistry()->registerEntry("test_cases2", (voidP) (new std::string("fitness2.txt")), ECF::STRING);
14 }
15
16 bool initialize(StateP state)
17 {
18 state_ = state;
19 voidP sptr = state->getRegistry()->getEntry("log.filename");
20 logfilename = *((std::string*) sptr.get());
21
22 // setup test cases evaluator
23 testEvalOp = static_cast<SchedulingEvalOpP> (new SchedulingEvalOp);
24 sptr = state->getRegistry()->getEntry("test_cases");
25 voidP sptr2 = state->getRegistry()->getEntry("test_cases2");
26 //state->getRegistry()->modifyEntry("test_cases", (voidP) (new std::string("fitness2.txt")));
27 state->getRegistry()->modifyEntry("test_cases", sptr2);
28 testEvalOp->initialize(state);
29 state->getRegistry()->modifyEntry("test_cases", sptr);
30
31 return true;
32 }
33
34 bool operate(StateP state)
35 {
36 ECF_LOG(state, 1, "Podaci\t" + uint2str(state->getGenerationNo()));
37 IndividualP bestInd = state->getPopulation()->getHof()->getBest().at(0);
38 ECF_LOG(state, 1, bestInd->toString());
39
40 TreeP bestTree = boost::dynamic_pointer_cast<Tree::Tree> (bestInd->getGenotype(0));
41 uint sizeOfBest = (uint) bestTree->size();
42
43 DemeP deme = state->getPopulation()->getLocalDeme();
44 uint popSize = (uint) deme->size();
45 uint totalSize = 0;
46 for(uint i = 0; i < popSize; i++) {
47 TreeP tree = boost::dynamic_pointer_cast<Tree::Tree> (deme->at(i)->getGenotype(0));
48 totalSize += (uint) tree->size();
49 }
50 uint averageSize = (uint) (1. * totalSize / popSize);
51
52 // evaluate best individual on test data set
53 double bestValue = testEvalOp->evaluate(bestInd)->getValue();
54
55 ECF_LOG(state, 1, uint2str(sizeOfBest) + "\t" + uint2str(averageSize) + "\t" + dbl2str(bestValue));
56
57 return true;
58 }
59};
60
bool operate(StateP state)
perform the designated operation
bool initialize(StateP state)
Perform initialization. Called before Operator::operate. By default, if the return value is false,...
void registerParameters(StateP state)
Register parameters with the Registry. Called before Operator::initialize.
Abstract operator class.
Definition: Operator.h:11