From 4510b6d7126f37370e63dd50f875cdda8b24fcb1 Mon Sep 17 00:00:00 2001 From: kuepper Date: Mon, 10 Oct 2005 21:42:31 +0000 Subject: [PATCH] cleanup, prepare vecSigmaInit change --- eo/NEWS | 2 +- eo/src/utils/eoParser.h | 86 +++++++++++++----------- eo/test/Makefile.am | 6 +- eo/test/t-eoESAll.cpp | 142 ++++++++++++++++++++-------------------- 4 files changed, 122 insertions(+), 114 deletions(-) diff --git a/eo/NEWS b/eo/NEWS index d61451b4..8fce0ae3 100644 --- a/eo/NEWS +++ b/eo/NEWS @@ -4,7 +4,7 @@ clean up the code considerably. Assume availability of sstream and limits. -* releases 0.9.3... (latest release is 0.9.3zz, 1. Oct. 2005) +* release 0.9.3z.1 (1. Oct. 2005) - Support gcc-3.4 and gcc.4.x. - Provide full automake/autoconf/configure support. diff --git a/eo/src/utils/eoParser.h b/eo/src/utils/eoParser.h index 612497db..1f69f310 100644 --- a/eo/src/utils/eoParser.h +++ b/eo/src/utils/eoParser.h @@ -1,33 +1,27 @@ -// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- +/* (c) Marc Schoenauer, Maarten Keijzer and GeNeura Team, 2000 -//----------------------------------------------------------------------------- -// eoParser.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 - 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 - Marc.Schoenauer@polytechnique.fr - mkeijzer@dhi.dk - */ -//----------------------------------------------------------------------------- -/** -CVS Info: $Date: 2005-09-28 21:49:26 $ $Version$ $Author: kuepper $ +Contact: http://eodev.sourceforge.net + todos@geneura.ugr.es, http://geneura.ugr.es + Marc.Schoenauer@polytechnique.fr + mkeijzer@dhi.dk */ -#ifndef eoParser_h -#define eoParser_h + + +#ifndef EO_PARSER_H +#define EO_PARSER_H #include #include @@ -37,10 +31,11 @@ CVS Info: $Date: 2005-09-28 21:49:26 $ $Version$ $Author: kuepper $ #include "eoObject.h" #include "eoPersistent.h" -/** - eoParameterLoader is an abstract class that can be used as a base for your own - parameter loading and saving. The command line parser eoParser is derived from - this class. +/** Parameter saving and loading + +eoParameterLoader is an abstract class that can be used as a base for your own +parameter loading and saving. The command line parser eoParser is derived from +this class. */ class eoParameterLoader { @@ -49,11 +44,10 @@ public : /** Need a virtual destructor */ virtual ~eoParameterLoader(); - /** - * processParam is used to register a parameter and set its value if it is known - * - * @param param the parameter to process - * @param section the section where this parameter belongs + /** Register a parameter and set its value if it is known + + @param param the parameter to process + @param section the section where this parameter belongs */ virtual void processParam(eoParam& param, std::string section = "") = 0; @@ -147,11 +141,12 @@ public: std::string ProgramName() { return programName; } - /** - * checks if _param has been actually entered by the user - */ - virtual bool isItThere(eoParam& _param) const - { return getValue(_param).first; } + /** Has param been entered by user? + + Checks if _param has been actually entered by the user + */ + virtual bool isItThere(eoParam& _param) const + { return getValue(_param).first; } /** * get a handle on a param from its longName @@ -278,4 +273,15 @@ private: }; -#endif + +#endif // EO_PARSER_H + + + +// Local Variables: +// coding: iso-8859-1 +// mode:C++ +// c-file-style: "Stroustrup" +// comment-column: 35 +// fill-column: 80 +// End: diff --git a/eo/test/Makefile.am b/eo/test/Makefile.am index 34ad1e61..bf0a37bf 100644 --- a/eo/test/Makefile.am +++ b/eo/test/Makefile.am @@ -54,6 +54,9 @@ EXTRA_DIST = run_tests # extra flags for specific targets t_eoVirus_CXXFLAGS = $(AM_CXXFLAGS) -I$(top_srcdir)/contrib +t_MGE_CXXFLAGS = -I$(top_srcdir)/contrib/MGE +t_MGE1bit_CXXFLAGS = -I$(top_srcdir)/contrib/MGE +t_MGE_control_CXXFLAGS = -I$(top_srcdir)/contrib/MGE # Specify source-files, # otherwise automake/make looks for C sources @@ -63,11 +66,8 @@ t_eofitness_SOURCES = t-eofitness.cpp t_eoFitnessAssembledEA_SOURCES = t-eoFitnessAssembledEA.cpp t_eobin_SOURCES = t-eobin.cpp t_eoVirus_SOURCES = t-eoVirus.cpp -t_MGE1bit_CXXFLAGS = -I$(top_srcdir)/contrib/MGE t_MGE1bit_SOURCES = t-MGE1bit.cpp -t_MGE_CXXFLAGS = -I$(top_srcdir)/contrib/MGE t_MGE_SOURCES = t-MGE.cpp -t_MGE_control_CXXFLAGS = -I$(top_srcdir)/contrib/MGE t_MGE_control_SOURCES = t-MGE-control.cpp t_eoStateAndParser_SOURCES = t-eoStateAndParser.cpp t_eoCheckpointing_SOURCES = t-eoCheckpointing.cpp diff --git a/eo/test/t-eoESAll.cpp b/eo/test/t-eoESAll.cpp index 8d728ec4..07949404 100644 --- a/eo/test/t-eoESAll.cpp +++ b/eo/test/t-eoESAll.cpp @@ -24,62 +24,63 @@ using namespace std; #include "real_value.h" // the sphere fitness -// Now the main -/////////////// +// Now the main +/////////////// typedef eoMinimizingFitness FitT; template void runAlgorithm(EOT, eoParser& _parser, eoState& _state); - -int main_function(int argc, char *argv[]) + +int main_function(int argc, char *argv[]) { - // Create the command-line parser - eoParser parser(argc, argv); // for user-parameter reading - - eoState state; // keeps all things allocated - - - eoValueParam& simpleParam = parser.createParam(true, "Isotropic", "Isotropic self-adaptive mutation", 'i', "ES mutation"); - eoValueParam& stdevsParam = parser.createParam(false, "Stdev", "One self-adaptive stDev per variable", 's', "ES mutation"); - eoValueParam& corrParam = parser.createParam(false, "Correl", "Use correlated mutations", 'c', "ES mutation"); - + // Create the command-line parser + eoParser parser(argc, argv); // for user-parameter reading + eoState state; // keeps all things allocated + eoValueParam& simpleParam = parser.getORcreateParam(true, "Isotropic", + "Isotropic self-adaptive mutation", + 'i', "ES mutation"); + eoValueParam& stdevsParam = parser.getORcreateParam(false, "Stdev", + "One self-adaptive stDev per variable", + 's', "ES mutation"); + eoValueParam& corrParam = parser.getORcreateParam(false, "Correl", + "Use correlated mutations", + 'c', "ES mutation"); // Run the appropriate algorithm if (simpleParam.value() == false) { - std::cout << "Using eoReal" << std::endl; - runAlgorithm(eoReal(), parser, state); + std::cout << "Using eoReal" << std::endl; + runAlgorithm(eoReal(), parser, state); } else if (stdevsParam.value() == false) { - std::cout << "Using eoEsSimple" << std::endl; - runAlgorithm(eoEsSimple(), parser, state); + std::cout << "Using eoEsSimple" << std::endl; + runAlgorithm(eoEsSimple(), parser, state); } else if (corrParam.value() == false) { - std::cout << "Using eoEsStdev" << std::endl; - runAlgorithm(eoEsStdev(), parser, state); + std::cout << "Using eoEsStdev" << std::endl; + runAlgorithm(eoEsStdev(), parser, state); } - else + else { - std::cout << "Using eoEsFull" << std::endl; - runAlgorithm(eoEsFull(), parser, state); + std::cout << "Using eoEsFull" << std::endl; + runAlgorithm(eoEsFull(), parser, state); } - - return 0; + return 0; } + + // A main that catches the exceptions - int main(int argc, char **argv) { #ifdef _MSC_VER - // rng.reseed(42); + // rng.reseed(42); int flag = _CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF); - flag |= _CRTDBG_LEAK_CHECK_DF; + flag |= _CRTDBG_LEAK_CHECK_DF; _CrtSetDbgFlag(flag); -// _CrtSetBreakAlloc(100); + // _CrtSetBreakAlloc(100); #endif - try { main_function(argc, argv); @@ -88,61 +89,62 @@ int main(int argc, char **argv) { std::cout << "Exception: " << e.what() << '\n'; } - } + + /** The templatized main (sort of) - * quite similar to the main of other genotypes - * (e.g. t-eoReal and t-eoGA in test dir) - */ + +quite similar to the main of other genotypes (e.g. t-eoReal and t-eoGA +in test dir) +*/ template void runAlgorithm(EOT, eoParser& _parser, eoState& _state) { - typedef typename EOT::Fitness FitT; + typedef typename EOT::Fitness FitT; - ///// FIRST, problem or representation dependent stuff - ////////////////////////////////////////////////////// + ///// FIRST, problem or representation dependent stuff + ////////////////////////////////////////////////////// - // The evaluation fn - encapsulated into an eval counter for output - eoEvalFuncPtr&> - mainEval( real_value ); - eoEvalFuncCounter eval(mainEval); + // The evaluation fn - encapsulated into an eval counter for output + eoEvalFuncPtr&> mainEval( real_value ); + eoEvalFuncCounter eval(mainEval); - // the genotype - through a genotype initializer - eoRealInitBounded& init = make_genotype(_parser, _state, EOT()); + // the genotype - through a genotype initializer + eoRealInitBounded& init = make_genotype(_parser, _state, EOT()); - // Build the variation operator (any seq/prop construct) - eoGenOp& op = make_op(_parser, _state, init); + // Build the variation operator (any seq/prop construct) + eoGenOp& op = make_op(_parser, _state, init); - //// Now the representation-independent things - ////////////////////////////////////////////// + //// 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); + // 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); + // 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); + ///// End of construction of the algorith + ///////////////////////////////////////// + // to be called AFTER all parameters have been read!!! + make_help(_parser); - //// GO - /////// - std::cout << "Initial Population\n"; - pop.sortedPrintOn(std::cout); - std::cout << std::endl; + //// GO + /////// + std::cout << "Initial Population\n"; + pop.sortedPrintOn(std::cout); + std::cout << std::endl; - run_ea(ga, pop); // run the ga + run_ea(ga, pop); // run the ga - std::cout << "Final Population\n"; - pop.sortedPrintOn(std::cout); - std::cout << std::endl; + std::cout << "Final Population\n"; + pop.sortedPrintOn(std::cout); + std::cout << std::endl; }