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
00063
00064 bool operator<(const ScalarType& other) const
00065 { return Compare()(value, other); }
00066
00067
00068 bool operator>( const eoScalarFitness<ScalarType, Compare>& y ) const { return y < *this; }
00069
00070 bool operator<=( const eoScalarFitness<ScalarType, Compare>& y ) const { return !(*this > y); }
00071
00072 bool operator>=(const eoScalarFitness<ScalarType, Compare>& y ) const { return !(*this < y); }
00073
00074
00075 private :
00076 ScalarType value;
00077 };
00078
00085 typedef eoScalarFitness<double, std::less<double> > eoMaximizingFitness;
00086 typedef eoScalarFitness<double, std::greater<double> > eoMinimizingFitness;
00087
00088 template <class F, class Cmp>
00089 std::ostream& operator<<(std::ostream& os, const eoScalarFitness<F, Cmp>& f)
00090 {
00091 os << (F) f;
00092 return os;
00093 }
00094
00095 template <class F, class Cmp>
00096 std::istream& operator>>(std::istream& is, eoScalarFitness<F, Cmp>& f)
00097 {
00098 F value;
00099 is >> value;
00100 f = value;
00101 return is;
00102 }
00103
00104 #endif