Use member arithmetic operators and friend stream operators in dual fitness

This commit is contained in:
Johann Dreo 2013-06-11 09:23:16 +02:00 committed by LPTK
commit b79b5689b3

View file

@ -146,7 +146,7 @@ public:
//! Copy operator from another eoDualFitness //! Copy operator from another eoDualFitness
template <class F, class Cmp> template <class F, class Cmp>
eoDualFitness<F,Cmp> & operator=(const eoDualFitness<BaseType, Compare>& other ) eoDualFitness<BaseType,Compare> & operator=(const eoDualFitness<BaseType, Compare>& other )
{ {
if (this != &other) { if (this != &other) {
this->_value = other._value; this->_value = other._value;
@ -215,9 +215,15 @@ public:
// (for minimizing and maximizing) // (for minimizing and maximizing)
//! Add a given fitness to the current one //! Add a given fitness to the current one
template <class F, class Cmp> template<class T>
// friend eoDualFitness<BaseType,Compare> & operator+=( const T that )
eoDualFitness<F,Cmp> & operator+=( /*eoDualFitness<F,Cmp> & from,*/ const eoDualFitness<F,Cmp> & that ) {
this->_value += that;
return *this;
}
//! Add a given fitness to the current one
eoDualFitness<BaseType,Compare> & operator+=( const eoDualFitness<BaseType,Compare> & that )
{ {
// from._value += that._value; // from._value += that._value;
this->_value += that._value; this->_value += that._value;
@ -230,8 +236,15 @@ public:
} }
//! Substract a given fitness to the current one //! Substract a given fitness to the current one
template <class F, class Cmp> template<class T>
eoDualFitness<F,Cmp> & operator-=( const eoDualFitness<F,Cmp> & that ) eoDualFitness<BaseType,Compare> & operator-=( const T that )
{
this->_value -= that;
return *this;
}
//! Substract a given fitness to the current one
eoDualFitness<BaseType,Compare> & operator-=( const eoDualFitness<BaseType,Compare> & that )
{ {
this->_value -= that._value; this->_value -= that._value;
@ -241,27 +254,17 @@ public:
return *this; return *this;
} }
//! Add a given fitness to the current one //! Add a given fitness to the current one
template <class T, class F, class Cmp> template<class T>
eoDualFitness<F,Cmp> & operator+=( const T that ) eoDualFitness<BaseType,Compare> & operator/=( T that )
{ {
this->_value += that; this->_value /= that;
return *this; return *this;
} }
//! Substract a given fitness to the current one
template <class T, class F, class Cmp>
eoDualFitness<F,Cmp> & operator-=( const T that )
{
this->_value -= that;
return *this;
}
//! Add a given fitness to the current one //! Add a given fitness to the current one
template <class F, class Cmp> eoDualFitness<BaseType,Compare> & operator/=( const eoDualFitness<BaseType,Compare> & that )
eoDualFitness<F,Cmp> & operator/=( const eoDualFitness<F,Cmp> & that )
{ {
this->_value /= that._value; this->_value /= that._value;
@ -271,61 +274,69 @@ public:
return *this; return *this;
} }
template<class T>
//! Add a given fitness to the current one eoDualFitness<BaseType,Compare> operator+( T that )
template <class T, class F, class Cmp>
eoDualFitness<F,Cmp> & operator/=( T that )
{ {
this->_value /= that; this->_value += that;
return *this; return *this;
} }
// Add this fitness's value to that other, and return a _new_ instance with the result. // Add this fitness's value to that other, and return a _new_ instance with the result.
template <class F, class Cmp> eoDualFitness<BaseType,Compare> operator+( const eoDualFitness<BaseType,Compare> & that )
eoDualFitness<F,Cmp> operator+(const eoDualFitness<F,Cmp> & that)
{ {
eoDualFitness<F,Cmp> from( *this ); eoDualFitness<BaseType,Compare> from( *this );
return from += that; return from += that;
} }
// Add this fitness's value to that other, and return a _new_ instance with the result. template<class T>
template <class F, class Cmp> eoDualFitness<BaseType,Compare> operator-( T that )
eoDualFitness<F,Cmp> operator-(const eoDualFitness<F,Cmp> & that)
{ {
eoDualFitness<F,Cmp> from( *this ); this->_value -= that;
return *this;
}
// Add this fitness's value to that other, and return a _new_ instance with the result.
eoDualFitness<BaseType,Compare> operator-( const eoDualFitness<BaseType,Compare> & that )
{
eoDualFitness<BaseType,Compare> from( *this );
return from -= that; return from -= that;
} }
// Add this fitness's value to that other, and return a _new_ instance with the result. template<class T>
template <class F, class Cmp> eoDualFitness<BaseType,Compare> operator/( T that )
eoDualFitness<F,Cmp> operator/(const eoDualFitness<F,Cmp> & that)
{ {
eoDualFitness<F,Cmp> from( *this ); this->_value /= that;
return *this;
}
// Add this fitness's value to that other, and return a _new_ instance with the result.
eoDualFitness<BaseType,Compare> operator/( const eoDualFitness<BaseType,Compare> & that )
{
eoDualFitness<BaseType,Compare> from( *this );
return from /= that; return from /= that;
} }
//! Print an eoDualFitness instance as a pair of numbers, separated by a space //! Print an eoDualFitness instance as a pair of numbers, separated by a space
template <class F, class Cmp> friend
std::ostream& operator<<(std::ostream& os) std::ostream& operator<<( std::ostream& os, const eoDualFitness<BaseType,Compare> & fitness )
{ {
os << this->_value << " " << this->_is_feasible; os << fitness._value << " " << fitness._is_feasible;
return os; return os;
} }
//! Read an eoDualFitness instance as a pair of numbers, separated by a space //! Read an eoDualFitness instance as a pair of numbers, separated by a space
template <class F, class Cmp> friend
std::istream& operator>>(std::istream& is) std::istream& operator>>( std::istream& is, eoDualFitness<BaseType,Compare> & fitness )
{ {
F value; BaseType value;
is >> value; is >> value;
bool feasible; bool feasible;
is >> feasible; is >> feasible;
this->_value = value; fitness._value = value;
this->_is_feasible = feasible; fitness._is_feasible = feasible;
return is; return is;
} }
}; };