EvolvingObjects
eoScalarFitness.h
00001 /* -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
00002 
00003   -----------------------------------------------------------------------------
00004   eoScalarFitness.h
00005 
00006  (c) Maarten Keijzer (mkeijzer@mad.scientist.com) and GeNeura Team, 1999, 2000
00007 
00008     This library is free software; you can redistribute it and/or
00009     modify it under the terms of the GNU Lesser General Public
00010     License as published by the Free Software Foundation; either
00011     version 2 of the License, or (at your option) any later version.
00012 
00013     This library is distributed in the hope that it will be useful,
00014     but WITHOUT ANY WARRANTY; without even the implied warranty of
00015     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016     Lesser General Public License for more details.
00017 
00018     You should have received a copy of the GNU Lesser General Public
00019     License along with this library; if not, write to the Free Software
00020     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00021 
00022     Contact: todos@geneura.ugr.es, http://geneura.ugr.es
00023  */
00024 
00025 
00026 #ifndef eoScalarFitness_h
00027 #define eoScalarFitness_h
00028 
00029 #include <functional>
00030 #include <iostream>
00031 
00051 template <class ScalarType, class Compare >
00052 class eoScalarFitness
00053 {
00054     public :
00055 
00056     eoScalarFitness() : value() {}
00057     eoScalarFitness(const eoScalarFitness& other) : value(other.value) {}
00058     eoScalarFitness(const ScalarType& v) : value(v) {}
00059 
00060     eoScalarFitness& operator=(const eoScalarFitness& other)
00061     { value = other.value; return *this; }
00062     eoScalarFitness& operator=(const ScalarType& v)
00063     { value = v; return *this; }
00064 
00072     operator ScalarType(void) const { return value; }
00073 
00075     bool operator<(const eoScalarFitness& other) const
00076     { return Compare()(value, other.value); }
00077 
00079         //  needed for MSVC 8 (MSVC 2005) added by J.Eggermont 20-11-2006
00080     bool operator<(const ScalarType& other) const
00081     { return Compare()(value, other); }
00082 
00083     // implementation of the other operators
00084     bool operator>( const eoScalarFitness<ScalarType, Compare>& y ) const  { return y < *this; }
00085     // implementation of the other operators
00086     bool operator<=( const eoScalarFitness<ScalarType, Compare>& y ) const { return !(*this > y); }
00087     // implementation of the other operators
00088     bool operator>=(const eoScalarFitness<ScalarType, Compare>& y ) const { return !(*this < y); }
00089 
00090 
00091     private :
00092         ScalarType value;
00093 };
00105 #if defined(__CUDACC__)
00106 typedef eoScalarFitness<float, std::less<float> >    eoMaximizingFitness;
00107 typedef eoScalarFitness<float, std::greater<float> > eoMinimizingFitness;
00108 #else
00109 typedef eoScalarFitness<double, std::less<double> >    eoMaximizingFitness;
00110 typedef eoScalarFitness<double, std::greater<double> > eoMinimizingFitness;
00111 #endif
00112 
00113 template <class F, class Cmp>
00114 std::ostream& operator<<(std::ostream& os, const eoScalarFitness<F, Cmp>& f)
00115 {
00116     os << (F) f;
00117     return os;
00118 }
00119 
00120 template <class F, class Cmp>
00121 std::istream& operator>>(std::istream& is, eoScalarFitness<F, Cmp>& f)
00122 {
00123     F value;
00124     is >> value;
00125     f = value;
00126     return is;
00127 }
00128 
00130 #endif
 All Classes Namespaces Files Functions Variables Typedefs Friends