fixing tests

This commit is contained in:
gustavo 1999-09-20 11:48:52 +00:00
commit f3ebe8be70
6 changed files with 21 additions and 23 deletions

View file

@ -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] );

View file

@ -7,7 +7,8 @@
//-----------------------------------------------------------------------------
#include <eo>
#include <eoPop.h> // eoPop
#include <eoPopOps.h> // eoMerge
/*****************************************************************************
* eoInclusion: A replacement algorithm. *

View file

@ -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:

View file

@ -63,7 +63,7 @@ t_eobin_LDADD = $(LDADDS)
t_eolottery_SOURCES = t-eolottery.cpp
t_eolottery_DEPENDENCIES = $(DEPS)
t_eovector_LDFLAGS = -lm
t_eolottery_LDFLAGS = -lm
t_eolottery_LDADD = $(LDADDS)
###############################################################################

View file

@ -137,7 +137,7 @@ t_eobin_LDADD = $(LDADDS)
t_eolottery_SOURCES = t-eolottery.cpp
t_eolottery_DEPENDENCIES = $(DEPS)
t_eovector_LDFLAGS = -lm
t_eolottery_LDFLAGS = -lm
t_eolottery_LDADD = $(LDADDS)
mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
CONFIG_CLEAN_FILES =
@ -161,7 +161,6 @@ t_eoproblem_DEPENDENCIES =
t_eobin_OBJECTS = t-eobin.o
t_eobin_LDFLAGS =
t_eolottery_OBJECTS = t-eolottery.o
t_eolottery_LDFLAGS =
CXXFLAGS = @CXXFLAGS@
CXXCOMPILE = $(CXX) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
LTCXXCOMPILE = $(LIBTOOL) --mode=compile $(CXX) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)

View file

@ -50,7 +50,7 @@ main()
cout << pop[i] << " " << pop[i].fitness() << endl;
eoBinBitFlip<Chrom> bitflip;
eoBinCrossover<Chrom> xover;
eoBinCrossover<Chrom> xover;
eoProportionalOpSel<Chrom> propSel;
eoBreeder<Chrom> breeder( propSel );
propSel.addOp(bitflip, 0.25);