StandardPropagation.cpp

Go to the documentation of this file.
00001 #include "StandardPropagation.h"
00002 #include <algorithm>
00003 using namespace std;
00004 namespace ublas = boost::numeric::ublas;
00005 #include <boost/numeric/ublas/matrix_proxy.hpp>
00006 #include <boost/numeric/ublas/io.hpp>
00007 #include <iostream>
00008 StandardPropagation::StandardPropagation(GeneralSelect* const LocalSelect, GeneralPopulation* const LocalPopulation, GeneralRNG* const LocalRandom):
00009 GeneralPropagation(LocalSelect,LocalPopulation,LocalRandom)
00010 {}
00011 
00012 StandardPropagation::~StandardPropagation()
00013 {}
00014 
00015 
00016 void StandardPropagation::NextGeneration()
00017 {
00018         const int popsize = Population->GetPopulation().size1();
00019         const int genesize = Population->GetPopulation().size2();
00020         tpopulation NewPopulation(popsize,genesize);
00021         
00022         tpopmember father(genesize), mother(genesize);
00023         
00024         //Select->Init(Population->GetProbabilities(),Population->GetCrowdingDistance());
00025         Select->Init();
00026         for (int i = 0; i < popsize-1; i+=2)
00027         {
00028                 const int fatherindex = Select->GetOne();
00029                 const int motherindex = Select->GetOne();
00030                 //cout << "Father: " << fatherindex << " Mother: " << motherindex << endl;
00031                 father.assign(ublas::row(Population->GetPopulation(),fatherindex));
00032                 mother.assign(ublas::row(Population->GetPopulation(),motherindex));
00033                 
00034                 Crossover(father, mother);
00035                 Mutation(father);
00036                 Mutation(mother);
00037                 ublas::row(NewPopulation,i) = father;
00038                 ublas::row(NewPopulation,i+1) = mother;
00039         }
00040         if ((popsize % 2) != 0)
00041         {
00042                 const int fatherindex = Select->GetOne();
00043                 //cout << "FatherIndex: " << fatherindex << endl;
00044                 father.assign(ublas::row(Population->GetPopulation(),fatherindex));
00045                 //cout << "Father: " << father << endl;
00046                 Mutation(father);
00047                 ublas::row(NewPopulation,popsize-1) = father;
00048         }
00049         Population->SetPopulation(NewPopulation);
00050 }

Generated on Fri Jul 4 15:30:21 2008 for GPLIB++ by  doxygen 1.5.5