00001
00002
00003 #ifdef _MSC_VER
00004 #pragma warning(disable:4786)
00005 #endif
00006
00007 #include <algorithm>
00008 #include <string>
00009 #include <iostream>
00010 #include <iterator>
00011 #include <stdexcept>
00012 #include <time.h>
00013
00014 using namespace std;
00015
00016 #include <eo>
00017
00018
00019 #include <es/make_es.h>
00020
00021 #include "real_value.h"
00022
00023
00025 typedef eoMinimizingFitness FitT;
00026
00027 template <class EOT>
00028 void runAlgorithm(EOT, eoParser& _parser, eoState& _state);
00029
00030 int main_function(int argc, char *argv[])
00031 {
00032
00033 eoParser parser(argc, argv);
00034
00035 eoState state;
00036
00037
00038 eoValueParam<bool>& simpleParam = parser.createParam(true, "Isotropic", "Isotropic self-adaptive mutation", 'i', "ES mutation");
00039 eoValueParam<bool>& stdevsParam = parser.createParam(false, "Stdev", "One self-adaptive stDev per variable", 's', "ES mutation");
00040 eoValueParam<bool>& corrParam = parser.createParam(false, "Correl", "Use correlated mutations", 'c', "ES mutation");
00041
00042
00043 if (simpleParam.value() == false)
00044 {
00045 cout << "Using eoReal" << endl;
00046 runAlgorithm(eoReal<FitT>(), parser, state);
00047 }
00048 else if (stdevsParam.value() == false)
00049 {
00050 cout << "Using eoEsSimple" << endl;
00051 runAlgorithm(eoEsSimple<FitT>(), parser, state);
00052 }
00053 else if (corrParam.value() == false)
00054 {
00055 cout << "Using eoEsStdev" << endl;
00056 runAlgorithm(eoEsStdev<FitT>(), parser, state);
00057 }
00058 else
00059 {
00060 cout << "Using eoEsFull" << endl;
00061 runAlgorithm(eoEsFull<FitT>(), parser, state);
00062 }
00063
00064 return 0;
00065 }
00066
00067
00068
00069 int main(int argc, char **argv)
00070 {
00071 try
00072 {
00073 main_function(argc, argv);
00074 }
00075 catch(exception& e)
00076 {
00077 cout << "Exception: " << e.what() << '\n';
00078 }
00079
00080 return 1;
00081 }
00082
00087 template <class EOT>
00088 void runAlgorithm(EOT, eoParser& _parser, eoState& _state)
00089 {
00090 typedef typename EOT::Fitness FitT;
00091
00094
00095
00096 eoEvalFuncPtr<EOT, double, const std::vector<double>&>
00097 mainEval( real_value );
00098 eoEvalFuncCounter<EOT> eval(mainEval);
00099
00100
00101 eoRealInitBounded<EOT>& init = make_genotype(_parser, _state, EOT());
00102
00103
00104 eoGenOp<EOT>& op = make_op(_parser, _state, init);
00105
00108
00109
00110
00111 eoPop<EOT>& pop = make_pop(_parser, _state, init);
00112 apply<EOT>(eval, pop);
00113
00114
00115 eoContinue<EOT> & term = make_continue(_parser, _state, eval);
00116
00117 eoCheckPoint<EOT> & checkpoint = make_checkpoint(_parser, _state, eval, term);
00118
00119 eoAlgo<EOT>& ga = make_algo_scalar(_parser, _state, eval, checkpoint, op);
00120
00123
00124 make_help(_parser);
00125
00128 cout << "Initial Population\n";
00129 pop.sortedPrintOn(cout);
00130 cout << endl;
00131
00132 run_ea(ga, pop);
00133
00134 cout << "Final Population\n";
00135 pop.sortedPrintOn(cout);
00136 cout << endl;
00137 }