Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members  

SIG_GPSimpleTournament.cpp

00001 #include "SIGEL_GP/SIG_GPSimpleTournament.h"
00002 #include "SIGEL_Tools/SIG_IO.h"
00003 
00004 
00005 SIGEL_GP::SIG_GPSimpleTournament::SIG_GPSimpleTournament(SIGEL_Tools::SIG_Randomizer& randomizer,
00006                                                          SIG_GPFitnessTrainer& trainer,
00007                                                          SIG_GPPopulation& actPool,
00008                                                          SIG_GPParameter& gpParameter,
00009                                                          SIGEL_Robot::SIG_LanguageParameters &languageP,
00010                                                          int ppos1,
00011                                                          int ppos2)
00012   : SIG_GPTournament(randomizer,trainer,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_GPSimpleTournament::~SIG_GPSimpleTournament()
00021 { };
00022 
00023 bool SIGEL_GP::SIG_GPSimpleTournament::run()
00024 {      
00025    //Die Positionen der beiden Teilnehmern
00026 
00027   SIG_GPIndividual &ind1 = gpPool.getIndividual( indis[0]->indNumber );
00028   SIG_GPIndividual &ind2 = gpPool.getIndividual( indis[1]->indNumber );
00029 
00030   int popos1=ind1.getPoolPos();
00031   int popos2=ind2.getPoolPos();
00032  
00033    //Die Fitnesswerte der beiden Teilnehmern
00034 
00035    double var1=ind1.getFitness();
00036    double var2=ind2.getFitness();
00037    
00038    //Die Tournament-Aktion
00039    
00040    SIG_GPIndividual *winner = 0;
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 reproduced..\n";
00059 #endif
00060 
00061      SIG_GPIndividual& rind = SIG_GPOperations::reproduction( *winner,
00062                                                                name,
00063                                                                looserPos,
00064                                                                randomizer,
00065                                                                gpParameter,
00066                                                                languageP );
00067 
00068      rind.setFitness( winner->getFitness() );
00069 
00070 #ifdef SIG_DEBUG
00071     SIGEL_Tools::SIG_IO::cerr <<"the Individual " <<winnerPos<<" have been reproduced and inserted at the Pool Position " << looserPos << " .\n";
00072 #endif
00073 
00074     SIG_GPIndividual &looser = gpPool.getIndividual( looserPos );
00075 
00076     inhume( looser );
00077 
00078     gpPool.setIndividual(rind, looserPos);
00079 
00080     return true; 
00081  };
00082  
00083  
00084    
00085 

Generated at Mon Sep 3 01:32:25 2001 for PG 368 - SIGEL by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000