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

SIG_GPCrossOverTournament.cpp

00001 #include "SIGEL_GP/SIG_GPCrossOverTournament.h"
00002 #include "SIGEL_Tools/SIG_IO.h"
00003 #include <qarray.h> 
00004 
00005 
00006 
00007 SIGEL_GP::SIG_GPCrossOverTournament::SIG_GPCrossOverTournament(SIGEL_Tools::SIG_Randomizer& randomizer,
00008                                                                SIGEL_GP::SIG_GPFitnessTrainer& fitTrain,
00009                                                                SIGEL_GP::SIG_GPPopulation& actPool,
00010                                                                SIGEL_GP::SIG_GPParameter& gpParameter,
00011                                                                SIGEL_Robot::SIG_LanguageParameters &languageP,
00012                                                                int indPos1,
00013                                                                int indPos2,
00014                                                                int indPos3,
00015                                                                int indPos4)
00016   : SIG_GPTournament(randomizer,fitTrain,actPool,gpParameter,languageP),
00017     name1( actPool.getNextIdentifier() ),
00018     name2( actPool.getNextIdentifier() )
00019 {
00020   indis.resize( 4 );
00021   indis.insert( 0, new SIG_GPTournamentIndividual( indPos1 ) );
00022   indis.insert( 1, new SIG_GPTournamentIndividual( indPos2 ) );
00023   indis.insert( 2, new SIG_GPTournamentIndividual( indPos3 ) );
00024   indis.insert( 3, new SIG_GPTournamentIndividual( indPos4 ) );
00025 };
00026 
00027 SIGEL_GP::SIG_GPCrossOverTournament::~SIG_GPCrossOverTournament()
00028 { };
00029 
00030 bool SIGEL_GP::SIG_GPCrossOverTournament::run()
00031 {
00032   SIG_GPIndividual &ind1_1 = gpPool.getIndividual( indis[0]->indNumber );
00033   SIG_GPIndividual &ind1_2 = gpPool.getIndividual( indis[1]->indNumber );
00034   SIG_GPIndividual &ind2_1 = gpPool.getIndividual( indis[2]->indNumber );
00035   SIG_GPIndividual &ind2_2 = gpPool.getIndividual( indis[3]->indNumber );
00036 
00037    //Die  Hilfe-Positionen der verschiedenen Individuen
00038    
00039    int popos1_1=ind1_1.getPoolPos();
00040    int popos1_2=ind1_2.getPoolPos();
00041    int popos2_1=ind2_1.getPoolPos();
00042    int popos2_2=ind2_2.getPoolPos();
00043 
00044    //Die Fitnesswerte der verschiedenen Individuen
00045 
00046    double fitness1_1=ind1_1.getFitness();
00047    double fitness1_2=ind1_2.getFitness();
00048    double fitness2_1=ind2_1.getFitness();
00049    double fitness2_2=ind2_2.getFitness();
00050    
00051    
00052    SIG_GPIndividual *winner1 = 0;
00053    SIG_GPIndividual *winner2 = 0;
00054    int looserPos1 = 0;
00055    int looserPos2 = 0;
00056    int winnerPos1 = 0;
00057    int winnerPos2 = 0;
00058 
00059    //Die Tournament-Aktion
00060    
00061 
00062    if (fitness1_1 >= fitness1_2)
00063      {
00064        winner1 = &ind1_1;
00065        winnerPos1 = popos1_1;
00066        looserPos1 = popos1_2;
00067      }
00068    else
00069      {
00070        winner1 = &ind1_2;
00071        winnerPos1 = popos1_2;
00072        looserPos1 = popos1_1;
00073      };
00074 
00075    if (fitness2_1 >= fitness2_2)
00076      {
00077        winner2 = &ind2_1;
00078        winnerPos2 = popos2_1;
00079        looserPos2 = popos2_2;
00080      }
00081    else
00082      {
00083        winner2 = &ind2_2;
00084        winnerPos2 = popos2_2;
00085        looserPos2 = popos2_1;
00086      };
00087 
00088 #ifdef SIG_DEBUG
00089    SIGEL_Tools::SIG_IO::cerr <<"\nthe Individuals " <<winnerPos1<<" and "<<winnerPos2<<" winns the Tournament and will be crossed..\n";
00090 #endif
00091 
00092    QVector< SIG_GPIndividual > cinds = SIG_GPOperations::crossOver(*winner1,
00093                                                                    looserPos1,
00094                                                                    *winner2,
00095                                                                    looserPos2,
00096                                                                    name1,
00097                                                                    name2,
00098                                                                    randomizer,
00099                                                                    gpParameter,
00100                                                                    languageP);
00101 
00102 #ifdef SIG_DEBUG
00103    SIGEL_Tools::SIG_IO::cerr <<"the Individuals have been crossed and inserted at the Pool Positions " <<looserPos1<<" and "<<looserPos2<<" .\n";
00104 #endif
00105 
00106    SIG_GPIndividual &looser1 = gpPool.getIndividual( looserPos1 );
00107    SIG_GPIndividual &looser2 = gpPool.getIndividual( looserPos2 );
00108 
00109    inhume( looser1 );
00110    inhume( looser2 );
00111 
00112    gpPool.setIndividual(*cinds[0],looserPos1);
00113    gpPool.setIndividual(*cinds[1],looserPos2);
00114    
00115    return true;
00116 };
00117 
00118 

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