From d3642e4fde60773c5640a525e89f1f71bd1fdf28 Mon Sep 17 00:00:00 2001 From: jmerelo Date: Fri, 17 Dec 1999 09:19:13 +0000 Subject: [PATCH] Changes --- eo/Makefile.am | 9 ++- eo/configure.in | 6 +- eo/src/eoBin.h | 154 +++++++++++++++++++------------------ eo/src/eoGeneration.h | 6 +- eo/test/Makefile.am | 15 +++- eo/test/Makefile.in | 31 +++++--- eo/test/t-eoRandom.cpp | 82 +++++++++++++------- eo/test/t-eobin.cpp | 38 +++++++++- eo/test/t-eobreeder.cpp | 155 +++++++++++++++++++++----------------- eo/test/t-eoinclusion.cpp | 15 +--- eo/test/t-selectOne.cpp | 87 +++++++++++++++++++++ eo/win/Makefile.am | 6 ++ 12 files changed, 397 insertions(+), 207 deletions(-) create mode 100644 eo/test/t-selectOne.cpp create mode 100644 eo/win/Makefile.am diff --git a/eo/Makefile.am b/eo/Makefile.am index ba1a0dcc..7765a8a3 100644 --- a/eo/Makefile.am +++ b/eo/Makefile.am @@ -4,9 +4,14 @@ ## ############################################################################### -SUBDIRS = src test +SUBDIRS = src test win +#Directory for documents DOCDIR = ~/public_html/eodocs +#Directory for indices -- not useful for the user +IDXDIR = ~/index + +EXTRA_DIST=LICENSE docs: doc++ -d $(DOCDIR) -B foot.html -f src/*.h src/*.cpp - /home/jmerelo/bin/index -e html -i /home/jmerelo/index/neweo.idx /home/jmerelo/public_html/eodocs/ -v 3 \ No newline at end of file + /home/jmerelo/bin/index -e html -i $(IDXDIR)/neweo.idx $(DOCDIR)/ -v 3 \ No newline at end of file diff --git a/eo/configure.in b/eo/configure.in index 715a42c9..46910ca5 100644 --- a/eo/configure.in +++ b/eo/configure.in @@ -1,11 +1,13 @@ AC_INIT(src/eo) -AM_INIT_AUTOMAKE(eo, 0.0.5) +AM_INIT_AUTOMAKE(eo, 0.0.8) AC_PROG_CXX +CXXFLAGS=-g + AM_PROG_LIBTOOL AM_MAINTAINER_MODE -AC_OUTPUT(Makefile src/Makefile test/Makefile) +AC_OUTPUT(Makefile src/Makefile test/Makefile win/Makefile) diff --git a/eo/src/eoBin.h b/eo/src/eoBin.h index b56054ed..0fb9a82b 100644 --- a/eo/src/eoBin.h +++ b/eo/src/eoBin.h @@ -1,78 +1,76 @@ -//----------------------------------------------------------------------------- -// eoBin.h -//----------------------------------------------------------------------------- - -#ifndef eoBin_h -#define eoBin_h - -//----------------------------------------------------------------------------- - -#include // ostream, istream -#include // bind2nd -#include // string -#include // EO - -/***************************************************************************** - * eoBin: implementation of binary chromosome. * - * based on STL's bit_vector (vector). * - *****************************************************************************/ - -template class eoBin: public eoVector -{ - public: - - /** - * (Default) Constructor. - * @param size Size of the binary string. - */ - eoBin(unsigned size = 0, bool value = false): - eoVector(size, value) {} - - /** - * Constructor. - * @param size Size of the binary string. - */ - eoBin(unsigned size, const eoRnd& rnd): eoVector(size) - { - generate(begin(), end(), rnd); - } - - /** Constructor from istream. - @param is The istream to read from.*/ - eoBin(istream& _is):eoVector(_is){}; - - /// My class name. - string className() const - { - return "eoBin"; - } - - /** - * To print me on a stream. - * @param os The ostream. - */ - void printOn(ostream& os) const - { - copy(begin(), end(), ostream_iterator(os)); - } - - /** - * To read me from a stream. - * @param is The istream. - */ - void readFrom(istream& is) - { - string bits; - is >> bits; - if (is) - { - resize(bits.size()); - transform(bits.begin(), bits.end(), begin(), - bind2nd(equal_to(), '1')); - } - } -}; - -//----------------------------------------------------------------------------- - -#endif eoBin_h +//----------------------------------------------------------------------------- +// eoBin.h +//----------------------------------------------------------------------------- + +#ifndef eoBin_h +#define eoBin_h + +//----------------------------------------------------------------------------- + +#include // ostream, istream +#include // bind2nd +#include // string +#include // EO + +/** eoBin: implementation of binary chromosome. + * based on STL's bit_vector (vector). +*/ +template class eoBin: public eoVector +{ + public: + + /** + * (Default) Constructor. + * @param size Size of the binary string. + */ + eoBin(unsigned size = 0, bool value = false): + eoVector(size, value) {} + + /** + * Constructor. + * @param size Size of the binary string. + */ + eoBin(unsigned size, const eoRnd& rnd): eoVector(size) + { + generate(begin(), end(), rnd); + } + + /** Constructor from istream. + @param is The istream to read from.*/ + eoBin(istream& _is):eoVector(_is){}; + + /// My class name. + string className() const + { + return "eoBin"; + } + + /** + * To print me on a stream. + * @param os The ostream. + */ + void printOn(ostream& os) const + { + copy(begin(), end(), ostream_iterator(os)); + } + + /** + * To read me from a stream. + * @param is The istream. + */ + void readFrom(istream& is) + { + string bits; + is >> bits; + if (is) + { + resize(bits.size()); + transform(bits.begin(), bits.end(), begin(), + bind2nd(equal_to(), '1')); + } + } +}; + +//----------------------------------------------------------------------------- + +#endif eoBin_h diff --git a/eo/src/eoGeneration.h b/eo/src/eoGeneration.h index 81c2f50b..5db81e72 100644 --- a/eo/src/eoGeneration.h +++ b/eo/src/eoGeneration.h @@ -31,10 +31,12 @@ #include #include // eoSelect, eoTranform, eoMerge -//----------------------------------------------------------------------------- -// eoGeneration //----------------------------------------------------------------------------- +/** eoGeneration + * Single step of a evolutionary algorithm. Applies selection, then genetic + * operators, replaces using a replacement policy, and finally evaluates the + * new ones */ template class eoGeneration: public eoAlgo { public: diff --git a/eo/test/Makefile.am b/eo/test/Makefile.am index b8357480..d922e2fa 100644 --- a/eo/test/Makefile.am +++ b/eo/test/Makefile.am @@ -5,6 +5,7 @@ ############################################################################### DEPS = $(top_builddir)/src/libeo.a +EXTRA_DIST = LICENSE ############################################################################### @@ -13,7 +14,17 @@ LDADDS = $(top_builddir)/src/libeo.a ############################################################################### -noinst_PROGRAMS = t-eobreeder t-eoinclusion t-eoinsertion t-eo t-eofitness t-eoproblem t-eobin t-eolottery t-eo2dVector t-eogeneration t-eoEasyEA t-eoNonUniform t-eoUniform t-eoRandom t-parser t-eoESFull t-eoESOps t-eoAtomOps +noinst_PROGRAMS = t-eobreeder t-eoinclusion t-eoinsertion t-eo t-eofitness \ + t-eoproblem t-eobin t-eolottery t-eo2dVector t-eogeneration t-eoEasyEA\ + t-eoNonUniform t-eoUniform t-eoRandom t-parser t-eoESFull t-eoESOps\ + t-eoAtomOps t-selectOne + +############################################################################### + +t_selectOne_SOURCES = t-selectOne.cpp +t_selectOne_DEPENDENCIES = $(DEPS) +t_selectOne_LDFLAGS = -lm +t_selectOne_LDADD = $(LDADDS) ############################################################################### @@ -73,7 +84,7 @@ t_eoEasyEA_LDADD = $(LDADDS) ############################################################################### -t_eobreeder_SOURCES = t-eobreeder.cpp +t_eobreeder_SOURCES = t-eobreeder.cpp binary_value.h t_eobreeder_DEPENDENCIES = $(DEPS) t_eobreeder_LDFLAGS = -lm t_eobreeder_LDADD = $(LDADDS) diff --git a/eo/test/Makefile.in b/eo/test/Makefile.in index 67ed6e7d..a10890d4 100644 --- a/eo/test/Makefile.in +++ b/eo/test/Makefile.in @@ -1,4 +1,4 @@ -# Makefile.in generated automatically by automake 1.4a from Makefile.am +# Makefile.in generated automatically by automake 1.4 from Makefile.am # Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc. # This Makefile.in is free software; the Free Software Foundation @@ -49,10 +49,9 @@ AUTOMAKE = @AUTOMAKE@ AUTOHEADER = @AUTOHEADER@ INSTALL = @INSTALL@ -INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ $(AM_INSTALL_PROGRAM_FLAGS) INSTALL_DATA = @INSTALL_DATA@ INSTALL_SCRIPT = @INSTALL_SCRIPT@ -INSTALL_STRIP_FLAG = transform = @program_transform_name@ NORMAL_INSTALL = : @@ -79,6 +78,7 @@ RANLIB = @RANLIB@ VERSION = @VERSION@ DEPS = $(top_builddir)/src/libeo.a +EXTRA_DIST = LICENSE ############################################################################### @@ -87,7 +87,15 @@ LDADDS = $(top_builddir)/src/libeo.a ############################################################################### -noinst_PROGRAMS = t-eobreeder t-eoinclusion t-eoinsertion t-eo t-eofitness t-eoproblem t-eobin t-eolottery t-eo2dVector t-eogeneration t-eoEasyEA t-eoNonUniform t-eoUniform t-eoRandom t-parser t-eoESFull t-eoESOps t-eoAtomOps +noinst_PROGRAMS = t-eobreeder t-eoinclusion t-eoinsertion t-eo t-eofitness t-eoproblem t-eobin t-eolottery t-eo2dVector t-eogeneration t-eoEasyEA t-eoNonUniform t-eoUniform t-eoRandom t-parser t-eoESFull t-eoESOps t-eoAtomOps t-selectOne + + +############################################################################### + +t_selectOne_SOURCES = t-selectOne.cpp +t_selectOne_DEPENDENCIES = $(DEPS) +t_selectOne_LDFLAGS = -lm +t_selectOne_LDADD = $(LDADDS) ############################################################################### @@ -147,7 +155,7 @@ t_eoEasyEA_LDADD = $(LDADDS) ############################################################################### -t_eobreeder_SOURCES = t-eobreeder.cpp +t_eobreeder_SOURCES = t-eobreeder.cpp binary_value.h t_eobreeder_DEPENDENCIES = $(DEPS) t_eobreeder_LDFLAGS = -lm t_eobreeder_LDADD = $(LDADDS) @@ -241,6 +249,7 @@ t_parser_OBJECTS = t-parser.o t_eoESFull_OBJECTS = t-eoESFull.o t_eoESOps_OBJECTS = t-eoESOps.o t_eoAtomOps_OBJECTS = t-eoAtomOps.o +t_selectOne_OBJECTS = t-selectOne.o CXXFLAGS = @CXXFLAGS@ CXXCOMPILE = $(CXX) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) LTCXXCOMPILE = $(LIBTOOL) --mode=compile $(CXX) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) @@ -258,8 +267,8 @@ DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST) TAR = gtar GZIP_ENV = --best -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) $(t_eo2dVector_SOURCES) $(t_eogeneration_SOURCES) $(t_eoEasyEA_SOURCES) $(t_eoNonUniform_SOURCES) $(t_eoUniform_SOURCES) $(t_eoRandom_SOURCES) $(t_parser_SOURCES) $(t_eoESFull_SOURCES) $(t_eoESOps_SOURCES) $(t_eoAtomOps_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) $(t_eo2dVector_OBJECTS) $(t_eogeneration_OBJECTS) $(t_eoEasyEA_OBJECTS) $(t_eoNonUniform_OBJECTS) $(t_eoUniform_OBJECTS) $(t_eoRandom_OBJECTS) $(t_parser_OBJECTS) $(t_eoESFull_OBJECTS) $(t_eoESOps_OBJECTS) $(t_eoAtomOps_OBJECTS) +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) $(t_eo2dVector_SOURCES) $(t_eogeneration_SOURCES) $(t_eoEasyEA_SOURCES) $(t_eoNonUniform_SOURCES) $(t_eoUniform_SOURCES) $(t_eoRandom_SOURCES) $(t_parser_SOURCES) $(t_eoESFull_SOURCES) $(t_eoESOps_SOURCES) $(t_eoAtomOps_SOURCES) $(t_selectOne_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) $(t_eo2dVector_OBJECTS) $(t_eogeneration_OBJECTS) $(t_eoEasyEA_OBJECTS) $(t_eoNonUniform_OBJECTS) $(t_eoUniform_OBJECTS) $(t_eoRandom_OBJECTS) $(t_parser_OBJECTS) $(t_eoESFull_OBJECTS) $(t_eoESOps_OBJECTS) $(t_eoAtomOps_OBJECTS) $(t_selectOne_OBJECTS) all: all-redirect .SUFFIXES: @@ -390,6 +399,10 @@ t-eoESOps: $(t_eoESOps_OBJECTS) $(t_eoESOps_DEPENDENCIES) t-eoAtomOps: $(t_eoAtomOps_OBJECTS) $(t_eoAtomOps_DEPENDENCIES) @rm -f t-eoAtomOps $(CXXLINK) $(t_eoAtomOps_LDFLAGS) $(t_eoAtomOps_OBJECTS) $(t_eoAtomOps_LDADD) $(LIBS) + +t-selectOne: $(t_selectOne_OBJECTS) $(t_selectOne_DEPENDENCIES) + @rm -f t-selectOne + $(CXXLINK) $(t_selectOne_LDFLAGS) $(t_selectOne_OBJECTS) $(t_selectOne_LDADD) $(LIBS) .cc.o: $(CXXCOMPILE) -c $< .cc.lo: @@ -436,7 +449,7 @@ distdir: $(DISTFILES) @for file in $(DISTFILES); do \ d=$(srcdir); \ if test -d $$d/$$file; then \ - cp -pr $$d/$$file $(distdir)/$$file; \ + cp -pr $$/$$file $(distdir)/$$file; \ else \ test -f $(distdir)/$$file \ || ln $$d/$$file $(distdir)/$$file 2> /dev/null \ @@ -465,7 +478,7 @@ uninstall: uninstall-am all-am: Makefile $(PROGRAMS) all-redirect: all-am install-strip: - $(MAKE) $(AM_MAKEFLAGS) INSTALL_STRIP_FLAG=-s install + $(MAKE) $(AM_MAKEFLAGS) AM_INSTALL_PROGRAM_FLAGS=-s install installdirs: diff --git a/eo/test/t-eoRandom.cpp b/eo/test/t-eoRandom.cpp index 764b0dac..c0be81b1 100644 --- a/eo/test/t-eoRandom.cpp +++ b/eo/test/t-eoRandom.cpp @@ -1,29 +1,53 @@ -//----------------------------------------------------------------------------- -// t-eouniform -//----------------------------------------------------------------------------- - -#include // cout -#include // ostrstream, istrstream -#include // eoBin -#include -#include - -//----------------------------------------------------------------------------- - -main() { - eoNormal n1(-2.5,3.5); - eoNormal n2(0.003, 0.0005 ); - eoNormal n3( 10000000U, 10000U); - eoNegExp e1(3.5); - eoNegExp e2(0.003 ); - eoNegExp e3( 10000U); - cout << "n1\t\tn2\t\tn3\t\te1\t\te2\t\te3" << endl; - for ( unsigned i = 0; i < 100; i ++) { - cout << n1() << "\t" << n2() << "\t" << n3() << "\t" << - e1() << "\t" << e2() << "\t" << e3() << endl; - } - - return 0; // to avoid VC++ complaints -} - -//----------------------------------------------------------------------------- +// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- + +/*----------------------------------------------------------------------------- + * t-eoRandom + * Testing program for the eoRNG class + * (c) GeNeura Team, 1999 + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU 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. + + 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 + +*/ + +//----------------------------------------------------------------------------- + + +#include // cout +#include // ostrstream, istrstream +#include // eoBin +#include +#include + +//----------------------------------------------------------------------------- + +main() { + eoNormal n1(-2.5,3.5); + eoNormal n2(0.003, 0.0005 ); + eoNormal n3( 10000000U, 10000U); + eoNegExp e1(3.5); + eoNegExp e2(0.003 ); + eoNegExp e3( 10000U); + cout << "n1\t\tn2\t\tn3\t\te1\t\te2\t\te3" << endl; + for ( unsigned i = 0; i < 100; i ++) { + cout << n1() << "\t" << n2() << "\t" << n3() << "\t" << + e1() << "\t" << e2() << "\t" << e3() << endl; + } + + return 0; // to avoid VC++ complaints +} + +//----------------------------------------------------------------------------- diff --git a/eo/test/t-eobin.cpp b/eo/test/t-eobin.cpp index deac01e5..9ad0eed3 100644 --- a/eo/test/t-eobin.cpp +++ b/eo/test/t-eobin.cpp @@ -1,5 +1,27 @@ +// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- + //----------------------------------------------------------------------------- // t-eobin.cpp +// This program test the the binary cromosomes and several genetic operators +// (c) GeNeura Team, 1999 +/* + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU 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. + + 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 + +*/ //----------------------------------------------------------------------------- #include // cout @@ -102,7 +124,7 @@ main() for (float r = 0.1; r < 1.0; r += 0.1) { - eoBinUxOver uxover(r); + eoUniformXOver uxover(r); fill(chrom.begin(), chrom.end(), false); fill(chrom2.begin(), chrom2.end(), true); uxover(chrom, chrom2); @@ -110,6 +132,20 @@ main() << chrom << " " << chrom2 << endl; } + // Check multiOps + eoMultiMonOp mOp( &next ); + mOp.adOp( &bitflip ); + cout << "before multiMonOp............ " << chrom << endl; + mOp( chrom ); + cout << "after multiMonOp .............. " << chrom << endl; + + eoBinGxOver gxover(2, 4); + eoMultiBinOp mbOp( &gxover ); + mOp.adOp( &bitflip ); + cout << "before multiBinOp............ " << chrom << " " << chrom2 << endl; + mbOp( chrom, chrom2 ); + cout << "after multiBinOp .............. " << chrom << " " << chrom2 < // eoBin, eoPop, eoBreeder -#include -#include -#include -#include - -//----------------------------------------------------------------------------- - -typedef eoBin Chrom; - -//----------------------------------------------------------------------------- - -void binary_value(Chrom& chrom) -{ - float sum = 0; - for (unsigned i = 0; i < chrom.size(); i++) - if (chrom[i]) - sum += pow(2, chrom.size() - i - 1); - chrom.fitness(sum); -} - -//----------------------------------------------------------------------------- - -main() -{ - const unsigned POP_SIZE = 8, CHROM_SIZE = 4; - unsigned i; - - eoUniform uniform(false, true); - eoBinRandom random; - eoPop pop; - - for (i = 0; i < POP_SIZE; ++i) - { - Chrom chrom(CHROM_SIZE); - random(chrom); - binary_value(chrom); - pop.push_back(chrom); - } - - cout << "population:" << endl; - for (i = 0; i < pop.size(); ++i) - cout << pop[i] << " " << pop[i].fitness() << endl; - - eoBinBitFlip bitflip; - eoBinCrossover xover; - eoProportionalOpSel propSel; - eoBreeder breeder( propSel ); - propSel.addOp(bitflip, 0.25); - propSel.addOp(xover, 0.75); - - breeder(pop); - - // reevaluation of fitness - for_each(pop.begin(), pop.end(), binary_value); - - cout << "new population:" << endl; - for (i = 0; i < pop.size(); ++i) - cout << pop[i] << " " << pop[i].fitness() << endl; - - return 0; -} - -//----------------------------------------------------------------------------- +// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- + +//----------------------------------------------------------------------------- +// t-eobreeder.cpp +// This program test the breeder object +// (c) GeNeura Team, 1998 +/* + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU 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. + + 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 + +*/ +//----------------------------------------------------------------------------- + +// to avoid long name warnings +#pragma warning(disable:4786) + +#include // eoBin, eoPop, eoBreeder +#include +#include +#include +#include + +//----------------------------------------------------------------------------- + +typedef eoBin Chrom; + +#include "binary_value.h" + +//----------------------------------------------------------------------------- + +main() +{ + const unsigned POP_SIZE = 8, CHROM_SIZE = 4; + unsigned i; + + eoUniform uniform(false, true); + eoBinRandom random; + eoPop pop; + + for (i = 0; i < POP_SIZE; ++i) + { + Chrom chrom(CHROM_SIZE); + random(chrom); + binary_value(chrom); + pop.push_back(chrom); + } + + cout << "population:" << endl; + for (i = 0; i < pop.size(); ++i) + cout << pop[i] << " " << pop[i].fitness() << endl; + + eoBinBitFlip bitflip; + eoBinCrossover xover; + eoProportionalOpSel propSel; + eoBreeder breeder( propSel ); + propSel.addOp(bitflip, 0.25); + propSel.addOp(xover, 0.75); + + breeder(pop); + + // reevaluation of fitness + for_each(pop.begin(), pop.end(), binary_value); + + cout << "new population:" << endl; + for (i = 0; i < pop.size(); ++i) + cout << pop[i] << " " << pop[i].fitness() << endl; + + return 0; +} + +//----------------------------------------------------------------------------- diff --git a/eo/test/t-eoinclusion.cpp b/eo/test/t-eoinclusion.cpp index 415b7d20..c0d3494c 100644 --- a/eo/test/t-eoinclusion.cpp +++ b/eo/test/t-eoinclusion.cpp @@ -2,22 +2,15 @@ // t-eoinclusion.cpp //----------------------------------------------------------------------------- -#include // eoBin, eoPop, eoInclusion +#include +#include +#include //----------------------------------------------------------------------------- typedef eoBin Chrom; -//----------------------------------------------------------------------------- - -void binary_value(Chrom& chrom) -{ - float sum = 0; - for (unsigned i = 0; i < chrom.size(); i++) - if (chrom[i]) - sum += pow(2, chrom.size() - i - 1); - chrom.fitness(sum); -} +#include "binary_value.h" //----------------------------------------------------------------------------- diff --git a/eo/test/t-selectOne.cpp b/eo/test/t-selectOne.cpp new file mode 100644 index 00000000..a6848a71 --- /dev/null +++ b/eo/test/t-selectOne.cpp @@ -0,0 +1,87 @@ +// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- + +//----------------------------------------------------------------------------- +// t-selectOne.cpp +// This program test the breeder object +// (c) GeNeura Team, 1998 +/* + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; 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 + +*/ +//----------------------------------------------------------------------------- + +// to avoid long name warnings +#pragma warning(disable:4786) + +#include // eoBin, eoPop, eoBreeder +#include +#include + +#include +#include +#include + + +//----------------------------------------------------------------------------- + +typedef eoBin Chrom; + +#include "binary_value.h" + +//----------------------------------------------------------------------------- + +main() +{ + const unsigned POP_SIZE = 8, CHROM_SIZE = 4; + unsigned i; + + eoUniform uniform(false, true); + eoBinRandom random; + eoPop pop; + + // Create the population + for (i = 0; i < POP_SIZE; ++i) { + Chrom chrom(CHROM_SIZE); + random(chrom); + binary_value(chrom); + pop.push_back(chrom); + } + + // print population + cout << "population:" << endl; + for (i = 0; i < pop.size(); ++i) + cout << pop[i] << " " << pop[i].fitness() << endl; + + // Declare 1-selectors + eoUniformSelect uSelect; + + Chrom aChrom; + aChrom = uSelect( pop ); + cout << "Uniform Select " << aChrom << " " << aChrom.fitness() << endl; + + eoStochTournament sSelect(0.7); + aChrom = sSelect( pop ); + cout << "Stochastic Tournament " << aChrom << " " << aChrom.fitness() << endl; + + eoDetTournament dSelect(3); + aChrom = dSelect( pop ); + cout << "Deterministic Tournament " << aChrom << " " << aChrom.fitness() << endl; + + return 0; +} + +//----------------------------------------------------------------------------- diff --git a/eo/win/Makefile.am b/eo/win/Makefile.am new file mode 100644 index 00000000..81189d33 --- /dev/null +++ b/eo/win/Makefile.am @@ -0,0 +1,6 @@ +EXTRA_DIST=EO.dsw random.dsp t_eoinsertion.dsp t_ops.dsp\ + atomops.dsp t_eoaged.dsp t_eornd.dsp t_opsel.dsp\ + t_eobin.dsp t_eostring.dsp t_opselmason.dsp\ + eo.dsp t_eobitfact.dsp t_eovector.dsp t_pop.dsp\ + t_eobreeder.dsp t_es.dsp t_popops.dsp\ + eolib.dsp t_eoid.dsp t_lottery.dsp\