adding eoInsertion
This commit is contained in:
parent
5247c976ce
commit
46e19b13c3
6 changed files with 77 additions and 10 deletions
|
|
@ -5,3 +5,4 @@
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
SUBDIRS = src test
|
SUBDIRS = src test
|
||||||
|
|
||||||
|
|
|
||||||
7
eo/doc/Makefile.am
Normal file
7
eo/doc/Makefile.am
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
###############################################################################
|
||||||
|
##
|
||||||
|
## Makefile.am for eo/doc
|
||||||
|
##
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
|
@ -7,4 +7,4 @@
|
||||||
lib_LTLIBRARIES = libeo.la
|
lib_LTLIBRARIES = libeo.la
|
||||||
libeo_la_SOURCES = eoPrintable.cpp eoPersistent.cpp
|
libeo_la_SOURCES = eoPrintable.cpp eoPersistent.cpp
|
||||||
libeoincdir = $(includedir)/eo
|
libeoincdir = $(includedir)/eo
|
||||||
libeoinc_HEADERS = eo EO.h eoDup.h eoMultiMonOp.h eoPop.h eoUniform.h eoESChrom.h eoNegExp.h eoProblem.h eoVector.h eoFitness.h eoNormal.h eoRnd.h eoXOver2.h eo1d.h eoID.h eoObject.h eoString.h eoAged.h eoKill.h eoOp.h eoTranspose.h eoBin.h eoPrintable.h eoPersistent.h eoLottery.h eoMutation.h eoPopOps.h eoUniform.h
|
libeoinc_HEADERS = eo EO.h eoDup.h eoMultiMonOp.h eoPop.h eoUniform.h eoESChrom.h eoNegExp.h eoProblem.h eoVector.h eoFitness.h eoNormal.h eoRnd.h eoXOver2.h eo1d.h eoID.h eoObject.h eoString.h eoAged.h eoKill.h eoOp.h eoTranspose.h eoBin.h eoPrintable.h eoPersistent.h eoLottery.h eoMutation.h eoPopOps.h eoUniform.h eoInsertion.h
|
||||||
|
|
|
||||||
13
eo/src/eo
13
eo/src/eo
|
|
@ -39,11 +39,18 @@
|
||||||
#include <eoPop.h>
|
#include <eoPop.h>
|
||||||
#include <eoPopOps.h>
|
#include <eoPopOps.h>
|
||||||
|
|
||||||
#include <eoFitness.h> // what's the matter with you?
|
|
||||||
#include <eoProblem.h> // what's the matter with you?
|
|
||||||
|
|
||||||
#include <eoLottery.h>
|
#include <eoLottery.h>
|
||||||
|
|
||||||
|
#include <eoInsertion.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// to be continued ...
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#include <eoFitness.h> // what's the matter with you?
|
||||||
|
#include <eoProblem.h> // what's the matter with you?
|
||||||
// #include <eoGA.h>
|
// #include <eoGA.h>
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
|
||||||
49
eo/src/eoInsertion.h
Normal file
49
eo/src/eoInsertion.h
Normal file
|
|
@ -0,0 +1,49 @@
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// eoInsertion.h
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#ifndef eoInsertion_h
|
||||||
|
#define eoInsertion_h
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#include <eo>
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// eoInsertion
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
template<class Chrom> class eoInsertion: public eoMerge<Chrom>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
/// (Default) Constructor.
|
||||||
|
eoInsertion(const float& _rate = 1.0): eoMerge(_rate) {}
|
||||||
|
|
||||||
|
///
|
||||||
|
/// @param breeders
|
||||||
|
/// @param pop
|
||||||
|
void operator()(const eoPop<Chrom>& breeders, eoPop<Chrom>& 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;
|
||||||
|
|
||||||
|
copy(breeders.begin(), breeders.end(),
|
||||||
|
back_insert_iterator<eoPop<Chrom> >(pop));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#endif eoInsertion_h
|
||||||
|
|
@ -8,7 +8,6 @@
|
||||||
#ifndef _EOPOPOPS_H
|
#ifndef _EOPOPOPS_H
|
||||||
#define _EOPOPOPS_H
|
#define _EOPOPOPS_H
|
||||||
|
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -99,7 +98,7 @@ class eoMerge: public eoObject{
|
||||||
* @param breeders Tranformed individuals.
|
* @param breeders Tranformed individuals.
|
||||||
* @param pop The original population at the begining, the result at the end
|
* @param pop The original population at the begining, the result at the end
|
||||||
*/
|
*/
|
||||||
virtual operator () ( const eoPop<EOT>& breeders, eoPop<EOT>& pop ) = 0;
|
virtual void operator () ( const eoPop<EOT>& breeders, eoPop<EOT>& pop ) = 0;
|
||||||
|
|
||||||
/** @name Methods from eoObject */
|
/** @name Methods from eoObject */
|
||||||
//@{
|
//@{
|
||||||
|
|
@ -114,6 +113,10 @@ class eoMerge: public eoObject{
|
||||||
/// Return the rate to be selected from the original population
|
/// Return the rate to be selected from the original population
|
||||||
float rate() const { return rep_rate; }
|
float rate() const { return rep_rate; }
|
||||||
|
|
||||||
|
/// Set the rate to be obtained after replacement.
|
||||||
|
/// @param _rate The rate.
|
||||||
|
void rate(const float& _rate) { rep_rate = _rate; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
float rep_rate;
|
float rep_rate;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Reference in a new issue