00001
00024 #ifndef EO_make_genotype_h
00025 #define EO_make_genotype_h
00026
00027 #include <iostream>
00028 #include <sstream>
00029 #include <vector>
00030
00031 #include "es/eoReal.h"
00032 #include "es/eoEsChromInit.h"
00033 #include "utils/eoParser.h"
00034 #include "utils/eoRealVectorBounds.h"
00035 #include "utils/eoState.h"
00036
00037
00060 template <class EOT>
00061 eoEsChromInit<EOT> & do_make_genotype(eoParser& _parser, eoState& _state, EOT)
00062 {
00063
00064 typedef typename EOT::Fitness FitT;
00065 eoEsChromInit<EOT> *init;
00066
00067
00068 eoValueParam<unsigned>& vecSize
00069 = _parser.getORcreateParam(unsigned(10), "vecSize",
00070 "The number of variables ",
00071 'n', "Genotype Initialization");
00072
00073 eoValueParam<eoRealVectorBounds>& boundsParam
00074 = _parser.getORcreateParam(eoRealVectorBounds(vecSize.value(), -1, 1),
00075 "initBounds",
00076 "Bounds for initialization (MUST be bounded)",
00077 'B', "Genotype Initialization");
00078
00079
00080 eoValueParam<std::string>& sigmaParam
00081 = _parser.getORcreateParam(std::string("0.3"), "sigmaInit",
00082 "Initial value for Sigmas (with a '%' -> scaled by the range of each variable)",
00083 's', "Genotype Initialization");
00084
00085 bool to_scale = false;
00086 size_t pos = sigmaParam.value().find('%');
00087 if(pos < sigmaParam.value().size()) {
00088
00089 to_scale = true;
00090 sigmaParam.value().resize(pos);
00091 }
00092 std::istringstream is(sigmaParam.value());
00093 double sigma;
00094 is >> sigma;
00095
00096 if(sigma < 0)
00097 throw std::runtime_error("Negative sigma in make_genotype");
00098 if(to_scale)
00099 init = new eoEsChromInit<EOT>(boundsParam.value(), sigma, to_scale);
00100 else {
00101
00102 eoValueParam<std::vector<double> >& vecSigmaParam
00103 = _parser.getORcreateParam(std::vector<double>(vecSize.value(), sigma), "vecSigmaInit",
00104 "Initial value for Sigmas (only used when initSigma is not scaled)",
00105 'S', "Genotype Initialization");
00106 init = new eoEsChromInit<EOT>(boundsParam.value(), vecSigmaParam.value());
00107 }
00108
00109 _state.storeFunctor(init);
00110 return *init;
00111 }
00112
00113 #endif // EO_make_genotype_h
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123