testpropagation.cpp

Go to the documentation of this file.
00001 #include <iostream>
00002 #include "SimpleSelect.h"
00003 #include "BinaryTournamentSelect.h"
00004 #include "CUniformRNG.h"
00005 #include "gentypes.h"
00006 #include "BinaryPopulation.h"
00007 #include "StandardPropagation.h"
00008 #include <boost/function.hpp>
00009 #include <boost/bind.hpp>
00010 
00011 using namespace std;
00012 int main()
00013 {
00014         const int popsize = 10;
00015         const int genesize = 5;
00016         UniformRNG Random;
00017         
00018         BinaryPopulation Population(popsize,genesize,&Random,true);
00019         
00020         BinaryTournamentSelect Select(&Random,boost::bind(&GeneralPopulation::GetProbabilities,boost::ref(Population)),
00021                 boost::bind(&GeneralPopulation::GetCrowdingDistances,boost::ref(Population)));
00022         StandardPropagation Propagator(&Select,&Population,&Random);
00023         tprobabilityv probabilities(popsize);
00024         double sum=0;
00025         
00026         const double mutationprob = 0.01;
00027         const double crossoverprob = 0.2;
00028         Propagator.SetParams(mutationprob,crossoverprob);
00029         
00030         cout << "Pointers set" << endl <<flush;
00031         
00032         cout << "Population initialized" << endl <<flush;
00033         Population.PrintPopulation(cout);
00034         for (int j = 0; j < 3; ++j)
00035         {
00036                 for (int i = 0; i < popsize; ++i)
00037                 {
00038                         probabilities(i) = Random.GetNumber();
00039                         sum += probabilities(i);
00040                 }
00041                 for (int i = 0; i < popsize; ++i)
00042                 {
00043                         probabilities(i) /= sum;
00044                         cout << probabilities(i) << " ";
00045                 }
00046                 cout << endl;
00047                 Population.SetProbabilities(probabilities);
00048                 Propagator.NextGeneration();
00049                 cout << endl << flush;
00050                 Population.PrintPopulation(cout);
00051         }
00052 }

Generated on Mon Sep 15 12:54:34 2008 for GPLIB++ by  doxygen 1.5.5