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

📄 eolesson4.html

📁 这是linux下的进化计算的源代码。 === === === === === === === === === === === ===== check latest news at http:
💻 HTML
📖 第 1 页 / 共 5 页
字号:
: Recombination of object variables (discrete or intermediate)</font></font></tt></b><br><font color="#FF0000">String parameter:</font><font color="#000000">&nbsp;There are two possible crossovers in plain ES. The </font><b><tt><font color="#CC33CC"><font size=+1>discrete</font></font></tt></b><font color="#000000">crossover simpy exchanges variables among the parents. It is similar tothe plain uniform crossover for real variables. The&nbsp; crossover performsa linear combination of parents;variables - it si similar to the hypercubecrossover described for&nbsp; with alpah parameter set to 0. This parameterallso to choose the type of crossover that will be applied to the </font><b><font color="#FF6600">objectvariables</font></b><font color="#000000"> (i.e. the origianl variablesof the problem). </font><font color="#FF0000">Default is discrete.</font><p><b><tt><font color="#CC33CC"><font size=+1># --crossStdev=intermediate# -S : Recombination of mutation strategy parameters (intermediate or discrete)</font></font></tt></b><br><font color="#FF0000">String parameter:</font><font color="#000000">&nbsp;This parameter allows to choose the type of crossover (see above) thatwill be applied to the </font><b><font color="#FF6600">mutation strategyparameters</font></b><font color="#000000"> that are part of the genotype.</font><font color="#FF0000">Defaultis intermediate.</font><p><b><tt><font color="#CC33CC"><font size=+1># --TauLoc=1 # -l : LocalTau (before normalization)</font></font></tt></b><br><font color="#FF0000">Floating-point parameter:</font><font color="#000000">The local factor for the mutation of the mutation strategy parameters (theonly one used when a single standard deviation is used). </font><font color="#FF0000">Defaultis 1</font><font color="#000000">.</font><p><b><tt><font color="#CC33CC"><font size=+1># --TauGlob=1 # -g : GlobalTau (before normalization)</font></font></tt></b><br><font color="#FF0000">Floating-point parameter:</font><font color="#000000">The global factor for the mutation of the mutation strategy parameters(only useful when more than one standard deviation are used). </font><font color="#FF0000">Defaultis 1</font><font color="#000000">.</font><p><b><tt><font color="#CC33CC"><font size=+1># --Beta=0.0873 # -b : Beta</font></font></tt></b><br><font color="#FF0000">Floating-point parameter:</font><font color="#000000">The factor for the mutation of the rotation angles in the case of the fullcorrelated mutation. </font><font color="#FF0000">Default is 0.0873</font><font color="#000000">(following Schwefel).</font><p><hr SIZE=5 WIDTH="100%"><br><a NAME="programmerguide"></a><b><font color="#000099"><font size=+2>Programmer'sguide</font></font></b><p>At the moment, you will have to browse in the source (colored!) code(<a href="BitEA.html">Bit</a> - Real) almost by yourself, sorry.<p>Note that the main file is now very slim, as it only contains callsto some <b><tt><font color="#993300"><font size=+1>make_xxx</font></font></tt></b>functions - these functions contain the actual code, very similar to thecode of Lesson3, except for the memory management, performed through an<b><tt><font color="#993300"><font size=+1><a href="../../doc/html/classeo_state.html">eoState</a></font></font></tt></b>object (notice that all <b><tt><font color="#993300"><font size=+1>make_xxx</font></font></tt></b>calls have an eoState as second parameter).<p><b><font color="#000099"><font size=+2>Programmer's guide: </font></font><font color="#FF0000"><font size=+1>Themake_xxx files</font></font></b><p><b><font color="#FF0000">Interface</font></b>: all <b><tt><font color="#993300"><font size=+1>make_xxx</font></font></tt></b>files have as first two parameters an <b><tt><font color="#993300"><font size=+1><a href="../../doc/html/classeo_parser.html">eoParser</a></font></font></tt></b>and an <b><tt><font color="#993300"><font size=+1><a href="../../doc/html/classeo_state.html">eoState</a></font></font></tt></b>.The <b><tt><font color="#3366FF"><font size=+1>eoParser</font></font></tt></b>is be used within all functions to parse the command-line and/or a parameterfile in order to read any relevant user-parameter, while the <b><tt><font color="#3366FF"><font size=+1>eoState</font></font></tt></b>is used here to store all pointers to be allocated inside the function(see <a href="eoProgramming.html#memory">Programming hints</a> for moredetailed explanations).<p>There are 2 types of <b><tt><font color="#993300"><font size=+1>make_xxx</font></font></tt></b>files: the ones that do depend on representation, defining the <b><font color="#FF9900">genotype</font></b>and<b><font color="#CC33CC">initialization</font></b>(<b><tt><font color="#CC33CC"><font size=+1>make_genotype_xxx</font></font></tt></b>,with xxx being the type of genotype) and variation operators (<b><tt><font color="#CC33CC"><font size=+1>make_op_xxx</font></font></tt></b>),and the one that are truly representation-independent (<b><tt><font color="#993300"><font size=+1>make_pop,make_continue, make _checkpoint, make_algo </font></font></tt></b><font color="#000000">and</font><b><tt><font color="#993300"><font size=+1>make_run</font></font></tt></b>).<br>The former are located in the directory corresponding to the actualgenotype (<b><tt><font color="#FF9900"><font size=+1>src/ga</font></font></tt></b>for eoBit, <b><tt><font color="#FF9900"><font size=+1>src/es</font></font></tt></b>for eoReal and all eoESxxx genotypes). The latter are in the directory<b><tt><font color="#993300"><font size=+1>src/do.</font></font></tt></b><p>If you take a close look at the code of <b><tt><font color="#993300"><font size=+1><a href="../../src/do/make_continue.h">make_continue</a></font></font></tt></b>for instance, you will first notice that ... the function declared thereis called <b><tt><font color="#993300"><font size=+1>do_make_continue</font></font></tt></b>and is not <a href="BitEA.html#continue">the one you are calling</a> inthe main file, though it has the same parameters as arguments.<br>The explanation lies within the file <b><tt><font color="#FF9900"><font size=+1>make_continue_xxx.cpp</font></font></tt></b>(with xxx = ga or real/es)which, as its color (and name)&nbsp; should havetold you about, are representation-dependent: in fact the <b><tt><font color="#FF9900"><font size=+1>make_continue_xxx.cpp</font></font></tt></b>files only instanciates the general &lt;EOT> template into one of the possibletemplate for eoBit or eoReal/eoES - and this trick allows to <b><font color="#FF6600">compilethem separately</font></b>!<p>The other thing that you should notice is that the code there is verysimilar to the code that was in Lesson 3,&nbsp; regarding parameter readingand type of object that are allocated - except for memory management. Thisgoes for all <b><tt><font color="#993300"><font size=+1>make_xxx</font></font></tt></b>files - so the only thing you need to understand how it goes is to lookat the <a href="#memory">memory management section</a>.<p><b><font color="#FF0000">Pros</font></b>: you don't have to handle ahuge main function - and many of the make_xxx files can be directly usedin different applications (this is called <b><font color="#FF6600">modularity</font></b>:-)))<br>More interesting, you can even <b><font color="#FF6600">compile</font></b>the <b><tt><font color="#993300"><font size=+1>make_xxx</font></font></tt></b>files <b><font color="#FF6600">separately</font></b> for a given targettemplate, and link them e.g. with your fitness function when it is ready(remember that up to now you needed to compile everything altogether byincluding the code into your mail fine). Indeed, if you do a global make,you will notice that there are additional libraries compiled in <b><tt><font color="#FF9900"><font size=+1>src/ga</font></font></tt></b>and <b><tt><font color="#FF9900"><font size=+1>src/es</font></font></tt></b>...<p><b><font color="#FF0000">Cons</font></b>: It makes the code a littlemore complex to understand, first because of the indirection needed forpre-compilation with a given template, and second because of the memorymanagement that this imposes.<br>&nbsp;<br>&nbsp;<p><a NAME="memory"></a><b><font color="#000099"><font size=+2>Programmer'sguide: </font></font><font color="#FF0000"><font size=+1>Memory management</font></font></b><br>As already said, all functions have an <b><tt><font color="#3366FF"><font size=+1>eoState</font></font></tt></b>as second argument - and that object is used to store the functor objectsthat were simply declared as variables of the main function up to now :see <a href="eoProgramming.html#memory">Programming hints</a> for moredetailed explanations and take a look at the code of <b><tt><font color="#993300"><font size=+1><a href="../../src/do/make_continue.h">make_continue</a></font></font></tt></b>for instance, you will see the implementation of the memory managementin action.<p><a NAME="parameter"></a><b><font color="#000099"><font size=+2>Programmer'sguide: </font></font><font color="#FF0000"><font size=+1>Memory managementof eoParam objects</font></font></b><p>It has been seen in Lesson 3 that parameters could be read from command-lineand/or a parameter file using an <b><tt><font color="#3366FF"><font size=+1>eoParser</font></font></tt></b>object. However, the memory mangement problem also concerns EO parameterobjects (<b><tt><font color="#3366FF"><font size=+1>eoParam</font></font></tt></b>):the way there are read in <a href="eoLesson3.html#parameters">Lesson3</a>makes them local variables of the function they are defined in.<br>It is however possible to ask the <b><tt><font color="#3366FF"><font size=+1>eoParser</font></font></tt></b>to hold them, as done for instance in eoContinue for the maximum numberof generations. Local declaration would amount to something like :<p><b><tt><font color="#3366FF"><font size=+1>eoValueParam&lt;unsignedint>&amp; maxGenParam(100, "maxGen", "Maximum number of generations ()= none)",'G');</font></font></tt></b><br><b><tt><font color="#3366FF"><font size=+1>&nbsp;parser.processParam(maxGenParam, "Stopping criterion" );</font></font></tt></b><br><b><tt><font color="#3366FF"><font size=+1>&nbsp;unsigned maxGen =maxGenParam.value();</font></font></tt></b><p>while if you want the parser to hold those eoParam objects, you willwrite something like<p><b><tt><font color="#3366FF"><font size=+1>eoValueParam&lt;unsigned>&amp;maxGenParam = _parser.createParam(unsigned(100), "maxGen", "Maximum numberof generations () = none)",'G',"Stopping criterion");</font></font></tt></b><p>and then use <b><tt><font color="#3366FF"><font size=+1>maxGenParam.value()</font></font></tt></b>to get the value enterred by the user. In that case, you get a <b><font color="#FF6600">reference</font></b>to an eoParam object that is hold by the eoParser - and deleted whith it.<br>Note that there are <b><font color="#FF6600">two important differences</font></b>between the arguments of the constructor of an eoParam object and the methodcreateParam of an eoParser object: first, you need to provide the additionalsection parameter (used only when outputting the eoParser); second you<b><font color="#FF6600">must</font></b>make sure that the first argument is of the correct type otherwise thecompiler will complain.<p>Note that if you don't later need the eoParam, but simply its value,you can even diretly write<p><b><tt><font color="#3366FF"><font size=+1>unsigned maxGen = _parser.createParam(unsigned(100),"maxGen", "Maximum number of generations () = none)",'G',"Stopping criterion").value();</font></font></tt></b><p><b><font color="#FF0000"><font size=+1>Getting parameter values in differentfunctions:</font></font></b><p>It is often useful (though probably <b><font color="#FF6600">very badprogramming style </font></b>:-))) to be able to get the value of a user-definedparameter in two different places of the code without passing it aroundthrough many levels of call. You can then use the alternate function <b><tt><font color="#3366FF"><font size=+1>getORcreateParam</font></font></tt></b>with exactly the same syntax than <b><tt><font color="#3366FF"><font size=+1>createParam</font></font></tt></b>.<br>Be careful that the link between both parameters is made through theirlongmanes (second argument), and that you must so <b><font color="#FF6600">hard-code</font></b>that name in two different places with of course exactly the same spelling!!!<br><b><font color="#FF6600">Examples</font></b> can be found for instancein the make_genotype_xxx files, for the sizes of the genotypes: it is oftenthe case that the definition of the optimization problem requires (or computes)such size. The idea is then that you either read or compute that size,then create a (dummy) parameter with the name that is used later in themake_genotype file. For instance, for bitstrings, the make_genotype_ga.hcontains the following line defining the size of the bitstring<p><b><tt><font color="#3366FF"><font size=+1>&nbsp; unsigned theSize =_parser.getORcreateParam(unsigned(10), "chromSize", "The length of thebitstrings", 'n',"Problem").value();</font></font></tt></b><p>If you want to define that size earlier, you should write somewherebefore<br>&nbsp;<p><b><tt><font color="#3366FF"><font size=+1>&nbsp; unsigned requiredSize&nbsp;= ... ;</font></font></tt></b><br><b><tt><font color="#3366FF"><font size=+1>&nbsp;_parser.createParam(requiredSize,"chromSize", "The length of the bitstrings", 'n',"Problem");</font></font></tt><

⌨️ 快捷键说明

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