Changes to eo1d interface and bug fixes
This commit is contained in:
parent
06db0c058e
commit
759dba7ea8
47 changed files with 759 additions and 204 deletions
|
|
@ -1,10 +1,15 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// t-eobreeder.cpp
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// to avoid long name warnings
|
||||
#pragma warning(disable:4786)
|
||||
|
||||
#include <stdlib.h> // srand
|
||||
#include <time.h> // time
|
||||
#include <eo> // eoBin, eoPop, eoBreeder
|
||||
#include <eoBin.h> // eoBin, eoPop, eoBreeder
|
||||
#include <eoPop.h>
|
||||
#include <eoBitOp.h>
|
||||
#include <eoProportionalOpSel.h>
|
||||
#include <eoBreeder.h>
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
|
@ -25,14 +30,12 @@ void binary_value(Chrom& chrom)
|
|||
|
||||
main()
|
||||
{
|
||||
srand(time(NULL));
|
||||
|
||||
const unsigned POP_SIZE = 8, CHROM_SIZE = 4;
|
||||
unsigned i;
|
||||
|
||||
eoUniform<Chrom::Type> uniform(false, true);
|
||||
eoBinRandom<Chrom> random;
|
||||
eoPop<Chrom> pop, pop2;
|
||||
eoPop<Chrom> pop;
|
||||
|
||||
for (i = 0; i < POP_SIZE; i++)
|
||||
{
|
||||
|
|
@ -42,22 +45,22 @@ main()
|
|||
pop.push_back(chrom);
|
||||
}
|
||||
|
||||
eoBinBitFlip<Chrom> bitflip;
|
||||
eoBinCrossover<Chrom> xover;
|
||||
eoBreeder<Chrom> breeder;
|
||||
breeder.add(bitflip, 1.0);
|
||||
breeder.add(xover, 1.0);
|
||||
|
||||
pop2 = pop;
|
||||
breeder(pop2);
|
||||
|
||||
for (i = 0; i < pop2.size(); i++)
|
||||
binary_value(pop2[i]);
|
||||
|
||||
cout << "population: \tnew population" << endl;
|
||||
cout << "population:" << endl;
|
||||
for (i = 0; i < pop.size(); i++)
|
||||
cout << pop[i] << " " << pop[i].fitness() << " \t"
|
||||
<< pop2[i] << " " << pop2[i].fitness() << endl;
|
||||
cout << pop[i] << " " << pop[i].fitness() << endl;
|
||||
|
||||
eoBinBitFlip<Chrom> bitflip;
|
||||
eoBinCrossover<Chrom> xover;
|
||||
eoProportionalOpSel<Chrom> propSel;
|
||||
eoBreeder<Chrom> breeder( propSel );
|
||||
propSel.addOp(bitflip, 0.25);
|
||||
propSel.addOp(xover, 0.75);
|
||||
|
||||
breeder(pop);
|
||||
|
||||
cout << "new population:" << endl;
|
||||
for (i = 0; i < pop.size(); i++)
|
||||
cout << pop[i] << " " << pop[i].fitness() << endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
Reference in a new issue