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
00028 #ifndef __GNUG__
00029
00030 #pragma warning(disable:4786)
00031 #endif // __GNUG__
00032
00033 #include <iostream>
00034
00035 #include <ga/eoBin.h>
00036 #include <eoPop.h>
00037 #include <ga/eoBitOp.h>
00038 #include <eoProportionalGOpSel.h>
00039 #include <eoSequentialGOpSelector.h>
00040 #include <eoRandomIndiSelector.h>
00041
00042 #include <eoDetTournamentIndiSelector.h>
00043 #include <eoDetTournamentInserter.h>
00044 #include <eoStochTournamentInserter.h>
00045
00046 #include <eoGOpBreeder.h>
00047
00048 #include <utils/eoRNG.h>
00049 #include <utils/eoState.h>
00050
00051
00052 #include "binary_value.h"
00053
00054
00055
00056 typedef eoBin<float> Chrom;
00057
00058
00059
00060 main()
00061 {
00062 rng.reseed(42);
00063
00064 const unsigned POP_SIZE = 8, CHROM_SIZE = 4;
00065 unsigned i;
00066
00067 eoBinRandom<Chrom> random;
00068 eoPop<Chrom> pop;
00069
00070 for (i = 0; i < POP_SIZE; ++i)
00071 {
00072 Chrom chrom(CHROM_SIZE);
00073 random(chrom);
00074 chrom.fitness(binary_value(chrom));
00075 pop.push_back(chrom);
00076 }
00077
00078 std::cout << "population:" << std::endl;
00079 for (i = 0; i < pop.size(); ++i)
00080 std::cout << pop[i] << " " << pop[i].fitness() << std::endl;
00081
00082 eoBinBitFlip<Chrom> bitflip;
00083 eoBinCrossover<Chrom> xover;
00084
00085 eoEvalFuncPtr<Chrom> eval(binary_value);
00086
00087
00088
00089
00090 eoProportionalGOpSel<Chrom > propSel;
00091 eoSequentialGOpSel<Chrom> seqSel;
00092
00093 propSel.addOp(bitflip, 0.5);
00094 propSel.addOp(xover, 0.5);
00095
00096
00097
00098 seqSel.addOp(bitflip, 0.25);
00099 seqSel.addOp(xover, 0.5);
00100 seqSel.addOp(bitflip, 0.25);
00101
00102
00103 eoRandomIndiSelector<Chrom> selector1;
00104 eoDetTournamentIndiSelector<Chrom> selector2(2);
00105
00106 eoBackInserter<Chrom> inserter1;
00107 eoDetTournamentInserter<Chrom> inserter2(eval, 2);
00108 eoStochTournamentInserter<Chrom> inserter3(eval, 0.9f);
00109
00110 eoGOpBreeder<Chrom> breeder1(propSel, selector1);
00111 eoGOpBreeder<Chrom> breeder2(seqSel, selector1);
00112 eoGOpBreeder<Chrom> breeder3(propSel, selector2);
00113 eoGOpBreeder<Chrom> breeder4(seqSel, selector2);
00114
00115
00116
00117 breeder1(pop);
00118 breeder2(pop);
00119 breeder3(pop);
00120 breeder4(pop);
00121
00122 eoState state;
00123
00124 state.registerObject(pop);
00125
00126 state.save(std::std::cout);
00127
00128 return 0;
00129 }
00130
00131