00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef eoScalarFitness_h
00027 #define eoScalarFitness_h
00028
00029 #include <functional>
00030 #include <iostream>
00031
00042 template <class ScalarType, class Compare >
00043 class eoScalarFitness
00044 {
00045 public :
00046
00047 eoScalarFitness() : value() {}
00048 eoScalarFitness(const eoScalarFitness& other) : value(other.value) {}
00049 eoScalarFitness(const ScalarType& v) : value(v) {}
00050
00051 eoScalarFitness& operator=(const eoScalarFitness& other)
00052 { value = other.value; return *this; }
00053 eoScalarFitness& operator=(const ScalarType& v)
00054 { value = v; return *this; }
00055
00056 operator ScalarType(void) const { return value; }
00057
00059 bool operator<(const eoScalarFitness& other) const
00060 { return Compare()(value, other.value); }
00061
00062
00063 bool operator>( const eoScalarFitness<ScalarType, Compare>& y ) const { return y < *this; }
00064
00065 bool operator<=( const eoScalarFitness<ScalarType, Compare>& y ) const { return !(*this > y); }
00066
00067 bool operator>=(const eoScalarFitness<ScalarType, Compare>& y ) const { return !(*this < y); }
00068
00069
00070 private :
00071 ScalarType value;
00072 };
00073
00080 typedef eoScalarFitness<double, std::less<double> > eoMaximizingFitness;
00081 typedef eoScalarFitness<double, std::greater<double> > eoMinimizingFitness;
00082
00083 template <class F, class Cmp>
00084 std::ostream& operator<<(std::ostream& os, const eoScalarFitness<F, Cmp>& f)
00085 {
00086 os << (F) f;
00087 return os;
00088 }
00089
00090 template <class F, class Cmp>
00091 std::istream& operator>>(std::istream& is, eoScalarFitness<F, Cmp>& f)
00092 {
00093 F value;
00094 is >> value;
00095 f = value;
00096 return is;
00097 }
00098
00099 #endif