📄 make_op_onemax.html
字号:
<!doctype html public "-//w3c//dtd html 4.0 transitional//en"><html><head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <meta name="GENERATOR" content="Mozilla/4.78 [en] (X11; U; Linux 2.4.7-10 i686) [Netscape]"> <title>Templates/make_op_OneMax.h</title></head><body text="#000000" bgcolor="#C3C2B4" link="#0000EE" vlink="#551A8B" alink="#FF0000"><a href="eoLesson5.html">Back to Lesson 5</a>- <a href="eoTutorial.html">Tutorial main page </a>- <a href="eoTopDown.html">Top-Downpage</a> - <a href="eoBottomUp.html">Bottom-up page</a> - <a href="eoProgramming.html">Programminghints</a> - <font face="Arial,Helvetica"><a href="doc/html/index.html">EOdocumentation</a></font><br><hr WIDTH="100%"><!-- -------------- End of header ------------------ --><!-- ----------------------------------------------- --><center><h1><font color="#FF0000">Templates/make_op_OneMax.h</font></h1></center>The places where you have to put some code are on <b><font color="#FF6666">pinkbackground</font></b>.. Only the the <a href="eoTutorial.html#colors">charactercolors have the usual meaning</a>.<p><a NAME="start"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE ><tr NOSAVE><td NOSAVE><tt><font color="#993300">// -*- mode: c++; c-indent-level:4; c++-member-init-indent: 8; comment-column: 35; -*-</font></tt><p><tt><font color="#993300">//-----------------------------------------------------------------------------</font></tt><br><tt><font color="#993300">// make_op_OneMax.h</font></tt><br><tt><font color="#993300">// (c) Marc Schoenauer, Maarten Keijzer andGeNeura Team, 2001</font></tt><br><tt><font color="#993300">/* </font></tt><br><tt><font color="#993300"> This library isfree software; you can redistribute it and/or</font></tt><br><tt><font color="#993300"> modify it underthe terms of the GNU Lesser General Public</font></tt><br><tt><font color="#993300"> License as publishedby the Free Software Foundation; either</font></tt><br><tt><font color="#993300"> version 2 of theLicense, or (at your option) any later version.</font></tt><br><tt><font color="#993300"> This library isdistributed in the hope that it will be useful,</font></tt><br><tt><font color="#993300"> but WITHOUT ANYWARRANTY; without even the implied warranty of</font></tt><br><tt><font color="#993300"> MERCHANTABILITYor FITNESS FOR A PARTICULAR PURPOSE. See the GNU</font></tt><br><tt><font color="#993300"> Lesser General PublicLicense for more details.</font></tt><br><tt><font color="#993300"> You should havereceived a copy of the GNU Lesser General Public</font></tt><br><tt><font color="#993300"> License along withthis library; if not, write to the Free Software</font></tt><br><tt><font color="#993300"> Foundation, Inc.,59 Temple Place, Suite 330, Boston, MA 02111-1307 USA</font></tt><br><tt><font color="#993300"> Contact: todos@geneura.ugr.es,http://geneura.ugr.es</font></tt><br><tt><font color="#993300"> Marc.Schoenauer@inria.fr</font></tt><br><tt><font color="#993300"> mkeijzer@dhi.dk</font></tt><br><tt><font color="#993300">*/</font></tt><br><tt><font color="#993300">//-----------------------------------------------------------------------------</font></tt><p><b><tt><font color="#993300">#ifndef _make_op_OneMax_h</font></tt></b><br><b><tt><font color="#993300">#define _make_op_OneMax_h</font></tt></b><p><tt><font color="#993300">// the operators</font></tt><br><b><tt><font color="#993300">#include <eoOp.h></font></tt></b><br><b><tt><font color="#993300">#include <eoGenOp.h></font></tt></b><br><b><tt><font color="#993300">#include <eoCloneOps.h></font></tt></b><br><b><tt><font color="#993300">#include <eoOpContainer.h></font></tt></b><br><tt><font color="#993300">// combinations of simple eoOps (eoMonOpand eoQuadOp)</font></tt><br><b><tt><font color="#993300">#include <eoProportionalCombinedOp.h></font></tt></b><p><tt><font color="#993300">/** definition of mutation: </font></tt><br><tt><font color="#993300">* class eoOneMaxMonop MUST derive from eoMonOp<eoOneMax></font></tt><br><tt><font color="#993300">*/</font></tt><br><b><tt><font color="#993300">#include "eoOneMaxMutation.h"</font></tt></b><p><tt><font color="#993300">/** definition of crossover (either as eoBinOp(2->1) or eoQuadOp (2->2): </font></tt><br><tt><font color="#993300">* class eoOneMaxBinCrossover MUST derivefrom eoBinOp<eoOneMax></font></tt><br><tt><font color="#993300">* OR </font></tt><br><tt><font color="#993300">* class eoOneMaxQuadCrossover MUST derivefrom eoQuadOp<eoOneMax></font></tt><br><tt><font color="#993300">*/</font></tt><br><tt><font color="#993300">// #include "eoOneMaxBinOp.h"</font></tt><br><tt><font color="#993300">// OR</font></tt><br><b><tt><font color="#993300">#include "eoOneMaxQuadCrossover.h"</font></tt></b><p><tt><font color="#993300"><b> </b> // also need the parser andstate includes</font></tt><br><b><tt><font color="#993300">#include <utils/eoParser.h></font></tt></b><br><b><tt><font color="#993300">#include <utils/eoState.h></font></tt></b><p><tt><font color="#993300">/////////////////// variation operators ///////////////</font></tt><br><tt><font color="#993300">// canonical (crossover + mutation) onlyat the moment //</font></tt><p><tt><font color="#993300">/*</font></tt><br><tt><font color="#993300">* This function builds the operators thatwill be applied to the eoOneMax</font></tt><br><tt><font color="#993300">*</font></tt><br><tt><font color="#993300">* It uses a parser (to get user parameters),a state (to store the memory)</font></tt><br><tt><font color="#993300">* the lastparameter is an eoInit: if some operator needs some info </font></tt><br><tt><font color="#993300">* about thegenotypes, the init has it all (e.g. bounds, ...)</font></tt><br><tt><font color="#993300">* Simply do </font></tt><br><tt><font color="#993300">* EOT myEO;</font></tt><br><tt><font color="#993300">* _init(myEO);</font></tt><br><tt><font color="#993300">* and myEOis then an ACTUAL object</font></tt><br><tt><font color="#993300">*</font></tt><br><tt><font color="#993300">* As usual, the template is the completeEOT even though only the fitness</font></tt><br><tt><font color="#993300">* is actually templatized here: the followingonly applies to eoOneMax</font></tt><br><tt><font color="#993300">*/</font></tt></td></tr></table><a NAME="operators"></a><table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE ><tr><td><b><tt><font color="#993399">template <class EOT></font></tt></b><br><b><tt><font color="#993399">eoGenOp<EOT> & do_make_op(eoParameterLoader&_parser, eoState& _state, eoInit<EOT>& _init)</font></tt></b><br><b><tt><font color="#993399">{</font></tt></b><br><tt><font color="#993399"><b> </b> // this is a temporary version,while Maarten codes the full tree-structured</font></tt><br><tt><font color="#993399"><b> </b> // general operator input</font></tt><br><tt><font color="#993399"><b> </b> // BTW we must leave that simpleversion available somehow, as it is the one</font></tt><br><tt><font color="#993399"><b> </b> // that 90% people use!</font></tt><p><tt><font color="#993399"><b> </b> /////////////////////////////</font></tt><br><tt><font color="#993399"><b> </b> //Variation operators</font></tt><br><tt><font color="#993399"><b> </b> ////////////////////////////</font></tt><br><tt><font color="#993399"><b> </b> //read crossover and mutations, combine each in a proportional Op</font></tt><br><tt><font color="#993399"><b> </b> //and create the eoGenOp that calls crossover at rate pCross </font></tt><br><tt><font color="#993399"><b> </b> //then mutation with rate pMut</font></tt><p><tt><font color="#993399"><b> </b> // thecrossovers</font></tt><br><tt><font color="#993399"><b> </b> /////////////////</font></tt><p><tt><font color="#993399"><b> </b> // herewe can have eoQuadOp (2->2) only - no time for the eoBinOp case</font></tt><p><tt><font color="#993399"><b> </b> // youcan have more than one - combined in a proportional way</font></tt><p><tt><font color="#993399"><b> </b> // first,define the crossover objects and read their rates from the parser</font></tt><p><tt><font color="#993399"><b> </b> // Afirst crossover </font></tt><br><a NAME="cross_ctor"></a><tt><font color="#993399"><b> eoQuadOp<Indi> *cross = new eoOneMaxQuadCrossover<Indi> </b>/* </font><font color="#FF6666">(varType _anyVariable)</font><font color="#993399"> */;</font></tt><br><tt><font color="#993399"><b> </b> //store in the state</font></tt><br><b><tt><font color="#993399"> _state.storeFunctor(cross);</font></tt></b><p><tt><font color="#993399"><b> </b> // read its relative rate inthe combination</font></tt><br><b><tt><font color="#993399"> double cross1Rate= _parser.createParam(1.0, "cross1Rate", "Relative rate for crossover 1",'1', "Variation Operators").value();</font></tt></b><p><tt><font color="#993399"><b> </b> // and create the combined operatorwith this one</font></tt><br><b><tt><font color="#993399"> eoPropCombinedQuadOp<Indi> *propXover= </font></tt></b><br><b><tt><font color="#993399"> new eoPropCombinedQuadOp<Indi>(*cross,cross1Rate);</font></tt></b><br><tt><font color="#993399"><b> </b> // and of course stor it inthe state</font></tt><br><b><tt><font color="#993399"> _state.storeFunctor(propXover);</font></tt></b><br> </td></tr></table>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -