make_genotype_real.h

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     // the fitness type
00064     typedef typename EOT::Fitness FitT;
00065     eoEsChromInit<EOT> *init;
00066 
00067     // for eoReal, only thing needed is the size - but might have been created elswhere ...
00068     eoValueParam<unsigned>& vecSize
00069         = _parser.getORcreateParam(unsigned(10), "vecSize",
00070                                    "The number of variables ",
00071                                    'n',"Genotype Initialization");
00072     // to build an eoReal Initializer, we need bounds: [-1,1] by default
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     // now some initial value for sigmas - even if useless?
00079     // should be used in Normal mutation
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     // check if there is a vecSigmaInit
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         // now some initial value for sigmas - even if useless?
00094         // should be used in Normal mutation
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         // check for %
00101         bool to_scale = false;
00102         size_t pos =  sigmaParam.value().find('%');
00103         if(pos < sigmaParam.value().size())
00104         {
00105             //  found a % - use scaling and get rid of '%'
00106             to_scale = true;
00107             sigmaParam.value().resize(pos);
00108         }
00109         std::istringstream is(sigmaParam.value());
00110         double sigma;
00111         is >> sigma;
00112         // minimum check
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         // define parameter
00117         _parser.getORcreateParam(std::vector<double>(vecSize.value(), 0.3),
00118                                  "vecSigmaInit", "Initial value for Sigma(s)",
00119                                  'V',"Genotype Initialization");
00120     }
00121     // store in state
00122     _state.storeFunctor(init);
00123     return *init;
00124 }
00125 
00126 #endif // EO_make_genotype_h
00127 
00128 
00129 
00130 // Local Variables:
00131 // coding: iso-8859-1
00132 // mode:C++
00133 // c-file-style: "Stroustrup"
00134 // comment-column: 35
00135 // fill-column: 80
00136 // End:

Generated on Thu Oct 19 05:06:40 2006 for EO by  doxygen 1.3.9.1