diff --git a/eo/src/MGE/VirusOp.h b/eo/contrib/MGE/VirusOp.h similarity index 73% rename from eo/src/MGE/VirusOp.h rename to eo/contrib/MGE/VirusOp.h index 73038aa7..246fdad3 100644 --- a/eo/src/MGE/VirusOp.h +++ b/eo/contrib/MGE/VirusOp.h @@ -18,7 +18,7 @@ Contact: todos@geneura.ugr.es, http://geneura.ugr.es Marc.Schoenauer@polytechnique.fr -CVS Info: $Date: 2001-05-10 12:16:00 $ $Header: /home/nojhan/dev/eodev/eodev_cvs/eo/src/MGE/Attic/VirusOp.h,v 1.1 2001-05-10 12:16:00 jmerelo Exp $ $Author: jmerelo $ +CVS Info: $Date: 2001-05-17 10:08:25 $ $Header: /home/nojhan/dev/eodev/eodev_cvs/eo/contrib/MGE/VirusOp.h,v 1.1 2001-05-17 10:08:25 jmerelo Exp $ $Author: jmerelo $ */ #ifndef VirusOp_h @@ -33,9 +33,7 @@ CVS Info: $Date: 2001-05-10 12:16:00 $ $Header: /home/nojhan/dev/eodev/eodev_cvs #include #include -/** eoBitFlip --> changes 1 bit -\class eoBitBitFlip eoBitOp.h ga/eoBitOp.h -\ingroup bitstring +/** VirusBitFlip --> changes 1 bit */ template @@ -83,6 +81,46 @@ class VirusMutation: public eoMonOp > { } }; +/// Works for 1-bit virus; shifts the one to the right or left +template +class VirusShiftMutation: public eoMonOp > { + public: + + /// Ctor + VirusShiftMutation( ) {}; + + /// The class name. + virtual string className() const { return "VirusShiftMutation"; }; + + /** + * Change one bit. + * @param chrom The cromosome which one bit is going to be changed. + */ + bool operator()(eoVirus& _chrom) { + // Search for virus bits + eoBooleanGenerator gen; + for ( unsigned i = 0; i < _chrom.size(); i ++ ) { + if ( _chrom.virusBit(i) ) { + if ( gen() ) { + if ( i + 1 < _chrom.size() ) { + _chrom.virusBitSet(i+1,true); + _chrom.virusBitSet(i, false); + } + } else { + if ( i - 1 > 0 ) { + _chrom.virusBitSet(i-1,true); + _chrom.virusBitSet(i, false); + } + } + } + } + return true; + } + + private: +}; + + template class VirusTransmission: public eoBinOp > { public: diff --git a/eo/src/MGE/eoInitVirus.h b/eo/contrib/MGE/eoInitVirus.h similarity index 76% rename from eo/src/MGE/eoInitVirus.h rename to eo/contrib/MGE/eoInitVirus.h index 3659f476..082339c8 100644 --- a/eo/src/MGE/eoInitVirus.h +++ b/eo/contrib/MGE/eoInitVirus.h @@ -41,7 +41,7 @@ template class eoInitVirus: public eoInit< eoVirus > { public: - eoInitVirus(unsigned _combien, eoRndGenerator& _generator) + eoInitVirus(unsigned _combien, eoRndGenerator& _generator ) : combien(_combien), generator(_generator) {} virtual void operator()( eoVirus& chrom) @@ -61,4 +61,26 @@ private : eoSTLF generator; }; +/// Inits the virus with one bit to the left set to one +template +class eoInitVirus1bit: public eoInit< eoVirus > { +public: + + eoInitVirus1bit(unsigned _combien, eoRndGenerator& _generator ) + : combien(_combien), generator(_generator) {} + + virtual void operator()( eoVirus& chrom) + { + chrom.resize(combien); + chrom.virResize(combien); + std::generate(chrom.begin(), chrom.end(), generator); + chrom.virusBitSet(0, true ); + chrom.invalidate(); + } + +private : + unsigned combien; + /// generic wrapper for eoFunctor (s), to make them have the function-pointer style copy semantics + eoSTLF generator; +}; #endif diff --git a/eo/src/MGE/eoVirus.h b/eo/contrib/MGE/eoVirus.h similarity index 94% rename from eo/src/MGE/eoVirus.h rename to eo/contrib/MGE/eoVirus.h index 46e55c91..d49af26c 100644 --- a/eo/src/MGE/eoVirus.h +++ b/eo/contrib/MGE/eoVirus.h @@ -18,7 +18,7 @@ Contact: todos@geneura.ugr.es, http://geneura.ugr.es Marc.Schoenauer@polytechnique.fr -CVS Info: $Date: 2001-05-10 12:16:00 $ $Header: /home/nojhan/dev/eodev/eodev_cvs/eo/src/MGE/Attic/eoVirus.h,v 1.1 2001-05-10 12:16:00 jmerelo Exp $ $Author: jmerelo $ +CVS Info: $Date: 2001-05-17 10:08:25 $ $Header: /home/nojhan/dev/eodev/eodev_cvs/eo/contrib/MGE/eoVirus.h,v 1.1 2001-05-17 10:08:25 jmerelo Exp $ $Author: jmerelo $ */ #ifndef eoVirus_h diff --git a/eo/test/Makefile.am b/eo/test/Makefile.am index ceac9a94..db51f6f0 100644 --- a/eo/test/Makefile.am +++ b/eo/test/Makefile.am @@ -8,12 +8,13 @@ DEPS = $(top_builddir)/src/utils/libeoutils.a $(top_builddir)/src/libeo.a ############################################################################### -INCLUDES = -I$(top_builddir)/src +INCLUDES = -I$(top_builddir)/src -I$(top_builddir)/contrib LDADDS = $(top_builddir)/src/utils/libeoutils.a $(top_builddir)/src/libeo.a CXXFLAGS = -g -Wall ############################################################################### -check_PROGRAMS = t-eoParetoFitness t-eoPareto t-eofitness t-eoRandom t-eobin t-eoVirus t-MGE t-MGE-control t-eoStateAndParser t-eoCheckpointing t-eoSSGA \ +check_PROGRAMS = t-eoParetoFitness t-eoPareto t-eofitness t-eoRandom t-eobin t-eoVirus\ + t-MGE t-MGE1bit t-MGE-control t-eoStateAndParser t-eoCheckpointing t-eoSSGA \ t-eoExternalEO t-eoSymreg t-eo t-eoReplacement t-eoSelect t-eoGenOp t-eoGA t-eoReal t-eoVector t-eoESAll TESTS=run_tests t-eoVector t-eoRandom t-eoSSGA t-eoPareto t-eoParetoFitness # removing temporarily t-eoESFull @@ -45,6 +46,12 @@ t_eoVirus_LDADD = $(LDADDS) ############################################################################### +t_MGE1bit_SOURCES = t-MGE1bit.cpp binary_value.h +t_MGE1bit_DEPENDENCIES = $(DEPS) +t_MGE1bit_LDADD = $(LDADDS) + +############################################################################### + t_MGE_SOURCES = t-MGE.cpp binary_value.h t_MGE_DEPENDENCIES = $(DEPS) t_MGE_LDADD = $(LDADDS) diff --git a/eo/test/t-MGE-control.cpp b/eo/test/t-MGE-control.cpp index 61f3af61..4f74adb9 100644 --- a/eo/test/t-MGE-control.cpp +++ b/eo/test/t-MGE-control.cpp @@ -33,7 +33,7 @@ int main() eoPop pop; // Evaluation - RoyalRoad rr( 4 ); + RoyalRoad rr( 8 ); eoEvalFuncCounter eval( rr ); eoInitVirus random(CHROM_SIZE, gen); @@ -56,8 +56,8 @@ int main() eoUBitXover xover; eoProportionalOp propSel; eoGeneralBreeder breeder( lottery, propSel ); - propSel.add(vm, 0.8); - propSel.add(xover, 0.1); + propSel.add(vm, 0.2); + propSel.add(xover, 0.8); // Replace a single one eoCommaReplacement replace; diff --git a/eo/test/t-MGE.cpp b/eo/test/t-MGE.cpp index 112ca328..0af94356 100644 --- a/eo/test/t-MGE.cpp +++ b/eo/test/t-MGE.cpp @@ -33,7 +33,7 @@ int main() eoPop pop; // Evaluation - RoyalRoad rr( 4 ); + RoyalRoad rr( 8 ); eoEvalFuncCounter eval( rr ); eoInitVirus random(CHROM_SIZE, gen); @@ -58,10 +58,10 @@ int main() eoUBitXover xover; eoProportionalOp propSel; eoGeneralBreeder breeder( lottery, propSel ); - propSel.add(vm, 0.8); + propSel.add(vm, 0.1); propSel.add(vf, 0.05); propSel.add(vt, 0.05); - propSel.add(xover, 0.1); + propSel.add(xover, 0.8); // Replace a single one eoCommaReplacement replace;