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 #ifndef eoVirus_h
00026 #define eoVirus_h
00027
00028 #include <iostream>
00029 #include <functional>
00030 #include <string>
00031 #include <vector>
00032
00033 #include "ga/eoBit.h"
00034
00048 template <class FitT>
00049 class eoVirus : public eoBit<FitT>
00050 {
00051 public:
00052
00053 using eoBit<FitT>::begin;
00054 using eoBit<FitT>::end;
00055 using eoBit<FitT>::size;
00056
00057
00062 eoVirus(unsigned _size = 0, bool _value = false, bool _virValue = false):
00063 eoBit<FitT>(_size, _value), virus( _size, _virValue) {}
00064
00066 virtual std::string className() const {
00067 return "eoVirus";
00068 }
00069
00071 void virResize( unsigned _i ) {
00072 virus.resize(_i );
00073 }
00074
00076 bool virusBit( unsigned _i ) const {
00077 return virus[_i];
00078 }
00079
00081 void virusBitSet( unsigned _i, bool _bit ) {
00082 virus[_i ] = _bit;
00083 }
00084
00089 virtual void printOn(std::ostream& os) const {
00090 EO<FitT>::printOn(os);
00091 os << ' ';
00092 os << size() << ' ';
00093 std::copy(begin(), end(), std::ostream_iterator<bool>(os));
00094 std::cout << std::endl;
00095 std::copy(virus.begin(), virus.end(), std::ostream_iterator<bool>(os));
00096 }
00097
00102 virtual void readFrom(std::istream& is){
00103 eoBit<FitT>::readFrom(is);
00104 unsigned s;
00105 is >> s;
00106 std::string bits;
00107 is >> bits;
00108 if (is) {
00109 virus.resize(bits.size());
00110 std::transform(bits.begin(), bits.end(), virus.begin(),
00111 std::bind2nd(std::equal_to<char>(), '1'));
00112 }
00113 }
00114
00115
00116 private:
00117
00118 std::vector<bool> virus;
00119 };
00120
00121
00122
00123 #endif //eoBit_h
00124
00125
00126
00127
00128
00129
00130