⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 make_op_onemax.html

📁 这是linux下的进化计算的源代码。 === === === === === === === === === === === ===== check latest news at http:
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<!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">/*&nbsp;</font></tt><br><tt><font color="#993300">&nbsp;&nbsp;&nbsp;&nbsp; This library isfree software; you can redistribute it and/or</font></tt><br><tt><font color="#993300">&nbsp;&nbsp;&nbsp;&nbsp; modify it underthe terms of the GNU Lesser General Public</font></tt><br><tt><font color="#993300">&nbsp;&nbsp;&nbsp;&nbsp; License as publishedby the Free Software Foundation; either</font></tt><br><tt><font color="#993300">&nbsp;&nbsp;&nbsp;&nbsp; version 2 of theLicense, or (at your option) any later version.</font></tt><br><tt><font color="#993300">&nbsp;&nbsp;&nbsp;&nbsp; This library isdistributed in the hope that it will be useful,</font></tt><br><tt><font color="#993300">&nbsp;&nbsp;&nbsp;&nbsp; but WITHOUT ANYWARRANTY; without even the implied warranty of</font></tt><br><tt><font color="#993300">&nbsp;&nbsp;&nbsp;&nbsp; MERCHANTABILITYor FITNESS FOR A PARTICULAR PURPOSE.&nbsp; See the GNU</font></tt><br><tt><font color="#993300">&nbsp;&nbsp;&nbsp;&nbsp; Lesser General PublicLicense for more details.</font></tt><br><tt><font color="#993300">&nbsp;&nbsp;&nbsp;&nbsp; You should havereceived a copy of the GNU Lesser General Public</font></tt><br><tt><font color="#993300">&nbsp;&nbsp;&nbsp;&nbsp; License along withthis library; if not, write to the Free Software</font></tt><br><tt><font color="#993300">&nbsp;&nbsp;&nbsp;&nbsp; Foundation, Inc.,59 Temple Place, Suite 330, Boston, MA&nbsp; 02111-1307&nbsp; USA</font></tt><br><tt><font color="#993300">&nbsp;&nbsp;&nbsp;&nbsp; Contact: todos@geneura.ugr.es,http://geneura.ugr.es</font></tt><br><tt><font color="#993300">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Marc.Schoenauer@inria.fr</font></tt><br><tt><font color="#993300">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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 &lt;eoOp.h></font></tt></b><br><b><tt><font color="#993300">#include &lt;eoGenOp.h></font></tt></b><br><b><tt><font color="#993300">#include &lt;eoCloneOps.h></font></tt></b><br><b><tt><font color="#993300">#include &lt;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 &lt;eoProportionalCombinedOp.h></font></tt></b><p><tt><font color="#993300">/** definition of mutation:&nbsp;</font></tt><br><tt><font color="#993300">* class eoOneMaxMonop MUST derive from eoMonOp&lt;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):&nbsp;</font></tt><br><tt><font color="#993300">* class eoOneMaxBinCrossover MUST derivefrom eoBinOp&lt;eoOneMax></font></tt><br><tt><font color="#993300">* OR&nbsp;</font></tt><br><tt><font color="#993300">* class eoOneMaxQuadCrossover MUST derivefrom eoQuadOp&lt;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>&nbsp;</b> // also need the parser andstate includes</font></tt><br><b><tt><font color="#993300">#include &lt;utils/eoParser.h></font></tt></b><br><b><tt><font color="#993300">#include &lt;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">*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; the lastparameter is an eoInit: if some operator needs some info&nbsp;</font></tt><br><tt><font color="#993300">*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; about thegenotypes, the init has it all (e.g. bounds, ...)</font></tt><br><tt><font color="#993300">*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Simply do&nbsp;</font></tt><br><tt><font color="#993300">*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;EOT myEO;</font></tt><br><tt><font color="#993300">*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_init(myEO);</font></tt><br><tt><font color="#993300">*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 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 &lt;class EOT></font></tt></b><br><b><tt><font color="#993399">eoGenOp&lt;EOT> &amp; do_make_op(eoParameterLoader&amp;_parser, eoState&amp; _state, eoInit&lt;EOT>&amp; _init)</font></tt></b><br><b><tt><font color="#993399">{</font></tt></b><br><tt><font color="#993399"><b>&nbsp;</b> // this is a temporary version,while Maarten codes the full tree-structured</font></tt><br><tt><font color="#993399"><b>&nbsp;</b> // general operator input</font></tt><br><tt><font color="#993399"><b>&nbsp;</b> // BTW we must leave that simpleversion available somehow, as it is the one</font></tt><br><tt><font color="#993399"><b>&nbsp;</b> // that 90% people use!</font></tt><p><tt><font color="#993399"><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</b> /////////////////////////////</font></tt><br><tt><font color="#993399"><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</b> //Variation operators</font></tt><br><tt><font color="#993399"><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</b> ////////////////////////////</font></tt><br><tt><font color="#993399"><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</b> //read crossover and mutations, combine each in a proportional Op</font></tt><br><tt><font color="#993399"><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</b> //and create the eoGenOp that calls crossover at rate pCross&nbsp;</font></tt><br><tt><font color="#993399"><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</b> //then mutation with rate pMut</font></tt><p><tt><font color="#993399"><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</b> // thecrossovers</font></tt><br><tt><font color="#993399"><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</b> /////////////////</font></tt><p><tt><font color="#993399"><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</b> // herewe can have eoQuadOp (2->2) only - no time for the eoBinOp case</font></tt><p><tt><font color="#993399"><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</b> // youcan have more than one - combined in a proportional way</font></tt><p><tt><font color="#993399"><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</b> // first,define the crossover objects and read their rates from the parser</font></tt><p><tt><font color="#993399"><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</b> // Afirst crossover&nbsp;</font></tt><br><a NAME="cross_ctor"></a><tt><font color="#993399"><b>&nbsp;&nbsp;&nbsp;&nbsp;eoQuadOp&lt;Indi> *cross = new eoOneMaxQuadCrossover&lt;Indi> </b>/* </font><font color="#FF6666">(varType&nbsp;_anyVariable)</font><font color="#993399"> */;</font></tt><br><tt><font color="#993399"><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</b> //store in the state</font></tt><br><b><tt><font color="#993399">&nbsp;&nbsp;&nbsp;&nbsp; _state.storeFunctor(cross);</font></tt></b><p><tt><font color="#993399"><b>&nbsp;</b> // read its relative rate inthe combination</font></tt><br><b><tt><font color="#993399">&nbsp;&nbsp;&nbsp;&nbsp; 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>&nbsp;</b> // and create the combined operatorwith this one</font></tt><br><b><tt><font color="#993399">&nbsp;eoPropCombinedQuadOp&lt;Indi> *propXover=&nbsp;</font></tt></b><br><b><tt><font color="#993399">&nbsp;&nbsp;&nbsp;&nbsp; new eoPropCombinedQuadOp&lt;Indi>(*cross,cross1Rate);</font></tt></b><br><tt><font color="#993399"><b>&nbsp;</b> // and of course stor it inthe state</font></tt><br><b><tt><font color="#993399">&nbsp;&nbsp;&nbsp;&nbsp; _state.storeFunctor(propXover);</font></tt></b><br>&nbsp;</td></tr></table>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -