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:
parent
bc1f453978
commit
c3aec878e5
3609 changed files with 342772 additions and 0 deletions
|
|
@ -0,0 +1,175 @@
|
|||
<!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_general_replacement.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 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 Hierarchy</a> | <a class="qindex" href="classes.html">Alphabetical List</a> | <a class="qindex" href="annotated.html">Class List</a> | <a class="qindex" href="files.html">File List</a> | <a class="qindex" href="namespacemembers.html">Namespace Members</a> | <a class="qindex" href="functions.html">Class Members</a> | <a class="qindex" href="pages.html">Related Pages</a> | <span class="search"><u>S</u>earch for <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> / <a class="el" href="dir_000025.html">do</a></div>
|
||||
<h1>make_general_replacement.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_general_replacement.h</span>
|
||||
00005 <span class="comment">// (c) Marc Schoenauer and Pierre Collet, 2002</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_general_replacement_h</span>
|
||||
00028 <span class="preprocessor"></span><span class="preprocessor">#define _make_general_replacement_h</span>
|
||||
00029 <span class="preprocessor"></span>
|
||||
00030 <span class="preprocessor">#include <utils/eoData.h></span> <span class="comment">// for eo_is_a_rate</span>
|
||||
00031
|
||||
00032 <span class="comment">// Replacement</span>
|
||||
00033 <span class="preprocessor">#include <eoReduceMergeReduce.h></span>
|
||||
00034
|
||||
00035 <span class="comment">// also need the parser and param includes</span>
|
||||
00036 <span class="preprocessor">#include <utils/eoParser.h></span>
|
||||
00037 <span class="preprocessor">#include <utils/eoState.h></span>
|
||||
00038
|
||||
00039
|
||||
00043 <span class="keyword">template</span> <<span class="keyword">class</span> EOT>
|
||||
00044 <a class="code" href="classeo_reduce.html">eoReduce<EOT></a> & decode_reduce(<a class="code" href="classeo_param_param_type.html">eoParamParamType</a> & _ppReduce, <a class="code" href="classeo_state.html">eoState</a> & _state)
|
||||
00045 {
|
||||
00046 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> detSize;
|
||||
00047 <a class="code" href="classeo_reduce.html">eoReduce<EOT></a> * ptReduce;
|
||||
00048
|
||||
00049 <span class="comment">// ---------- Deterministic</span>
|
||||
00050 <span class="keywordflow">if</span> ( (_ppReduce.first == std::string(<span class="stringliteral">"Deterministic"</span>)) ||
|
||||
00051 (_ppReduce.first == std::string(<span class="stringliteral">"Sequential"</span>))
|
||||
00052 )
|
||||
00053 {
|
||||
00054 ptReduce = <span class="keyword">new</span> <a class="code" href="classeo_truncate.html">eoTruncate<EOT></a>;
|
||||
00055 }
|
||||
00056 <span class="comment">// ---------- EP</span>
|
||||
00057 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (_ppReduce.first == std::string(<span class="stringliteral">"EP"</span>))
|
||||
00058 {
|
||||
00059 <span class="keywordflow">if</span> (!_ppReduce.second.size()) <span class="comment">// no parameter added</span>
|
||||
00060 {
|
||||
00061 std::cerr << <span class="stringliteral">"WARNING, no parameter passed to EP, using 6"</span> << std::endl;
|
||||
00062 detSize = 6;
|
||||
00063 <span class="comment">// put back 6 in parameter for consistency (and status file)</span>
|
||||
00064 _ppReduce.second.push_back(std::string(<span class="stringliteral">"6"</span>));
|
||||
00065 }
|
||||
00066 <span class="keywordflow">else</span> <span class="comment">// parameter passed by user as EP(T)</span>
|
||||
00067 detSize = atoi(_ppReduce.second[0].c_str());
|
||||
00068 ptReduce = <span class="keyword">new</span> <a class="code" href="classeo_e_p_reduce.html">eoEPReduce<EOT></a>(detSize);
|
||||
00069 }
|
||||
00070 <span class="comment">// ---------- DetTour</span>
|
||||
00071 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (_ppReduce.first == std::string(<span class="stringliteral">"DetTour"</span>))
|
||||
00072 {
|
||||
00073 <span class="keywordflow">if</span> (!_ppReduce.second.size()) <span class="comment">// no parameter added</span>
|
||||
00074 {
|
||||
00075 std::cerr << <span class="stringliteral">"WARNING, no parameter passed to DetTour, using 2"</span> << std::endl;
|
||||
00076 detSize = 2;
|
||||
00077 <span class="comment">// put back 2 in parameter for consistency (and status file)</span>
|
||||
00078 _ppReduce.second.push_back(std::string(<span class="stringliteral">"2"</span>));
|
||||
00079 }
|
||||
00080 <span class="keywordflow">else</span> <span class="comment">// parameter passed by user as DetTour(T)</span>
|
||||
00081 detSize = atoi(_ppReduce.second[0].c_str());
|
||||
00082 ptReduce = <span class="keyword">new</span> <a class="code" href="classeo_det_tournament_truncate.html">eoDetTournamentTruncate<EOT></a>(detSize);
|
||||
00083 }
|
||||
00084 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (_ppReduce.first == std::string(<span class="stringliteral">"StochTour"</span>))
|
||||
00085 {
|
||||
00086 <span class="keywordtype">double</span> p;
|
||||
00087 <span class="keywordflow">if</span> (!_ppReduce.second.size()) <span class="comment">// no parameter added</span>
|
||||
00088 {
|
||||
00089 std::cerr << <span class="stringliteral">"WARNING, no parameter passed to StochTour, using 1"</span> << std::endl;
|
||||
00090 p = 1;
|
||||
00091 <span class="comment">// put back p in parameter for consistency (and status file)</span>
|
||||
00092 _ppReduce.second.push_back(std::string(<span class="stringliteral">"1"</span>));
|
||||
00093 }
|
||||
00094 <span class="keywordflow">else</span> <span class="comment">// parameter passed by user as DetTour(T)</span>
|
||||
00095 {
|
||||
00096 p = atof(_ppReduce.second[0].c_str());
|
||||
00097 <span class="keywordflow">if</span> ( (p<=0.5) || (p>1) )
|
||||
00098 <span class="keywordflow">throw</span> std::runtime_error(<span class="stringliteral">"Stochastic tournament size should be in [0.5,1]"</span>);
|
||||
00099 }
|
||||
00100
|
||||
00101 ptReduce = <span class="keyword">new</span> <a class="code" href="classeo_stoch_tournament_truncate.html">eoStochTournamentTruncate<EOT></a>(p);
|
||||
00102 }
|
||||
00103 <span class="keywordflow">else</span> <span class="keywordflow">if</span> ( (_ppReduce.first == std::string(<span class="stringliteral">"Uniform"</span>)) ||
|
||||
00104 (_ppReduce.first == std::string(<span class="stringliteral">"Random"</span>))
|
||||
00105 )
|
||||
00106 {
|
||||
00107 ptReduce = <span class="keyword">new</span> <a class="code" href="classeo_random_reduce.html">eoRandomReduce<EOT></a>;
|
||||
00108 }
|
||||
00109 <span class="keywordflow">else</span> <span class="comment">// no known reduction entered</span>
|
||||
00110 {
|
||||
00111 <span class="keywordflow">throw</span> std::runtime_error(<span class="stringliteral">"Unknown reducer: "</span> + _ppReduce.first);
|
||||
00112 }
|
||||
00113 <span class="comment">// all done, stores and return a reference</span>
|
||||
00114 _state.<a class="code" href="classeo_functor_store.html#a2">storeFunctor</a>(ptReduce);
|
||||
00115 <span class="keywordflow">return</span> (*ptReduce);
|
||||
00116 }
|
||||
00117
|
||||
00134 <span class="keyword">template</span> <<span class="keyword">class</span> EOT>
|
||||
00135 <a class="code" href="classeo_replacement.html">eoReplacement<EOT></a> & make_general_replacement(
|
||||
00136 <a class="code" href="classeo_parser.html">eoParser</a>& _parser, <a class="code" href="classeo_state.html">eoState</a>& _state,
|
||||
00137 <a class="code" href="classeo_how_many.html">eoHowMany</a> _elite = <a class="code" href="classeo_how_many.html">eoHowMany</a>(0),
|
||||
00138 <span class="keywordtype">bool</span> _strongElitism = <span class="keyword">false</span>,
|
||||
00139 <a class="code" href="classeo_how_many.html">eoHowMany</a> _surviveParents = <a class="code" href="classeo_how_many.html">eoHowMany</a>(0.0),
|
||||
00140 <a class="code" href="classeo_param_param_type.html">eoParamParamType</a> & _reduceParentType = <a class="code" href="classeo_param_param_type.html">eoParamParamType</a>(<span class="stringliteral">"Deterministic"</span>),
|
||||
00141 <a class="code" href="classeo_how_many.html">eoHowMany</a> _surviveOffspring = <a class="code" href="classeo_how_many.html">eoHowMany</a>(1.0),
|
||||
00142 <a class="code" href="classeo_param_param_type.html">eoParamParamType</a> & _reduceOffspringType = <a class="code" href="classeo_param_param_type.html">eoParamParamType</a>(<span class="stringliteral">"Deterministic"</span>),
|
||||
00143 <a class="code" href="classeo_param_param_type.html">eoParamParamType</a> & _reduceFinalType = <a class="code" href="classeo_param_param_type.html">eoParamParamType</a>(<span class="stringliteral">"Deterministic"</span>)
|
||||
00144 )
|
||||
00145 {
|
||||
00147 <span class="comment">// the replacement</span>
|
||||
00149 <span class="comment"></span>
|
||||
00150 <span class="comment">// Elitism</span>
|
||||
00151 <a class="code" href="classeo_how_many.html">eoHowMany</a> elite = _parser.<a class="code" href="classeo_parameter_loader.html#a3">createParam</a>(_elite, <span class="stringliteral">"elite"</span>, <span class="stringliteral">"Nb of elite parents (percentage or absolute)"</span>, <span class="charliteral">'\0'</span>, <span class="stringliteral">"Evolution Engine / Replacement"</span>).value();
|
||||
00152
|
||||
00153 <span class="keywordtype">bool</span> strongElitism = _parser.<a class="code" href="classeo_parameter_loader.html#a3">createParam</a>(_strongElitism,<span class="stringliteral">"eliteType"</span>, <span class="stringliteral">"Strong (true) or weak (false) elitism (set elite to 0 for none)"</span>, <span class="charliteral">'\0'</span>, <span class="stringliteral">"Evolution Engine / Replacement"</span>).value();
|
||||
00154
|
||||
00155 <span class="comment">// reduce the parents</span>
|
||||
00156 <a class="code" href="classeo_how_many.html">eoHowMany</a> surviveParents = _parser.<a class="code" href="classeo_parameter_loader.html#a3">createParam</a>(_surviveParents, <span class="stringliteral">"surviveParents"</span>, <span class="stringliteral">"Nb of surviving parents (percentage or absolute)"</span>, <span class="charliteral">'\0'</span>, <span class="stringliteral">"Evolution Engine / Replacement"</span>).value();
|
||||
00157
|
||||
00158 <a class="code" href="classeo_param_param_type.html">eoParamParamType</a> & reduceParentType = _parser.<a class="code" href="classeo_parameter_loader.html#a3">createParam</a>(_reduceParentType, <span class="stringliteral">"reduceParents"</span>, <span class="stringliteral">"Parents reducer: Deterministic, EP(T), DetTour(T), StochTour(t), Uniform"</span>, <span class="charliteral">'\0'</span>, <span class="stringliteral">"Evolution Engine / Replacement"</span>).value();
|
||||
00159
|
||||
00160 <a class="code" href="classeo_reduce.html">eoReduce<EOT></a> & reduceParent = decode_reduce<EOT>(reduceParentType, _state);
|
||||
00161
|
||||
00162 <span class="comment">// reduce the offspring</span>
|
||||
00163 <a class="code" href="classeo_how_many.html">eoHowMany</a> surviveOffspring = _parser.<a class="code" href="classeo_parameter_loader.html#a3">createParam</a>(_surviveOffspring, <span class="stringliteral">"surviveOffspring"</span>, <span class="stringliteral">"Nb of surviving offspring (percentage or absolute)"</span>, <span class="charliteral">'\0'</span>, <span class="stringliteral">"Evolution Engine / Replacement"</span>).value();
|
||||
00164
|
||||
00165 <a class="code" href="classeo_param_param_type.html">eoParamParamType</a> & reduceOffspringType = _parser.<a class="code" href="classeo_parameter_loader.html#a3">createParam</a>(_reduceOffspringType, <span class="stringliteral">"reduceOffspring"</span>, <span class="stringliteral">"Offspring reducer: Deterministic, EP(T), DetTour(T), StochTour(t), Uniform"</span>, <span class="charliteral">'\0'</span>, <span class="stringliteral">"Evolution Engine / Replacement"</span>).value();
|
||||
00166
|
||||
00167 <a class="code" href="classeo_reduce.html">eoReduce<EOT></a> & reduceOffspring = decode_reduce<EOT>(reduceOffspringType, _state);
|
||||
00168
|
||||
00169 <a class="code" href="classeo_param_param_type.html">eoParamParamType</a> & reduceFinalType = _parser.<a class="code" href="classeo_parameter_loader.html#a3">createParam</a>(_reduceFinalType, <span class="stringliteral">"reduceFinal"</span>, <span class="stringliteral">"Final reducer: Deterministic, EP(T), DetTour(T), StochTour(t), Uniform"</span>, <span class="charliteral">'\0'</span>, <span class="stringliteral">"Evolution Engine / Replacement"</span>).value();
|
||||
00170
|
||||
00171 <a class="code" href="classeo_reduce.html">eoReduce<EOT></a> & reduceFinal = decode_reduce<EOT>(reduceFinalType, _state);
|
||||
00172
|
||||
00173 <span class="comment">// now the replacement itself</span>
|
||||
00174 <a class="code" href="classeo_reduce_merge_reduce.html">eoReduceMergeReduce<EOT></a> *ptReplace = <span class="keyword">new</span> <a class="code" href="classeo_reduce_merge_reduce.html">eoReduceMergeReduce<EOT></a>(elite, strongElitism, surviveParents, reduceParent, surviveOffspring, reduceOffspring, reduceFinal);
|
||||
00175 _state.<a class="code" href="classeo_functor_store.html#a2">storeFunctor</a>(ptReplace);
|
||||
00176
|
||||
00177 <span class="comment">// that's it!</span>
|
||||
00178 <span class="keywordflow">return</span> *ptReplace;
|
||||
00179 }
|
||||
00180
|
||||
00181 <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
|
||||
<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>
|
||||
Loading…
Add table
Add a link
Reference in a new issue