# eoVirus.h

    00001 /* eoVirus.h
    00002
    00003 (c) GeNeura Team 2001, Marc Schoenauer 2000
    00004
    00005 This library is free software; you can redistribute it and/or modify
    00006 it under the terms of the GNU Lesser General Public License as
    00007 published by the Free Software Foundation; either version 2 of the
    00008 License, or (at your option) any later version.
    00009
    00010 This library is distributed in the hope that it will be useful, but
    00011 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
    00018 USA
    00019
    00020 Contact: todos@geneura.ugr.es, http://geneura.ugr.es
    00021          Marc.Schoenauer@polytechnique.fr
    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 // Local Variables:
    00127 // coding: iso-8859-1
    00128 // mode: C++
    00129 // c-file-style: "Stroustrup"
    00130 // End: