looking for a bug in eoInsertion
This commit is contained in:
parent
2141b13f9d
commit
204b0bcac8
3 changed files with 32 additions and 40 deletions
|
|
@ -2,13 +2,8 @@ AC_INIT(src/eo)
|
||||||
|
|
||||||
AM_INIT_AUTOMAKE(eo, 0.0.0)
|
AM_INIT_AUTOMAKE(eo, 0.0.0)
|
||||||
|
|
||||||
AM_CONFIG_HEADER(config.h:config.in)
|
|
||||||
|
|
||||||
AC_PROG_CXX
|
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_PROG_LIBTOOL
|
||||||
|
|
||||||
AM_MAINTAINER_MODE
|
AM_MAINTAINER_MODE
|
||||||
|
|
|
||||||
|
|
@ -8,20 +8,14 @@
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
#include <iostream> // ostream, istream
|
#include <iostream> // ostream, istream
|
||||||
#include <function.h> // bind2nd
|
#include <functional> // bind2nd
|
||||||
|
|
||||||
#ifdef HAVE_BVECTOR_H
|
#if defined( _MSC_VER ) || defined( __BCPLUSPLUS__ ) //
|
||||||
#include <bvector.h>
|
#include <vector> //
|
||||||
#error "incluyo bvector.h"
|
typedef vector<bool> bit_vector; // bit_vector
|
||||||
#elseif
|
#else //
|
||||||
#ifdef HAVE_VECTOR
|
#include <bvector.h> //
|
||||||
#include <vector>
|
#endif //
|
||||||
#define bit_vector vector<bool>
|
|
||||||
#error "incluyo vector"
|
|
||||||
#elseif
|
|
||||||
#error "are you kidding?"
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <string> // string
|
#include <string> // string
|
||||||
#include <EO.h> // EO
|
#include <EO.h> // EO
|
||||||
|
|
|
||||||
|
|
@ -9,9 +9,13 @@
|
||||||
|
|
||||||
#include <eo>
|
#include <eo>
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
/******************************************************************************
|
||||||
// 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 Chrom> class eoInsertion: public eoMerge<Chrom>
|
template<class Chrom> class eoInsertion: public eoMerge<Chrom>
|
||||||
{
|
{
|
||||||
|
|
@ -19,25 +23,24 @@ template<class Chrom> class eoInsertion: public eoMerge<Chrom>
|
||||||
/// (Default) Constructor.
|
/// (Default) Constructor.
|
||||||
eoInsertion(const float& _rate = 1.0): eoMerge(_rate) {}
|
eoInsertion(const float& _rate = 1.0): eoMerge(_rate) {}
|
||||||
|
|
||||||
///
|
/**
|
||||||
/// @param breeders
|
* Creates a new population based on breeders and original population
|
||||||
/// @param pop
|
* @param breeders The population of breeders.
|
||||||
|
* @param pop The original population.
|
||||||
|
*/
|
||||||
void operator()(const eoPop<Chrom>& breeders, eoPop<Chrom>& pop)
|
void operator()(const eoPop<Chrom>& breeders, eoPop<Chrom>& pop)
|
||||||
{
|
{
|
||||||
cout << pop << endl;
|
|
||||||
|
|
||||||
sort(pop.begin(), pop.end());
|
sort(pop.begin(), pop.end());
|
||||||
|
|
||||||
cout << pop << endl;
|
if (rated() > 1)
|
||||||
|
pop.erase(pop.end() +
|
||||||
cout << "cte = "
|
(int)(pop.size() * (rate() - 1) - breeders.size()),
|
||||||
<< (int)(pop.size() * (rate() - 1) - breeders.size()) << endl;
|
|
||||||
|
|
||||||
pop.erase(pop.end() + (int)(pop.size() * (rate() - 1) - breeders.size()),
|
|
||||||
pop.end());
|
pop.end());
|
||||||
|
else
|
||||||
cout << "cte = "
|
{
|
||||||
<< (int)(pop.size() * (rate() - 1) - breeders.size()) << endl;
|
cout << "eoInsertion no funciona con rate < 1"
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
copy(breeders.begin(), breeders.end(),
|
copy(breeders.begin(), breeders.end(),
|
||||||
back_insert_iterator<eoPop<Chrom> >(pop));
|
back_insert_iterator<eoPop<Chrom> >(pop));
|
||||||
|
|
|
||||||
Reference in a new issue