00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef EO_make_op_h
00024 #define EO_make_op_h
00025
00026
00027 #include <eoOp.h>
00028 #include <eoGenOp.h>
00029 #include <eoCloneOps.h>
00030 #include <eoOpContainer.h>
00031
00032 #include <eoProportionalCombinedOp.h>
00033
00034
00035 #include <es/eoReal.h>
00036 #include <es/eoRealAtomXover.h>
00037 #include <es/eoEsChromInit.h>
00038 #include <es/eoEsMutationInit.h>
00039 #include <es/eoEsMutate.h>
00040 #include <es/eoEsGlobalXover.h>
00041 #include <es/eoEsStandardXover.h>
00042
00043 #include <utils/eoParser.h>
00044 #include <utils/eoState.h>
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066 template <class EOT>
00067 eoGenOp<EOT> & do_make_op(eoParser& _parser, eoState& _state, eoRealInitBounded<EOT>& _init)
00068 {
00069
00070 unsigned vecSize = _init.size();
00071
00072
00073 eoValueParam<eoRealVectorBounds>& boundsParam
00074 = _parser.getORcreateParam(eoRealVectorBounds(vecSize,eoDummyRealNoBounds),
00075 "objectBounds", "Bounds for variables",
00076 'B', "Variation Operators");
00077
00078 std::cerr << boundsParam.value() << std::endl;
00079
00080
00081 eoValueParam<std::string>& operatorParam
00082 = _parser.getORcreateParam(std::string("SGA"), "operator",
00083 "Description of the operator (SGA only now)",
00084 'o', "Variation Operators");
00085
00086 if (operatorParam.value() != std::string("SGA"))
00087 throw std::runtime_error("Sorry, only SGA-like operator available right now\n");
00088
00089
00090
00091
00092
00093 eoValueParam<double>& pCrossParam
00094 = _parser.getORcreateParam(1.0, "pCross", "Probability of Crossover",
00095 'C', "Variation Operators" );
00096
00097 if ( (pCrossParam.value() < 0) || (pCrossParam.value() > 1) )
00098 throw std::runtime_error("Invalid pCross");
00099
00100 eoValueParam<double>& pMutParam
00101 = _parser.getORcreateParam(1.0, "pMut", "Probability of Mutation",
00102 'M', "Variation Operators" );
00103
00104 if ( (pMutParam.value() < 0) || (pMutParam.value() > 1) )
00105 throw std::runtime_error("Invalid pMut");
00106
00107
00108
00110
00111 eoValueParam<std::string>& crossTypeParam
00112 = _parser.getORcreateParam(std::string("global"), "crossType",
00113 "Type of ES recombination (global or standard)",
00114 'C', "Variation Operators");
00115
00116 eoValueParam<std::string>& crossObjParam
00117 = _parser.getORcreateParam(std::string("discrete"), "crossObj",
00118 "Recombination of object variables (discrete, intermediate or none)",
00119 'O', "Variation Operators");
00120 eoValueParam<std::string>& crossStdevParam
00121 = _parser.getORcreateParam(std::string("intermediate"), "crossStdev",
00122 "Recombination of mutation strategy parameters "
00123 "(intermediate, discrete or none)",
00124 'S', "Variation Operators");
00125
00126
00127 eoBinOp<double> *ptObjAtomCross = NULL;
00128 eoBinOp<double> *ptStdevAtomCross = NULL;
00129
00130 eoGenOp<EOT> *ptCross;
00131
00132
00133 if (crossObjParam.value() == std::string("discrete"))
00134 ptObjAtomCross = new eoDoubleExchange;
00135 else if (crossObjParam.value() == std::string("intermediate"))
00136 ptObjAtomCross = new eoDoubleIntermediate;
00137 else if (crossObjParam.value() == std::string("none"))
00138 ptObjAtomCross = new eoBinCloneOp<double>;
00139 else throw std::runtime_error("Invalid Object variable crossover type");
00140
00141 if (crossStdevParam.value() == std::string("discrete"))
00142 ptStdevAtomCross = new eoDoubleExchange;
00143 else if (crossStdevParam.value() == std::string("intermediate"))
00144 ptStdevAtomCross = new eoDoubleIntermediate;
00145 else if (crossStdevParam.value() == std::string("none"))
00146 ptStdevAtomCross = new eoBinCloneOp<double>;
00147 else throw std::runtime_error("Invalid mutation strategy parameter crossover type");
00148
00149
00150 if (crossTypeParam.value() == std::string("global"))
00151 ptCross = new eoEsGlobalXover<EOT>(*ptObjAtomCross, *ptStdevAtomCross);
00152 else if (crossTypeParam.value() == std::string("standard"))
00153 {
00154 eoBinOp<EOT> & crossTmp = _state.storeFunctor(
00155 new eoEsStandardXover<EOT>(*ptObjAtomCross, *ptStdevAtomCross)
00156 );
00157 ptCross = new eoBinGenOp<EOT>(crossTmp);
00158 }
00159 else throw std::runtime_error("Invalide Object variable crossover type");
00160
00161
00162 _state.storeFunctor(ptObjAtomCross);
00163 _state.storeFunctor(ptStdevAtomCross);
00164 _state.storeFunctor(ptCross);
00165
00166
00168
00169
00170
00171 eoEsMutationInit mutateInit(_parser, "Variation Operators");
00172
00173 eoEsMutate<EOT> & mut = _state.storeFunctor(
00174 new eoEsMutate<EOT>(mutateInit, boundsParam.value()));
00175
00176
00177
00178
00179
00180 eoSequentialOp<EOT> & op = _state.storeFunctor(new eoSequentialOp<EOT>);
00181 op.add(*ptCross, pCrossParam.value());
00182 op.add(mut, pMutParam.value());
00183
00184
00185 return op;
00186 }
00187 #endif // EO_make_op_h
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197