Changed the general operator interface to be consistent with the rest

of EO, updated some documentation.
This commit is contained in:
mac 2000-04-09 09:41:29 +00:00
commit ed45375451
17 changed files with 230 additions and 52 deletions

View file

@ -32,8 +32,17 @@
#include <eoPop.h>
#include <ga/eoBitOp.h>
#include <eoProportionalGOpSel.h>
//#include <eoAltBreeder.h>
#include <eoSequentialGOpSelector.h>
#include <eoRandomIndiSelector.h>
#include <eoDetTournamentIndiSelector.h>
#include <eoDetTournamentInserter.h>
#include <eoStochTournamentInserter.h>
#include <eoGOpBreeder.h>
#include <utils/eoRNG.h>
#include <utils/eoState.h>
// Fitness evaluation
#include "binary_value.h"
@ -46,6 +55,8 @@ typedef eoBin<float> Chrom;
main()
{
rng.reseed(42); // reproducible random seed
const unsigned POP_SIZE = 8, CHROM_SIZE = 4;
unsigned i;
@ -68,16 +79,49 @@ main()
eoBinBitFlip<Chrom> bitflip;
eoBinCrossover<Chrom> xover;
eoEvalFuncPtr<Chrom> eval(binary_value);
//Create the proportional operator selector and add the
// two operators creatd above to it.
eoProportionalGOpSel<Chrom > propSel;
eoSequentialGOpSel<Chrom> seqSel;
propSel.addOp(bitflip, 0.5);
propSel.addOp(xover, 0.5);
for ( i = 0; i < POP_SIZE; i ++ ) {
eoGeneralOp<Chrom>& foo = propSel.selectOp();
}
// seqSel selects operator in sequence, creating a combined operator
// add a bitflip, an xover and another bitflip
seqSel.addOp(bitflip, 0.25);
seqSel.addOp(xover, 0.5);
seqSel.addOp(bitflip, 0.25);
eoRandomIndiSelector<Chrom> selector1;
eoDetTournamentIndiSelector<Chrom> selector2(2);
eoBackInserter<Chrom> inserter1;
eoDetTournamentInserter<Chrom> inserter2(eval, 2);
eoStochTournamentInserter<Chrom> inserter3(eval, 0.9f);
eoGOpBreeder<Chrom> breeder1(propSel, selector1);
eoGOpBreeder<Chrom> breeder2(seqSel, selector1);
eoGOpBreeder<Chrom> breeder3(propSel, selector2);
eoGOpBreeder<Chrom> breeder4(seqSel, selector2);
// test the breeders
breeder1(pop);
breeder2(pop);
breeder3(pop);
breeder4(pop);
eoState state;
state.registerObject(pop);
state.save(std::cout);
return 0;
}