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:
|
case binary:
|
||||||
{
|
{
|
||||||
eoBinOp<Chrom>* binop =
|
eoBinOp<Chrom>* binop = static_cast<eoBinOp<Chrom>* >(op);
|
||||||
static_cast<eoBinOp<Chrom>* >(op);
|
|
||||||
eoUniform<unsigned> u(0, pop.size() );
|
eoUniform<unsigned> u(0, pop.size() );
|
||||||
(*binop)(pop[i], pop[ u() ] );
|
(*binop)(pop[i], pop[ u() ] );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Nary:
|
case Nary:
|
||||||
{
|
{
|
||||||
eoNaryOp<Chrom>* Nop =
|
eoNaryOp<Chrom>* Nop = static_cast<eoNaryOp<Chrom>* >(op);
|
||||||
static_cast<eoNaryOp<Chrom>* >(op);
|
|
||||||
eoUniform<unsigned> u(0, pop.size() );
|
eoUniform<unsigned> u(0, pop.size() );
|
||||||
eoPop<Chrom> tmpVec;
|
eoPop<Chrom> tmpVec;
|
||||||
tmpVec.push_back( pop[i] );
|
tmpVec.push_back( pop[i] );
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,8 @@
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
#include <eo>
|
#include <eoPop.h> // eoPop
|
||||||
|
#include <eoPopOps.h> // eoMerge
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
* eoInclusion: A replacement algorithm. *
|
* eoInclusion: A replacement algorithm. *
|
||||||
|
|
|
||||||
|
|
@ -38,27 +38,27 @@ template<class Chrom> class eoLottery: public eoSelect<Chrom>
|
||||||
partial_sum(score.begin(), score.end(), score.begin());
|
partial_sum(score.begin(), score.end(), score.begin());
|
||||||
|
|
||||||
// generates random numbers
|
// generates random numbers
|
||||||
vector<float> random(pop.size());
|
vector<float> random(rint(rate * pop.size()));
|
||||||
generate(random.begin(), random.end(), eoUniform<float>(0,1));
|
generate(random.begin(), random.end(), eoUniform<float>(0,1));
|
||||||
sort(random.begin(), random.end(), less<float>());
|
sort(random.begin(), random.end(), less<float>());
|
||||||
|
|
||||||
// selection of chromosomes
|
// selection of chromosomes
|
||||||
unsigned score_index = 0; // position in score vector
|
unsigned score_index = 0; // position in score vector
|
||||||
unsigned random_index = 0; // position in random vector
|
unsigned random_index = 0; // position in random vector
|
||||||
unsigned num_chroms = (unsigned)(rate * pop.size());
|
while (breeders.size() < random.size())
|
||||||
do {
|
{
|
||||||
if(random[random_index] < score[score_index])
|
if(random[random_index] < score[score_index])
|
||||||
{
|
{
|
||||||
breeders.push_back(pop[score_index]);
|
breeders.push_back(pop[score_index]);
|
||||||
random_index++;
|
random_index++;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
if (score_index < pop.size())
|
|
||||||
score_index++;
|
|
||||||
else
|
else
|
||||||
fill_n(back_insert_iterator<eoPop<Chrom> >(breeders),
|
if (score_index < pop.size())
|
||||||
num_chroms - breeders.size(), pop.back());
|
score_index++;
|
||||||
} while (breeders.size() < num_chroms);
|
else
|
||||||
|
fill_n(back_insert_iterator<eoPop<Chrom> >(breeders),
|
||||||
|
random.size() - breeders.size(), pop.back());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
||||||
|
|
@ -63,7 +63,7 @@ t_eobin_LDADD = $(LDADDS)
|
||||||
|
|
||||||
t_eolottery_SOURCES = t-eolottery.cpp
|
t_eolottery_SOURCES = t-eolottery.cpp
|
||||||
t_eolottery_DEPENDENCIES = $(DEPS)
|
t_eolottery_DEPENDENCIES = $(DEPS)
|
||||||
t_eovector_LDFLAGS = -lm
|
t_eolottery_LDFLAGS = -lm
|
||||||
t_eolottery_LDADD = $(LDADDS)
|
t_eolottery_LDADD = $(LDADDS)
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
|
||||||
|
|
@ -137,7 +137,7 @@ t_eobin_LDADD = $(LDADDS)
|
||||||
|
|
||||||
t_eolottery_SOURCES = t-eolottery.cpp
|
t_eolottery_SOURCES = t-eolottery.cpp
|
||||||
t_eolottery_DEPENDENCIES = $(DEPS)
|
t_eolottery_DEPENDENCIES = $(DEPS)
|
||||||
t_eovector_LDFLAGS = -lm
|
t_eolottery_LDFLAGS = -lm
|
||||||
t_eolottery_LDADD = $(LDADDS)
|
t_eolottery_LDADD = $(LDADDS)
|
||||||
mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
|
mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
|
||||||
CONFIG_CLEAN_FILES =
|
CONFIG_CLEAN_FILES =
|
||||||
|
|
@ -161,7 +161,6 @@ t_eoproblem_DEPENDENCIES =
|
||||||
t_eobin_OBJECTS = t-eobin.o
|
t_eobin_OBJECTS = t-eobin.o
|
||||||
t_eobin_LDFLAGS =
|
t_eobin_LDFLAGS =
|
||||||
t_eolottery_OBJECTS = t-eolottery.o
|
t_eolottery_OBJECTS = t-eolottery.o
|
||||||
t_eolottery_LDFLAGS =
|
|
||||||
CXXFLAGS = @CXXFLAGS@
|
CXXFLAGS = @CXXFLAGS@
|
||||||
CXXCOMPILE = $(CXX) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_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)
|
LTCXXCOMPILE = $(LIBTOOL) --mode=compile $(CXX) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS)
|
||||||
|
|
|
||||||
Reference in a new issue