adding eoGeneration

This commit is contained in:
gustavo 1999-02-15 17:47:30 +00:00
commit c1cddf3236
5 changed files with 91 additions and 100 deletions

View file

@ -48,6 +48,7 @@
#include <eoInsertion.h>
#include <eoInclusion.h>
#include <eoGeneratio.h>
//-----------------------------------------------------------------------------
// to be continued ...
@ -55,7 +56,6 @@
#include <eoFitness.h> // what's the matter with you?
#include <eoProblem.h> // what's the matter with you?
// #include <eoGA.h>
//-----------------------------------------------------------------------------

View file

@ -7,6 +7,8 @@
//-----------------------------------------------------------------------------
#include <algorithm> // swap_ranges
#include <eoUniform.h> // eoUniform
#include <eoBin.h> // eoBin
#include <eoOp.h> // eoMonOp
@ -210,10 +212,7 @@ template<class Chrom> class eoBinNxOver: public eoBinOp<Chrom>
eoBinNxOver(const unsigned& _num_points = 2): num_points(_num_points)
{
if (num_points < 1)
{
cerr << "NxOver --> invalid number of points " << num_points << endl;
exit(EXIT_FAILURE);
}
runtime_error("NxOver --> invalid number of points");
}
/// The class name.
@ -272,15 +271,9 @@ template<class Chrom> class eoBinGxOver: public eoBinOp<Chrom>
gene_size(_gene_size), num_points(_num_points)
{
if (gene_size < 1)
{
cerr << "GxOver --> invalid gene size " << gene_size << endl;
exit(EXIT_FAILURE);
}
runtime_error("GxOver --> invalid gene size");
if (num_points < 1)
{
cerr << "GxOver --> invalid number of points " << num_points << endl;
exit(EXIT_FAILURE);
}
runtime_error("GxOver --> invalid number of points");
}
/// The class name
@ -329,15 +322,12 @@ template<class Chrom> class eoBinGxOver: public eoBinOp<Chrom>
template<class Chrom> class eoBinUxOver: public eoBinOp<Chrom>
{
public:
public:
/// (Default) Constructor.
eoBinUxOver(const float _rate = 0.5): rate(_rate)
{
if (rate < 0 || rate > 1)
{
cerr << "UxOver --> invalid rate " << rate << endl;
exit(EXIT_FAILURE);
}
runtime_error("UxOver --> invalid rate");
}
/// The class name.

View file

@ -8,11 +8,14 @@
//-----------------------------------------------------------------------------
#include <vector> // vector
#include <eoUniform.h> // eoUniform
#include <eoOp.h> // eoOp, eoMonOp, eoBinOp
#include <eoPop.h> // eoPop
#include <eoPopOps.h> // eoTransform
#include <eoOpSelector.h> // eoOpSelector
using namespace std;
#include <eo> // eoTransform, eoUniform, eoOp, eoMonOp, eoBinOp, eoPop
/*****************************************************************************
* eoBreeder: transforms a population using genetic operators. *
* For every operator there is a rated to be applyed. *
@ -24,18 +27,16 @@ template<class Chrom> class eoBreeder: public eoTransform<Chrom>
/// Default constructor.
eoBreeder( eoOpSelector<Chrom>& _opSel): opSel( _opSel ) {}
/// Destructor.
virtual ~eoBreeder() { }
virtual ~eoBreeder() {}
/**
* Transforms a population.
* @param pop The population to be transformed.
*/
void operator()(eoPop<Chrom>& pop)
{
for (unsigned i = 0; i < pop.size(); i ++ ) {
for (unsigned i = 0; i < pop.size(); i++) {
eoOp<Chrom>* op = opSel.Op();
switch (op->readArity()) {
case unary:
@ -65,11 +66,6 @@ template<class Chrom> class eoBreeder: public eoTransform<Chrom>
(*Nop)( tmpVec );
break;
}
default:
{
throw runtime_error( "eoBreeder:operator() Not implemented yet!" );
break;
}
}
}
};

View file

@ -1,9 +1,9 @@
//-----------------------------------------------------------------------------
// eoGA.h
// eoGeneration.h
//-----------------------------------------------------------------------------
#ifndef eoGA_h
#define eoGA_h
#ifndef eoGeneration_h
#define eoGeneration_h
//-----------------------------------------------------------------------------
@ -11,18 +11,21 @@
#include <eoPopOps.h> // eoSelect, eoTranform, eoMerge
//-----------------------------------------------------------------------------
// eoGA
// eoGeneration
//-----------------------------------------------------------------------------
class eoGA
template<class Chrom> class eoGeneration: public eoTransform<Chrom>
{
public:
/// Constructor.
eoGA(eoSelect& _select, eoTranform& _transform, eoMerge& _replace)
{
}
eoGeneration(eoSelect& _select,
eoTranform& _transform,
eoMerge& _replace):
eoTransform<Chrom>() {}
///
/**
*
*/
void operator()(eoPop& pop)
{
eoPop breeders;
@ -32,6 +35,9 @@ class eoGA
replace(breeders, pop);
}
/// Class name.
string className() const { return "eoGeneration"; }
private:
eoSelect& select;
eoTranform& transform;
@ -40,4 +46,4 @@ class eoGA
//-----------------------------------------------------------------------------
#endif eoGA_h
#endif eoGeneration_h

View file

@ -25,8 +25,7 @@ template<class EOT>
class eoTransform: public eoObject{
public:
/** ctor
*/
/** ctor */
eoTransform() {};
/// Dtor