diff --git a/eo/app/gpsymreg/main.cpp b/eo/app/gpsymreg/main.cpp index 2db9ba37..aeb7c645 100644 --- a/eo/app/gpsymreg/main.cpp +++ b/eo/app/gpsymreg/main.cpp @@ -3,16 +3,16 @@ 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 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 jeggermo@liacs.nl */ @@ -26,8 +26,8 @@ #endif #include -#include -#include +#include "gp/eoParseTree.h" +#include "eo" using namespace gp_parse_tree; using namespace std; @@ -43,7 +43,7 @@ using namespace std; typedef eoParseTree EoType; -typedef eoPop Pop; +typedef eoPop Pop; //----------------------------------------------------------------------------- @@ -52,23 +52,23 @@ int main(int argc, char *argv[]) // the vector containing the possible nodes vector initSequence; - - // initialise parameters - Parameters parameter(argc, argv); - + + // initialise parameters + Parameters parameter(argc, argv); + // set the randomseed rng.reseed(parameter.randomseed); - + // Create a generation counter eoValueParam generationCounter(0, "Gen."); - - // Create an incrementor (sub-class of eoUpdater). Note that the - // parameter's value is passed by reference, + + // Create an incrementor (sub-class of eoUpdater). Note that the + // parameter's value is passed by reference, // so every time the incrementer is updated (every generation), // the data in generationCounter will change. eoIncrementor increment(generationCounter.value()); - - + + // create an instantiation of the fitness/evaluation function // it initializes the initSequence vector // the parameters are passed on as well @@ -76,44 +76,44 @@ int main(int argc, char *argv[]) // Depth Initializor, set for Ramped Half and Half Initialization eoParseTreeDepthInit initializer(parameter.InitMaxDepth, initSequence, true, true); - + // create the initial population Pop pop(parameter.population_size, initializer); - // and evaluate the individuals + // and evaluate the individuals apply(eval, pop); - + generationCounter.value()++; // set the generationCounter to 1 - + // define X-OVER - + eoSubtreeXOver xover(parameter.MaxSize); - + // define MUTATION eoBranchMutation mutation(initializer, parameter.MaxSize); // eoExpansionMutation mutation(initializer, parameter.MaxSize); // eoCollapseSubtreeMutation mutation(initializer, parameter.MaxSize); // eoPointMutation mutation(initSequence); // eoHoistMutation mutation; - - // The operators are encapsulated into an eoTRansform object, + + // The operators are encapsulated into an eoTRansform object, // that performs sequentially crossover and mutation eoSGATransform transform(xover, parameter.xover_rate, mutation, parameter.mutation_rate); - + // The robust tournament selection // in our case 5-tournament selection eoDetTournamentSelect selectOne(parameter.tournamentsize); // is now encapsulated in a eoSelectMany eoSelectMany select(selectOne, parameter.offspring_size, eo_is_an_integer); - + // and the generational replacement //eoGenerationalReplacement replace; // or the SteadtState replacment //eoSSGAWorseReplacement replace; // or comma selection eoCommaReplacement replace; - + // Terminators eoGenContinue term(parameter.nGenerations); @@ -124,13 +124,13 @@ int main(int argc, char *argv[]) eoBestFitnessStat best; - // Add it to the checkpoint, + // Add it to the checkpoint, // so the counter is updated (here, incremented) every generation checkPoint.add(increment); checkPoint.add(avg); checkPoint.add(best); - -#if !defined(NO_GNUPLOT) + +#ifdef HAVE_GNUPLOT eoGnuplot1DMonitor gnuplotmonitor("gnuplotBestStats"); gnuplotmonitor.add(generationCounter); gnuplotmonitor.add(best); @@ -147,7 +147,7 @@ int main(int argc, char *argv[]) checkPoint.add(gnuplotmonitor); checkPoint.add(gnuplotAvgmonitor); -#endif +#endif // GP Generation eoEasyEA gp(checkPoint, eval, select, transform, replace); diff --git a/eo/src/do/make_checkpoint.h b/eo/src/do/make_checkpoint.h index 0ee6f129..93488ac8 100644 --- a/eo/src/do/make_checkpoint.h +++ b/eo/src/do/make_checkpoint.h @@ -3,7 +3,7 @@ //----------------------------------------------------------------------------- // make_checkpoint.h // (c) Maarten Keijzer, Marc Schoenauer 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 @@ -45,7 +45,7 @@ eoCheckPoint& do_make_checkpoint(eoParser& _parser, eoState& _state, eoEval // first, create a checkpoint from the eoContinue eoCheckPoint *checkpoint = new eoCheckPoint(_continue); _state.storeFunctor(checkpoint); - + /////////////////// // Counters ////////////////// @@ -55,14 +55,14 @@ eoCheckPoint& do_make_checkpoint(eoParser& _parser, eoState& _state, eoEval // if we want the time, we need an eoTimeCounter eoTimeCounter * tCounter = NULL; - - // Create anyway a generation-counter - // Recent change (03/2002): it is now an eoIncrementorParam, both + + // Create anyway a generation-counter + // Recent change (03/2002): it is now an eoIncrementorParam, both // a parameter AND updater so you can store it into the eoState eoIncrementorParam *generationCounter = new eoIncrementorParam("Gen."); // store it in the state _state.storeFunctor(generationCounter); - // And add it to the checkpoint, + // And add it to the checkpoint, checkpoint->add(*generationCounter); // dir for DISK output @@ -91,7 +91,7 @@ eoCheckPoint& do_make_checkpoint(eoParser& _parser, eoState& _state, eoEval eoValueParam& fileBestParam = _parser.createParam(false, "fileBestStat", "Output bes/avg/std to file", '\0', "Output - Disk"); eoBestFitnessStat *bestStat = NULL; - if ( printBestParam.value() || plotBestParam.value() || fileBestParam.value() ) + if ( printBestParam.value() || plotBestParam.value() || fileBestParam.value() ) // we need the bestStat for at least one of the 3 above { bestStat = new eoBestFitnessStat; @@ -147,11 +147,11 @@ eoCheckPoint& do_make_checkpoint(eoParser& _parser, eoState& _state, eoEval // The monitors /////////////// // do we want an eoStdoutMonitor? - bool needStdoutMonitor = printBestParam.value() + bool needStdoutMonitor = printBestParam.value() || printPopParam.value() ; - // The Stdout monitor will print parameters to the screen ... - if ( needStdoutMonitor ) + // The Stdout monitor will print parameters to the screen ... + if ( needStdoutMonitor ) { eoStdoutMonitor *monitor = new eoStdoutMonitor(false); _state.storeFunctor(monitor); @@ -180,7 +180,7 @@ eoCheckPoint& do_make_checkpoint(eoParser& _parser, eoState& _state, eoEval } // first handle the dir test - if we need at least one file - if ( ( fileBestParam.value() || plotBestParam.value() || + if ( ( fileBestParam.value() || plotBestParam.value() || plotHistogramParam.value() ) && !dirOK ) // just in case we add something before dirOK = testDirRes(dirNameParam.value(), eraseParam.value()); // TRUE @@ -204,11 +204,10 @@ eoCheckPoint& do_make_checkpoint(eoParser& _parser, eoState& _state, eoEval // std::cout << "On met timecounter\n"; fileMonitor->add(*tCounter); } - fileMonitor->add(*bestStat); + fileMonitor->add(*bestStat); fileMonitor->add(*secondStat); } -#if !defined(NO_GNUPLOT) if (plotBestParam.value()) // an eoGnuplot1DMonitor for best & average { std::string stmp = dirNameParam.value() + "/gnu_best.xg"; @@ -241,7 +240,6 @@ eoCheckPoint& do_make_checkpoint(eoParser& _parser, eoState& _state, eoEval // and of course add it to the checkpoint checkpoint->add(*fitSnapshot); } -#endif ////////////////////////////////// // State savers @@ -263,12 +261,12 @@ eoCheckPoint& do_make_checkpoint(eoParser& _parser, eoState& _state, eoEval #else std::string stmp = dirNameParam.value() + "/generations"; #endif - eoCountedStateSaver *stateSaver1 = new eoCountedStateSaver(freq, _state, stmp); + eoCountedStateSaver *stateSaver1 = new eoCountedStateSaver(freq, _state, stmp); _state.storeFunctor(stateSaver1); checkpoint->add(*stateSaver1); } - // save state every T seconds + // save state every T seconds eoValueParam& saveTimeIntervalParam = _parser.createParam(unsigned(0), "saveTimeInterval", "Save every T seconds (0 or absent = never)", '\0',"Persistence" ); if (_parser.isItThere(saveTimeIntervalParam) && saveTimeIntervalParam.value()>0) { @@ -281,7 +279,7 @@ eoCheckPoint& do_make_checkpoint(eoParser& _parser, eoState& _state, eoEval #else std::string stmp = dirNameParam.value() + "/time"; #endif - eoTimedStateSaver *stateSaver2 = new eoTimedStateSaver(saveTimeIntervalParam.value(), _state, stmp); + eoTimedStateSaver *stateSaver2 = new eoTimedStateSaver(saveTimeIntervalParam.value(), _state, stmp); _state.storeFunctor(stateSaver2); checkpoint->add(*stateSaver2); } diff --git a/eo/src/do/make_checkpoint_assembled.h b/eo/src/do/make_checkpoint_assembled.h index 92d855d4..c28cd066 100644 --- a/eo/src/do/make_checkpoint_assembled.h +++ b/eo/src/do/make_checkpoint_assembled.h @@ -11,16 +11,16 @@ 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. - + 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 Marc.Schoenauer@inria.fr mak@dhi.dk @@ -49,18 +49,26 @@ template eoCheckPoint& do_make_checkpoint_assembled(eoParser& _parser, eoState& _state, eoEvalFuncCounter& _eval, eoContinue& _continue) { - // SOME PARSER PARAMETERS - // ---------------------- - std::string dirName = _parser.createParam(std::string("Res"), "resDir", "Directory to store DISK outputs", '\0', "Output").value(); - bool erase = _parser.createParam(true, "eraseDir", "Erase files in dirName if any", '\0', "Output").value(); -#if !defined(NO_GNUPLOT) - bool gnuplots = _parser.createParam(true,"plots","Plot stuff using GnuPlot",'\0',"Output").value(); -#endif - bool printFile = _parser.createParam(true,"printFile","Print statistics file",'\0',"Output").value(); + // SOME PARSER PARAMETERS + // ---------------------- + std::string dirName = _parser.getORcreateParam(std::string("Res"), "resDir", + "Directory to store DISK outputs", + '\0', "Output").value(); + bool erase = _parser.getORcreateParam(true, "eraseDir", + "Erase files in dirName if any", + '\0', "Output").value(); + bool gnuplots = _parser.getORcreateParam(true, "plots", + "Plot stuff using GnuPlot", + '\0', "Output").value(); + bool printFile = _parser.getORcreateParam(true, "printFile", + "Print statistics file", + '\0', "Output").value(); + + eoValueParam& saveFrequencyParam + = _parser.getORcreateParam(unsigned(0), "saveFrequency", + "Save every F generation (0 = only final state, absent = never)", + '\0', "Persistence" ); - eoValueParam& saveFrequencyParam = - _parser.createParam(unsigned(0),"saveFrequency","Save every F generation (0 = only final state, absent = never)",'\0',"Persistence" ); - testDirRes(dirName, erase); // TRUE // CREATE CHECKPOINT FROM eoContinue @@ -88,7 +96,7 @@ eoCheckPoint& do_make_checkpoint_assembled(eoParser& _parser, eoState& _sta Fit fit; std::vector fitness_descriptions = fit.getDescriptionVector(); unsigned nTerms = fitness_descriptions.size(); - + // STAT VALUES OF A POPULATION // --------------------------- @@ -109,7 +117,7 @@ eoCheckPoint& do_make_checkpoint_assembled(eoParser& _parser, eoState& _sta _state.storeFunctor( bestvals[j] ); checkpoint->add( *bestvals[j] ); } - + // STDOUT // ------ eoStdoutMonitor *monitor = new eoStdoutMonitor(false); @@ -125,10 +133,9 @@ eoCheckPoint& do_make_checkpoint_assembled(eoParser& _parser, eoState& _sta // Add all average vals for (unsigned l=0; l < nTerms; ++l) monitor->add( *avgvals[l] ); - + // GNUPLOT // ------- -#if !defined(NO_GNUPLOT) if (gnuplots ){ std::string stmp; @@ -144,7 +151,7 @@ eoCheckPoint& do_make_checkpoint_assembled(eoParser& _parser, eoState& _sta // and of course add it to the checkpoint checkpoint->add(*fitSnapshot); - std::vector gnumonitors(nTerms, NULL ); + std::vector gnumonitors(nTerms, NULL ); for (unsigned k=0; k < nTerms; ++k){ stmp = dirName + "/gnuplot_" + fitness_descriptions[k] + ".xg"; gnumonitors[k] = new eoGnuplot1DMonitor(stmp,true); @@ -156,7 +163,6 @@ eoCheckPoint& do_make_checkpoint_assembled(eoParser& _parser, eoState& _sta } } -#endif // WRITE STUFF TO FILE // ------------------- @@ -181,10 +187,10 @@ eoCheckPoint& do_make_checkpoint_assembled(eoParser& _parser, eoState& _sta // feed the state to state savers if (_parser.isItThere(saveFrequencyParam)) { - + unsigned freq = (saveFrequencyParam.value() > 0 ? saveFrequencyParam.value() : UINT_MAX ); std::string stmp = dirName + "/generations"; - eoCountedStateSaver *stateSaver1 = new eoCountedStateSaver(freq, _state, stmp); + eoCountedStateSaver *stateSaver1 = new eoCountedStateSaver(freq, _state, stmp); _state.storeFunctor(stateSaver1); checkpoint->add(*stateSaver1); } diff --git a/eo/src/do/make_checkpoint_pareto.h b/eo/src/do/make_checkpoint_pareto.h index 3d399ee4..5f2b84e6 100644 --- a/eo/src/do/make_checkpoint_pareto.h +++ b/eo/src/do/make_checkpoint_pareto.h @@ -44,22 +44,24 @@ bool testDirRes(std::string _dirName, bool _erase); /** Of course, Fitness needs to be an eoParetoFitness!!! */ template -eoCheckPoint& do_make_checkpoint_pareto(eoParser& _parser, eoState& _state, eoEvalFuncCounter& _eval, eoContinue& _continue) +eoCheckPoint& do_make_checkpoint_pareto(eoParser& _parser, eoState& _state, + eoEvalFuncCounter& _eval, eoContinue& _continue) { - // first, create a checkpoint from the eoContinue - and store in _state - eoCheckPoint & checkpoint = - _state.storeFunctor(new eoCheckPoint(_continue)); + // first, create a checkpoint from the eoContinue - and store in _state + eoCheckPoint & checkpoint = _state.storeFunctor(new eoCheckPoint(_continue)); - /////// get number of obectives from Fitness - not very elegant - typedef typename EOT::Fitness Fit; - Fit fit; - unsigned nObj = fit.size(); + /////// get number of obectives from Fitness - not very elegant + typedef typename EOT::Fitness Fit; + Fit fit; + unsigned nObj = fit.size(); - /////////////////// - // Counters - ////////////////// - // is nb Eval to be used as counter? - bool useEval = _parser.createParam(true, "useEval", "Use nb of eval. as counter (vs nb of gen.)", '\0', "Output").value(); + /////////////////// + // Counters + ////////////////// + // is nb Eval to be used as counter? + bool useEval = _parser.getORcreateParam(true, "useEval", + "Use nb of eval. as counter (vs nb of gen.)", + '\0', "Output").value(); // Create anyway a generation-counter parameter WARNING: not stored anywhere!!! eoValueParam *generationCounter = new eoValueParam(0, "Gen."); @@ -70,9 +72,13 @@ eoCheckPoint& do_make_checkpoint_pareto(eoParser& _parser, eoState& _state, checkpoint.add(increment); // dir for DISK output - std::string & dirName = _parser.getORcreateParam(std::string("Res"), "resDir", "Directory to store DISK outputs", '\0', "Output - Disk").value(); + std::string & dirName = _parser.getORcreateParam(std::string("Res"), "resDir", + "Directory to store DISK outputs", + '\0', "Output - Disk").value(); // shoudl we empty it if exists - eoValueParam& eraseParam = _parser.createParam(true, "eraseDir", "erase files in dirName if any", '\0', "Output - Disk"); + eoValueParam& eraseParam = _parser.getORcreateParam(true, "eraseDir", + "erase files in dirName if any", + '\0', "Output - Disk"); bool dirOK = false; // not tested yet ///////////////////////////////////////// @@ -84,22 +90,20 @@ eoCheckPoint& do_make_checkpoint_pareto(eoParser& _parser, eoState& _state, * eoSortedPopStat : whole population - type std::string (!!) */ - eoValueParam& fPlotParam = _parser.createParam( - eoParamParamType("1(0,1)"), "frontFileFrequency", + eoValueParam& fPlotParam + = _parser.getORcreateParam(eoParamParamType("1(0,1)"), "frontFileFrequency", "File save frequency in objective spaces (std::pairs of comma-separated objectives " \ "in 1 single parentheses std::pair)", - '\0', "Output - Disk"); + '\0', "Output - Disk"); -#if !defined(NO_GNUPLOT) - bool boolGnuplot = _parser.createParam(false, "plotFront", - "Objective plots (requires corresponding files " \ - "- see frontFileFrequency", - '\0', "Output - Graphical").value(); -#endif + bool boolGnuplot = _parser.getORcreateParam(false, "plotFront", + "Objective plots (requires corresponding files " \ + "- see frontFileFrequency", + '\0', "Output - Graphical").value(); - eoParamParamType & fPlot = fPlotParam.value(); // std::pair > - unsigned frequency = atoi(fPlot.first.c_str()); - if (frequency) // something to plot + eoParamParamType & fPlot = fPlotParam.value(); // std::pair > + unsigned frequency = atoi(fPlot.first.c_str()); + if (frequency) // something to plot { unsigned nbPlot = fPlot.second.size(); if ( nbPlot % 2 ) // odd! @@ -145,20 +149,20 @@ eoCheckPoint& do_make_checkpoint_pareto(eoParser& _parser, eoState& _state, snapshot.add(*theStats[obj2]); // and create the gnuplotter from the fileSnapshot -#if !defined(NO_GNUPLOT) - if (boolGnuplot) + if(boolGnuplot) { eoGnuplot1DSnapshot & plotSnapshot = _state.storeFunctor(new eoGnuplot1DSnapshot(snapshot)); plotSnapshot.pointSize =3; checkpoint.add(plotSnapshot); } -#endif } } // Dump of the whole population //----------------------------- - bool printPop = _parser.createParam(false, "printPop", "Print sorted pop. every gen.", '\0', "Output").value(); + bool printPop = _parser.getORcreateParam(false, "printPop", + "Print sorted pop. every gen.", + '\0', "Output").value(); eoSortedPopStat * popStat; if ( printPop ) // we do want pop dump { @@ -217,7 +221,9 @@ eoCheckPoint& do_make_checkpoint_pareto(eoParser& _parser, eoState& _state, } // save state every T seconds - eoValueParam& saveTimeIntervalParam = _parser.createParam(unsigned(0), "saveTimeInterval", "Save every T seconds (0 or absent = never)", '\0',"Persistence" ); + eoValueParam& saveTimeIntervalParam + = _parser.getORcreateParam(unsigned(0), "saveTimeInterval", + "Save every T seconds (0 or absent = never)", '\0',"Persistence" ); if (_parser.isItThere(saveTimeIntervalParam) && saveTimeIntervalParam.value()>0) { // first make sure dirName is OK diff --git a/eo/src/utils/eoGnuplot.cpp b/eo/src/utils/eoGnuplot.cpp index 47007748..55bca8d1 100644 --- a/eo/src/utils/eoGnuplot.cpp +++ b/eo/src/utils/eoGnuplot.cpp @@ -44,30 +44,34 @@ eoGnuplot::eoGnuplot(std::string _title, std::string _extra) eoGnuplot::~eoGnuplot() { +#ifdef HAVE_GNUPLOT if( gpCom ) { PipeComSend( gpCom, "quit\n" ); PipeComClose( gpCom ); gpCom =NULL; } +#endif } void eoGnuplot::gnuplotCommand(const char *_command) { +#ifdef HAVE_GNUPLOT if(gpCom) { PipeComSend( gpCom, _command ); PipeComSend( gpCom, "\n" ); } +#endif } void eoGnuplot::initGnuPlot(std::string _title, std::string _extra) { +#ifdef HAVE_GNUPLOT std::ostringstream os; - os << "250x150-0+" << numWindow*170; - numWindow++; + os << "250x150-0+" << 170 * numWindow++; char *args[6]; args[0] = strdup( GNUPLOT_PROGRAM ); args[1] = strdup( "-geometry" ); @@ -83,6 +87,7 @@ void eoGnuplot::initGnuPlot(std::string _title, std::string _extra) PipeComSend( gpCom, _extra.c_str() ); PipeComSend( gpCom, "\n" ); } +#endif } diff --git a/eo/src/utils/eoGnuplot1DMonitor.cpp b/eo/src/utils/eoGnuplot1DMonitor.cpp index de560bb3..f716c33c 100644 --- a/eo/src/utils/eoGnuplot1DMonitor.cpp +++ b/eo/src/utils/eoGnuplot1DMonitor.cpp @@ -29,29 +29,30 @@ #include -#include "eoGnuplot1DMonitor.h" -#include "eoParam.h" +#include "utils/eoGnuplot1DMonitor.h" +#include "utils/eoParam.h" eoMonitor& eoGnuplot1DMonitor::operator() (void) { - // update file using the eoFileMonitor - eoFileMonitor::operator()(); - - // sends plot order to gnuplot - // assumes successive plots will have same nb of columns!!! - if (firstTime) + // update file using the eoFileMonitor + eoFileMonitor::operator()(); +#ifdef HAVE_GNUPLOT + // sends plot order to gnuplot + // assumes successive plots will have same nb of columns!!! + if (firstTime) { - FirstPlot(); - firstTime = false; + FirstPlot(); + firstTime = false; } - else + else { - if( gpCom ) { - PipeComSend( gpCom, "replot\n" ); - } + if( gpCom ) { + PipeComSend( gpCom, "replot\n" ); + } } - return *this; +#endif + return *this; } @@ -62,6 +63,7 @@ void eoGnuplot1DMonitor::FirstPlot() { throw std::runtime_error("Must have some stats to plot!\n"); } +#ifdef HAVE_GNUPLOT std::ostringstream os; os << "plot"; for (unsigned i=1; i mainEval( binary_value); eoEvalFuncCounter eval(mainEval); @@ -83,7 +83,7 @@ int main(int argc, char* argv[]) eoCheckPoint & checkpoint = make_checkpoint(parser, state, eval, term); // add a graphical output for the distribution - // first, get the direname from the parser + // first, get the direname from the parser // it has been enetered in make_checkoint eoParam* ptParam = parser.getParamWithLongName(string("resDir")); @@ -91,24 +91,26 @@ int main(int argc, char* argv[]) if (!ptDirNameParam) // not found throw runtime_error("Parameter resDir not found where it was supposed to be"); -#if !defined(NO_GNUPLOT) // now create the snapshot monitor - eoValueParam& plotDistribParam = parser.createParam(false, "plotDistrib", "Plot Distribution", '\0', "Output - Graphical"); + eoValueParam& plotDistribParam = parser.getORcreateParam(false, "plotDistrib", + "Plot Distribution", '\0', + "Output - Graphical"); if (plotDistribParam.value()) { unsigned frequency=1; // frequency of plots updates - eoGnuplot1DSnapshot *distribSnapshot = new eoGnuplot1DSnapshot(ptDirNameParam->value(), frequency, "distrib"); + eoGnuplot1DSnapshot *distribSnapshot = new eoGnuplot1DSnapshot(ptDirNameParam->value(), + frequency, "distrib"); state.storeFunctor(distribSnapshot); // add the distribution (it is an eoValueParam >) distribSnapshot->add(distrib); // and of course add it to the checkpoint checkpoint.add(*distribSnapshot); } -#endif // the algorithm: EDA // don't know where else to put the population size! - unsigned popSize = parser.createParam(unsigned(100), "popSize", "Population Size", 'P', "Algorithm").value(); + unsigned popSize = parser.getORcreateParam(unsigned(100), "popSize", + "Population Size", 'P', "Algorithm").value(); eoSimpleEDA eda(update, eval, popSize, checkpoint); ///// End of construction of the algorith @@ -125,14 +127,12 @@ int main(int argc, char* argv[]) distrib.printOn(std::cout); std::cout << std::endl; -#if !defined(NO_GNUPLOT) // wait - for graphical output if (plotDistribParam.value()) { string foo; cin >> foo; } -#endif } catch(std::exception& e) { diff --git a/eo/test/t-eoPareto.cpp b/eo/test/t-eoPareto.cpp index be61e71d..f98a0d96 100644 --- a/eo/test/t-eoPareto.cpp +++ b/eo/test/t-eoPareto.cpp @@ -205,7 +205,6 @@ void the_main(int argc, char* argv[]) cp.add(fitness0); cp.add(fitness1); -#if !defined(NO_GNUPLOT) eoGnuplot1DSnapshot snapshot("pareto"); //snapshot.with(eoGnuplot::Points(3)); @@ -213,7 +212,6 @@ void the_main(int argc, char* argv[]) snapshot.add(fitness0); snapshot.add(fitness1); -#endif // the algo eoEasyEA ea(cp, eval, breeder, replace); diff --git a/eo/tutorial/Templates/MyStructSEA.cpp b/eo/tutorial/Templates/MyStructSEA.cpp index 39c4dea1..0f18519a 100644 --- a/eo/tutorial/Templates/MyStructSEA.cpp +++ b/eo/tutorial/Templates/MyStructSEA.cpp @@ -17,7 +17,7 @@ main file BitEA in tutorial/Lesson4 dir. Or you can wait until we do it :-) */ -// Miscilaneous include and declaration +// Miscilaneous include and declaration #include using namespace std; @@ -29,17 +29,17 @@ using namespace std; // include here whatever specific files for your representation // Basically, this should include at least the following -/** definition of representation: +/** definition of representation: * class eoMyStruct MUST derive from EO for some fitness */ #include "eoMyStruct.h" -/** definition of initilizqtion: +/** definition of initilizqtion: * class eoMyStructInit MUST derive from eoInit */ #include "eoMyStructInit.h" -/** definition of evaluation: +/** definition of evaluation: * class eoMyStructEvalFunc MUST derive from eoEvalFunc * and should test for validity before doing any computation * see tutorial/Templates/evalFunc.tmpl @@ -47,7 +47,7 @@ using namespace std; #include "eoMyStructEvalFunc.h" /** definitions of operators: write as many classes as types of operators - * and include them here. In this simple example, + * and include them here. In this simple example, * one crossover (2->2) and one mutation (1->1) operators are used */ #include "eoMyStructQuadCrossover.h" @@ -61,17 +61,17 @@ using namespace std; //*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* // START fitness type: double or eoMaximizingFitness if you are maximizing // eoMinimizingFitness if you are minimizing -typedef eoMinimizingFitness MyFitT ; // type of fitness +typedef eoMinimizingFitness MyFitT ; // type of fitness // END fitness type //*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-* // Then define your EO objects using that fitness type -typedef eoMyStruct Indi; // ***MUST*** derive from EO +typedef eoMyStruct Indi; // ***MUST*** derive from EO // Use existing modules to define representation independent routines -// how to initialize the population +// how to initialize the population // it IS representation independent if an eoInit is given #include eoPop& make_pop(eoParser& _parser, eoState& _state, eoInit & _init) @@ -88,7 +88,7 @@ eoContinue& make_continue(eoParser& _parser, eoState& _state, eoEvalFuncCo // outputs (stats, population dumps, ...) #include -eoCheckPoint& make_checkpoint(eoParser& _parser, eoState& _state, eoEvalFuncCounter& _eval, eoContinue& _continue) +eoCheckPoint& make_checkpoint(eoParser& _parser, eoState& _state, eoEvalFuncCounter& _eval, eoContinue& _continue) { return do_make_checkpoint(_parser, _state, _eval, _continue); } @@ -100,7 +100,7 @@ eoAlgo& make_algo_scalar(eoParser& _parser, eoState& _state, eoEvalFunc // the instanciating fitnesses @@ -120,40 +120,40 @@ int main(int argc, char* argv[]) try { eoParser parser(argc, argv); // for user-parameter reading - + eoState state; // keeps all things allocated - + // The fitness ////////////// eoMyStructEvalFunc plainEval/* (varType _anyVariable) */; // turn that object into an evaluation counter eoEvalFuncCounter eval(plainEval); - + // a genotype initializer eoMyStructInit init; - // or, if you need some parameters, you might as well + // or, if you need some parameters, you might as well // - write a constructor of the eoMyStructInit that uses a parser // - call it from here: // eoMyStructInit init(parser); - + // if you want to do sharing, you'll need a distance. // see file utils/eoDistance.h // - // IF you representation has an operator[]() double-castable, + // IF you representation has an operator[]() double-castable, // then you can use for instance the quadratic distance (L2 norm) // eoQuadDistance dist; // or the Hamming distance (L1 norm) // eoHammingDistance dist; - + // Build the variation operator (any seq/prop construct) // here, a simple example with only 1 crossover (2->2, a QuadOp) and // one mutation, is given. // Hints to have choice among multiple crossovers and mutations are given - + // A (first) crossover (possibly use the parser in its Ctor) eoMyStructQuadCrossover cross /* (eoParser parser) */; - + // IF MORE THAN ONE: // read its relative rate in the combination @@ -167,9 +167,9 @@ try // 2- include that file here together with eoMyStructQuadCrossover above // 3- uncomment and duplicate the following lines: // -// eoMyStructSecondCrossover cross2(eoParser parser); -// double cross2Rate = parser.createParam(1.0, "cross2Rate", "Relative rate for crossover 2", '2', "Variation Operators").value(); -// cross.add(cross2, cross2Rate); +// eoMyStructSecondCrossover cross2(eoParser parser); +// double cross2Rate = parser.createParam(1.0, "cross2Rate", "Relative rate for crossover 2", '2', "Variation Operators").value(); +// cross.add(cross2, cross2Rate); // NOTE: if you want some gentle output, the last one shoudl be like // cross.add(cross, crossXXXRate, true); @@ -192,9 +192,9 @@ try // 2- include that file here together with eoMyStructMutation above // 3- uncomment and duplicate the following lines: // -// eoMyStructSecondMutation mut2(eoParser parser); -// double mut2Rate = parser.createParam(1.0, "mut2Rate", "Relative rate for mutation 2", '2', "Variation Operators").value(); -// mut.add(mut2, mut2Rate); +// eoMyStructSecondMutation mut2(eoParser parser); +// double mut2Rate = parser.createParam(1.0, "mut2Rate", "Relative rate for mutation 2", '2', "Variation Operators").value(); +// mut.add(mut2, mut2Rate); // NOTE: if you want some gentle output, the last one shoudl be like // mut.add(mut, mutXXXRate, true); @@ -217,7 +217,7 @@ try eoSGAGenOp op(cross, pCross, mut, pMut); - //// Now some representation-independent things + //// Now some representation-independent things // // You do not need to modify anything beyond this point // unless you want to add specific statistics to the checkpoint @@ -240,7 +240,7 @@ try // if uncommented, it is assumed that you will want to print some stat. // if not, then the following objects will be created uselessly - but what the heck! - eoMyStructStat myStat; // or maybe myStat(parser); + eoMyStructStat myStat; // or maybe myStat(parser); checkpoint.add(myStat); // This one is probably redundant with the one in make_checkpoint, but w.t.h. eoIncrementorParam generationCounter("Gen."); @@ -252,7 +252,7 @@ try // those need to be pointers because of the if's eoStdoutMonitor *myStdOutMonitor; eoFileMonitor *myFileMonitor; -#if !defined(NO_GNUPLOT) +#ifdef HAVE_GNUPLOT eoGnuplot1DMonitor *myGnuMonitor; #endif @@ -283,7 +283,7 @@ try // should we write it to a file ? if (fileMyStructStat) { - // the file name is hard-coded - of course you can read + // the file name is hard-coded - of course you can read // a string parameter in the parser if you prefer myFileMonitor = new eoFileMonitor(dirName + "myStat.xg"); // don't forget to store the memory in the state @@ -296,14 +296,14 @@ try myFileMonitor->add(myStat); } -#if !defined(NO_GNUPLOT) +#ifdef HAVE_GNUPLOT // should we PLOT it on StdOut ? (one dot per generation, incremental plot) if (plotMyStructStat) { myGnuMonitor = new eoGnuplot1DMonitor(dirName+"plot_myStat.xg",minimizing_fitness()); // NOTE: you cand send commands to gnuplot at any time with the method // myGnuMonitor->gnuplotCommand(string) - // par exemple, gnuplotCommand("set logscale y") + // par exemple, gnuplotCommand("set logscale y") // don't forget to store the memory in the state state.storeFunctor(myGnuMonitor);