Changed stuff to make eoGeneration work
This commit is contained in:
parent
c853631219
commit
ba4ace6324
4 changed files with 50 additions and 28 deletions
|
|
@ -7,23 +7,14 @@
|
|||
|
||||
#include <eo>
|
||||
|
||||
#include "binary_value.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
typedef eoBin<float> Chrom;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void binary_value(Chrom& chrom)
|
||||
{
|
||||
float sum = 0;
|
||||
for (unsigned i = 0; i < chrom.size(); i++)
|
||||
if (chrom[i])
|
||||
sum += pow(2, chrom.size() - i - 1);
|
||||
chrom.fitness(sum);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
main()
|
||||
{
|
||||
const unsigned POP_SIZE = 8, CHROM_SIZE = 16;
|
||||
|
|
@ -59,16 +50,19 @@ main()
|
|||
|
||||
// replacement
|
||||
eoInclusion<Chrom> inclusion;
|
||||
|
||||
|
||||
// Evaluation
|
||||
eoEvalFuncPtr<Chrom> eval( binary_value );
|
||||
|
||||
// GA generation
|
||||
eoGeneration<Chrom> generation(lottery, breeder, inclusion);
|
||||
eoGeneration<Chrom> generation(lottery, breeder, inclusion, eval);
|
||||
|
||||
// evolution
|
||||
unsigned g = 0;
|
||||
do {
|
||||
try
|
||||
{
|
||||
generation(pop, binary_value);
|
||||
generation(pop);
|
||||
}
|
||||
catch (exception& e)
|
||||
{
|
||||
|
|
|
|||
Reference in a new issue