From 204b0bcac835821b74f15b4b2f16a247bc62266d Mon Sep 17 00:00:00 2001 From: gustavo Date: Mon, 8 Feb 1999 18:47:07 +0000 Subject: [PATCH] looking for a bug in eoInsertion --- eo/configure.in | 5 ----- eo/src/eoBin.h | 26 ++++++++++---------------- eo/src/eoInsertion.h | 41 ++++++++++++++++++++++------------------- 3 files changed, 32 insertions(+), 40 deletions(-) diff --git a/eo/configure.in b/eo/configure.in index d28c58ac..98cb2e3d 100644 --- a/eo/configure.in +++ b/eo/configure.in @@ -2,13 +2,8 @@ AC_INIT(src/eo) AM_INIT_AUTOMAKE(eo, 0.0.0) -AM_CONFIG_HEADER(config.h:config.in) - AC_PROG_CXX -AC_CHECK_HEADERS(vector bvector.h) -AC_EGREP_HEADER(bit_vector, bvector.h, AC_DEFINE(HAVE_BIT_VECTOR)) - AM_PROG_LIBTOOL AM_MAINTAINER_MODE diff --git a/eo/src/eoBin.h b/eo/src/eoBin.h index 148a55ab..2382b8ce 100644 --- a/eo/src/eoBin.h +++ b/eo/src/eoBin.h @@ -7,24 +7,18 @@ //----------------------------------------------------------------------------- -#include // ostream, istream -#include // bind2nd +#include // ostream, istream +#include // bind2nd -#ifdef HAVE_BVECTOR_H -#include -#error "incluyo bvector.h" -#elseif -#ifdef HAVE_VECTOR -#include -#define bit_vector vector -#error "incluyo vector" -#elseif -#error "are you kidding?" -#endif -#endif +#if defined( _MSC_VER ) || defined( __BCPLUSPLUS__ ) // +#include // +typedef vector bit_vector; // bit_vector +#else // +#include // +#endif // -#include // string -#include // EO +#include // string +#include // EO //----------------------------------------------------------------------------- /// eoBin: implementation of binary chromosome. diff --git a/eo/src/eoInsertion.h b/eo/src/eoInsertion.h index f05c29c5..16183421 100644 --- a/eo/src/eoInsertion.h +++ b/eo/src/eoInsertion.h @@ -9,9 +9,13 @@ #include -//----------------------------------------------------------------------------- -// eoInsertion -//----------------------------------------------------------------------------- +/****************************************************************************** + * eoInsertion: A replacement algorithm. + * Takes two populations: breeders and original populations. At the en of the + * process, the original population has chenge in the followin way: + * (1) the worst individuals haa been erased + * (2) the best individuals from the breeders has been added + *****************************************************************************/ template class eoInsertion: public eoMerge { @@ -19,26 +23,25 @@ template class eoInsertion: public eoMerge /// (Default) Constructor. eoInsertion(const float& _rate = 1.0): eoMerge(_rate) {} - /// - /// @param breeders - /// @param pop + /** + * Creates a new population based on breeders and original population + * @param breeders The population of breeders. + * @param pop The original population. + */ void operator()(const eoPop& breeders, eoPop& pop) { - cout << pop << endl; - sort(pop.begin(), pop.end()); - cout << pop << endl; - - cout << "cte = " - << (int)(pop.size() * (rate() - 1) - breeders.size()) << endl; - - pop.erase(pop.end() + (int)(pop.size() * (rate() - 1) - breeders.size()), - pop.end()); - - cout << "cte = " - << (int)(pop.size() * (rate() - 1) - breeders.size()) << endl; - + if (rated() > 1) + pop.erase(pop.end() + + (int)(pop.size() * (rate() - 1) - breeders.size()), + pop.end()); + else + { + cout << "eoInsertion no funciona con rate < 1" + exit(1); + } + copy(breeders.begin(), breeders.end(), back_insert_iterator >(pop)); }