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 eoParam *vecSigmaParam = _parser.getParamWithLongName("vecSigmaInit");
00086 if(vecSigmaParam) {
00087 eoValueParam<std::vector<double> >& vecSigmaParam
00088 = _parser.getORcreateParam(std::vector<double>(vecSize.value(), 0.3),
00089 "vecSigmaInit", "Initial value for Sigma(s)",
00090 'V',"Genotype Initialization");
00091 init = new eoEsChromInit<EOT>(boundsParam.value(), vecSigmaParam.value());
00092 } else {
00093
00094
00095 eoValueParam<std::string>& sigmaParam
00096 = _parser.getORcreateParam(std::string("0.3"), "sigmaInit",
00097 "Initial value for Sigmas "
00098 "(with '%' scaled by the range of each variable)",
00099 's',"Genotype Initialization");
00100
00101 bool to_scale = false;
00102 size_t pos = sigmaParam.value().find('%');
00103 if(pos < sigmaParam.value().size())
00104 {
00105
00106 to_scale = true;
00107 sigmaParam.value().resize(pos);
00108 }
00109 std::istringstream is(sigmaParam.value());
00110 double sigma;
00111 is >> sigma;
00112
00113 if(sigma < 0)
00114 throw std::runtime_error("Negative sigma in make_genotype");
00115 init = new eoEsChromInit<EOT>(boundsParam.value(), sigma, to_scale);
00116
00117 _parser.getORcreateParam(std::vector<double>(vecSize.value(), 0.3),
00118 "vecSigmaInit", "Initial value for Sigma(s)",
00119 'V',"Genotype Initialization");
00120 }
00121
00122 _state.storeFunctor(init);
00123 return *init;
00124 }
00125
00126 #endif // EO_make_genotype_h
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136