00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef __GNUG__
00028
00029 #pragma warning(disable:4786)
00030 #endif // __GNUG__
00031
00032 #include <ga/eoBin.h>
00033 #include <eoPop.h>
00034 #include <ga/eoBitOp.h>
00035 #include <eoProportionalOpSel.h>
00036 #include <eoBreeder.h>
00037
00038
00039
00040 typedef eoBin<float> Chrom;
00041
00042 #include "binary_value.h"
00043
00044
00045
00046 main()
00047 {
00048 const unsigned POP_SIZE = 8, CHROM_SIZE = 4;
00049 unsigned i;
00050
00051 eoBinRandom<Chrom> random;
00052 eoPop<Chrom> pop;
00053
00054 BinaryValue eval;
00055
00056 for (i = 0; i < POP_SIZE; ++i)
00057 {
00058 Chrom chrom(CHROM_SIZE);
00059 random(chrom);
00060 eval(chrom);
00061 pop.push_back(chrom);
00062 }
00063
00064 std::cout << "population:" << std::endl;
00065 for (i = 0; i < pop.size(); ++i)
00066 std::cout << pop[i] << " " << pop[i].fitness() << std::endl;
00067
00068 eoBinBitFlip<Chrom> bitflip;
00069 eoBinCrossover<Chrom> xover;
00070 eoProportionalOpSel<Chrom> propSel;
00071 eoBreeder<Chrom> breeder( propSel );
00072 propSel.addOp(bitflip, 0.25);
00073 propSel.addOp(xover, 0.75);
00074
00075 breeder(pop);
00076
00077
00078 for_each(pop.begin(), pop.end(), BinaryValue());
00079
00080 std::cout << "new population:" << std::endl;
00081 for (i = 0; i < pop.size(); ++i)
00082 std::cout << pop[i] << " " << pop[i].fitness() << std::endl;
00083
00084 return 0;
00085 }
00086
00087