38 AnnealEvoPopulation::AnnealEvoPopulation(
int populationSize,
configuration config)
40 compareAverageScores=
true;
41 clearScoresBetweenGenerations=
false;
42 this->compareAverageScores=config.getintvalue(
"compareAverageScores");
43 this->clearScoresBetweenGenerations=config.getintvalue(
"clearScoresBetweenGenerations");
45 for(
int i=0;i<populationSize;i++)
52 AnnealEvoPopulation::~AnnealEvoPopulation()
54 for(std::size_t i=0;i<controllers.size();i++)
56 delete controllers[i];
60 void AnnealEvoPopulation::mutate(std::tr1::ranlux64_base_01 *engPntr,std::size_t numMutate,
double T)
62 for(std::size_t i=0;i<numMutate;i++)
65 int copyTo = this->controllers.size()-1-i;
66 controllers.at(copyTo)->copyFrom(controllers.at(copyFrom));
67 controllers.at(copyTo)->mutate(engPntr, T);
74 return elm1->averageScore > elm2->averageScore;
78 return elm1->maxScore > elm2->maxScore;
82 void AnnealEvoPopulation::orderPopulation()
85 for(std::size_t i=0;i<this->controllers.size();i++)
87 double ave = std::accumulate(controllers[i]->pastScores.begin(),controllers[i]->pastScores.end(),0);
88 ave /= (double) controllers[i]->pastScores.size();
89 controllers[i]->averageScore=ave;
90 if(clearScoresBetweenGenerations)
91 controllers[i]->pastScores.clear();
94 if(compareAverageScores)
95 sort(controllers.begin(),controllers.end(),this->comparisonFuncForAverage);
97 sort(controllers.begin(),controllers.end(),this->comparisonFuncForMax);
101 void AnnealEvoPopulation::readConfigFromXML(std::string configFile)
106 in.open(configFile.c_str());
109 cerr << endl <<
"impossible to read file " << configFile << endl;
116 in >> ws >> elementTxt;
117 if(elementTxt ==
"<!--")
121 in >> ws >> elementTxt;
122 }
while(elementTxt !=
"-->");
124 else if(elementTxt ==
"compareAverageScores")
126 in >> ws >> intValue;
127 this->compareAverageScores=intValue;
129 else if(elementTxt ==
"clearScoresBetweenGenerations")
131 in >> ws >> intValue;
132 this->clearScoresBetweenGenerations=intValue;
134 else if(elementTxt ==
"populationSize")
136 in >> ws >> intValue;
137 this->populationSize=intValue;
139 }
while(elementTxt !=
"</configuration>" || in.eof());
Contains the definition of class AnnealEvoPopulation Adapting NeuroEvolution to do Simulated Annealin...