diff --git a/eo/contrib/MGE/eoVirus.h b/eo/contrib/MGE/eoVirus.h index a7a61a63..a7c6aaee 100644 --- a/eo/contrib/MGE/eoVirus.h +++ b/eo/contrib/MGE/eoVirus.h @@ -1,36 +1,36 @@ -/* - eoVirus.h - (c) GeNeura Team 2001, Marc Schoenauer 2000 +/* eoVirus.h - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. +(c) GeNeura Team 2001, Marc Schoenauer 2000 - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. +This library is free software; you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as +published by the Free Software Foundation; either version 2 of the +License, or (at your option) any later version. - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +This library is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. - Contact: todos@geneura.ugr.es, http://geneura.ugr.es - Marc.Schoenauer@polytechnique.fr -CVS Info: $Date: 2004-12-23 15:29:07 $ $Header: /home/nojhan/dev/eodev/eodev_cvs/eo/contrib/MGE/eoVirus.h,v 1.3 2004-12-23 15:29:07 kuepper Exp $ $Author: kuepper $ +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +USA + +Contact: todos@geneura.ugr.es, http://geneura.ugr.es + Marc.Schoenauer@polytechnique.fr */ + #ifndef eoVirus_h #define eoVirus_h -//----------------------------------------------------------------------------- +#include +#include +#include +#include -#include // ostream, istream -#include // bind2nd -#include // std::string - -#include +#include "ga/eoBit.h" /** \defgroup bitstring @@ -38,13 +38,15 @@ CVS Info: $Date: 2004-12-23 15:29:07 $ $Header: /home/nojhan/dev/eodev/eodev_cvs Various functions for a bitstring representation */ -/** eoBit: implementation of bitstring chromosome. -\class eoBit eoBit.h ga/eoBit.h -\ingroup bitstring - * based on STL's vector specialization. +/** Implementation of bitstring chromosome. + +@class eoBit eoBit.h ga/eoBit.h +@ingroup bitstring + +Based on STL's vector specialization. */ template -class eoVirus: public eoBit +class eoVirus : public eoBit { public: @@ -53,64 +55,67 @@ public: using eoBit::size; - /** - * (Default) Constructor. - * @param size Size of the binary std::string. - */ - eoVirus(unsigned _size = 0, bool _value = false, bool _virValue = false): - eoBit(_size, _value), virus( _size, _virValue) {} + /** (Default) Constructor - /// My class name. - virtual std::string className() const { - return "eoVirus"; - } + @param size Size of the binary std::string. + */ + eoVirus(unsigned _size = 0, bool _value = false, bool _virValue = false): + eoBit(_size, _value), virus( _size, _virValue) {} - /// Access to virus features - void virResize( unsigned _i ) { - virus.resize(_i ); - } - - /// Access to virus features - bool virusBit( unsigned _i ) const { - return virus[_i]; - } - - /// Change virus features - void virusBitSet( unsigned _i, bool _bit ) { - virus[_i ] = _bit; - } - - /** - * To print me on a stream. - * @param os The ostream. - */ - virtual void printOn(std::ostream& os) const { - EO::printOn(os); - os << ' '; - os << size() << ' '; - std::copy(begin(), end(), std::ostream_iterator(os)); - std::cout << std::endl; - std::copy(virus.begin(), virus.end(), std::ostream_iterator(os)); - } - - /** - * To read me from a stream. - * @param is The istream. - */ - virtual void readFrom(std::istream& is){ - eoBit::readFrom(is); - unsigned s; - is >> s; - std::string bits; - is >> bits; - if (is) { - virus.resize(bits.size()); - std::transform(bits.begin(), bits.end(), virus.begin(), - std::bind2nd(std::equal_to(), '1')); - } + /// My class name + virtual std::string className() const { + return "eoVirus"; } - private: - std::vector virus; + + /// Access to virus features + void virResize( unsigned _i ) { + virus.resize(_i ); + } + + /// Access to virus features + bool virusBit( unsigned _i ) const { + return virus[_i]; + } + + /// Change virus features + void virusBitSet( unsigned _i, bool _bit ) { + virus[_i ] = _bit; + } + + /** To print me on a stream. + + @param os The ostream. + */ + virtual void printOn(std::ostream& os) const { + EO::printOn(os); + os << ' '; + os << size() << ' '; + std::copy(begin(), end(), std::ostream_iterator(os)); + std::cout << std::endl; + std::copy(virus.begin(), virus.end(), std::ostream_iterator(os)); + } + + /** To read me from a stream. + + @param is The istream. + */ + virtual void readFrom(std::istream& is){ + eoBit::readFrom(is); + unsigned s; + is >> s; + std::string bits; + is >> bits; + if (is) { + virus.resize(bits.size()); + std::transform(bits.begin(), bits.end(), virus.begin(), + std::bind2nd(std::equal_to(), '1')); + } + } + + +private: + + std::vector virus; }; //----------------------------------------------------------------------------- @@ -119,6 +124,7 @@ public: // Local Variables: +// coding: iso-8859-1 // mode: C++ // c-file-style: "Stroustrup" // End: diff --git a/eo/src/eoVector.h b/eo/src/eoVector.h index b4ce1b9a..40facddf 100644 --- a/eo/src/eoVector.h +++ b/eo/src/eoVector.h @@ -22,7 +22,7 @@ Marc.Schoenauer@polytechnique.fr mak@dhi.dk - CVS Info: $Date: 2004-12-23 15:29:06 $ $Header: /home/nojhan/dev/eodev/eodev_cvs/eo/src/eoVector.h,v 1.16 2004-12-23 15:29:06 kuepper Exp $ $Author: kuepper $ + CVS Info: $Date: 2005-10-06 17:22:40 $ $Header: /home/nojhan/dev/eodev/eodev_cvs/eo/src/eoVector.h,v 1.17 2005-10-06 17:22:40 kuepper Exp $ $Author: kuepper $ */ //----------------------------------------------------------------------------- @@ -31,7 +31,7 @@ #define _eoVector_h #include -#include // needed for GCC 3.2 +#include #include /** diff --git a/eo/src/ga/eoBit.h b/eo/src/ga/eoBit.h index fbe0b44a..d77d3218 100644 --- a/eo/src/ga/eoBit.h +++ b/eo/src/ga/eoBit.h @@ -39,18 +39,19 @@ #include // bind2nd #include // std::string -#include +#include "eoVector.h" -/** -\defgroup bitstring +/** @defgroup bitstring - Various functions for a bitstring representation +Various functions for a bitstring representation */ -/** eoBit: implementation of bitstring chromosome. -\class eoBit eoBit.h ga/eoBit.h -\ingroup bitstring - * based on STL's std::vector specialization. +/** Implementation of bitstring chromosome. + +@class eoBit eoBit.h ga/eoBit.h +@ingroup bitstring + +Based on STL's std::vector specialization. */ template class eoBit: public eoVector { diff --git a/eo/test/Makefile.am b/eo/test/Makefile.am index 98af15ad..34ad1e61 100644 --- a/eo/test/Makefile.am +++ b/eo/test/Makefile.am @@ -63,8 +63,11 @@ t_eofitness_SOURCES = t-eofitness.cpp t_eoFitnessAssembledEA_SOURCES = t-eoFitnessAssembledEA.cpp t_eobin_SOURCES = t-eobin.cpp t_eoVirus_SOURCES = t-eoVirus.cpp +t_MGE1bit_CXXFLAGS = -I$(top_srcdir)/contrib/MGE t_MGE1bit_SOURCES = t-MGE1bit.cpp +t_MGE_CXXFLAGS = -I$(top_srcdir)/contrib/MGE t_MGE_SOURCES = t-MGE.cpp +t_MGE_control_CXXFLAGS = -I$(top_srcdir)/contrib/MGE t_MGE_control_SOURCES = t-MGE-control.cpp t_eoStateAndParser_SOURCES = t-eoStateAndParser.cpp t_eoCheckpointing_SOURCES = t-eoCheckpointing.cpp diff --git a/eo/test/t-MGE-control.cpp b/eo/test/t-MGE-control.cpp index d9db93a7..240dd368 100644 --- a/eo/test/t-MGE-control.cpp +++ b/eo/test/t-MGE-control.cpp @@ -2,20 +2,24 @@ // t-eoMGE.cpp //----------------------------------------------------------------------------- +#ifdef HAVE_CONFIG_H +#include +#endif + #ifndef __GNUG__ // to avoid long name warnings #pragma warning(disable:4786) #endif // __GNUG__ -#include -#include +#include "eo" +#include "ga/eoBitOp.h" #include "RoyalRoad.h" // Viri -#include "../contrib/MGE/VirusOp.h" -#include "../contrib/MGE/eoVirus.h" -#include "../contrib/MGE/eoInitVirus.h" +#include "VirusOp.h" +#include "eoVirus.h" +#include "eoInitVirus.h" //----------------------------------------------------------------------------- @@ -29,25 +33,25 @@ int main() unsigned i; eoBooleanGenerator gen; - // the populations: - eoPop pop; + // the populations: + eoPop pop; // Evaluation - RoyalRoad rr( 8 ); + RoyalRoad rr( 8 ); eoEvalFuncCounter eval( rr ); - eoInitVirus random(CHROM_SIZE, gen); + eoInitVirus random(CHROM_SIZE, gen); for (i = 0; i < POP_SIZE; ++i) { Chrom chrom; random(chrom); eval(chrom); pop.push_back(chrom); } - + std::cout << "population:" << std::endl; for (i = 0; i < pop.size(); ++i) std::cout << "\t" << pop[i] << " " << pop[i].fitness() << std::endl; - + // selection eoStochTournamentSelect lottery(0.9 ); @@ -58,14 +62,14 @@ int main() eoGeneralBreeder breeder( lottery, propSel ); propSel.add(vm, 0.2); propSel.add(xover, 0.8); - + // Replace a single one eoCommaReplacement replace; // Terminators eoGenContinue continuator1(10); eoFitContinue continuator2(CHROM_SIZE); - eoCombinedContinue continuator(continuator1, continuator2); + eoCombinedContinue continuator(continuator1, continuator2); eoCheckPoint checkpoint(continuator); eoStdoutMonitor monitor; checkpoint.add(monitor); @@ -88,7 +92,7 @@ int main() std::cout << "exception: " << e.what() << std::endl;; exit(EXIT_FAILURE); } - + std::cout << "pop" << std::endl; for (i = 0; i < pop.size(); ++i) std::cout << "\t" << pop[i] << " " << pop[i].fitness() << std::endl; diff --git a/eo/test/t-MGE.cpp b/eo/test/t-MGE.cpp index b19aba9b..a122b5e7 100644 --- a/eo/test/t-MGE.cpp +++ b/eo/test/t-MGE.cpp @@ -2,6 +2,10 @@ // t-eoMGE.cpp //----------------------------------------------------------------------------- +#ifdef HAVE_CONFIG_H +#include +#endif + #ifndef __GNUG__ // to avoid long name warnings #pragma warning(disable:4786) @@ -13,9 +17,9 @@ #include "RoyalRoad.h" // Viri -#include "../contrib/MGE/VirusOp.h" -#include "../contrib/MGE/eoVirus.h" -#include "../contrib/MGE/eoInitVirus.h" +#include "VirusOp.h" +#include "eoVirus.h" +#include "eoInitVirus.h" //----------------------------------------------------------------------------- @@ -29,25 +33,25 @@ int main() unsigned i; eoBooleanGenerator gen; - // the populations: - eoPop pop; + // the populations: + eoPop pop; // Evaluation - RoyalRoad rr( 8 ); + RoyalRoad rr( 8 ); eoEvalFuncCounter eval( rr ); - eoInitVirus random(CHROM_SIZE, gen); + eoInitVirus random(CHROM_SIZE, gen); for (i = 0; i < POP_SIZE; ++i) { Chrom chrom; random(chrom); eval(chrom); pop.push_back(chrom); } - + std::cout << "population:" << std::endl; for (i = 0; i < pop.size(); ++i) std::cout << "\t" << pop[i] << " " << pop[i].fitness() << std::endl; - + // selection eoStochTournamentSelect lottery(0.9 ); @@ -62,14 +66,14 @@ int main() propSel.add(vf, 0.05); propSel.add(vt, 0.05); propSel.add(xover, 0.8); - + // Replace a single one eoCommaReplacement replace; // Terminators eoGenContinue continuator1(10); eoFitContinue continuator2(CHROM_SIZE); - eoCombinedContinue continuator(continuator1, continuator2); + eoCombinedContinue continuator(continuator1, continuator2); eoCheckPoint checkpoint(continuator); eoStdoutMonitor monitor; checkpoint.add(monitor); @@ -92,7 +96,7 @@ int main() std::cout << "exception: " << e.what() << std::endl;; exit(EXIT_FAILURE); } - + std::cout << "pop" << std::endl; for (i = 0; i < pop.size(); ++i) std::cout << "\t" << pop[i] << " " << pop[i].fitness() << std::endl; diff --git a/eo/test/t-MGE1bit.cpp b/eo/test/t-MGE1bit.cpp index 2d6571a1..781f5c74 100644 --- a/eo/test/t-MGE1bit.cpp +++ b/eo/test/t-MGE1bit.cpp @@ -2,20 +2,23 @@ // t-eoMGE.cpp //----------------------------------------------------------------------------- +#ifdef HAVE_CONFIG_H +#include +#endif + #ifndef __GNUG__ // to avoid long name warnings #pragma warning(disable:4786) #endif // __GNUG__ -#include -#include - +#include "eo" +#include "ga/eoBitOp.h" #include "RoyalRoad.h" // Viri -#include "../contrib/MGE/VirusOp.h" -#include "../contrib/MGE/eoVirus.h" -#include "../contrib/MGE/eoInitVirus.h" +#include "VirusOp.h" +#include "eoVirus.h" +#include "eoInitVirus.h" //-----------------------------------------------------------------------------