Commit f50f76db authored by maitre's avatar maitre

elitism bug tracking

parent 4945abf3
......@@ -7,6 +7,7 @@ using namespace std;
#include <iostream>
#include "EASEATools.hpp"
#include "EASEAIndividual.hpp"
#include <time.h>
RandomGenerator* globalRandomGenerator;
......@@ -17,12 +18,15 @@ int main(int argc, char** argv){
parseArguments("EASEA.prm",argc,argv);
size_t parentPopulationSize = setVariable("popSize",\POP_SIZE);
size_t offspringPopulationSize = setVariable("popSize",\OFF_SIZE);
size_t offspringPopulationSize = setVariable("nbOffspring",\OFF_SIZE);
float pCrossover = \XOVER_PROB;
float pMutation = \MUT_PROB;
float pMutationPerGene = 0.05;
globalRandomGenerator = new RandomGenerator(0);
time_t seed = setVariable("seed",time(0));
globalRandomGenerator = new RandomGenerator(seed);
std::cout << "Seed is : " << seed << std::endl;
SelectionOperator* selectionOperator = new \SELECTOR;
SelectionOperator* replacementOperator = new \RED_FINAL;
......@@ -36,7 +40,7 @@ int main(int argc, char** argv){
EvolutionaryAlgorithm ea(parentPopulationSize,offspringPopulationSize,selectionPressure,replacementPressure,
selectionOperator,replacementOperator,pCrossover, pMutation, pMutationPerGene,outputfile,inputfile);
StoppingCriterion* sc = new GenerationalCriterion(&ea,\NB_GEN);
StoppingCriterion* sc = new GenerationalCriterion(&ea,setVariable("nbGen",\NB_GEN));
ea.addStoppingCriterion(sc);
Population* pop = ea.getPopulation();
......@@ -275,7 +279,29 @@ void EvolutionaryAlgorithm::runEvolutionaryLoop(){
currentAverageFitness=0.0;
currentSTDEV=0.0;
//Calcul de la moyenne et de l'ecart type
showPopulationStats();
\INSERT_GEN_FCT_CALL
}
population->sortParentPopulation();
//std::cout << *population << std::endl;
std::cout << "Generation : " << currentGeneration << std::endl;
if( outputfile ){
DEBUG_PRT("Dumping final population to file : %s",outputfile->c_str());
std::ofstream ofs(outputfile->c_str());
boost::archive::text_oarchive oa(ofs);
population->syncOutVector();
oa << *population ;
}
}
void EvolutionaryAlgorithm::showPopulationStats(){
//Calcul de la moyenne et de l'ecart type
for(int i=0; i<population->parentPopulationSize; i++){
currentAverageFitness+=population->parents[i]->getFitness();
if(currentGeneration== 1 && i==0)
......@@ -294,30 +320,13 @@ void EvolutionaryAlgorithm::runEvolutionaryLoop(){
//Affichage
if(currentGeneration==1){
printf("GEN\tTIME\tEVAL\tBEST\t\tAVG\t\tSTDEV\n\n");
printf("%d\t%d\t%d\t%f\t%f\t%f\n",currentGeneration,0,population->currentEvaluationNb,population->Best->getFitness(),currentAverageFitness,currentSTDEV);
}
else
printf("%d\t%d\t%d\t%f\t%f\t%f\n",currentGeneration,0,population->currentEvaluationNb,population->Best->getFitness(),currentAverageFitness,currentSTDEV);
\INSERT_GEN_FCT_CALL
}
population->sortParentPopulation();
std::cout << *population << std::endl;
std::cout << "Generation : " << currentGeneration << std::endl;
if( outputfile ){
DEBUG_PRT("Dumping final population to file : %s",outputfile->c_str());
std::ofstream ofs(outputfile->c_str());
boost::archive::text_oarchive oa(ofs);
population->syncOutVector();
oa << *population ;
}
printf("GEN\tTIME\tEVAL\tBEST\t\tAVG\t\tSTDEV\n\n");
printf("%d\t%d\t%d\t%f\t%f\t%f\n",currentGeneration,0,population->currentEvaluationNb,population->Best->getFitness(),currentAverageFitness,currentSTDEV);
}
else
printf("%d\t%d\t%d\t%f\t%f\t%f\n",currentGeneration,0,population->currentEvaluationNb,population->Best->getFitness(),currentAverageFitness,currentSTDEV);
}
bool EvolutionaryAlgorithm::allCriteria(){
for( size_t i=0 ; i<stoppingCriteria.size(); i++ ){
......@@ -418,6 +427,8 @@ public:
Population* population;
size_t reduceParents;
size_t reduceOffsprings;
void showPopulationStats();
std::vector<StoppingCriterion*> stoppingCriteria;
std::string* outputfile;
......@@ -1137,6 +1148,7 @@ void parseArguments(const char* parametersFileName, int ac, char** av,
("nbOffspring",po::value<int>(),"set the offspring population size")
("elite",po::value<int>(),"Nb of elite parents (absolute)")
("eliteType",po::value<int>(),"Strong (1) or weak (1)")
("nbGen",po::value<int>(),"Set the number of generation")
("surviveParents",po::value<int>()," Nb of surviving parents (absolute)")
("surviveOffsprings",po::value<int>()," Nb of surviving offsprings (absolute)")
("outputfile",po::value<string>(),"Set an output file for the final population (default : none)")
......@@ -1489,7 +1501,7 @@ clean:
# Parameter file generated by AESAE-EO v0.7b
#
#***************************************
--seed=0 # -S : Random number seed. It is possible to give a specific seed.
# --seed=0 # -S : Random number seed. It is possible to give a specific seed.
###### Evolution Engine ######
--popSize=\POP_SIZE # -P : Population Size
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment