EvolvingObjects
|
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 <algorithm> 00039 #include <functional> 00040 #include <iostream> 00041 #include <string> 00042 00043 #include "eoVector.h" 00044 00062 template <class FitT> class eoBit: public eoVector<FitT, bool> 00063 { 00064 public: 00065 00066 using eoVector< FitT, bool >::begin; 00067 using eoVector< FitT, bool >::end; 00068 using eoVector< FitT, bool >::resize; 00069 using eoVector< FitT, bool >::size; 00070 00076 eoBit(unsigned size = 0, bool value = false): 00077 eoVector<FitT, bool>(size, value) {} 00078 00080 virtual std::string className() const 00081 { 00082 return "eoBit"; 00083 } 00084 00089 virtual void printOn(std::ostream& os) const 00090 { 00091 EO<FitT>::printOn(os); 00092 os << ' '; 00093 os << size() << ' '; 00094 std::copy(begin(), end(), std::ostream_iterator<bool>(os)); 00095 } 00096 00101 virtual void readFrom(std::istream& is) 00102 { 00103 EO<FitT>::readFrom(is); 00104 unsigned s; 00105 is >> s; 00106 std::string bits; 00107 is >> bits; 00108 if (is) 00109 { 00110 resize(bits.size()); 00111 std::transform(bits.begin(), bits.end(), begin(), 00112 std::bind2nd(std::equal_to<char>(), '1')); 00113 } 00114 } 00115 }; 00116 00117 //----------------------------------------------------------------------------- 00118 00119 #endif //eoBit_h 00120 00121 00122 // Local Variables: 00123 // coding: iso-8859-1 00124 // mode: C++ 00125 // c-file-offsets: ((c . 0)) 00126 // c-file-style: "Stroustrup" 00127 // fill-column: 80 00128 // End: