00001 #include "SIGEL_GP/SIG_GPMutationTournament.h"
00002 #include "SIGEL_Tools/SIG_IO.h"
00003
00004
00005 SIGEL_GP::SIG_GPMutationTournament::SIG_GPMutationTournament(SIGEL_Tools::SIG_Randomizer& randomizer,
00006 SIG_GPFitnessTrainer& fitTrain,
00007 SIG_GPPopulation& actPool,
00008 SIG_GPParameter& gpParameter,
00009 SIGEL_Robot::SIG_LanguageParameters &languageP,
00010 int ppos1,
00011 int ppos2)
00012 :SIG_GPTournament(randomizer,fitTrain,actPool,gpParameter,languageP),
00013 name(actPool.getNextIdentifier())
00014 {
00015 indis.resize( 2 );
00016 indis.insert( 0, new SIG_GPTournamentIndividual( ppos1 ) );
00017 indis.insert( 1, new SIG_GPTournamentIndividual( ppos2 ) );
00018 };
00019
00020 SIGEL_GP::SIG_GPMutationTournament::~SIG_GPMutationTournament()
00021 { };
00022
00023 bool SIGEL_GP::SIG_GPMutationTournament::run()
00024 {
00025 SIG_GPIndividual &ind1 = gpPool.getIndividual( indis[0]->indNumber );
00026 SIG_GPIndividual &ind2 = gpPool.getIndividual( indis[1]->indNumber );
00027
00028
00029
00030 int popos1=ind1.getPoolPos();
00031 int popos2=ind2.getPoolPos();
00032
00033
00034
00035 double var1=ind1.getFitness();
00036 double var2=ind2.getFitness();
00037
00038
00039
00040 SIG_GPIndividual *winner;
00041 int looserPos = 0;
00042 int winnerPos = 0;
00043
00044 if (var1>=var2)
00045 {
00046 winner = &ind1;
00047 looserPos = popos2;
00048 winnerPos = popos1;
00049 }
00050 else
00051 {
00052 winner = &ind2;
00053 looserPos = popos1;
00054 winnerPos = popos2;
00055 };
00056
00057 #ifdef SIG_DEBUG
00058 SIGEL_Tools::SIG_IO::cerr <<"\nthe Individual " <<winnerPos<<" winns the Tournament and will be mutated..\n";
00059 #endif
00060
00061 SIG_GPIndividual& mind = SIG_GPOperations::mutation(*winner,
00062 looserPos,
00063 name,
00064 randomizer,
00065 gpParameter,
00066 languageP);
00067
00068 #ifdef SIG_DEBUG
00069 SIGEL_Tools::SIG_IO::cerr <<"the Individual " <<winnerPos<<" have been mutated and inserted at the Pool Position " << looserPos << " .\n";
00070 #endif
00071
00072 SIG_GPIndividual &looser = gpPool.getIndividual( looserPos );
00073
00074 inhume( looser );
00075
00076 gpPool.setIndividual(mind, looserPos);
00077
00078 return true;
00079 };
00080
00081