diff --git a/eo/src/eo b/eo/src/eo index 75e0716d9..8d180d543 100644 --- a/eo/src/eo +++ b/eo/src/eo @@ -60,11 +60,12 @@ #include #include - #include - #include #include +#include + +#include //----------------------------------------------------------------------------- // to be continued ... diff --git a/eo/src/eoGeneration.h b/eo/src/eoGeneration.h index f604d02cf..ac062bb26 100644 --- a/eo/src/eoGeneration.h +++ b/eo/src/eoGeneration.h @@ -18,19 +18,20 @@ template class eoGeneration { public: /// Constructor. - eoGeneration(eoSelect& _select, - eoTranform& _transform, - eoMerge& _replace): + eoGeneration(eoSelect& _select, + eoTransform& _transform, + eoMerge& _replace): select(_select), transform(_transform), replace(_replace) {} - /// apply one generation of evolution to the population - void operator()(eoPop& pop) + /// Apply one generation of evolution to the population. + template void operator()(eoPop& pop, + Evaluator evaluator) { - eoPop breeders; + eoPop breeders; select(pop, breeders); transform(breeders); - for_each(pop.begin(), pop.end(), Chrom::Fitness); + for_each(breeders.begin(), breeders.end(), evaluator); replace(breeders, pop); } @@ -38,9 +39,9 @@ template class eoGeneration string className() const { return "eoGeneration"; } private: - eoSelect& select; - eoTranform& transform; - eoMerge& replace; + eoSelect& select; + eoTransform& transform; + eoMerge& replace; }; //----------------------------------------------------------------------------- diff --git a/eo/src/eoInsertion.h b/eo/src/eoInsertion.h index be0f43739..7674b958a 100644 --- a/eo/src/eoInsertion.h +++ b/eo/src/eoInsertion.h @@ -7,7 +7,8 @@ //----------------------------------------------------------------------------- -#include +#include // eoPop +#include // eoMerge /****************************************************************************** * eoInsertion: A replacement algorithm. diff --git a/eo/src/eoMerge.h b/eo/src/eoMerge.h deleted file mode 100644 index 62656af81..000000000 --- a/eo/src/eoMerge.h +++ /dev/null @@ -1,57 +0,0 @@ -//----------------------------------------------------------------------------- -// eoMerge.h -//----------------------------------------------------------------------------- - -#ifndef eoMerge_h -#define eoMerge_h - -//----------------------------------------------------------------------------- - -#include // eoPop - -//----------------------------------------------------------------------------- - -/** eoMerge involves three populations, that can be merged and transformed to -give a third -*/ -template -class eoMerge: public eoObject{ - - public: - /// (Default) Constructor. - eoMerge(const float& _rate = 1.0): rep_rate(_rate) {} - - /// Dtor - virtual ~eoMerge() {} - - /** Pure virtual transformation function. Extracts something from breeders - * and transfers it to the pop - * @param breeders Tranformed individuals. - * @param pop The original population at the begining, the result at the end - */ - virtual void operator () ( eoPop& breeders, eoPop& pop ) = 0; - - /** @name Methods from eoObject */ - //@{ - /** readFrom and printOn are not overriden - */ - /** Inherited from eoObject. Returns the class name. - @see eoObject - */ - string className() const {return "eoMerge";}; - //@} - - /// Return the rate to be selected from the original population - float rate() const { return rep_rate; } - - /// Set the rate to be obtained after replacement. - /// @param _rate The rate. - void rate(const float& _rate) { rep_rate = _rate; } - -private: - float rep_rate; -}; - -//----------------------------------------------------------------------------- - -#endif eoMerge_h diff --git a/eo/src/eoPopOps.h b/eo/src/eoPopOps.h index 9c0dfc66f..7f39c2100 100644 --- a/eo/src/eoPopOps.h +++ b/eo/src/eoPopOps.h @@ -1,28 +1,28 @@ // eoPopOps.h -// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- - -//----------------------------------------------------------------------------- -// eo1d.h -// (c) GeNeura Team, 1998 +// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- + +//----------------------------------------------------------------------------- +// eo1d.h +// (c) GeNeura Team, 1998 /* - 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. + 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. - 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 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. - 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 + 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 + Contact: todos@geneura.ugr.es, http://geneura.ugr.es */ -//----------------------------------------------------------------------------- - +//----------------------------------------------------------------------------- + #ifndef _EOPOPOPS_H #define _EOPOPOPS_H @@ -31,71 +31,113 @@ using namespace std; /** @author Geneura Team @version 0.0 -*/ - -//----------------------------------------------------------------------------- -#include - -//----------------------------------------------------------------------------- -/** eoTransform is a class that transforms or does something on a population. */ + +//----------------------------------------------------------------------------- +#include + +//----------------------------------------------------------------------------- +/** eoTransform is a class that transforms or does something on a population. + */ template class eoTransform: public eoObject{ public: /** ctor */ eoTransform() {}; - - /// Dtor - virtual ~eoTransform(){}; - - /// Pure virtual transformation function. Does something on the population - virtual void operator () ( eoPop& _pop ) = 0; - /** @name Methods from eoObject */ - //@{ + /// Dtor + virtual ~eoTransform(){}; + + /// Pure virtual transformation function. Does something on the population + virtual void operator () ( eoPop& _pop ) = 0; + + /** @name Methods from eoObject */ + //@{ /** readFrom and printOn are not overriden - */ + */ /** Inherited from eoObject. Returns the class name. - @see eoObject - */ - string className() const {return "eoTransform";}; + @see eoObject + */ + string className() const {return "eoTransform";}; //@} -}; - -/** eoSelect usually takes elements from one population, with or without -transformation, and transfers them to the other population -*/ -template -class eoSelect: public eoObject{ - - public: - /** ctor - */ - eoSelect() {}; - - /// Dtor - virtual ~eoSelect(){}; - - /** Pure virtual transformation function. Extracts something from the parents, - and transfers it to the siblings - @param _parents the initial generation. Will be kept constant - @param _siblings the created offspring. Will be usually an empty population - */ - virtual void operator () ( const eoPop& _parents, eoPop& _siblings ) const = 0; - - /** @name Methods from eoObject */ - //@{ - /** readFrom and printOn are not overriden - */ - /** Inherited from eoObject. Returns the class name. - @see eoObject - */ - string className() const {return "eoSelect";}; - //@} - -}; - +}; + +//----------------------------------------------------------------------------- + +/** eoSelect usually takes elements from one population, with or without transformation, and transfers them to the other population */ +template +class eoSelect: public eoObject{ + + public: + /** ctor + */ + eoSelect() {}; + + /// Dtor + virtual ~eoSelect(){}; + + /** Pure virtual transformation function. Extracts something from the parents, + and transfers it to the siblings + @param _parents the initial generation. Will be kept constant + @param _siblings the created offspring. Will be usually an empty population + */ + virtual void operator () ( const eoPop& _parents, eoPop& _siblings ) const = 0; + + /** @name Methods from eoObject */ + //@{ + /** readFrom and printOn are not overriden + */ + /** Inherited from eoObject. Returns the class name. + @see eoObject + */ + string className() const {return "eoSelect";}; + //@} + +}; + +/** eoMerge involves three populations, that can be merged and transformed to +give a third +*/ +template +class eoMerge: public eoObject{ + + public: + /// (Default) Constructor. + eoMerge(const float& _rate = 1.0): rep_rate(_rate) {} + + /// Dtor + virtual ~eoMerge() {} + + /** Pure virtual transformation function. Extracts something from breeders + * and transfers it to the pop + * @param breeders Tranformed individuals. + * @param pop The original population at the begining, the result at the end + */ + virtual void operator () ( eoPop& breeders, eoPop& pop ) = 0; + + /** @name Methods from eoObject */ + //@{ + /** readFrom and printOn are not overriden + */ + /** Inherited from eoObject. Returns the class name. + @see eoObject + */ + string className() const {return "eoMerge";}; + //@} + + /// Return the rate to be selected from the original population + float rate() const { return rep_rate; } + + /// Set the rate to be obtained after replacement. + /// @param _rate The rate. + void rate(const float& _rate) { rep_rate = _rate; } + + private: + float rep_rate; +}; + +//----------------------------------------------------------------------------- #endif diff --git a/eo/test/Makefile.am b/eo/test/Makefile.am index fafe1a2bf..e022db384 100644 --- a/eo/test/Makefile.am +++ b/eo/test/Makefile.am @@ -13,7 +13,14 @@ LDADDS = $(top_builddir)/src/libeo.a ############################################################################### -noinst_PROGRAMS = t-eobreeder t-eoinclusion t-eoinsertion t-eo t-eofitness t-eoproblem t-eobin t-eolottery +noinst_PROGRAMS = t-eogeneration t-eobreeder t-eoinclusion t-eoinsertion t-eo t-eofitness t-eoproblem t-eobin t-eolottery + +############################################################################### + +t_eogeneration_SOURCES = t-eogeneration.cpp +t_eogeneration_DEPENDENCIES = $(DEPS) +t_eogeneration_LDFLAGS = -lm +t_eogeneration_LDADD = $(LDADDS) ############################################################################### diff --git a/eo/test/Makefile.in b/eo/test/Makefile.in index f7c0037cd..61e66d154 100644 --- a/eo/test/Makefile.in +++ b/eo/test/Makefile.in @@ -87,7 +87,14 @@ LDADDS = $(top_builddir)/src/libeo.a ############################################################################### -noinst_PROGRAMS = t-eobreeder t-eoinclusion t-eoinsertion t-eo t-eofitness t-eoproblem t-eobin t-eolottery +noinst_PROGRAMS = t-eogeneration t-eobreeder t-eoinclusion t-eoinsertion t-eo t-eofitness t-eoproblem t-eobin t-eolottery + +############################################################################### + +t_eogeneration_SOURCES = t-eogeneration.cpp +t_eogeneration_DEPENDENCIES = $(DEPS) +t_eogeneration_LDFLAGS = -lm +t_eogeneration_LDADD = $(LDADDS) ############################################################################### @@ -148,6 +155,7 @@ DEFS = @DEFS@ -I. -I$(srcdir) CPPFLAGS = @CPPFLAGS@ LDFLAGS = @LDFLAGS@ LIBS = @LIBS@ +t_eogeneration_OBJECTS = t-eogeneration.o t_eobreeder_OBJECTS = t-eobreeder.o t_eoinclusion_OBJECTS = t-eoinclusion.o t_eoinsertion_OBJECTS = t-eoinsertion.o @@ -174,10 +182,10 @@ DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST) TAR = gtar GZIP_ENV = --best DEP_FILES = .deps/t-eo.P .deps/t-eobin.P .deps/t-eobreeder.P \ -.deps/t-eofitness.P .deps/t-eoinclusion.P .deps/t-eoinsertion.P \ -.deps/t-eolottery.P .deps/t-eoproblem.P -SOURCES = $(t_eobreeder_SOURCES) $(t_eoinclusion_SOURCES) $(t_eoinsertion_SOURCES) $(t_eo_SOURCES) $(t_eofitness_SOURCES) $(t_eoproblem_SOURCES) $(t_eobin_SOURCES) $(t_eolottery_SOURCES) -OBJECTS = $(t_eobreeder_OBJECTS) $(t_eoinclusion_OBJECTS) $(t_eoinsertion_OBJECTS) $(t_eo_OBJECTS) $(t_eofitness_OBJECTS) $(t_eoproblem_OBJECTS) $(t_eobin_OBJECTS) $(t_eolottery_OBJECTS) +.deps/t-eofitness.P .deps/t-eogeneration.P .deps/t-eoinclusion.P \ +.deps/t-eoinsertion.P .deps/t-eolottery.P .deps/t-eoproblem.P +SOURCES = $(t_eogeneration_SOURCES) $(t_eobreeder_SOURCES) $(t_eoinclusion_SOURCES) $(t_eoinsertion_SOURCES) $(t_eo_SOURCES) $(t_eofitness_SOURCES) $(t_eoproblem_SOURCES) $(t_eobin_SOURCES) $(t_eolottery_SOURCES) +OBJECTS = $(t_eogeneration_OBJECTS) $(t_eobreeder_OBJECTS) $(t_eoinclusion_OBJECTS) $(t_eoinsertion_OBJECTS) $(t_eo_OBJECTS) $(t_eofitness_OBJECTS) $(t_eoproblem_OBJECTS) $(t_eobin_OBJECTS) $(t_eolottery_OBJECTS) all: all-redirect .SUFFIXES: @@ -231,6 +239,10 @@ distclean-libtool: maintainer-clean-libtool: +t-eogeneration: $(t_eogeneration_OBJECTS) $(t_eogeneration_DEPENDENCIES) + @rm -f t-eogeneration + $(CXXLINK) $(t_eogeneration_LDFLAGS) $(t_eogeneration_OBJECTS) $(t_eogeneration_LDADD) $(LIBS) + t-eobreeder: $(t_eobreeder_OBJECTS) $(t_eobreeder_DEPENDENCIES) @rm -f t-eobreeder $(CXXLINK) $(t_eobreeder_LDFLAGS) $(t_eobreeder_OBJECTS) $(t_eobreeder_LDADD) $(LIBS)