fixing tests
This commit is contained in:
parent
6daefd1ccf
commit
f3ebe8be70
6 changed files with 21 additions and 23 deletions
|
|
@ -47,16 +47,14 @@ template<class Chrom> class eoBreeder: public eoTransform<Chrom>
|
|||
}
|
||||
case binary:
|
||||
{
|
||||
eoBinOp<Chrom>* binop =
|
||||
static_cast<eoBinOp<Chrom>* >(op);
|
||||
eoBinOp<Chrom>* binop = static_cast<eoBinOp<Chrom>* >(op);
|
||||
eoUniform<unsigned> u(0, pop.size() );
|
||||
(*binop)(pop[i], pop[ u() ] );
|
||||
break;
|
||||
}
|
||||
case Nary:
|
||||
{
|
||||
eoNaryOp<Chrom>* Nop =
|
||||
static_cast<eoNaryOp<Chrom>* >(op);
|
||||
eoNaryOp<Chrom>* Nop = static_cast<eoNaryOp<Chrom>* >(op);
|
||||
eoUniform<unsigned> u(0, pop.size() );
|
||||
eoPop<Chrom> tmpVec;
|
||||
tmpVec.push_back( pop[i] );
|
||||
|
|
|
|||
|
|
@ -7,7 +7,8 @@
|
|||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include <eo>
|
||||
#include <eoPop.h> // eoPop
|
||||
#include <eoPopOps.h> // eoMerge
|
||||
|
||||
/*****************************************************************************
|
||||
* eoInclusion: A replacement algorithm. *
|
||||
|
|
|
|||
|
|
@ -38,27 +38,27 @@ template<class Chrom> class eoLottery: public eoSelect<Chrom>
|
|||
partial_sum(score.begin(), score.end(), score.begin());
|
||||
|
||||
// generates random numbers
|
||||
vector<float> random(pop.size());
|
||||
vector<float> random(rint(rate * pop.size()));
|
||||
generate(random.begin(), random.end(), eoUniform<float>(0,1));
|
||||
sort(random.begin(), random.end(), less<float>());
|
||||
|
||||
// selection of chromosomes
|
||||
unsigned score_index = 0; // position in score vector
|
||||
unsigned random_index = 0; // position in random vector
|
||||
unsigned num_chroms = (unsigned)(rate * pop.size());
|
||||
do {
|
||||
if(random[random_index] < score[score_index])
|
||||
{
|
||||
breeders.push_back(pop[score_index]);
|
||||
random_index++;
|
||||
}
|
||||
else
|
||||
if (score_index < pop.size())
|
||||
score_index++;
|
||||
while (breeders.size() < random.size())
|
||||
{
|
||||
if(random[random_index] < score[score_index])
|
||||
{
|
||||
breeders.push_back(pop[score_index]);
|
||||
random_index++;
|
||||
}
|
||||
else
|
||||
fill_n(back_insert_iterator<eoPop<Chrom> >(breeders),
|
||||
num_chroms - breeders.size(), pop.back());
|
||||
} while (breeders.size() < num_chroms);
|
||||
if (score_index < pop.size())
|
||||
score_index++;
|
||||
else
|
||||
fill_n(back_insert_iterator<eoPop<Chrom> >(breeders),
|
||||
random.size() - breeders.size(), pop.back());
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue