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,245 @@
<!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_checkpoint_pareto.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_checkpoint_pareto.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_checkpoint_pareto.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@inria.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_checkpoint_pareto_h</span>
00028 <span class="preprocessor"></span><span class="preprocessor">#define _make_checkpoint_pareto_h</span>
00029 <span class="preprocessor"></span>
00030 <span class="preprocessor">#include &lt;stdlib.h&gt;</span>
00031 <span class="preprocessor">#include &lt;sstream&gt;</span>
00032
00033 <span class="preprocessor">#include "EO.h"</span>
00034 <span class="preprocessor">#include "eoParetoFitness.h"</span>
00035 <span class="preprocessor">#include "eoEvalFuncCounter.h"</span>
00036 <span class="preprocessor">#include "utils/checkpointing"</span>
00037 <span class="preprocessor">#include "utils/selectors.h"</span>
00038
00039 <span class="comment">// at the moment, in utils/make_help.cpp</span>
00040 <span class="comment">// this should become some eoUtils.cpp with corresponding eoUtils.h</span>
00041 <span class="keywordtype">bool</span> testDirRes(std::string _dirName, <span class="keywordtype">bool</span> _erase);
00043
00046 <span class="keyword">template</span> &lt;<span class="keyword">class</span> EOT&gt;
00047 <a class="code" href="classeo_check_point.html">eoCheckPoint&lt;EOT&gt;</a>&amp; do_make_checkpoint_pareto(<a class="code" href="classeo_parser.html">eoParser</a>&amp; _parser, <a class="code" href="classeo_state.html">eoState</a>&amp; _state,
00048 <a class="code" href="classeo_eval_func_counter.html">eoEvalFuncCounter&lt;EOT&gt;</a>&amp; _eval, <a class="code" href="classeo_continue.html">eoContinue&lt;EOT&gt;</a>&amp; _continue)
00049 {
00050 <span class="comment">// first, create a checkpoint from the eoContinue - and store in _state</span>
00051 <a class="code" href="classeo_check_point.html">eoCheckPoint&lt;EOT&gt;</a> &amp; checkpoint = _state.<a class="code" href="classeo_functor_store.html#a2">storeFunctor</a>(<span class="keyword">new</span> <a class="code" href="classeo_check_point.html">eoCheckPoint&lt;EOT&gt;</a>(_continue));
00052
00054 <span class="keyword">typedef</span> <span class="keyword">typename</span> EOT::Fitness Fit;
00055 Fit fit;
00056 <span class="keywordtype">unsigned</span> nObj = fit.size();
00057
00059 <span class="comment">// Counters</span>
00061 <span class="comment"></span> <span class="comment">// is nb Eval to be used as counter?</span>
00062 <span class="keywordtype">bool</span> useEval = _parser.<a class="code" href="classeo_parser.html#a10">getORcreateParam</a>(<span class="keyword">true</span>, <span class="stringliteral">"useEval"</span>,
00063 <span class="stringliteral">"Use nb of eval. as counter (vs nb of gen.)"</span>,
00064 <span class="charliteral">'\0'</span>, <span class="stringliteral">"Output"</span>).value();
00065
00066 <span class="comment">// Create anyway a generation-counter parameter WARNING: not stored anywhere!!!</span>
00067 <a class="code" href="classeo_value_param.html">eoValueParam&lt;unsigned&gt;</a> *generationCounter = <span class="keyword">new</span> <a class="code" href="classeo_value_param.html">eoValueParam&lt;unsigned&gt;</a>(0, <span class="stringliteral">"Gen."</span>);
00068 <span class="comment">// Create an incrementor (sub-class of eoUpdater).</span>
00069 <a class="code" href="classeo_incrementor.html">eoIncrementor&lt;unsigned&gt;</a> &amp; increment =
00070 _state.<a class="code" href="classeo_functor_store.html#a2">storeFunctor</a>(<span class="keyword">new</span> <a class="code" href="classeo_incrementor.html">eoIncrementor&lt;unsigned&gt;</a>(generationCounter-&gt;<a class="code" href="classeo_value_param.html#a2">value</a>()) );
00071 <span class="comment">// Add it to the checkpoint,</span>
00072 checkpoint.<a class="code" href="classeo_check_point.html#a2">add</a>(increment);
00073
00074 <span class="comment">// dir for DISK output</span>
00075 std::string &amp; dirName = _parser.<a class="code" href="classeo_parser.html#a10">getORcreateParam</a>(std::string(<span class="stringliteral">"Res"</span>), <span class="stringliteral">"resDir"</span>,
00076 <span class="stringliteral">"Directory to store DISK outputs"</span>,
00077 <span class="charliteral">'\0'</span>, <span class="stringliteral">"Output - Disk"</span>).value();
00078 <span class="comment">// shoudl we empty it if exists</span>
00079 <a class="code" href="classeo_value_param.html">eoValueParam&lt;bool&gt;</a>&amp; eraseParam = _parser.<a class="code" href="classeo_parser.html#a10">getORcreateParam</a>(<span class="keyword">true</span>, <span class="stringliteral">"eraseDir"</span>,
00080 <span class="stringliteral">"erase files in dirName if any"</span>,
00081 <span class="charliteral">'\0'</span>, <span class="stringliteral">"Output - Disk"</span>);
00082 <span class="keywordtype">bool</span> dirOK = <span class="keyword">false</span>; <span class="comment">// not tested yet</span>
00083
00085 <span class="comment">// now some statistics on the population:</span>
00087 <span class="comment"></span>
00093 <a class="code" href="classeo_value_param.html">eoValueParam&lt;eoParamParamType&gt;</a>&amp; fPlotParam
00094 = _parser.<a class="code" href="classeo_parser.html#a10">getORcreateParam</a>(<a class="code" href="classeo_param_param_type.html">eoParamParamType</a>(<span class="stringliteral">"1(0,1)"</span>), <span class="stringliteral">"frontFileFrequency"</span>,
00095 <span class="stringliteral">"File save frequency in objective spaces (std::pairs of comma-separated objectives "</span> \
00096 <span class="stringliteral">"in 1 single parentheses std::pair)"</span>,
00097 <span class="charliteral">'\0'</span>, <span class="stringliteral">"Output - Disk"</span>);
00098
00099 <span class="keywordtype">bool</span> boolGnuplot = _parser.<a class="code" href="classeo_parser.html#a10">getORcreateParam</a>(<span class="keyword">false</span>, <span class="stringliteral">"plotFront"</span>,
00100 <span class="stringliteral">"Objective plots (requires corresponding files "</span> \
00101 <span class="stringliteral">"- see frontFileFrequency"</span>,
00102 <span class="charliteral">'\0'</span>, <span class="stringliteral">"Output - Graphical"</span>).value();
00103
00104 <a class="code" href="classeo_param_param_type.html">eoParamParamType</a> &amp; fPlot = fPlotParam.<a class="code" href="classeo_value_param.html#a2">value</a>(); <span class="comment">// std::pair&lt;std::string,std::vector&lt;std::string&gt; &gt;</span>
00105 <span class="keywordtype">unsigned</span> frequency = atoi(fPlot.first.c_str());
00106 <span class="keywordflow">if</span> (frequency) <span class="comment">// something to plot</span>
00107 {
00108 <span class="keywordtype">unsigned</span> nbPlot = fPlot.second.size();
00109 <span class="keywordflow">if</span> ( nbPlot % 2 ) <span class="comment">// odd!</span>
00110 <span class="keywordflow">throw</span> std::runtime_error(<span class="stringliteral">"Odd number of front description in make_checkpoint_pareto"</span>);
00111
00112 <span class="comment">// only create the necessary stats</span>
00113 std::vector&lt;bool&gt; bStat(nObj, <span class="keyword">false</span>); <span class="comment">// track of who's already there</span>
00114 std::vector&lt;eoMOFitnessStat&lt;EOT&gt;* &gt; theStats(nObj);
00115
00116 <span class="comment">// first create the stats</span>
00117 <span class="keywordflow">for</span> (<span class="keywordtype">unsigned</span> i=0; i&lt;nbPlot; i+=2)
00118 {
00119 <span class="keywordtype">unsigned</span> obj1 = atoi(fPlot.second[i].c_str());
00120 <span class="keywordtype">unsigned</span> obj2 = atoi(fPlot.second[i+1].c_str());
00121 <a class="code" href="classeo_m_o_fitness_stat.html">eoMOFitnessStat&lt;EOT&gt;</a>* fStat;
00122 <span class="keywordflow">if</span> (!bStat[obj1]) { <span class="comment">// not already there: create it</span>
00123 std::ostringstream os;
00124 os &lt;&lt; <span class="stringliteral">"Obj. "</span> &lt;&lt; obj1 &lt;&lt; std::ends;
00125 fStat = <span class="keyword">new</span> <a class="code" href="classeo_m_o_fitness_stat.html">eoMOFitnessStat&lt;EOT&gt;</a>(obj1, os.str().c_str());
00126 _state.<a class="code" href="classeo_functor_store.html#a2">storeFunctor</a>(fStat);
00127 bStat[obj1]=<span class="keyword">true</span>;
00128 theStats[obj1]=fStat;
00129 checkpoint.<a class="code" href="classeo_check_point.html#a2">add</a>(*fStat);
00130 }
00131 <span class="keywordflow">if</span> (!bStat[obj2]) { <span class="comment">// not already there: create it</span>
00132 std::ostringstream os;
00133 os &lt;&lt; <span class="stringliteral">"Obj. "</span> &lt;&lt; obj2 &lt;&lt; std::ends;
00134 fStat = <span class="keyword">new</span> <a class="code" href="classeo_m_o_fitness_stat.html">eoMOFitnessStat&lt;EOT&gt;</a>(obj2, os.str().c_str());
00135 _state.<a class="code" href="classeo_functor_store.html#a2">storeFunctor</a>(fStat);
00136 bStat[obj2]=<span class="keyword">true</span>;
00137 theStats[obj2]=fStat;
00138 checkpoint.<a class="code" href="classeo_check_point.html#a2">add</a>(*fStat);
00139 }
00140
00141 <span class="comment">// then the fileSnapshots</span>
00142 std::ostringstream os;
00143 os &lt;&lt; <span class="stringliteral">"Front."</span> &lt;&lt; obj1 &lt;&lt; <span class="stringliteral">"."</span> &lt;&lt; obj2 &lt;&lt; <span class="stringliteral">"."</span> &lt;&lt; std::ends;
00144 <a class="code" href="classeo_file_snapshot.html">eoFileSnapshot</a>&amp; snapshot = _state.<a class="code" href="classeo_functor_store.html#a2">storeFunctor</a>(
00145 <span class="keyword">new</span> <a class="code" href="classeo_file_snapshot.html">eoFileSnapshot</a>(dirName, frequency, os.str().c_str()));
00146 checkpoint.<a class="code" href="classeo_check_point.html#a2">add</a>(snapshot);
00147
00148 snapshot.<a class="code" href="classeo_file_snapshot.html#a9">add</a>(*theStats[obj1]);
00149 snapshot.<a class="code" href="classeo_file_snapshot.html#a9">add</a>(*theStats[obj2]);
00150
00151 <span class="comment">// and create the gnuplotter from the fileSnapshot</span>
00152 <span class="keywordflow">if</span>(boolGnuplot)
00153 {
00154 <a class="code" href="classeo_gnuplot1_d_snapshot.html">eoGnuplot1DSnapshot</a> &amp; plotSnapshot = _state.<a class="code" href="classeo_functor_store.html#a2">storeFunctor</a>(<span class="keyword">new</span>
00155 <a class="code" href="classeo_gnuplot1_d_snapshot.html">eoGnuplot1DSnapshot</a>(snapshot));
00156 plotSnapshot.<a class="code" href="classeo_gnuplot1_d_snapshot.html#a8">setPointSize</a>(3);
00157 checkpoint.<a class="code" href="classeo_check_point.html#a2">add</a>(plotSnapshot);
00158 }
00159 }
00160 }
00161 <span class="comment">// Dump of the whole population</span>
00162 <span class="comment">//-----------------------------</span>
00163 <span class="keywordtype">bool</span> printPop = _parser.<a class="code" href="classeo_parser.html#a10">getORcreateParam</a>(<span class="keyword">false</span>, <span class="stringliteral">"printPop"</span>,
00164 <span class="stringliteral">"Print sorted pop. every gen."</span>,
00165 <span class="charliteral">'\0'</span>, <span class="stringliteral">"Output"</span>).value();
00166 <a class="code" href="classeo_sorted_pop_stat.html">eoSortedPopStat&lt;EOT&gt;</a> * popStat;
00167 <span class="keywordflow">if</span> ( printPop ) <span class="comment">// we do want pop dump</span>
00168 {
00169 std::cout &lt;&lt; <span class="stringliteral">"On cree printpop\n"</span>;
00170 popStat = &amp; _state.<a class="code" href="classeo_functor_store.html#a2">storeFunctor</a>(<span class="keyword">new</span> <a class="code" href="classeo_sorted_pop_stat.html">eoSortedPopStat&lt;EOT&gt;</a>);
00171 <span class="comment">// add it to the checkpoint</span>
00172 checkpoint.<a class="code" href="classeo_check_point.html#a2">add</a>(*popStat);
00173 }
00174
00176 <span class="comment">// The monitors</span>
00178 <span class="comment"></span> <span class="comment">// do we want an eoStdoutMonitor?</span>
00179 <span class="keywordtype">bool</span> needStdoutMonitor = printPop ; <span class="comment">// only this one at the moment</span>
00180
00181 <span class="comment">// The Stdout monitor will print parameters to the screen ...</span>
00182 <span class="keywordflow">if</span> ( needStdoutMonitor )
00183 {
00184 <a class="code" href="classeo_stdout_monitor.html">eoStdoutMonitor</a> &amp; monitor = _state.<a class="code" href="classeo_functor_store.html#a2">storeFunctor</a>(<span class="keyword">new</span> <a class="code" href="classeo_stdout_monitor.html">eoStdoutMonitor</a>(<span class="keyword">false</span>));
00185
00186 <span class="comment">// when called by the checkpoint (i.e. at every generation)</span>
00187 checkpoint.<a class="code" href="classeo_check_point.html#a2">add</a>(monitor);
00188
00189 <span class="comment">// the monitor will output a series of parameters: add them</span>
00190 monitor.<a class="code" href="classeo_monitor.html#a1">add</a>(*generationCounter);
00191 <span class="keywordflow">if</span> (useEval) <span class="comment">// we want nb of evaluations</span>
00192 monitor.<a class="code" href="classeo_monitor.html#a1">add</a>(_eval);
00193 <span class="keywordflow">if</span> ( printPop)
00194 monitor.<a class="code" href="classeo_monitor.html#a1">add</a>(*popStat);
00195 }
00196
00197
00199 <span class="comment">// State savers</span>
00201 <span class="comment"></span>
00202 <span class="comment">// feed the state to state savers</span>
00203 <span class="comment">// save state every N generation</span>
00204 <a class="code" href="classeo_value_param.html">eoValueParam&lt;unsigned&gt;</a>&amp; saveFrequencyParam = _parser.<a class="code" href="classeo_parameter_loader.html#a3">createParam</a>(<span class="keywordtype">unsigned</span>(0), <span class="stringliteral">"saveFrequency"</span>, <span class="stringliteral">"Save every F generation (0 = only final state, absent = never)"</span>, <span class="charliteral">'\0'</span>, <span class="stringliteral">"Persistence"</span> );
00205
00206 <span class="keywordflow">if</span> (_parser.<a class="code" href="classeo_parser.html#a8">isItThere</a>(saveFrequencyParam))
00207 {
00208 <span class="comment">// first make sure dirName is OK</span>
00209 <span class="keywordflow">if</span> (! dirOK )
00210 dirOK = testDirRes(dirName, eraseParam.<a class="code" href="classeo_value_param.html#a2">value</a>()); <span class="comment">// TRUE</span>
00211
00212 <span class="keywordtype">unsigned</span> freq = (saveFrequencyParam.<a class="code" href="classeo_value_param.html#a2">value</a>()&gt;0 ? saveFrequencyParam.<a class="code" href="classeo_value_param.html#a2">value</a>() : UINT_MAX );
00213 <span class="preprocessor">#ifdef _MSVC</span>
00214 <span class="preprocessor"></span> std::string stmp = dirName + <span class="stringliteral">"\generations"</span>;
00215 <span class="preprocessor">#else</span>
00216 <span class="preprocessor"></span> std::string stmp = dirName + <span class="stringliteral">"/generations"</span>;
00217 <span class="preprocessor">#endif</span>
00218 <span class="preprocessor"></span> <a class="code" href="classeo_counted_state_saver.html">eoCountedStateSaver</a> *stateSaver1 = <span class="keyword">new</span> <a class="code" href="classeo_counted_state_saver.html">eoCountedStateSaver</a>(freq, _state, stmp);
00219 _state.<a class="code" href="classeo_functor_store.html#a2">storeFunctor</a>(stateSaver1);
00220 checkpoint.<a class="code" href="classeo_check_point.html#a2">add</a>(*stateSaver1);
00221 }
00222
00223 <span class="comment">// save state every T seconds</span>
00224 <a class="code" href="classeo_value_param.html">eoValueParam&lt;unsigned&gt;</a>&amp; saveTimeIntervalParam
00225 = _parser.<a class="code" href="classeo_parser.html#a10">getORcreateParam</a>(<span class="keywordtype">unsigned</span>(0), <span class="stringliteral">"saveTimeInterval"</span>,
00226 <span class="stringliteral">"Save every T seconds (0 or absent = never)"</span>, <span class="charliteral">'\0'</span>,<span class="stringliteral">"Persistence"</span> );
00227 <span class="keywordflow">if</span> (_parser.<a class="code" href="classeo_parser.html#a8">isItThere</a>(saveTimeIntervalParam) &amp;&amp; saveTimeIntervalParam.<a class="code" href="classeo_value_param.html#a2">value</a>()&gt;0)
00228 {
00229 <span class="comment">// first make sure dirName is OK</span>
00230 <span class="keywordflow">if</span> (! dirOK )
00231 dirOK = testDirRes(dirName, eraseParam.<a class="code" href="classeo_value_param.html#a2">value</a>()); <span class="comment">// TRUE</span>
00232
00233 <span class="preprocessor">#ifdef _MSVC</span>
00234 <span class="preprocessor"></span> std::string stmp = dirName + <span class="stringliteral">"\time"</span>;
00235 <span class="preprocessor">#else</span>
00236 <span class="preprocessor"></span> std::string stmp = dirName + <span class="stringliteral">"/time"</span>;
00237 <span class="preprocessor">#endif</span>
00238 <span class="preprocessor"></span> <a class="code" href="classeo_timed_state_saver.html">eoTimedStateSaver</a> *stateSaver2 = <span class="keyword">new</span> <a class="code" href="classeo_timed_state_saver.html">eoTimedStateSaver</a>(saveTimeIntervalParam.<a class="code" href="classeo_value_param.html#a2">value</a>(), _state, stmp);
00239 _state.<a class="code" href="classeo_functor_store.html#a2">storeFunctor</a>(stateSaver2);
00240 checkpoint.<a class="code" href="classeo_check_point.html#a2">add</a>(*stateSaver2);
00241 }
00242
00243 <span class="comment">// and that's it for the (control and) output</span>
00244 <span class="keywordflow">return</span> checkpoint;
00245 }
00246
00247 <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>