From dea8a51f7ed34f198ce7f30dee4b438c62dec0e0 Mon Sep 17 00:00:00 2001 From: maartenkeijzer Date: Mon, 12 Feb 2001 13:58:51 +0000 Subject: [PATCH] Ok, updated the Makefile.am again to use the make check Command I picked up in the automake documentation (RTFM, you know) Tagged a lot of header functions in the GnuPlot files with 'inline', so they can be used from more than one sourcefile. Ok, now the interesting news. Started a new library libga (not to be confused with Matthew's GaLib). Here I suggest we put a fairly complete and configurable genetic algorithm. Just to see how far we can stretch ourselves and also to have a GA-componenent that can be used in other applications without having to rebuild the entire thing. test/t-eoGA.cpp tests this library --- eo/Makefile.am | 7 ++- eo/src/ga/Makefile.am | 8 ++- eo/src/ga/ga.cpp | 91 ++++++++++++++++++++++++++++++ eo/src/ga/ga.h | 24 ++++++++ eo/src/utils/Makefile.am | 2 +- eo/src/utils/eoGnuplot.h | 46 +++++++-------- eo/src/utils/eoGnuplot1DMonitor.h | 24 ++++---- eo/src/utils/eoGnuplot1DSnapshot.h | 2 +- eo/src/utils/eoState.h | 28 ++++++--- eo/test/Makefile.am | 68 ++++++++++++---------- eo/test/run_tests | 5 +- eo/test/t-eoGA.cpp | 36 ++++++++++++ 12 files changed, 260 insertions(+), 81 deletions(-) create mode 100644 eo/src/ga/ga.cpp create mode 100644 eo/src/ga/ga.h create mode 100644 eo/test/t-eoGA.cpp diff --git a/eo/Makefile.am b/eo/Makefile.am index d90e06e7..0dea0e13 100644 --- a/eo/Makefile.am +++ b/eo/Makefile.am @@ -4,7 +4,7 @@ ## ############################################################################### -SUBDIRS = src win tutorial app +SUBDIRS = src test win tutorial app #Directory for documents DOCDIR = ~/public_html/eodocs #Directory for indices -- not useful for the user @@ -17,8 +17,9 @@ EXTRA_DIST=LICENSE lib: pushd src; $(MAKE) all; popd -test: test/run_tests - pushd test; $(MAKE) all; ./run_tests; touch run_tests; popd +# The test directory should be run explicitely, to check if nothing is broken +test: test/run_tests test/Makefile + pushd test; touch run_tests; $(MAKE) all; ./run_tests; popd # so that make doc always compiles the doc ... doc: doc/eo.cfg diff --git a/eo/src/ga/Makefile.am b/eo/src/ga/Makefile.am index 12060fa5..38d1695c 100644 --- a/eo/src/ga/Makefile.am +++ b/eo/src/ga/Makefile.am @@ -4,5 +4,11 @@ ## ############################################################################### +INCLUDES = -I$(top_builddir)/src +lib_LIBRARIES = libga.a +libga_a_SOURCES = ga.cpp +CPPFLAGS = -O2 -Wall + + libeoincdir = $(includedir)/eo/ga -libeoinc_HEADERS = eoBit.h eoBitOp.h eoBitOpFactory.h +libeoinc_HEADERS = eoBit.h eoBitOp.h eoBitOpFactory.h ga.h diff --git a/eo/src/ga/ga.cpp b/eo/src/ga/ga.cpp new file mode 100644 index 00000000..802834b2 --- /dev/null +++ b/eo/src/ga/ga.cpp @@ -0,0 +1,91 @@ +#include +#include + +eoValueParam xoverRate(0.6f, "xoverrate", "The crossover rate", 'x'); +eoValueParam mutRate(1.0f, "mutationrate", "The mutation rate", 'm'); +eoValueParam chromSize(unsigned(10), "chromosomeSize", "The length of the bitstrings", 'n'); +eoValueParam popSize(unsigned(20), "PopSize", "Population Size", 'P'); + +template +eoAlgo >& do_make_ga(eoParameterLoader& _parser, eoEvalFunc >& _eval, eoCheckPoint >& _checkpoint, eoState& _state) +{ + typedef eoBit EOT; + + _parser.processParam(xoverRate, "genetics"); + _parser.processParam(mutRate, "genetics"); + _parser.processParam(chromSize, "initialization"); + + eoBitMutation* mutOp = new eoBitMutation(1. / float(chromSize.value())); + _state.storeFunctor(mutOp); + + eo1PtBitXover* crossOp = new eo1PtBitXover; + _state.storeFunctor(crossOp); + + eoSelectOne* select = new eoDetTournamentSelect(2); + _state.storeFunctor(select); + + eoSGA >* sga = new eoSGA(*select, *crossOp, xoverRate.value(), *mutOp, mutRate.value(), _eval, _checkpoint); + _state.storeFunctor(sga); + return *sga; +} + +template +eoPop >& do_init_ga(eoParameterLoader& _parser, eoState& _state, FitT) +{ + typedef eoBit EOT; + + _parser.processParam(chromSize, "initialization"); + _parser.processParam(popSize, "initialization"); + + eoInitFixedLength init(chromSize.value(), boolean_generator()); + + + // Let the state handle the memory + eoPop& pop = _state.takeOwnership(eoPop()); + + _state.registerObject(pop); + + // initialize the population + + pop.append(popSize.value(), init); + + return pop; +} + +template +void do_run_ga(eoAlgo >& _ga, eoPop >& _pop) +{ + _ga(_pop); +} + +/// The following function merely call the templatized do_* functions above + +eoAlgo >& make_ga(eoParameterLoader& _parser, eoEvalFunc >& _eval, eoCheckPoint >& _checkpoint, eoState& _state) +{ + return do_make_ga(_parser, _eval, _checkpoint, _state); +} + +eoAlgo >& make_ga(eoParameterLoader& _parser, eoEvalFunc >& _eval, eoCheckPoint >& _checkpoint, eoState& _state) +{ + return do_make_ga(_parser, _eval, _checkpoint, _state); +} + +eoPop >& init_ga(eoParameterLoader& _parser, eoState& _state, double _d) +{ + return do_init_ga(_parser, _state, _d); +} + +eoPop >& init_ga(eoParameterLoader& _parser, eoState& _state, eoMinimizingFitness _d) +{ + return do_init_ga(_parser, _state, _d); +} + +void run_ga(eoAlgo >& _ga, eoPop >& _pop) +{ + do_run_ga(_ga, _pop); +} + +void run_ga(eoAlgo >& _ga, eoPop >& _pop) +{ + do_run_ga(_ga, _pop); +} diff --git a/eo/src/ga/ga.h b/eo/src/ga/ga.h new file mode 100644 index 00000000..7a829f54 --- /dev/null +++ b/eo/src/ga/ga.h @@ -0,0 +1,24 @@ +#ifndef ga_h +#define ga_h + +#include +#include +#include +#include +#include +#include + +#include +#include + + +eoAlgo >& make_ga(eoParameterLoader& _parser, eoEvalFunc >& _eval, eoCheckPoint >& _checkpoint, eoState& state); +eoAlgo >& make_ga(eoParameterLoader& _parser, eoEvalFunc >& _eval, eoCheckPoint >& _checkpoint, eoState& state); + +eoPop >& init_ga(eoParameterLoader& _parser, eoState& _state, double); +eoPop >& init_ga(eoParameterLoader& _parser, eoState& _state, eoMinimizingFitness); + +void run_ga(eoAlgo >& _ga, eoPop >& _pop); +void run_ga(eoAlgo >& _ga, eoPop >& _pop); + +#endif diff --git a/eo/src/utils/Makefile.am b/eo/src/utils/Makefile.am index c7843abe..109533af 100644 --- a/eo/src/utils/Makefile.am +++ b/eo/src/utils/Makefile.am @@ -5,7 +5,7 @@ ############################################################################### INCLUDES = -I$(top_builddir)/src -CPPFLAGS = -O2 +CPPFLAGS = -O2 -Wall lib_LIBRARIES = libeoutils.a libeoutils_a_SOURCES = eoParser.cpp eoRNG.cpp eoState.cpp eoUpdater.cpp eoFileMonitor.cpp eoStdoutMonitor.cpp diff --git a/eo/src/utils/eoGnuplot.h b/eo/src/utils/eoGnuplot.h index d588348f..fb5a5c3a 100644 --- a/eo/src/utils/eoGnuplot.h +++ b/eo/src/utils/eoGnuplot.h @@ -78,7 +78,7 @@ class eoGnuplot } -protected: +protected: void initGnuPlot(std::string _title, std::string _extra); // the private data bool firstTime; // the stats might be unknown in Ctor @@ -86,12 +86,12 @@ protected: private: }; -// the following should be placed in a separate eoGnuplot.cpp +// the following should be placed in a separate eoGnuplot.cpp static unsigned numWindow=0; //////////////////////////////////////////////////////////// -void eoGnuplot::initGnuPlot(std::string _title, std::string _extra) +inline void eoGnuplot::initGnuPlot(std::string _title, std::string _extra) ///////////////////////////////////////////////////////// { char snum[255]; @@ -103,7 +103,7 @@ void eoGnuplot::initGnuPlot(std::string _title, std::string _extra) args[1] = strdup( "-geometry" ); args[2] = strdup( os.str() ); args[3] = strdup( "-title" ); - args[4] = strdup( _title.c_str() ); + args[4] = strdup( _title.c_str() ); args[5] = 0; gpCom = PipeComOpenArgv( "gnuplot", args ); if( ! gpCom ) @@ -115,21 +115,21 @@ void eoGnuplot::initGnuPlot(std::string _title, std::string _extra) } } - + // the following should be placed in a separate file pipecom.c // together with the corresponding pipecom.h -// but first their MSC equivalent must be written and tested +// but first their MSC equivalent must be written and tested // or some #idef instructions put with clear message at compile time // that this is for Unix only ??? /* ---------------------------------------------------------------------- - * Where........: CMAP - Polytechnique + * Where........: CMAP - Polytechnique * File.........: pipecom.c * Author.......: Bertrand Lamy (Equipe genetique) * Created......: Mon Mar 13 13:50:11 1995 * Description..: Communication par pipe bidirectionnel avec un autre process - * - * Ident........: $Id: eoGnuplot.h,v 1.2 2001-02-01 05:17:16 evomarc Exp $ + * + * Ident........: $Id: eoGnuplot.h,v 1.3 2001-02-12 13:58:51 maartenkeijzer Exp $ * ---------------------------------------------------------------------- */ @@ -142,7 +142,7 @@ void eoGnuplot::initGnuPlot(std::string _title, std::string _extra) // #include "pipecom.h" -int Check( PCom *com ) +inline int Check( PCom *com ) { if( ! com ) { fprintf( stderr, "PipeCom: Null pointer.\n" ); @@ -158,16 +158,16 @@ int Check( PCom *com ) } -PCom * PipeComOpen( char *prog ) +inline PCom * PipeComOpen( char *prog ) { char *args[2]; args[0] = prog; args[1] = NULL; - return PipeComOpenArgv( prog, args ); + return PipeComOpenArgv( prog, args ); } -PCom * PipeComOpenArgv( char *prog, char *argv[] ) +inline PCom * PipeComOpenArgv( char *prog, char *argv[] ) { int toFils[2]; int toPere[2]; @@ -188,7 +188,7 @@ PCom * PipeComOpenArgv( char *prog, char *argv[] ) perror("PipeComOpen: fork failed" ); return ret; break; - + case 0: /* --- Here's the son --- */ /* --- replace old stdin --- */ @@ -197,7 +197,7 @@ PCom * PipeComOpenArgv( char *prog, char *argv[] ) exit( -1 ); /* --- AVOIR: kill my father --- */ } - if( dup2( toPere[1], fileno(stdout) ) < 0 ) { + if( dup2( toPere[1], fileno(stdout) ) < 0 ) { perror( "PipeComOpen(son): could not connect" ); exit( -1 ); } @@ -211,7 +211,7 @@ PCom * PipeComOpenArgv( char *prog, char *argv[] ) ret = (PCom *) malloc( sizeof(PCom) ); if( ! ret ) return NULL; - + ret->fWrit = (FILE *)fdopen( toFils[1], "w" ); ret->fRead = (FILE *)fdopen( toPere[0], "r" ); ret->pid = sonPid; @@ -220,7 +220,7 @@ PCom * PipeComOpenArgv( char *prog, char *argv[] ) } -int PipeComSend( PCom *to, const char *line ) +inline int PipeComSend( PCom *to, const char *line ) { int nb = 0; if( ! Check(to ) ) @@ -231,10 +231,10 @@ int PipeComSend( PCom *to, const char *line ) } -int PipeComSendn( PCom *to, const char *data, int n ) +inline int PipeComSendn( PCom *to, const char *data, int n ) { int nb = 0; - if( ! Check(to) ) + if( ! Check(to) ) return nb; nb = fwrite( data, 1, n, to->fWrit ); @@ -243,9 +243,9 @@ int PipeComSendn( PCom *to, const char *data, int n ) } -int PipeComReceive( PCom *from, char *data, int max ) +inline int PipeComReceive( PCom *from, char *data, int max ) { - if( ! Check(from) ) + if( ! Check(from) ) return 0; if( ! data ) { fprintf( stderr, "PipeComReceive: Invalid data pointer\n" ); @@ -259,7 +259,7 @@ int PipeComReceive( PCom *from, char *data, int max ) -int PipeComClose( PCom *to ) +inline int PipeComClose( PCom *to ) { if( ! Check(to) ) return 0; @@ -271,7 +271,7 @@ int PipeComClose( PCom *to ) -int PipeComWaitFor( PCom *from, char *what ) +inline int PipeComWaitFor( PCom *from, char *what ) { char buffer[256]; do { diff --git a/eo/src/utils/eoGnuplot1DMonitor.h b/eo/src/utils/eoGnuplot1DMonitor.h index dc38dbf8..e7550875 100644 --- a/eo/src/utils/eoGnuplot1DMonitor.h +++ b/eo/src/utils/eoGnuplot1DMonitor.h @@ -48,34 +48,34 @@ This class plots through gnuplot the eoStat given as argument /** eoGnuplot1DMonitor plots stats through gnuplot - * assumes that the same file is appened every so and so, + * assumes that the same file is appened every so and so, * and replots it everytime */ class eoGnuplot1DMonitor: public eoFileMonitor, public eoGnuplot { public: // Ctor - eoGnuplot1DMonitor(std::string _filename, bool _top=false) : - eoFileMonitor(_filename, " "), + eoGnuplot1DMonitor(std::string _filename, bool _top=false) : + eoFileMonitor(_filename, " "), eoGnuplot(_filename,(_top?"":"set key bottom")) {} - + // Dtor virtual ~eoGnuplot1DMonitor(){} virtual eoMonitor& operator() (void) ; - virtual void FirstPlot(); + virtual void FirstPlot(); /// Class name. virtual string className() const { return "eoGnuplot1DMonitor"; } -private: +private: }; -// the following should be placed in a separate eoGnuplot1DMonitor.cpp - +// the following should be placed in a separate eoGnuplot1DMonitor.cpp +// then the inline specifier should dissappear //////////////////////////////////////////////////////////// -eoMonitor& eoGnuplot1DMonitor::operator() (void) +inline eoMonitor& eoGnuplot1DMonitor::operator() (void) ///////////////////////////////////////////////////////// { // update file using the eoFileMonitor @@ -98,10 +98,10 @@ eoMonitor& eoGnuplot1DMonitor::operator() (void) } //////////////////////////////////////////////////////////// -void eoGnuplot1DMonitor::FirstPlot() +inline void eoGnuplot1DMonitor::FirstPlot() //////////////////////////////////////////////////////// { - if (vec.size() < 2) + if (vec.size() < 2) { throw runtime_error("Must have some stats to plot!\n"); } @@ -118,5 +118,5 @@ void eoGnuplot1DMonitor::FirstPlot() os << '\0'; PipeComSend( gpCom, buff ); } - + #endif _eoGnuplot1DMonitor_H diff --git a/eo/src/utils/eoGnuplot1DSnapshot.h b/eo/src/utils/eoGnuplot1DSnapshot.h index d6ad08bd..d8e575a5 100644 --- a/eo/src/utils/eoGnuplot1DSnapshot.h +++ b/eo/src/utils/eoGnuplot1DSnapshot.h @@ -81,7 +81,7 @@ private: // the following should be placed in a separate eoGnuplot1DMonitor.cpp //////////////////////////////////////////////////////////// -eoMonitor& eoGnuplot1DSnapshot::operator() (void) +inline eoMonitor& eoGnuplot1DSnapshot::operator() (void) ///////////////////////////////////////////////////////// { // update file using the eoFileMonitor diff --git a/eo/src/utils/eoState.h b/eo/src/utils/eoState.h index b37a590e..d069338d 100644 --- a/eo/src/utils/eoState.h +++ b/eo/src/utils/eoState.h @@ -3,7 +3,7 @@ //----------------------------------------------------------------------------- // eoState.h // (c) Marc Schoenauer, Maarten Keijzer and GeNeura Team, 2000 -/* +/* 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 @@ -32,6 +32,8 @@ #include #include +#include + class eoObject; class eoPersistent; @@ -40,7 +42,7 @@ class eoPersistent; * then in turn implement the persistence framework through members load * and save, that will call readFrom and printOn for the registrated objects. */ -class eoState +class eoState { public : @@ -54,7 +56,7 @@ public : void registerObject(eoPersistent& registrant); /** - * Copies the object (MUST be derived from eoPersistent) + * Copies the object (MUST be derived from eoPersistent) * and returns a reference to the owned object. * Note: it does not register the object, this must be done afterwards! */ @@ -65,7 +67,13 @@ public : ownedObjects.push_back(new T(persistent)); return static_cast(*ownedObjects.back()); } - + + void storeFunctor(eoFunctorBase* _functor) + { + // add it to the functorStore, fo + functorStore.add(_functor); + } + /** * Loading error thrown when nothing seems to work. */ @@ -82,21 +90,21 @@ public : * @param _filename the name of the file to load from */ void load(const std::string& _filename); - + /** * Reads the file specified * * @param is the stream to load from */ void load(std::istream& is); - + /** * Saves the state in file specified * * @param _filename the name of the file to save into */ void save(const std::string& _filename) const; - + /** * Saves the state in file specified * @@ -109,13 +117,15 @@ private : // first is Persistent, second is the raw data associated with it. typedef std::map ObjectMap; - + ObjectMap objectMap; std::vector creationOrder; - std::vector ownedObjects; + // And a functor store to boot + eoFunctorStore functorStore; + // private copy and assignment as eoState is supposed to be unique eoState(const eoState&); eoState& operator=(const eoState&); diff --git a/eo/test/Makefile.am b/eo/test/Makefile.am index f8c3d784..85cea015 100644 --- a/eo/test/Makefile.am +++ b/eo/test/Makefile.am @@ -13,16 +13,17 @@ LDADDS = $(top_builddir)/src/libeo.a $(top_builddir)/src/utils/libeoutils.a CXXFLAGS = -g ############################################################################### -noinst_PROGRAMS = t-eofitness t-eobin t-eoStateAndParser t-eoCheckpointing t-eoExternalEO t-eoSymreg t-eo t-eoReplacement t-eoSelect t-eoGenOp +check_PROGRAMS = t-eofitness t-eobin t-eoStateAndParser t-eoCheckpointing t-eoExternalEO t-eoSymreg t-eo t-eoReplacement t-eoSelect t-eoGenOp t-eoGA +TESTS=run_tests # removing temporarily t-eoESFull -# noinst_PROGRAMS = t-eofitness t-eobin t-eoStateAndParser t-eoCheckpointing t-eoExternalEO t-eoESFull t-eoSymreg t-eo t-eoReplacement t-eoSelect +#noinst_PROGRAMS = t-eofitness t-eobin t-eoStateAndParser t-eoCheckpointing t-eoExternalEO t-eoESFull t-eoSymreg t-eo t-eoReplacement t-eoSelect t-eoGenOp t-eoGA ############################################################################### -# t_eoESFull_SOURCES = t-eoESFull.cpp real_value.h -# t_eoESFull_DEPENDENCIES = $(DEPS) -# t_eoESFull_LDFLAGS = -lm -# t_eoESFull_LDADD = $(LDADDS) +#t_eoESFull_SOURCES = t-eoESFull.cpp real_value.h +#t_eoESFull_DEPENDENCIES = $(DEPS) +#t_eoESFull_LDFLAGS = -lm +#t_eoESFull_LDADD = $(LDADDS) ############################################################################### @@ -39,57 +40,64 @@ t_eobin_LDADD = $(LDADDS) ############################################################################### t_eoStateAndParser_SOURCES = t-eoStateAndParser.cpp -t_eoStateAndParser_DEPENDENCIES = $(DEPS) -t_eoStateAndParser_LDFLAGS = -lm -t_eoStateAndParser_LDADD = $(LDADDS) +t_eoStateAndParser_DEPENDENCIES = $(DEPS) +t_eoStateAndParser_LDFLAGS = -lm +t_eoStateAndParser_LDADD = $(LDADDS) ############################################################################### t_eoCheckpointing_SOURCES = t-eoCheckpointing.cpp -t_eoCheckpointing_DEPENDENCIES = $(DEPS) -t_eoCheckpointing_LDFLAGS = -lm -t_eoCheckpointing_LDADD = $(LDADDS) +t_eoCheckpointing_DEPENDENCIES = $(DEPS) +t_eoCheckpointing_LDFLAGS = -lm +t_eoCheckpointing_LDADD = $(LDADDS) ############################################################################### t_eoReplacement_SOURCES = t-eoReplacement.cpp -t_eoReplacement_DEPENDENCIES = $(DEPS) -t_eoReplacement_LDFLAGS = -lm -t_eoReplacement_LDADD = $(LDADDS) +t_eoReplacement_DEPENDENCIES = $(DEPS) +t_eoReplacement_LDFLAGS = -lm +t_eoReplacement_LDADD = $(LDADDS) ############################################################################### t_eoSelect_SOURCES = t-eoSelect.cpp -t_eoSelect_DEPENDENCIES = $(DEPS) -t_eoSelect_LDFLAGS = -lm -t_eoSelect_LDADD = $(LDADDS) +t_eoSelect_DEPENDENCIES = $(DEPS) +t_eoSelect_LDFLAGS = -lm +t_eoSelect_LDADD = $(LDADDS) ############################################################################### t_eoExternalEO_SOURCES = t-eoExternalEO.cpp -t_eoExternalEO_DEPENDENCIES = $(DEPS) -t_eoExternalEO_LDFLAGS = -lm -t_eoExternalEO_LDADD = $(LDADDS) +t_eoExternalEO_DEPENDENCIES = $(DEPS) +t_eoExternalEO_LDFLAGS = -lm +t_eoExternalEO_LDADD = $(LDADDS) ############################################################################### t_eoSymreg_SOURCES = t-eoSymreg.cpp -t_eoSymreg_DEPENDENCIES = $(DEPS) -t_eoSymreg_LDFLAGS = -lm -t_eoSymreg_LDADD = $(LDADDS) +t_eoSymreg_DEPENDENCIES = $(DEPS) +t_eoSymreg_LDFLAGS = -lm +t_eoSymreg_LDADD = $(LDADDS) ############################################################################### t_eo_SOURCES = t-eo.cpp -t_eo_DEPENDENCIES = $(DEPS) -t_eo_LDFLAGS = -lm -t_eo_LDADD = $(LDADDS) +t_eo_DEPENDENCIES = $(DEPS) +t_eo_LDFLAGS = -lm +t_eo_LDADD = $(LDADDS) ############################################################################### t_eoGenOp_SOURCES = t-eoGenOp.cpp -t_eoGenOp_DEPENDENCIES = $(DEPS) -t_eoGenOp_LDFLAGS = -lm -t_eoGenOp_LDADD = $(LDADDS) +t_eoGenOp_DEPENDENCIES = $(DEPS) +t_eoGenOp_LDFLAGS = -lm +t_eoGenOp_LDADD = $(LDADDS) + +############################################################################### + +t_eoGA_SOURCES = t-eoGA.cpp binary_value.h +t_eoGA_DEPENDENCIES = $(DEPS) $(top_builddir)/src/ga/libga.a +t_eoGA_LDFLAGS = -lm +t_eoGA_LDADD = $(top_builddir)/src/ga/libga.a $(LDADDS) ############################################################################### diff --git a/eo/test/run_tests b/eo/test/run_tests index 5f3b5af1..59e02684 100755 --- a/eo/test/run_tests +++ b/eo/test/run_tests @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/sh echo "Starting t-eo" ./t-eo > eo.log @@ -33,6 +33,9 @@ echo "Testing t-eobin" echo "Testing t-eofitness" ./t-eofitness > fitness.log +echo "Testing t-eoGA" +./t-eoGA > t-eoGA.log + echo "Finished" #TODO test if an error occured diff --git a/eo/test/t-eoGA.cpp b/eo/test/t-eoGA.cpp new file mode 100644 index 00000000..fe1f7571 --- /dev/null +++ b/eo/test/t-eoGA.cpp @@ -0,0 +1,36 @@ +#include + +#include +#include "binary_value.h" +#include + +using namespace std; + +int main(int argc, char* argv[]) +{ + + try + { + typedef eoBit EoType; + + eoParser parser(argc, argv); + + eoState state; // keeps all things allocated, including eoEasyEA and eoPop! + + eoEvalFuncPtr eval( binary_value ); + eoGenContinue term(20); + eoCheckPoint checkpoint(term); + + eoAlgo& ga = make_ga(parser, eval, checkpoint, state); + + eoPop& pop = init_ga(parser, state, double()); + + apply(eval, pop); + + run_ga(ga, pop); // run the ga + } + catch(exception& e) + { + cout << e.what() << endl; + } +} \ No newline at end of file