From 4968d64b0541ac25fa9462e118cf3afea712e367 Mon Sep 17 00:00:00 2001 From: evomarc Date: Thu, 26 Apr 2001 15:24:53 +0000 Subject: [PATCH] Doing libes.a in src/es and adding t-eoReal.cpp in test I had to move eoRealBounds to utils dir because of global objects Some domino consequences here and there ... --- eo/src/es.h | 3 -- eo/src/es/Makefile.am | 11 +++++ eo/src/es/eoEsChromInit.h | 2 +- eo/src/es/eoEsMutate.h | 2 +- eo/src/es/eoEsStdevXOver.h | 2 +- eo/src/es/eoNormalMutation.h | 2 +- eo/src/es/eoRealOp.h | 2 +- eo/src/ga/make_algo_scalar_ga.cpp | 6 +-- eo/src/ga/make_continue_ga.cpp | 4 +- eo/src/ga/make_pop_ga.cpp | 4 +- eo/src/utils/Makefile.am | 2 +- eo/src/utils/eoGnuplot1DMonitor.h | 2 +- eo/src/utils/eoParam.h | 2 +- eo/src/utils/eoRealBounds.cpp | 7 +++ eo/src/{es => utils}/eoRealBounds.h | 9 ++-- eo/test/Makefile.am | 11 ++++- eo/test/t-eoReal.cpp | 70 +++++++++++++++++++++++++++++ eo/tutorial/Lesson1/FirstBitGA.cpp | 2 +- eo/tutorial/Lesson3/exercise3.1.cpp | 2 +- 19 files changed, 120 insertions(+), 25 deletions(-) create mode 100644 eo/src/utils/eoRealBounds.cpp rename eo/src/{es => utils}/eoRealBounds.h (98%) create mode 100644 eo/test/t-eoReal.cpp diff --git a/eo/src/es.h b/eo/src/es.h index d96b9746b..491f67490 100644 --- a/eo/src/es.h +++ b/eo/src/es.h @@ -48,9 +48,6 @@ #include #include -// and their generic counterparts -#include - // the ES-mutations #include #include diff --git a/eo/src/es/Makefile.am b/eo/src/es/Makefile.am index 8b275335f..f1129f62a 100644 --- a/eo/src/es/Makefile.am +++ b/eo/src/es/Makefile.am @@ -4,5 +4,16 @@ ## ############################################################################### +INCLUDES = -I$(top_builddir)/src +lib_LIBRARIES = libes.a +libes_a_SOURCES = make_algo_scalar_real.cpp \ + make_checkpoint_real.cpp \ + make_continue_real.cpp \ + make_genotype_real.cpp \ + make_help.cpp \ + make_op_real.cpp \ + make_pop_real.cpp \ + make_run_real.cpp +CPPFLAGS = -Wall libeoincdir = $(includedir)/eo/es libeoinc_HEADERS = eoEsChromInit.h eoEsFull.h eoEsMutate.h eoEsMutationInit.h eoEsSimple.h eoEsStdev.h eoEsStdevXOver.h eoGenericRealOp.h eoNormalMutation.h eoReal.h eoRealBounds.h eoRealOp.h diff --git a/eo/src/es/eoEsChromInit.h b/eo/src/es/eoEsChromInit.h index 43a61af0d..895cbe8bd 100644 --- a/eo/src/es/eoEsChromInit.h +++ b/eo/src/es/eoEsChromInit.h @@ -27,7 +27,7 @@ #ifndef _eoEsChromInit_H #define _eoEsChromInit_H -#include +#include #include #include #include diff --git a/eo/src/es/eoEsMutate.h b/eo/src/es/eoEsMutate.h index 9b453ecdf..bee67f2a4 100644 --- a/eo/src/es/eoEsMutate.h +++ b/eo/src/es/eoEsMutate.h @@ -37,7 +37,7 @@ #include #include #include -#include +#include #include diff --git a/eo/src/es/eoEsStdevXOver.h b/eo/src/es/eoEsStdevXOver.h index be5071e7d..1e0aa388c 100644 --- a/eo/src/es/eoEsStdevXOver.h +++ b/eo/src/es/eoEsStdevXOver.h @@ -28,7 +28,7 @@ #define _eoEsStdevXOver_h #include -#include +#include /** \ingroup EvolutionStrategies diff --git a/eo/src/es/eoNormalMutation.h b/eo/src/es/eoNormalMutation.h index 3398e7a05..2c4718c47 100644 --- a/eo/src/es/eoNormalMutation.h +++ b/eo/src/es/eoNormalMutation.h @@ -33,7 +33,7 @@ #include #include #include -#include +#include //----------------------------------------------------------------------------- /** Simple normal mutation of a vector of real values. diff --git a/eo/src/es/eoRealOp.h b/eo/src/es/eoRealOp.h index b13619d6c..ed7ae3043 100644 --- a/eo/src/es/eoRealOp.h +++ b/eo/src/es/eoRealOp.h @@ -31,7 +31,7 @@ #include // swap_ranges #include #include -#include +#include //----------------------------------------------------------------------------- diff --git a/eo/src/ga/make_algo_scalar_ga.cpp b/eo/src/ga/make_algo_scalar_ga.cpp index c3bbaba4c..a7ae453b1 100644 --- a/eo/src/ga/make_algo_scalar_ga.cpp +++ b/eo/src/ga/make_algo_scalar_ga.cpp @@ -24,15 +24,15 @@ */ //----------------------------------------------------------------------------- -/** This file contains all ***INSTANCIATED DEFINITIONS*** of operators +/** This file contains all ***INSTANCIATED DEFINITIONS*** of pop. init. * of the library for ***BISTRING*** evolution inside EO. * It should be included in the file that calls any of the corresponding fns * Compiling this file allows one to generate part of the library (i.e. object * files that you just need to link with your own main and fitness code). * * The corresponding ***INSTANCIATED DECLARATIONS*** are contained - * in make_algo_scalar_ga.h - * while the TEMPLATIZED code is define in make_algo_scalar.h in the do dir + * in src/ga/ga.h + * while the TEMPLATIZED code is define in make_algo_scalar.h in the src/do dir * * Unlike most EO .h files, it does not (and should not) contain any code, * just declarations diff --git a/eo/src/ga/make_continue_ga.cpp b/eo/src/ga/make_continue_ga.cpp index 09a0aefee..def01ab3b 100644 --- a/eo/src/ga/make_continue_ga.cpp +++ b/eo/src/ga/make_continue_ga.cpp @@ -31,8 +31,8 @@ * files that you just need to link with your own main and fitness code). * * The corresponding ***INSTANCIATED DECLARATIONS*** are contained - * in make_continue_ga.h - * while the TEMPLATIZED code is define in make_contninue.h in the do dir + * in ga.h + * while the TEMPLATIZED code is define in make_contninue.h in the src/do dir * * Unlike most EO .h files, it does not (and should not) contain any code, * just declarations diff --git a/eo/src/ga/make_pop_ga.cpp b/eo/src/ga/make_pop_ga.cpp index a67e37d38..ae014f4fb 100644 --- a/eo/src/ga/make_pop_ga.cpp +++ b/eo/src/ga/make_pop_ga.cpp @@ -31,8 +31,8 @@ * files that you just need to link with your own main and fitness code). * * The corresponding ***INSTANCIATED DECLARATIONS*** are contained - * in make_pop_ga.h - * while the TEMPLATIZED code is define in make_pop.h in the do dir + * in ga.h + * while the TEMPLATIZED code is define in make_pop.h in the src/do dir * * Unlike most EO .h files, it does not (and should not) contain any code, * just declarations diff --git a/eo/src/utils/Makefile.am b/eo/src/utils/Makefile.am index d38ddbe12..2f1d0c4d1 100644 --- a/eo/src/utils/Makefile.am +++ b/eo/src/utils/Makefile.am @@ -7,7 +7,7 @@ INCLUDES = -I$(top_builddir)/src CPPFLAGS = -O2 -Wall lib_LIBRARIES = libeoutils.a -libeoutils_a_SOURCES = eoParser.cpp eoRNG.cpp eoState.cpp eoUpdater.cpp eoFileMonitor.cpp eoStdoutMonitor.cpp +libeoutils_a_SOURCES = eoParser.cpp eoRNG.cpp eoState.cpp eoUpdater.cpp eoFileMonitor.cpp eoStdoutMonitor.cpp eoRealBounds.cpp libeoincdir = $(includedir)/eo/utils libeoinc_HEADERS = checkpointing *.h diff --git a/eo/src/utils/eoGnuplot1DMonitor.h b/eo/src/utils/eoGnuplot1DMonitor.h index ac5bfc80f..e75508750 100644 --- a/eo/src/utils/eoGnuplot1DMonitor.h +++ b/eo/src/utils/eoGnuplot1DMonitor.h @@ -103,7 +103,7 @@ inline void eoGnuplot1DMonitor::FirstPlot() { if (vec.size() < 2) { - throw runtime_error("eoGnuplot1DMonitor needs at least 2 stats (X and Y)!\n"); + throw runtime_error("Must have some stats to plot!\n"); } char buff[1024]; ostrstream os(buff, 1024); diff --git a/eo/src/utils/eoParam.h b/eo/src/utils/eoParam.h index a30690e3a..45e53c3ad 100644 --- a/eo/src/utils/eoParam.h +++ b/eo/src/utils/eoParam.h @@ -470,7 +470,7 @@ public: // so here we do have arguments string t = _value.substr(pos+1);// the arguments _value.resize(pos); - first = _value; // done for the keyword + first = _value; // done for the keyword (NOTE: may be empty string!) // now all arguments string delim(" (),"); diff --git a/eo/src/utils/eoRealBounds.cpp b/eo/src/utils/eoRealBounds.cpp new file mode 100644 index 000000000..5349ed822 --- /dev/null +++ b/eo/src/utils/eoRealBounds.cpp @@ -0,0 +1,7 @@ +#include +#include "eoRealBounds.h" + +// the global dummy bounds +// (used for unbounded variables when bounds are required) +eoRealNoBounds eoDummyRealNoBounds; +eoRealVectorNoBounds eoDummyVectorNoBounds; diff --git a/eo/src/es/eoRealBounds.h b/eo/src/utils/eoRealBounds.h similarity index 98% rename from eo/src/es/eoRealBounds.h rename to eo/src/utils/eoRealBounds.h index 55a00f368..d0cd8df04 100644 --- a/eo/src/es/eoRealBounds.h +++ b/eo/src/utils/eoRealBounds.h @@ -27,6 +27,9 @@ #ifndef _eoRealBounds_h #define _eoRealBounds_h +#include // exceptions! +#include + /** \defgroup EvolutionStrategies @@ -408,7 +411,7 @@ Anyone with extra time in his agenda is welcome to change that :-) class eoRealVectorBounds : public vector { public: - // virtual desctructor (to avoid warining?) + // virtual desctructor (to avoid warning?) virtual ~eoRealVectorBounds(){} /** Default Ctor @@ -649,6 +652,6 @@ public: }; // one object for all -eoRealNoBounds eoDummyRealNoBounds; -eoRealVectorNoBounds eoDummyVectorNoBounds; +extern eoRealNoBounds eoDummyRealNoBounds; +extern eoRealVectorNoBounds eoDummyVectorNoBounds; #endif diff --git a/eo/test/Makefile.am b/eo/test/Makefile.am index 557839924..6197c15a0 100644 --- a/eo/test/Makefile.am +++ b/eo/test/Makefile.am @@ -14,10 +14,10 @@ CXXFLAGS = -g -Wall ############################################################################### check_PROGRAMS = t-eoParetoFitness t-eoPareto t-eofitness t-eoRandom t-eobin t-eoStateAndParser t-eoCheckpointing t-eoSSGA \ - t-eoExternalEO t-eoSymreg t-eo t-eoReplacement t-eoSelect t-eoGenOp t-eoGA t-eoVector + t-eoExternalEO t-eoSymreg t-eo t-eoReplacement t-eoSelect t-eoGenOp t-eoGA t-eoReal t-eoVector TESTS=run_tests t-eoVector t-eoRandom t-eoSSGA t-eoPareto t-eoParetoFitness # 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 t-eoGenOp t-eoGA +# 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-eoReal ############################################################################### @@ -115,6 +115,13 @@ t_eoGA_LDADD = $(top_builddir)/src/ga/libga.a $(LDADDS) ############################################################################### +t_eoReal_SOURCES = t-eoReal.cpp real_value.h +t_eoReal_DEPENDENCIES = $(DEPS) $(top_builddir)/src/es/libes.a +t_eoReal_LDFLAGS = -lm +t_eoReal_LDADD = $(top_builddir)/src/es/libes.a $(LDADDS) + +############################################################################### + t_eoSSGA_SOURCES = t-eoSSGA.cpp binary_value.h t_eoSSGA_DEPENDENCIES = $(DEPS) $(top_builddir)/src/ga/libga.a t_eoSSGA_LDFLAGS = -lm diff --git a/eo/test/t-eoReal.cpp b/eo/test/t-eoReal.cpp new file mode 100644 index 000000000..efc67f4d2 --- /dev/null +++ b/eo/test/t-eoReal.cpp @@ -0,0 +1,70 @@ +#include + +#include +#include "real_value.h" +#include + +using namespace std; + +int main(int argc, char* argv[]) +{ + + try + { + typedef eoReal EOT; + + eoParser parser(argc, argv); // for user-parameter reading + + eoState state; // keeps all things allocated + + ///// FIRST, problem or representation dependent stuff + ////////////////////////////////////////////////////// + + // The evaluation fn - encapsulated into an eval counter for output + eoEvalFuncPtr&> + mainEval( real_value ); + eoEvalFuncCounter eval(mainEval); + + // the genotype - through a genotype initializer + eoInit& init = make_genotype(parser, state, eoMinimizingFitness()); + + // Build the variation operator (any seq/prop construct) + eoGenOp& op = make_op(parser, state, init); + + //// Now the representation-independent things + ////////////////////////////////////////////// + + // initialize the population - and evaluate + // yes, this is representation indepedent once you have an eoInit + eoPop& pop = make_pop(parser, state, init); + apply(eval, pop); + + // stopping criteria + eoContinue & term = make_continue(parser, state, eval); + // output + eoCheckPoint & checkpoint = make_checkpoint(parser, state, eval, term); + // algorithm (need the operator!) + eoAlgo& ga = make_algo_scalar(parser, state, eval, checkpoint, op); + + ///// End of construction of the algorith + ///////////////////////////////////////// + // to be called AFTER all parameters have been read!!! + make_help(parser); + + //// GO + /////// + cout << "Initial Population\n"; + pop.sortedPrintOn(cout); + cout << endl; + + run_ea(ga, pop); // run the ga + + cout << "Final Population\n"; + pop.sortedPrintOn(cout); + cout << endl; + } + catch(exception& e) + { + cout << e.what() << endl; + } +} diff --git a/eo/tutorial/Lesson1/FirstBitGA.cpp b/eo/tutorial/Lesson1/FirstBitGA.cpp index 4ff0ff0c9..23bce2cb5 100644 --- a/eo/tutorial/Lesson1/FirstBitGA.cpp +++ b/eo/tutorial/Lesson1/FirstBitGA.cpp @@ -15,7 +15,7 @@ #include #include -// REPRESENTATION +// REPRESENTATION //----------------------------------------------------------------------------- // define your individuals typedef eoBit Indi; // A bitstring with fitness double diff --git a/eo/tutorial/Lesson3/exercise3.1.cpp b/eo/tutorial/Lesson3/exercise3.1.cpp index 3bdab13d3..9e401959c 100644 --- a/eo/tutorial/Lesson3/exercise3.1.cpp +++ b/eo/tutorial/Lesson3/exercise3.1.cpp @@ -315,7 +315,7 @@ void main_function(int argc, char **argv) fileMonitor.add(generationCounter); fileMonitor.add(bestStat); fileMonitor.add(SecondStat); - // the fileMonitor can monitor parameters, too, but you must tell it! + // the gnuMonitor can monitor parameters, too, but you must tell it! gnuMonitor.add(eval); gnuMonitor.add(bestStat); gnuMonitor.add(averageStat);