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
|
||||
|
||||
|
|
|
|||
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
|
||||
libeo_la_SOURCES = eoPrintable.cpp eoPersistent.cpp
|
||||
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
|
||||
|
|
|
|||
15
eo/src/eo
15
eo/src/eo
|
|
@ -39,12 +39,19 @@
|
|||
#include <eoPop.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 <eoGA.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>
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
|
|
|||
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
|
||||
#define _EOPOPOPS_H
|
||||
|
||||
|
||||
using namespace std;
|
||||
|
||||
/**
|
||||
|
|
@ -99,13 +98,13 @@ class eoMerge: public eoObject{
|
|||
* @param breeders Tranformed individuals.
|
||||
* @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 */
|
||||
//@{
|
||||
/** readFrom and printOn are not overriden
|
||||
/** readFrom and printOn are not overriden
|
||||
*/
|
||||
/** Inherited from eoObject. Returns the class name.
|
||||
/** Inherited from eoObject. Returns the class name.
|
||||
@see eoObject
|
||||
*/
|
||||
string className() const {return "eoMerge";};
|
||||
|
|
@ -113,6 +112,10 @@ class eoMerge: public eoObject{
|
|||
|
||||
/// Return the rate to be selected from the original population
|
||||
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:
|
||||
float rep_rate;
|
||||
|
|
|
|||
Reference in a new issue