// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- //----------------------------------------------------------------------------- // make_op.h - the real-valued version // (c) Maarten Keijzer, Marc Schoenauer and GeNeura Team, 2001 /* This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Contact: todos@geneura.ugr.es, http://geneura.ugr.es Marc.Schoenauer@polytechnique.fr mkeijzer@dhi.dk */ //----------------------------------------------------------------------------- #ifndef _make_op_h #define _make_op_h // the operators #include #include #include #include // combinations of simple eoOps (eoMonOp and eoQuadOp) #include // the specialized Real stuff #include #include #include #include #include #include #include // also need the parser and param includes #include #include /* * This function builds the operators that will be applied to the eoReal * * It uses a parser (to get user parameters) and a state (to store the memory) * the last argument is an individual, needed for 2 reasons * it disambiguates the call after instanciations * some operator might need some private information about the indis * * This is why the template is the complete EOT even though only the fitness * is actually templatized here: the following only applies to bitstrings * * Note : the last parameter is an eoInit: if some operator needs some info * about the gneotypes, the init has it all (e.g. bounds, ...) * Simply do * EOT myEO; * _init(myEO); * and myEO is then an ACTUAL object */ template eoGenOp & do_make_op(eoParameterLoader& _parser, eoState& _state, eoRealInitBounded& _init) { // get vector size unsigned vecSize = _init.size(); // First, decide whether the objective variables are bounded eoValueParam& boundsParam = _parser.createParam(eoRealVectorBounds(vecSize,eoDummyRealNoBounds), "objectBounds", "Bounds for variables", 'B', "Variation Operators"); // now we read Pcross and Pmut, eoValueParam& operatorParam = _parser.createParam(string("SGA"), "operator", "Description of the operator (SGA only now)", 'o', "Variation Operators"); if (operatorParam.value() != string("SGA")) throw runtime_error("Sorry, only SGA-like operator available right now\n"); // now we read Pcross and Pmut, // and create the eoGenOp that is exactly // crossover with pcross + mutation with pmut eoValueParam& pCrossParam = _parser.createParam(1.0, "pCross", "Probability of Crossover", 'C', "Variation Operators" ); // minimum check if ( (pCrossParam.value() < 0) || (pCrossParam.value() > 1) ) throw runtime_error("Invalid pCross"); eoValueParam& pMutParam = _parser.createParam(1.0, "pMut", "Probability of Mutation", 'M', "Variation Operators" ); // minimum check if ( (pMutParam.value() < 0) || (pMutParam.value() > 1) ) throw runtime_error("Invalid pMut"); // crossover ///////////// // ES crossover eoValueParam& crossTypeParam = _parser.createParam(string("global"), "crossType", "Type of ES recombination (global or standard)", 'C', "Variation Operators"); eoValueParam& crossObjParam = _parser.createParam(string("discrete"), "crossObj", "Recombination of object variables (discrete or intermediate)", 'O', "Variation Operators"); eoValueParam& crossStdevParam = _parser.createParam(string("intermediate"), "crossStdev", "Recombination of mutation strategy parameters (intermediate or discrete)", 'S', "Variation Operators"); // The pointers: first the atom Xover eoBinOp *ptObjAtomCross = NULL; eoBinOp *ptStdevAtomCross = NULL; // then the global one eoGenOp *ptCross; // check for the atom Xovers if (crossObjParam.value() == string("discrete")) ptObjAtomCross = new eoRealAtomExchange; else if (crossObjParam.value() == string("intermediate")) ptObjAtomCross = new eoRealAtomExchange; else throw runtime_error("Invalid Object variable crossover type"); if (crossStdevParam.value() == string("discrete")) ptStdevAtomCross = new eoRealAtomExchange; else if (crossStdevParam.value() == string("intermediate")) ptStdevAtomCross = new eoRealAtomExchange; else throw runtime_error("Invalid mutation strategy parameter crossover type"); // and build the indi Xover if (crossTypeParam.value() == string("global")) ptCross = new eoEsGlobalXover(*ptObjAtomCross, *ptStdevAtomCross); else if (crossTypeParam.value() == string("standard")) ptCross = new eoEsLocalXover(*ptObjAtomCross, *ptStdevAtomCross); else throw runtime_error("Invalide Object variable crossover type"); // now that everything is OK, DON'T FORGET TO STORE MEMORY _state.storeFunctor(ptObjAtomCross); _state.storeFunctor(ptStdevAtomCross); _state.storeFunctor(ptCross); // mutation ///////////// // Ok, time to set up the self-adaptive mutation // Proxy for the mutation parameters eoEsMutationInit mutateInit(_parser, "Variation Operators"); eoEsMutate * ptMon = new eoEsMutate(mutateInit, boundsParam.value()); _state.storeFunctor(ptMon); // encapsulate into an eoGenop eoMonGenOp * op = new eoMonGenOp(*ptMon); _state.storeFunctor(op); // that's it! return *op; } #endif