[galib] Best Genomes
Παναγιώτης Παναγή
panagi at iti.gr
Mon Nov 7 07:29:22 EST 2005
Write a terminate function and inside store the best genomes of each
generation, something like this:
GABoolean GATerminateUpponGeneration(GAGeneticAlgorithm& ga){
string s;
//output best genomes of each generation
s=(string)ImageNumber+"\\";
s+="FitnessBestGenomes.txt";
ofstream qout(s.c_str(),ios::app);
qout<<"Current generation is: "<< ga.generation()<<'\n';
qout<<"Rank\t\tFitness"<<"\n----\t\t-------\n";
for (int i=0;i<10;i++){
qout<<i+1<<"\t\t"<<ga.statistics().bestIndividual(i).score()<<'\n';
}
qout<<"\n\n";
deviation=ga.statistics().current(GAStatistics::Deviation);
return(ga.generation() < ga.nGenerations() ? gaFalse : gaTrue);
}
You can set the number of best genomes to keep with this:
ga.nBestGenomes(nbestgen);
So in this example nbestgen is 10
-------
Panos Panagi
More information about the galib
mailing list