diff --git a/eo/src/eoBin.h b/eo/src/eoBin.h index c5031deca..7d8b3a0f2 100644 --- a/eo/src/eoBin.h +++ b/eo/src/eoBin.h @@ -33,7 +33,7 @@ template class eoBin: public eoVector * Constructor. * @param size Size of the binary string. */ - eoBin(const unsigned& size, const eoRnd& rnd): eoVector(size) + eoBin(const unsigned& size, const eoRnd& rnd): eoVector(size) { generate(begin(), end(), rnd); } diff --git a/eo/src/eoBreeder.h b/eo/src/eoBreeder.h index d457d3c3d..8fa445dcc 100644 --- a/eo/src/eoBreeder.h +++ b/eo/src/eoBreeder.h @@ -7,8 +7,10 @@ //----------------------------------------------------------------------------- -#include // vector -#include // pair +#include // vector + +using namespace std; + #include // eoTransform, eoUniform, eoOp, eoMonOp, eoBinOp, eoPop /***************************************************************************** @@ -20,73 +22,64 @@ template class eoBreeder: public eoTransform { public: /// Default constructor. - eoBreeder(): uniform(0.0, 1.0) {} - - /** - * Adds a genetic operator. - * @param operator The operator. - * @param rate Rate to apply the operator. - */ - void add(eoOp& op, float rate = 1.0) - { - operators.push_back(pair*>(rate, &op)); - } + eoBreeder( eoOpSelector& _opSel): opSel( _opSel ) {} + + /// Destructor. + virtual ~eoBreeder() { } + /** * Transforms a population. * @param pop The population to be transformed. */ - void operator()(eoPop& pop) + + void operator()(eoPop& pop) { - unsigned i; - - for (Operators::const_iterator op = operators.begin(); - op != operators.end(); - op++) - switch (op->second->readArity()) - { - case unary: - { - eoMonOp& monop = (eoMonOp&)*(op->second); - for (i = 0; i < pop.size(); i++) - if (uniform() < op->first) - monop(pop[i]); - break; + for (unsigned i = 0; i < pop.size(); i ++ ) { + eoOp* op = opSel.Op(); + switch (op->readArity()) { + case unary: + { + eoMonOp* monop = static_cast* >(op); + (*monop)( pop[i] ); + break; + } + case binary: + { + eoBinOp* binop = + static_cast* >(op); + eoUniform u(0, pop.size() ); + (*binop)(pop[i], pop[ u() ] ); + break; + } + case Nary: + { + eoNaryOp* Nop = + static_cast* >(op); + eoUniform u(0, pop.size() ); + eoPop tmpVec; + tmpVec.push_back( pop[i] ); + for ( unsigned i = 0; i < u(); i ++ ) { + tmpVec.push_back( pop[ u() ] ); + } + (*Nop)( tmpVec ); + break; + } + default: + { + throw runtime_error( "eoBreeder:operator() Not implemented yet!" ); + break; + } } - case binary: - { - vector pos(pop.size()); - iota(pos.begin(), pos.end(), 0); - random_shuffle(pos.begin(), pos.end()); - - cout << "pos = "; - copy(pos.begin(), pos.end(), - ostream_iterator(cout, " ")); - cout << endl; - - eoBinOp& binop = (eoBinOp&)*(op->second); - for (i = 1; i < pop.size(); i += 2) - if (uniform() < op->first) - binop(pop[pos[i - 1]], pop[pos[i]]); - break; - } - default: - { - cerr << "eoBreeder:operator() Not implemented yet!" << endl; - exit(EXIT_FAILURE); - break; - } - } - } + } + }; /// The class name. string classname() const { return "eoBreeder"; } private: - typedef vector*> > Operators; - - eoUniform uniform; - Operators operators; + eoOpSelector& opSel; + }; //----------------------------------------------------------------------------- diff --git a/eo/src/eoData.h b/eo/src/eoData.h index d24938241..fcbf013e4 100644 --- a/eo/src/eoData.h +++ b/eo/src/eoData.h @@ -20,13 +20,10 @@ using namespace std; #define MINFLOAT numeric_limits::min() #define MAXDOUBLE numeric_limits::max() #define MAXINT numeric_limits::max() - #define min _MIN - #define max _MAX #else #include #include #include - #ifndef MAXFLOAT #define MAXFLOAT (float)1e127 #define MAXDOUBLE (double)1.79769313486231570e+308 diff --git a/eo/src/eoInclusion.h b/eo/src/eoInclusion.h index 8de6d5ec1..e090e4567 100644 --- a/eo/src/eoInclusion.h +++ b/eo/src/eoInclusion.h @@ -19,7 +19,7 @@ template class eoInclusion: public eoMerge { public: /// (Default) Constructor. - eoInclusion(const float& _rate = 1.0): eoMerge(_rate) {} + eoInclusion(const float& _rate = 1.0): eoMerge(_rate) {} /** * Creates a new population based on breeders and original populations. diff --git a/eo/src/eoOp.h b/eo/src/eoOp.h index d12a162a0..ac7027616 100644 --- a/eo/src/eoOp.h +++ b/eo/src/eoOp.h @@ -148,6 +148,7 @@ public: }; +#include /** eoNaryOp is the N-ary operator: genetic operator that takes several EOs. It could be called an {\em orgy} operator */ @@ -168,7 +169,7 @@ public: /** applies randomly operator, to the object. */ -// virtual void operator()( EOPop & _eop) const = 0; + virtual void operator()( eoPop & _eop) const = 0; /** @name Methods from eoObject readFrom and printOn are directly inherited from eoObject. diff --git a/eo/src/eoOpSelector.h b/eo/src/eoOpSelector.h index 4a8aae68c..717071c38 100644 --- a/eo/src/eoOpSelector.h +++ b/eo/src/eoOpSelector.h @@ -47,7 +47,7 @@ public: virtual deleteOp( ID _id ) = 0; /// Returns a genetic operator according to the established criteria - virtual const eoOp& Op() = 0; + virtual eoOp* Op() = 0; /// Methods inherited from eoObject //@{ diff --git a/eo/src/eoProportionalOpSel.h b/eo/src/eoProportionalOpSel.h index 7f14581f5..ba2556962 100644 --- a/eo/src/eoProportionalOpSel.h +++ b/eo/src/eoProportionalOpSel.h @@ -26,11 +26,11 @@ Operators are represented as pairs (proportion,operator) */ template class eoProportionalOpSel: public eoOpSelector, - public multimap*,greater > + public multimap*,greater > { public: - typedef multimap*,greater > MMF; + typedef multimap*,greater > MMF; /// default ctor eoProportionalOpSel() @@ -79,7 +79,7 @@ public: }; /// Returns a genetic operator according to the established criteria - virtual const eoOp& Op() { + virtual eoOp* Op() { // Check that all add up to one float acc = 0; MMF::iterator i; @@ -100,7 +100,7 @@ public: } while ( (acc <= aRnd ) && (i++!=end() ) ); if ( i == end() ) throw runtime_error( "Operator not found in eoProportionalOpSelector" ); - return *(i->second); + return i->second; //return i->second; } diff --git a/eo/win/EO.dsw b/eo/win/EO.dsw index cddc547a7..4cac45ee6 100644 --- a/eo/win/EO.dsw +++ b/eo/win/EO.dsw @@ -51,6 +51,18 @@ Package=<4> ############################################################################### +Project: "t_eobreeder"=.\t_eobreeder.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + Project: "t_eoid"=.\t_eoid.dsp - Package Owner=<4> Package=<5> @@ -63,6 +75,18 @@ Package=<4> ############################################################################### +Project: "t_eoinclusion"=.\t_eoinclusion.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + Project: "t_eoinsertion"=.\t_eoinsertion.dsp - Package Owner=<4> Package=<5>