00001 /* 00002 eoBit.h 00003 (c) GeNeura Team 1998, Marc Schoenauer 2000 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Lesser General Public 00007 License as published by the Free Software Foundation; either 00008 version 2 of the License, or (at your option) any later version. 00009 00010 This library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Lesser General Public License for more details. 00014 00015 You should have received a copy of the GNU Lesser General Public 00016 License along with this library; if not, write to the Free Software 00017 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00018 00019 Contact: todos@geneura.ugr.es, http://geneura.ugr.es 00020 Marc.Schoenauer@polytechnique.fr 00021 */ 00022 00023 /* MS, Nov. 23, 2000 00024 Added the calls to base class I/O routines that print the fitness 00025 Left printing/reading of the size of the bitstring, 00026 for backward compatibility, and as it is a general practice in EO 00027 00028 MS, Feb. 7, 2001 00029 replaced all ...Bin... names with ...Bit... names - for bitstring 00030 as it was ambiguous with bin...ary things 00031 */ 00032 00033 #ifndef eoBit_h 00034 #define eoBit_h 00035 00036 //----------------------------------------------------------------------------- 00037 00038 #include <iostream> // std::ostream, std::istream 00039 #include <functional> // bind2nd 00040 #include <string> // std::string 00041 00042 #include "eoVector.h" 00043 00056 template <class FitT> class eoBit: public eoVector<FitT, bool> 00057 { 00058 public: 00059 00060 using eoVector< FitT, bool >::begin; 00061 using eoVector< FitT, bool >::end; 00062 using eoVector< FitT, bool >::resize; 00063 using eoVector< FitT, bool >::size; 00064 00069 eoBit(unsigned size = 0, bool value = false): 00070 eoVector<FitT, bool>(size, value) {} 00071 00073 virtual std::string className() const 00074 { 00075 return "eoBit"; 00076 } 00077 00082 virtual void printOn(std::ostream& os) const 00083 { 00084 EO<FitT>::printOn(os); 00085 os << ' '; 00086 os << size() << ' '; 00087 std::copy(begin(), end(), std::ostream_iterator<bool>(os)); 00088 } 00089 00094 virtual void readFrom(std::istream& is) 00095 { 00096 EO<FitT>::readFrom(is); 00097 unsigned s; 00098 is >> s; 00099 std::string bits; 00100 is >> bits; 00101 if (is) 00102 { 00103 resize(bits.size()); 00104 std::transform(bits.begin(), bits.end(), begin(), 00105 std::bind2nd(std::equal_to<char>(), '1')); 00106 } 00107 } 00108 }; 00109 00110 //----------------------------------------------------------------------------- 00111 00112 #endif //eoBit_h 00113 00114 00115 // Local Variables: 00116 // mode: C++ 00117 // c-file-style: "Stroustrup" 00118 // End:
1.3.9.1