From 11b14cf597756f645d4b43b944f5d675c1f36512 Mon Sep 17 00:00:00 2001 From: Johann Dreo Date: Fri, 22 Oct 2010 10:07:09 +0200 Subject: [PATCH] Arithmetic operators (note: priority to unfeasibility) --- eo/src/eoDualFitness.h | 43 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/eo/src/eoDualFitness.h b/eo/src/eoDualFitness.h index d54750ba..c57d9fcc 100644 --- a/eo/src/eoDualFitness.h +++ b/eo/src/eoDualFitness.h @@ -143,6 +143,48 @@ public: public: + //! Add a given fitness to the current one + template + friend + eoDualFitness & operator+=( eoDualFitness & from, const eoDualFitness & that ) + { + from._value += that._value; + + // true only if the two are feasible, else false + from._is_feasible = from._is_feasible && that._is_feasible; + + return from; + } + + //! Substract a given fitness to the current one + template + friend + eoDualFitness & operator-=( eoDualFitness & from, const eoDualFitness & that ) + { + from._value -= that._value; + + // true only if the two are feasible, else false + from._is_feasible = from._is_feasible && that._is_feasible; + + return from; + } + + // Add this fitness's value to that other, and return a _new_ instance with the result. + template + eoDualFitness operator+(const eoDualFitness & that) + { + eoDualFitness from( *this ); + return from += that; + } + + // Add this fitness's value to that other, and return a _new_ instance with the result. + template + eoDualFitness operator-(const eoDualFitness & that) + { + eoDualFitness from( *this ); + return from -= that; + } + //! Print an eoDualFitness instance as a pair of numbers, separated by a space template friend @@ -166,7 +208,6 @@ public: f = std::make_pair( value, feasible ); return is; } - }; //! Compare dual fitnesses as if we were maximizing