diff --git a/eo/test/t-eoESAll.cpp b/eo/test/t-eoESAll.cpp new file mode 100644 index 000000000..f673eaf78 --- /dev/null +++ b/eo/test/t-eoESAll.cpp @@ -0,0 +1,145 @@ +// Program to test several EO-ES features + +#ifdef _MSC_VER +#pragma warning(disable:4786) +#endif + +#include +#include +#include +#include +#include +#include + +using namespace std; + +#include + +// representation specific +#include + +#include "real_value.h" // the sphere fitness + +// Now the main +/////////////// +typedef eoMinimizingFitness FitT; + +template +void runAlgorithm(EOT, eoParser& _parser, eoState& _state); + +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"); + + // Run the appropriate algorithm + if (simpleParam.value() == false) + { + cout << "Using eoReal" << endl; + runAlgorithm(eoReal(), parser, state); + } + else if (stdevsParam.value() == false) + { + cout << "Using eoEsSimple" << endl; + runAlgorithm(eoEsSimple(), parser, state); + } + else if (corrParam.value() == false) + { + cout << "Using eoEsStdev" << endl; + runAlgorithm(eoEsStdev(), parser, state); + } + else + { + cout << "Using eoEsFull" << endl; + runAlgorithm(eoEsFull(), parser, state); + } + + return 0; +} + +// A main that catches the exceptions + +int main(int argc, char **argv) +{ +#ifdef _MSC_VER + // rng.reseed(42); + int flag = _CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF); + flag |= _CRTDBG_LEAK_CHECK_DF; + _CrtSetDbgFlag(flag); +// _CrtSetBreakAlloc(100); +#endif + + try + { + main_function(argc, argv); + } + catch(exception& e) + { + cout << "Exception: " << e.what() << '\n'; + } + + return 1; +} + +/** The templatized main (sort of) + * 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; + + ///// 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 + eoRealInitBounded& init = make_genotype(_parser, _state, EOT()); + + // 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; +}