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 
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     // implementation of the other operators
00063     bool operator>( const eoScalarFitness<ScalarType, Compare>& y ) const  { return y < *this; }
00064     // implementation of the other operators
00065     bool operator<=( const eoScalarFitness<ScalarType, Compare>& y ) const { return !(*this > y); }
00066     // implementation of the other operators
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

Generated on Thu Oct 19 05:06:38 2006 for EO by  doxygen 1.3.9.1