From f3ebe8be708214e09e425324e420ac7465cb23f6 Mon Sep 17 00:00:00 2001 From: gustavo Date: Mon, 20 Sep 1999 11:48:52 +0000 Subject: [PATCH] fixing tests --- eo/src/eoBreeder.h | 6 ++---- eo/src/eoInclusion.h | 3 ++- eo/src/eoLottery.h | 28 ++++++++++++++-------------- eo/test/Makefile.am | 2 +- eo/test/Makefile.in | 3 +-- eo/test/t-eobreeder.cpp | 2 +- 6 files changed, 21 insertions(+), 23 deletions(-) diff --git a/eo/src/eoBreeder.h b/eo/src/eoBreeder.h index 75cda90e..7d87c3d6 100644 --- a/eo/src/eoBreeder.h +++ b/eo/src/eoBreeder.h @@ -47,16 +47,14 @@ template class eoBreeder: public eoTransform } case binary: { - eoBinOp* binop = - static_cast* >(op); + eoBinOp* binop = static_cast* >(op); eoUniform u(0, pop.size() ); (*binop)(pop[i], pop[ u() ] ); break; } case Nary: { - eoNaryOp* Nop = - static_cast* >(op); + eoNaryOp* Nop = static_cast* >(op); eoUniform u(0, pop.size() ); eoPop tmpVec; tmpVec.push_back( pop[i] ); diff --git a/eo/src/eoInclusion.h b/eo/src/eoInclusion.h index e090e456..deb82b60 100644 --- a/eo/src/eoInclusion.h +++ b/eo/src/eoInclusion.h @@ -7,7 +7,8 @@ //----------------------------------------------------------------------------- -#include +#include // eoPop +#include // eoMerge /***************************************************************************** * eoInclusion: A replacement algorithm. * diff --git a/eo/src/eoLottery.h b/eo/src/eoLottery.h index ffbecade..a009f0b1 100644 --- a/eo/src/eoLottery.h +++ b/eo/src/eoLottery.h @@ -38,27 +38,27 @@ template class eoLottery: public eoSelect partial_sum(score.begin(), score.end(), score.begin()); // generates random numbers - vector random(pop.size()); + vector random(rint(rate * pop.size())); generate(random.begin(), random.end(), eoUniform(0,1)); sort(random.begin(), random.end(), less()); // 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 >(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 >(breeders), + random.size() - breeders.size(), pop.back()); + } } private: diff --git a/eo/test/Makefile.am b/eo/test/Makefile.am index 85b62fec..fafe1a2b 100644 --- a/eo/test/Makefile.am +++ b/eo/test/Makefile.am @@ -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) ############################################################################### diff --git a/eo/test/Makefile.in b/eo/test/Makefile.in index 12163120..f7c0037c 100644 --- a/eo/test/Makefile.in +++ b/eo/test/Makefile.in @@ -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) diff --git a/eo/test/t-eobreeder.cpp b/eo/test/t-eobreeder.cpp index 11e8ffb6..a0c5e4a4 100644 --- a/eo/test/t-eobreeder.cpp +++ b/eo/test/t-eobreeder.cpp @@ -50,7 +50,7 @@ main() cout << pop[i] << " " << pop[i].fitness() << endl; eoBinBitFlip bitflip; - eoBinCrossover xover; + eoBinCrossover xover; eoProportionalOpSel propSel; eoBreeder breeder( propSel ); propSel.addOp(bitflip, 0.25);