00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef _make_op_h
00028 #define _make_op_h
00029
00030
00031 #include <eoOp.h>
00032 #include <eoGenOp.h>
00033 #include <eoCloneOps.h>
00034 #include <eoOpContainer.h>
00035
00036 #include <eoProportionalCombinedOp.h>
00037
00038
00039 #include <ga/eoBit.h>
00040 #include <ga/eoBitOp.h>
00041
00042 #include <utils/eoParser.h>
00043 #include <utils/eoState.h>
00044
00045
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068 template <class EOT>
00069 eoGenOp<EOT> & do_make_op(eoParser& _parser, eoState& _state, eoInit<EOT>& _init)
00070 {
00071
00072
00073
00074
00075 eoValueParam<std::string>& operatorParam = _parser.createParam(std::string("SGA"), "operator", "Description of the operator (SGA only now)", 'o', "Variation Operators");
00076
00077 if (operatorParam.value() != std::string("SGA"))
00078 throw std::runtime_error("Only SGA-like operator available right now\n");
00079
00080
00081
00082
00083
00084
00085
00086 eoValueParam<double>& pCrossParam = _parser.createParam(0.6, "pCross", "Probability of Crossover", 'C', "Variation Operators" );
00087
00088 if ( (pCrossParam.value() < 0) || (pCrossParam.value() > 1) )
00089 throw std::runtime_error("Invalid pCross");
00090
00091 eoValueParam<double>& pMutParam = _parser.createParam(0.1, "pMut", "Probability of Mutation", 'M', "Variation Operators" );
00092
00093 if ( (pMutParam.value() < 0) || (pMutParam.value() > 1) )
00094 throw std::runtime_error("Invalid pMut");
00095
00096
00098
00099 eoValueParam<double>& onePointRateParam = _parser.createParam(double(1.0), "onePointRate", "Relative rate for one point crossover", '1', "Variation Operators" );
00100
00101 if ( (onePointRateParam.value() < 0) )
00102 throw std::runtime_error("Invalid onePointRate");
00103
00104 eoValueParam<double>& twoPointsRateParam = _parser.createParam(double(1.0), "twoPointRate", "Relative rate for two point crossover", '2', "Variation Operators" );
00105
00106 if ( (twoPointsRateParam.value() < 0) )
00107 throw std::runtime_error("Invalid twoPointsRate");
00108
00109 eoValueParam<double>& uRateParam = _parser.createParam(double(2.0), "uRate", "Relative rate for uniform crossover", 'U', "Variation Operators" );
00110
00111 if ( (uRateParam.value() < 0) )
00112 throw std::runtime_error("Invalid uRate");
00113
00114
00115 bool bCross = true;
00116 if (onePointRateParam.value()+twoPointsRateParam.value()+uRateParam.value()==0)
00117 {
00118 std::cerr << "Warning: no crossover" << std::endl;
00119 bCross = false;
00120 }
00121
00122
00123 eoPropCombinedQuadOp<EOT> *ptCombinedQuadOp = NULL;
00124 eoQuadOp<EOT> *ptQuad = NULL;
00125
00126 ptQuad = new eo1PtBitXover<EOT>;
00127 _state.storeFunctor(ptQuad);
00128 ptCombinedQuadOp = new eoPropCombinedQuadOp<EOT>(*ptQuad, onePointRateParam.value());
00129
00130
00131 ptQuad = new eoUBitXover<EOT>;
00132 _state.storeFunctor(ptQuad);
00133 ptCombinedQuadOp->add(*ptQuad, uRateParam.value());
00134
00135
00136 ptQuad = new eoNPtsBitXover<EOT>;
00137 _state.storeFunctor(ptQuad);
00138 ptCombinedQuadOp->add(*ptQuad, twoPointsRateParam.value());
00139
00140
00141 _state.storeFunctor(ptCombinedQuadOp);
00142
00143
00145
00146 eoValueParam<double> & pMutPerBitParam = _parser.createParam(0.01, "pMutPerBit", "Probability of flipping 1 bit in bit-flip mutation", 'b', "Variation Operators" );
00147
00148 if ( (pMutPerBitParam.value() < 0) || (pMutPerBitParam.value() > 0.5) )
00149 throw std::runtime_error("Invalid pMutPerBit");
00150
00151 eoValueParam<double> & bitFlipRateParam = _parser.createParam(0.01, "bitFlipRate", "Relative rate for bit-flip mutation", 's', "Variation Operators" );
00152
00153 if ( (bitFlipRateParam.value() < 0) )
00154 throw std::runtime_error("Invalid bitFlipRate");
00155
00156 eoValueParam<double> & oneBitRateParam = _parser.createParam(0.01, "oneBitRate", "Relative rate for deterministic bit-flip mutation", 'd', "Variation Operators" );
00157
00158 if ( (oneBitRateParam.value() < 0) )
00159 throw std::runtime_error("Invalid oneBitRate");
00160
00161
00162 bool bMut = true;
00163 if (bitFlipRateParam.value()+oneBitRateParam.value()==0)
00164 {
00165 std::cerr << "Warning: no mutation" << std::endl;
00166 bMut = false;
00167 }
00168
00169
00170 eoPropCombinedMonOp<EOT> *ptCombinedMonOp = NULL;
00171 eoMonOp<EOT> *ptMon = NULL;
00172
00173
00174 ptMon = new eoBitMutation<EOT>(pMutPerBitParam.value());
00175 _state.storeFunctor(ptMon);
00176
00177 ptCombinedMonOp = new eoPropCombinedMonOp<EOT>(*ptMon, bitFlipRateParam.value());
00178
00179
00180 ptMon = new eoDetBitFlip<EOT>;
00181 _state.storeFunctor(ptMon);
00182 ptCombinedMonOp->add(*ptMon, oneBitRateParam.value());
00183
00184 _state.storeFunctor(ptCombinedMonOp);
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195 eoProportionalOp<EOT> * cross = new eoProportionalOp<EOT> ;
00196 _state.storeFunctor(cross);
00197 ptQuad = new eoQuadCloneOp<EOT>;
00198 _state.storeFunctor(ptQuad);
00199 cross->add(*ptCombinedQuadOp, pCrossParam.value());
00200 cross->add(*ptQuad, 1-pCrossParam.value());
00201
00202
00203 eoSequentialOp<EOT> *op = new eoSequentialOp<EOT>;
00204 _state.storeFunctor(op);
00205 op->add(*cross, 1.0);
00206 op->add(*ptCombinedMonOp, pMutParam.value());
00207
00208
00209 return *op;
00210 }
00211 #endif