Paradiseo-eo sources added

git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@40 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
legrand 2006-12-12 14:49:08 +00:00
commit c3aec878e5
3609 changed files with 342772 additions and 0 deletions

View file

@ -0,0 +1,173 @@
<!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_continue.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_continue.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_continue.h</span>
00005 <span class="comment">// (c) Maarten Keijzer, Marc Schoenauer and GeNeura Team, 2000</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_continue_h</span>
00028 <span class="preprocessor"></span><span class="preprocessor">#define _make_continue_h</span>
00029 <span class="preprocessor"></span>
00030 <span class="comment">/*</span>
00031 <span class="comment">Contains the templatized version of parser-based choice of stopping criterion</span>
00032 <span class="comment">It can then be instantiated, and compiled on its own for a given EOType</span>
00033 <span class="comment">(see e.g. in dir ga, ga.cpp)</span>
00034 <span class="comment">*/</span>
00035
00036 <span class="comment">// Continuators - all include eoContinue.h</span>
00037 <span class="preprocessor">#include &lt;eoCombinedContinue.h&gt;</span>
00038 <span class="preprocessor">#include &lt;eoGenContinue.h&gt;</span>
00039 <span class="preprocessor">#include &lt;eoSteadyFitContinue.h&gt;</span>
00040 <span class="preprocessor">#include &lt;eoEvalContinue.h&gt;</span>
00041 <span class="preprocessor">#include &lt;eoFitContinue.h&gt;</span>
00042 <span class="preprocessor">#ifndef _MSC_VER</span>
00043 <span class="preprocessor"></span><span class="preprocessor">#include &lt;eoCtrlCContinue.h&gt;</span> <span class="comment">// CtrlC handling (using 2 global variables!)</span>
00044 <span class="preprocessor">#endif</span>
00045 <span class="preprocessor"></span>
00046 <span class="comment">// also need the parser and param includes</span>
00047 <span class="preprocessor">#include &lt;utils/eoParser.h&gt;</span>
00048 <span class="preprocessor">#include &lt;utils/eoState.h&gt;</span>
00049
00050
00052 <span class="keyword">template</span> &lt;<span class="keyword">class</span> Indi&gt;
00053 <a class="code" href="classeo_combined_continue.html">eoCombinedContinue&lt;Indi&gt;</a> * make_combinedContinue(<a class="code" href="classeo_combined_continue.html">eoCombinedContinue&lt;Indi&gt;</a> *_combined, <a class="code" href="classeo_continue.html">eoContinue&lt;Indi&gt;</a> *_cont)
00054 {
00055 <span class="keywordflow">if</span> (_combined) <span class="comment">// already exists</span>
00056 _combined-&gt;<a class="code" href="classeo_combined_continue.html#a2">add</a>(*_cont);
00057 <span class="keywordflow">else</span>
00058 _combined = <span class="keyword">new</span> <a class="code" href="classeo_combined_continue.html">eoCombinedContinue&lt;Indi&gt;</a>(*_cont);
00059 <span class="keywordflow">return</span> _combined;
00060 }
00061
00062 <span class="keyword">template</span> &lt;<span class="keyword">class</span> Indi&gt;
00063 <a class="code" href="classeo_continue.html">eoContinue&lt;Indi&gt;</a> &amp; do_make_continue(<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_eval_func_counter.html">eoEvalFuncCounter&lt;Indi&gt;</a> &amp; _eval)
00064 {
00066 <span class="comment">// the combined continue - to be filled</span>
00067 <a class="code" href="classeo_combined_continue.html">eoCombinedContinue&lt;Indi&gt;</a> *continuator = NULL;
00068
00069 <span class="comment">// for each possible criterion, check if wanted, otherwise do nothing</span>
00070
00071 <span class="comment">// First the eoGenContinue - need a default value so you can run blind</span>
00072 <span class="comment">// but we also need to be able to avoid it &lt;--&gt; 0</span>
00073 <a class="code" href="classeo_value_param.html">eoValueParam&lt;unsigned&gt;</a>&amp; maxGenParam = _parser.<a class="code" href="classeo_parser.html#a10">getORcreateParam</a>(<span class="keywordtype">unsigned</span>(100), <span class="stringliteral">"maxGen"</span>, <span class="stringliteral">"Maximum number of generations () = none)"</span>,<span class="charliteral">'G'</span>,<span class="stringliteral">"Stopping criterion"</span>);
00074
00075 <span class="keywordflow">if</span> (maxGenParam.<a class="code" href="classeo_value_param.html#a2">value</a>()) <span class="comment">// positive: -&gt; define and store</span>
00076 {
00077 <a class="code" href="classeo_gen_continue.html">eoGenContinue&lt;Indi&gt;</a> *genCont = <span class="keyword">new</span> <a class="code" href="classeo_gen_continue.html">eoGenContinue&lt;Indi&gt;</a>(maxGenParam.<a class="code" href="classeo_value_param.html#a2">value</a>());
00078 _state.<a class="code" href="classeo_functor_store.html#a2">storeFunctor</a>(genCont);
00079 <span class="comment">// and "add" to combined</span>
00080 continuator = make_combinedContinue&lt;Indi&gt;(continuator, genCont);
00081 }
00082
00083 <span class="comment">// the steadyGen continue - only if user imput</span>
00084 <a class="code" href="classeo_value_param.html">eoValueParam&lt;unsigned&gt;</a>&amp; steadyGenParam = _parser.<a class="code" href="classeo_parameter_loader.html#a3">createParam</a>(<span class="keywordtype">unsigned</span>(100), <span class="stringliteral">"steadyGen"</span>, <span class="stringliteral">"Number of generations with no improvement"</span>,<span class="charliteral">'s'</span>, <span class="stringliteral">"Stopping criterion"</span>);
00085 <a class="code" href="classeo_value_param.html">eoValueParam&lt;unsigned&gt;</a>&amp; minGenParam = _parser.<a class="code" href="classeo_parameter_loader.html#a3">createParam</a>(<span class="keywordtype">unsigned</span>(0), <span class="stringliteral">"minGen"</span>, <span class="stringliteral">"Minimum number of generations"</span>,<span class="charliteral">'g'</span>, <span class="stringliteral">"Stopping criterion"</span>);
00086 <span class="keywordflow">if</span> (_parser.<a class="code" href="classeo_parser.html#a8">isItThere</a>(steadyGenParam))
00087 {
00088 <a class="code" href="classeo_steady_fit_continue.html">eoSteadyFitContinue&lt;Indi&gt;</a> *steadyCont = <span class="keyword">new</span> <a class="code" href="classeo_steady_fit_continue.html">eoSteadyFitContinue&lt;Indi&gt;</a>
00089 (minGenParam.<a class="code" href="classeo_value_param.html#a2">value</a>(), steadyGenParam.<a class="code" href="classeo_value_param.html#a2">value</a>());
00090 <span class="comment">// store</span>
00091 _state.<a class="code" href="classeo_functor_store.html#a2">storeFunctor</a>(steadyCont);
00092 <span class="comment">// add to combinedContinue</span>
00093 continuator = make_combinedContinue&lt;Indi&gt;(continuator, steadyCont);
00094 }
00095
00096 <span class="comment">// Same thing with Eval - but here default value is 0</span>
00097 <a class="code" href="classeo_value_param.html">eoValueParam&lt;unsigned long&gt;</a>&amp; maxEvalParam
00098 = _parser.<a class="code" href="classeo_parser.html#a10">getORcreateParam</a>((<span class="keywordtype">unsigned</span> <span class="keywordtype">long</span>)0, <span class="stringliteral">"maxEval"</span>,
00099 <span class="stringliteral">"Maximum number of evaluations (0 = none)"</span>,
00100 <span class="charliteral">'E'</span>, <span class="stringliteral">"Stopping criterion"</span>);
00101
00102 <span class="keywordflow">if</span> (maxEvalParam.<a class="code" href="classeo_value_param.html#a2">value</a>()) <span class="comment">// positive: -&gt; define and store</span>
00103 {
00104 <a class="code" href="classeo_eval_continue.html">eoEvalContinue&lt;Indi&gt;</a> *evalCont = <span class="keyword">new</span> <a class="code" href="classeo_eval_continue.html">eoEvalContinue&lt;Indi&gt;</a>(_eval, maxEvalParam.<a class="code" href="classeo_value_param.html#a2">value</a>());
00105 _state.<a class="code" href="classeo_functor_store.html#a2">storeFunctor</a>(evalCont);
00106 <span class="comment">// and "add" to combined</span>
00107 continuator = make_combinedContinue&lt;Indi&gt;(continuator, evalCont);
00108 }
00109 <span class="comment">/*</span>
00110 <span class="comment"> // the steadyEval continue - only if user imput</span>
00111 <span class="comment"> eoValueParam&lt;unsigned&gt;&amp; steadyGenParam = _parser.createParam(unsigned(100), "steadyGen", "Number of generations with no improvement",'s', "Stopping criterion");</span>
00112 <span class="comment"> eoValueParam&lt;unsigned&gt;&amp; minGenParam = _parser.createParam(unsigned(0), "minGen", "Minimum number of generations",'g', "Stopping criterion");</span>
00113 <span class="comment"> if (_parser.isItThere(steadyGenParam))</span>
00114 <span class="comment"> {</span>
00115 <span class="comment"> eoSteadyGenContinue&lt;Indi&gt; *steadyCont = new eoSteadyFitContinue&lt;Indi&gt;</span>
00116 <span class="comment"> (minGenParam.value(), steadyGenParam.value());</span>
00117 <span class="comment"> // store</span>
00118 <span class="comment"> _state.storeFunctor(steadyCont);</span>
00119 <span class="comment"> // add to combinedContinue</span>
00120 <span class="comment"> continuator = make_combinedContinue&lt;Indi&gt;(continuator, steadyCont);</span>
00121 <span class="comment"> }</span>
00122 <span class="comment"> */</span>
00123 <span class="comment">// the target fitness</span>
00124 <a class="code" href="classeo_fit_continue.html">eoFitContinue&lt;Indi&gt;</a> *fitCont;
00125 <a class="code" href="classeo_value_param.html">eoValueParam&lt;double&gt;</a>&amp; targetFitnessParam = _parser.<a class="code" href="classeo_parameter_loader.html#a3">createParam</a>(<span class="keywordtype">double</span>(0.0), <span class="stringliteral">"targetFitness"</span>, <span class="stringliteral">"Stop when fitness reaches"</span>,<span class="charliteral">'T'</span>, <span class="stringliteral">"Stopping criterion"</span>);
00126 <span class="keywordflow">if</span> (_parser.<a class="code" href="classeo_parser.html#a8">isItThere</a>(targetFitnessParam))
00127 {
00128 fitCont = <span class="keyword">new</span> <a class="code" href="classeo_fit_continue.html">eoFitContinue&lt;Indi&gt;</a>
00129 (targetFitnessParam.<a class="code" href="classeo_value_param.html#a2">value</a>());
00130 <span class="comment">// store</span>
00131 _state.<a class="code" href="classeo_functor_store.html#a2">storeFunctor</a>(fitCont);
00132 <span class="comment">// add to combinedContinue</span>
00133 continuator = make_combinedContinue&lt;Indi&gt;(continuator, fitCont);
00134 }
00135
00136 <span class="preprocessor">#ifndef _MSC_VER</span>
00137 <span class="preprocessor"></span> <span class="comment">// the CtrlC interception (Linux only I'm afraid)</span>
00138 <a class="code" href="classeo_ctrl_c_continue.html">eoCtrlCContinue&lt;Indi&gt;</a> *ctrlCCont;
00139 <a class="code" href="classeo_value_param.html">eoValueParam&lt;bool&gt;</a>&amp; ctrlCParam = _parser.<a class="code" href="classeo_parameter_loader.html#a3">createParam</a>(<span class="keyword">false</span>, <span class="stringliteral">"CtrlC"</span>, <span class="stringliteral">"Terminate current generation upon Ctrl C"</span>,<span class="charliteral">'C'</span>, <span class="stringliteral">"Stopping criterion"</span>);
00140 <span class="keywordflow">if</span> (ctrlCParam.<a class="code" href="classeo_value_param.html#a2">value</a>())
00141 {
00142 ctrlCCont = <span class="keyword">new</span> <a class="code" href="classeo_ctrl_c_continue.html">eoCtrlCContinue&lt;Indi&gt;</a>;
00143 <span class="comment">// store</span>
00144 _state.<a class="code" href="classeo_functor_store.html#a2">storeFunctor</a>(ctrlCCont);
00145 <span class="comment">// add to combinedContinue</span>
00146 continuator = make_combinedContinue&lt;Indi&gt;(continuator, ctrlCCont);
00147 }
00148 <span class="preprocessor">#endif</span>
00149 <span class="preprocessor"></span>
00150 <span class="comment">// now check that there is at least one!</span>
00151 <span class="keywordflow">if</span> (!continuator)
00152 <span class="keywordflow">throw</span> std::runtime_error(<span class="stringliteral">"You MUST provide a stopping criterion"</span>);
00153 <span class="comment">// OK, it's there: store in the eoState</span>
00154 _state.<a class="code" href="classeo_functor_store.html#a2">storeFunctor</a>(continuator);
00155
00156 <span class="comment">// and return</span>
00157 <span class="keywordflow">return</span> *continuator;
00158 }
00159
00160 <span class="preprocessor">#endif</span>
</pre></div><hr size="1"><address style="align: right;"><small>Generated on Thu Oct 19 05:06:40 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>