paradiseo/trunk/paradiseo-eo/doc/html/make__pop_8h-source.html
legrand c3aec878e5 Paradiseo-eo sources added
git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@40 331e1502-861f-0410-8da2-ba01fb791d7f
2006-12-12 14:49:08 +00:00

114 lines
11 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>EO: make_pop.h Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.3.9.1 -->
<div class="qindex"> <form class="search" action="search.php" method="get">
<a class="qindex" href="main.html">Main&nbsp;Page</a> | <a class="qindex" href="modules.html">Modules</a> | <a class="qindex" href="namespaces.html">Namespace List</a> | <a class="qindex" href="hierarchy.html">Class&nbsp;Hierarchy</a> | <a class="qindex" href="classes.html">Alphabetical&nbsp;List</a> | <a class="qindex" href="annotated.html">Class&nbsp;List</a> | <a class="qindex" href="files.html">File&nbsp;List</a> | <a class="qindex" href="namespacemembers.html">Namespace&nbsp;Members</a> | <a class="qindex" href="functions.html">Class&nbsp;Members</a> | <a class="qindex" href="pages.html">Related&nbsp;Pages</a> | <span class="search"><u>S</u>earch&nbsp;for&nbsp;<input class="search" type="text" name="query" value="" size="20" accesskey="s"/></span></form></div>
<div class="nav">
<a class="el" href="dir_000000.html">src</a>&nbsp;/&nbsp;<a class="el" href="dir_000025.html">do</a></div>
<h1>make_pop.h</h1><div class="fragment"><pre class="fragment">00001 <span class="comment">// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-</span>
00002
00003 <span class="comment">//-----------------------------------------------------------------------------</span>
00004 <span class="comment">// make_pop.h</span>
00005 <span class="comment">// (c) Maarten Keijzer, Marc Schoenauer and GeNeura Team, 2001</span>
00006 <span class="comment">/*</span>
00007 <span class="comment"> This library is free software; you can redistribute it and/or</span>
00008 <span class="comment"> modify it under the terms of the GNU Lesser General Public</span>
00009 <span class="comment"> License as published by the Free Software Foundation; either</span>
00010 <span class="comment"> version 2 of the License, or (at your option) any later version.</span>
00011 <span class="comment"></span>
00012 <span class="comment"> This library is distributed in the hope that it will be useful,</span>
00013 <span class="comment"> but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
00014 <span class="comment"> MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU</span>
00015 <span class="comment"> Lesser General Public License for more details.</span>
00016 <span class="comment"></span>
00017 <span class="comment"> You should have received a copy of the GNU Lesser General Public</span>
00018 <span class="comment"> License along with this library; if not, write to the Free Software</span>
00019 <span class="comment"> Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA</span>
00020 <span class="comment"></span>
00021 <span class="comment"> Contact: todos@geneura.ugr.es, http://geneura.ugr.es</span>
00022 <span class="comment"> Marc.Schoenauer@polytechnique.fr</span>
00023 <span class="comment"> mkeijzer@dhi.dk</span>
00024 <span class="comment"> */</span>
00025 <span class="comment">//-----------------------------------------------------------------------------</span>
00026
00027 <span class="preprocessor">#ifndef _make_pop_h</span>
00028 <span class="preprocessor"></span><span class="preprocessor">#define _make_pop_h</span>
00029 <span class="preprocessor"></span>
00030 <span class="preprocessor">#include &lt;ctime&gt;</span> <span class="comment">// for time(0) for random seeding</span>
00031 <span class="preprocessor">#include &lt;eoPop.h&gt;</span>
00032 <span class="preprocessor">#include &lt;eoInit.h&gt;</span>
00033 <span class="preprocessor">#include &lt;utils/eoRNG.h&gt;</span>
00034 <span class="preprocessor">#include &lt;utils/eoParser.h&gt;</span>
00035 <span class="preprocessor">#include &lt;utils/eoState.h&gt;</span>
00036
00037
00039
00048 <span class="keyword">template</span> &lt;<span class="keyword">class</span> EOT&gt;
00049 <a class="code" href="classeo_pop.html">eoPop&lt;EOT&gt;</a>&amp; do_make_pop(<a class="code" href="classeo_parser.html">eoParser</a> &amp; _parser, <a class="code" href="classeo_state.html">eoState</a>&amp; _state, <a class="code" href="classeo_init.html">eoInit&lt;EOT&gt;</a> &amp; _init)
00050 {
00051 <span class="comment">// random seed</span>
00052 <a class="code" href="classeo_value_param.html">eoValueParam&lt;uint32_t&gt;</a>&amp; seedParam = _parser.<a class="code" href="classeo_parameter_loader.html#a3">createParam</a>(uint32_t(0), <span class="stringliteral">"seed"</span>, <span class="stringliteral">"Random number seed"</span>, <span class="charliteral">'S'</span>);
00053 <span class="keywordflow">if</span> (seedParam.<a class="code" href="classeo_value_param.html#a2">value</a>() == 0)
00054 seedParam.<a class="code" href="classeo_value_param.html#a2">value</a>() = time(0);
00055 <a class="code" href="classeo_value_param.html">eoValueParam&lt;unsigned&gt;</a>&amp; popSize = _parser.<a class="code" href="classeo_parameter_loader.html#a3">createParam</a>(<span class="keywordtype">unsigned</span>(20), <span class="stringliteral">"popSize"</span>, <span class="stringliteral">"Population Size"</span>, <span class="charliteral">'P'</span>, <span class="stringliteral">"Evolution Engine"</span>);
00056
00057 <span class="comment">// Either load or initialize</span>
00058 <span class="comment">// create an empty pop and let the state handle the memory</span>
00059 <a class="code" href="classeo_pop.html">eoPop&lt;EOT&gt;</a>&amp; pop = _state.<a class="code" href="classeo_state.html#a3">takeOwnership</a>(<a class="code" href="classeo_pop.html">eoPop&lt;EOT&gt;</a>());
00060
00061 <a class="code" href="classeo_value_param.html">eoValueParam&lt;std::string&gt;</a>&amp; loadNameParam = _parser.<a class="code" href="classeo_parameter_loader.html#a3">createParam</a>(std::string(<span class="stringliteral">""</span>), <span class="stringliteral">"Load"</span>,<span class="stringliteral">"A save file to restart from"</span>,<span class="charliteral">'L'</span>, <span class="stringliteral">"Persistence"</span> );
00062 <a class="code" href="classeo_value_param.html">eoValueParam&lt;bool&gt;</a> &amp; recomputeFitnessParam = _parser.<a class="code" href="classeo_parameter_loader.html#a3">createParam</a>(<span class="keyword">false</span>, <span class="stringliteral">"recomputeFitness"</span>, <span class="stringliteral">"Recompute the fitness after re-loading the pop.?"</span>, <span class="charliteral">'r'</span>, <span class="stringliteral">"Persistence"</span> );
00063
00064 <span class="keywordflow">if</span> (loadNameParam.<a class="code" href="classeo_value_param.html#a2">value</a>() != <span class="stringliteral">""</span>) <span class="comment">// something to load</span>
00065 {
00066 <span class="comment">// create another state for reading</span>
00067 <a class="code" href="classeo_state.html">eoState</a> inState; <span class="comment">// a state for loading - WITHOUT the parser</span>
00068 <span class="comment">// register the rng and the pop in the state, so they can be loaded,</span>
00069 <span class="comment">// and the present run will be the exact continuation of the saved run</span>
00070 <span class="comment">// eventually with different parameters</span>
00071 inState.<a class="code" href="classeo_state.html#a2">registerObject</a>(pop);
00072 inState.<a class="code" href="classeo_state.html#a2">registerObject</a>(rng);
00073 inState.<a class="code" href="classeo_state.html#a5">load</a>(loadNameParam.<a class="code" href="classeo_value_param.html#a2">value</a>()); <span class="comment">// load the pop and the rng</span>
00074 <span class="comment">// the fitness is read in the file:</span>
00075 <span class="comment">// do only evaluate the pop if the fitness has changed</span>
00076 <span class="keywordflow">if</span> (recomputeFitnessParam.<a class="code" href="classeo_value_param.html#a2">value</a>())
00077 {
00078 <span class="keywordflow">for</span> (<span class="keywordtype">unsigned</span> i=0; i&lt;pop.size(); i++)
00079 pop[i].<a class="code" href="classeo_pop.html#a19">invalidate</a>();
00080 }
00081 <span class="keywordflow">if</span> (pop.size() &lt; popSize.<a class="code" href="classeo_value_param.html#a2">value</a>())
00082 std::cerr &lt;&lt; <span class="stringliteral">"WARNING, only "</span> &lt;&lt; pop.size() &lt;&lt; <span class="stringliteral">" individuals read in file "</span> &lt;&lt; loadNameParam.<a class="code" href="classeo_value_param.html#a2">value</a>() &lt;&lt; <span class="stringliteral">"\nThe remaining "</span> &lt;&lt; popSize.<a class="code" href="classeo_value_param.html#a2">value</a>() - pop.size() &lt;&lt; <span class="stringliteral">" will be randomly drawn"</span> &lt;&lt; std::endl;
00083 <span class="keywordflow">if</span> (pop.size() &gt; popSize.<a class="code" href="classeo_value_param.html#a2">value</a>())
00084 {
00085 std::cerr &lt;&lt; <span class="stringliteral">"WARNING, Load file contained too many individuals. Only the best will be retained"</span> &lt;&lt; std::endl;
00086 pop.resize(popSize.<a class="code" href="classeo_value_param.html#a2">value</a>());
00087 }
00088 }
00089 <span class="keywordflow">else</span> <span class="comment">// nothing loaded from a file</span>
00090 {
00091 rng.<a class="code" href="classeo_rng.html#a2">reseed</a>(seedParam.<a class="code" href="classeo_value_param.html#a2">value</a>());
00092 }
00093
00094 <span class="keywordflow">if</span> (pop.size() &lt; popSize.<a class="code" href="classeo_value_param.html#a2">value</a>()) <span class="comment">// missing some guys</span>
00095 {
00096 <span class="comment">// Init pop from the randomizer: need to use the append function</span>
00097 pop.<a class="code" href="classeo_pop.html#a2">append</a>(popSize.<a class="code" href="classeo_value_param.html#a2">value</a>(), _init);
00098 }
00099
00100 <span class="comment">// for future stateSave, register the algorithm into the state</span>
00101 _state.<a class="code" href="classeo_state.html#a2">registerObject</a>(_parser);
00102 _state.<a class="code" href="classeo_state.html#a2">registerObject</a>(pop);
00103 _state.<a class="code" href="classeo_state.html#a2">registerObject</a>(rng);
00104
00105 <span class="keywordflow">return</span> pop;
00106 }
00107
00108 <span class="preprocessor">#endif</span>
</pre></div><hr size="1"><address style="align: right;"><small>Generated on Thu Oct 19 05:06:41 2006 for EO by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.3.9.1 </small></address>
</body>
</html>