2#include "OneMaxEvalOp.h"
9 state->getRegistry()->registerEntry(
"infile", (voidP) (
new std::string), ECF::STRING);
18 if(!state->getRegistry()->isModified(
"infile")) {
19 state->getLogger()->log(1,
"no input file defined (parameter 'infile'");
23 voidP sptr = state->getRegistry()->getEntry(
"infile");
24 std::string filePath = *((std::string*) sptr.get());
26 ifstream inFile(filePath);
29 uint genLength = 0, row = 0;
32 while(getline(inFile, str)) {
34 image.push_back(std::vector<int>(width));
36 for(uint col = 0; col < width; col++)
37 image[row][col] = (str[col] !=
' ') ? 1 : 0;
42 state->getRegistry()->modifyEntry(
"BitString.size", (voidP)
new uint(genLength));
45 state->getPopulation()->initialize(state);
69 for(uint i = 0; i<bitstr->bits.size(); i++){
72 if(bitstr->bits[i] ==
true && image[row][col] > 0)
74 else if(bitstr->bits[i] ==
false && image[row][col] == 0)
77 fitness->setValue(hits);
84 for(uint i = 0; i < height; i++) {
85 for(uint j = 0; j < width; j++) {
86 if(bitstr->bits[i*width + j] ==
true)
96 if(bestVal == bitstr->bits.size()) {
98 for(uint i = 0; i < height; i++)
99 for(uint j = 0; j < width; j++)
100 image[i][j] = !image[i][j];
BitString class - implements genotype as a series of bits.
Fitness for maximization problems.
FitnessP evaluate(IndividualP individual)
Evaluate a single individual. Method must create and return a Fitness object.
void registerParameters(StateP)
Register evaluator parameters. Called before EvaluateOp::initialize method.
bool initialize(StateP)
Initialize the evaluator. Called before first evaluation occurs.