From d3525298feb143dba22c0cdd0a70f90d46ed2aa2 Mon Sep 17 00:00:00 2001 From: evomarc Date: Wed, 7 Feb 2001 05:13:33 +0000 Subject: [PATCH] Added the handling of generic operators in Combined Ops --- eo/src/eoProportionalCombinedOp.h | 118 +++++++++++++++++++++++------- 1 file changed, 92 insertions(+), 26 deletions(-) diff --git a/eo/src/eoProportionalCombinedOp.h b/eo/src/eoProportionalCombinedOp.h index 1cb8daa1..5d52719b 100644 --- a/eo/src/eoProportionalCombinedOp.h +++ b/eo/src/eoProportionalCombinedOp.h @@ -28,6 +28,9 @@ #include #include #include +#include +#include +#include #include /** \defgroup PropCombined operators @@ -45,37 +48,66 @@ into an algorithm, chosing by a roulette wheel based on user-defined rates */ +////////////////////////////////////////////////////// +//// combined MonOp +////////////////////////////////////////////////////// -/** eoMonOp is the monary operator: genetic operator that takes only one EO */ +/** eoMonOp is the monary operator: genetic operator that takes only one EO + + * now accepts generic operators +*/ template class eoPropCombinedMonOp: public eoMonOp { public: - /// Ctor + /// Ctor from a "true" operator eoPropCombinedMonOp(eoMonOp & _first, const double _rate) { ops.push_back(&_first); rates.push_back(_rate); } -virtual string className() const { return "eoPropCombinedMonOp"; } + /// Ctor from a generic operator + eoPropCombinedMonOp(eoGenericMonOp & _first, const double _rate) + { + eoGeneric2TrueMonOp *trueFirst = + new eoGeneric2TrueMonOp(_first); + ops.push_back(trueFirst); + rates.push_back(_rate); + } -virtual void add(eoMonOp & _op, const double _rate, bool _verbose=false) + virtual string className() const { return "eoPropCombinedMonOp"; } + + virtual void add(eoMonOp & _op, const double _rate, bool _verbose=false) { ops.push_back(&_op); rates.push_back(_rate); // compute the relative rates in percent - to warn the user! if (_verbose) - { - double total = 0; - unsigned i; - for (i=0; iclassName() << " with rate " << 100*rates[i]/total << " %\n"; - } + printOn(cout); + } + + virtual void add(eoGenericMonOp & _op, const double _rate, bool _verbose=false) + { + eoGeneric2TrueMonOp *trueOp = new eoGeneric2TrueMonOp(_op); + ops.push_back(trueOp); + rates.push_back(_rate); + // compute the relative rates in percent - to warn the user! + if (_verbose) + printOn(cout); + } + + // outputs the operators and percentages + virtual void printOn(ostream & _os) + { + double total = 0; + unsigned i; + for (i=0; iclassName() << " with rate " << 100*rates[i]/total << " %\n"; } virtual void operator()(EOT & _indi) @@ -88,7 +120,9 @@ std::vector*> ops; std::vector rates; }; - +////////////////////////////////////////////////////// +//// combined BinOp +////////////////////////////////////////////////////// /** COmbined Binary genetic operator: * operator() has two operands, only the first one can be modified @@ -134,40 +168,72 @@ std::vector rates; }; +////////////////////////////////////////////////////// +//// combined QuadOp +////////////////////////////////////////////////////// + /** Quadratic genetic operator: subclasses eoOp, and defines basically the operator() with two operands, both can be modified. */ -/** COmbined Binary genetic operator: - * operator() has two operands, only the first one can be modified +/** COmbined quadratic genetic operator: + * operator() has two operands, both can be modified + + * generic operators are now allowed: there are imbedded into + * the corresponding "true" operator */ template class eoPropCombinedQuadOp: public eoQuadraticOp { public: - /// Ctor + /// Ctor from a true operator eoPropCombinedQuadOp(eoQuadraticOp & _first, const double _rate) { ops.push_back(&_first); rates.push_back(_rate); } + /// Ctor from a generic operator + eoPropCombinedQuadOp(eoGenericQuadOp & _first, const double _rate) + { + eoGeneric2TrueQuadOp *trueFirst = + new eoGeneric2TrueQuadOp(_first); + ops.push_back(trueFirst); + rates.push_back(_rate); + } + virtual string className() const { return "eoPropCombinedQuadOp"; } + // addition of a true operator virtual void add(eoQuadraticOp & _op, const double _rate, bool _verbose=false) { ops.push_back(&_op); rates.push_back(_rate); // compute the relative rates in percent - to warn the user! if (_verbose) - { - double total = 0; - unsigned i; - for (i=0; iclassName() << " with rate " << 100*rates[i]/total << " %\n"; - } + printOn(cout); + } + + // addition of a generic operator +virtual void add(eoGenericQuadOp & _op, const double _rate, bool _verbose=false) + { + eoGeneric2TrueQuadOp *trueOp = new eoGeneric2TrueQuadOp(_op); + ops.push_back(trueOp); + rates.push_back(_rate); + // compute the relative rates in percent - to warn the user! + if (_verbose) + printOn(cout); + } + + // outputs the operators and percentages + virtual void printOn(ostream & _os) + { + double total = 0; + unsigned i; + for (i=0; iclassName() << " with rate " << 100*rates[i]/total << " %\n"; } virtual void operator()(EOT & _indi1, EOT & _indi2)