git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@40 331e1502-861f-0410-8da2-ba01fb791d7f
218 lines
18 KiB
HTML
218 lines
18 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_algo_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 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_algo_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_algo_pareto.h</span>
|
|
00005 <span class="comment">// (c) Maarten Keijzer, Marc Schoenauer and GeNeura Team, 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@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_algo_pareto_h</span>
|
|
00028 <span class="preprocessor"></span><span class="preprocessor">#define _make_algo_pareto_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 <span class="comment">// everything tha's needed for the algorithms - SCALAR fitness</span>
|
|
00032
|
|
00033 <span class="comment">// Selection</span>
|
|
00034 <span class="comment">// the eoSelectOne's</span>
|
|
00035 <span class="preprocessor">#include "eoSelectFromWorth.h"</span>
|
|
00036 <span class="preprocessor">#include "eoNDSorting.h"</span>
|
|
00037
|
|
00038 <span class="comment">// Breeders</span>
|
|
00039 <span class="preprocessor">#include "eoGeneralBreeder.h"</span>
|
|
00040
|
|
00041 <span class="comment">// Replacement - at the moment limited to eoNDPlusReplacement, locally defined</span>
|
|
00042 <span class="preprocessor">#include "eoReplacement.h"</span>
|
|
00043
|
|
00044 <span class="keyword">template</span> <<span class="keyword">class</span> EOT, <span class="keyword">class</span> WorthT = <span class="keywordtype">double</span>>
|
|
<a name="l00045"></a><a class="code" href="classeo_n_d_plus_replacement.html">00045</a> <span class="keyword">class </span><a class="code" href="classeo_n_d_plus_replacement.html">eoNDPlusReplacement</a> : <span class="keyword">public</span> <a class="code" href="classeo_replacement.html">eoReplacement</a><EOT>
|
|
00046 {
|
|
00047 <span class="keyword">public</span>:
|
|
00048 <a class="code" href="classeo_n_d_plus_replacement.html">eoNDPlusReplacement</a>(<a class="code" href="classeo_perf2_worth.html">eoPerf2Worth<EOT, WorthT></a>& _perf2worth) : perf2worth(_perf2worth) {}
|
|
00049
|
|
00050 <span class="keyword">struct </span>WorthPair : <span class="keyword">public</span> std::pair<WorthT, const EOT*>
|
|
00051 {
|
|
00052 <span class="keywordtype">bool</span> operator<(<span class="keyword">const</span> WorthPair& other)<span class="keyword"> const </span>{ <span class="keywordflow">return</span> other.first < this->first; }
|
|
00053 };
|
|
00054
|
|
<a name="l00055"></a><a class="code" href="classeo_n_d_plus_replacement.html#a1">00055</a> <span class="keywordtype">void</span> <a class="code" href="classeo_n_d_plus_replacement.html#a1">operator()</a>(<a class="code" href="classeo_pop.html">eoPop<EOT></a>& _parents, <a class="code" href="classeo_pop.html">eoPop<EOT></a>& _offspring)
|
|
00056 {
|
|
00057 <span class="keywordtype">unsigned</span> sz = _parents.size();
|
|
00058 _parents.reserve(_parents.size() + _offspring.size());
|
|
00059 copy(_offspring.begin(), _offspring.end(), back_inserter(_parents));
|
|
00060
|
|
00061 <span class="comment">// calculate worths</span>
|
|
00062 perf2worth(_parents);
|
|
00063 perf2worth.sort_pop(_parents);
|
|
00064 perf2worth.resize(_parents, sz);
|
|
00065
|
|
00066 _offspring.clear();
|
|
00067 }
|
|
00068
|
|
00069 <span class="keyword">private</span> :
|
|
00070 <a class="code" href="classeo_perf2_worth.html">eoPerf2Worth<EOT, WorthT></a>& perf2worth;
|
|
00071 };
|
|
00072
|
|
00073
|
|
00074 <span class="comment">// Algorithm (only this one needed)</span>
|
|
00075 <span class="preprocessor">#include "eoEasyEA.h"</span>
|
|
00076
|
|
00077 <span class="comment">// also need the parser and param includes</span>
|
|
00078 <span class="preprocessor">#include "utils/eoParser.h"</span>
|
|
00079 <span class="preprocessor">#include "utils/eoState.h"</span>
|
|
00080
|
|
00081
|
|
00082 <span class="comment">/*</span>
|
|
00083 <span class="comment"> * This function builds the algorithm (i.e. selection and replacement)</span>
|
|
00084 <span class="comment"> * from existing continue (or checkpoint) and operators</span>
|
|
00085 <span class="comment"> *</span>
|
|
00086 <span class="comment"> * It uses a parser (to get user parameters) and a state (to store the memory)</span>
|
|
00087 <span class="comment"> * the last argument is an individual, needed for 2 reasons</span>
|
|
00088 <span class="comment"> * it disambiguates the call after instanciations</span>
|
|
00089 <span class="comment"> * some operator might need some private information about the indis</span>
|
|
00090 <span class="comment"> *</span>
|
|
00091 <span class="comment"> * This is why the template is the complete EOT even though only the fitness</span>
|
|
00092 <span class="comment"> * is actually templatized here</span>
|
|
00093 <span class="comment">*/</span>
|
|
00094
|
|
00095 <span class="keyword">template</span> <<span class="keyword">class</span> EOT>
|
|
00096 <a class="code" href="classeo_algo.html">eoAlgo<EOT></a> & do_make_algo_pareto(<a class="code" href="classeo_parser.html">eoParser</a>& _parser, <a class="code" href="classeo_state.html">eoState</a>& _state, <a class="code" href="classeo_eval_func.html">eoEvalFunc<EOT></a>& _eval, <a class="code" href="classeo_continue.html">eoContinue<EOT></a>& _continue, <a class="code" href="classeo_gen_op.html">eoGenOp<EOT></a>& _op)
|
|
00097 {
|
|
00098 <span class="comment">// the selection</span>
|
|
00099 std::string & selStr = _parser.<a class="code" href="classeo_parameter_loader.html#a3">createParam</a>(std::string(<span class="stringliteral">"NSGA-II"</span>), <span class="stringliteral">"selCrit"</span>, <span class="stringliteral">"Pareto Selection Criterion: NSGA, NSGA-II, ParetoRanking"</span>, <span class="charliteral">'S'</span>, <span class="stringliteral">"Evolution Engine"</span>).value();
|
|
00100 <span class="keywordtype">double</span> nicheSize = _parser.<a class="code" href="classeo_parameter_loader.html#a3">createParam</a>(1.0, <span class="stringliteral">"nicheSize"</span>, <span class="stringliteral">"Size of niche for NSGA-I"</span>, <span class="charliteral">'\0'</span>, <span class="stringliteral">"Evolution Engine"</span>).value();
|
|
00101 <a class="code" href="classeo_perf2_worth.html">eoPerf2Worth<EOT, double></a> *p2w;
|
|
00102 <span class="keywordflow">if</span> ( (selStr == std::string(<span class="stringliteral">"NSGA"</span>)) || (selStr == std::string(<span class="stringliteral">"NSGA-I"</span>) ) )
|
|
00103 p2w = <span class="keyword">new</span> <a class="code" href="classeo_n_d_sorting___i.html">eoNDSorting_I<EOT></a>(nicheSize);
|
|
00104 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (selStr == std::string(<span class="stringliteral">"NSGA-II"</span>))
|
|
00105 p2w = <span class="keyword">new</span> <a class="code" href="classeo_n_d_sorting___i_i.html">eoNDSorting_II<EOT></a>();
|
|
00106 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (selStr == std::string(<span class="stringliteral">"ParetoRanking"</span>))
|
|
00107 {
|
|
00108 <a class="code" href="classeo_dominance_map.html">eoDominanceMap<EOT></a>& dominance = _state.<a class="code" href="classeo_functor_store.html#a2">storeFunctor</a>(<span class="keyword">new</span> <a class="code" href="classeo_dominance_map.html">eoDominanceMap<EOT></a>);
|
|
00109 p2w = <span class="keyword">new</span> <a class="code" href="classeo_pareto_ranking.html">eoParetoRanking<EOT></a>(dominance);
|
|
00110 }
|
|
00111
|
|
00112 _state.<a class="code" href="classeo_functor_store.html#a2">storeFunctor</a>(p2w);
|
|
00113
|
|
00114 <span class="comment">// now the selector (from p2w) - cut-and-pasted from make_algo_scalar!</span>
|
|
00115 <span class="comment">// only all classes are now ...FromWorth ...</span>
|
|
00116 <span class="comment">// only the ranking is not re-implemented (yet?)</span>
|
|
00117 <a class="code" href="classeo_value_param.html">eoValueParam<eoParamParamType></a>& selectionParam = _parser.<a class="code" href="classeo_parameter_loader.html#a3">createParam</a>(<a class="code" href="classeo_param_param_type.html">eoParamParamType</a>(<span class="stringliteral">"DetTour(2)"</span>), <span class="stringliteral">"selection"</span>, <span class="stringliteral">"Selection: Roulette, DetTour(T), StochTour(t) or Random"</span>, <span class="charliteral">'S'</span>, <span class="stringliteral">"Evolution Engine"</span>);
|
|
00118
|
|
00119 <a class="code" href="classeo_param_param_type.html">eoParamParamType</a> & ppSelect = selectionParam.<a class="code" href="classeo_value_param.html#a2">value</a>(); <span class="comment">// std::pair<std::string,std::vector<std::string> ></span>
|
|
00120
|
|
00121 <a class="code" href="classeo_select_one.html">eoSelectOne<EOT></a>* select ;
|
|
00122 <span class="keywordflow">if</span> (ppSelect.first == std::string(<span class="stringliteral">"DetTour"</span>))
|
|
00123 {
|
|
00124 <span class="keywordtype">unsigned</span> detSize;
|
|
00125
|
|
00126 <span class="keywordflow">if</span> (!ppSelect.second.size()) <span class="comment">// no parameter added</span>
|
|
00127 {
|
|
00128 std::cerr << <span class="stringliteral">"WARNING, no parameter passed to DetTour, using 2"</span> << std::endl;
|
|
00129 detSize = 2;
|
|
00130 <span class="comment">// put back 2 in parameter for consistency (and status file)</span>
|
|
00131 ppSelect.second.push_back(std::string(<span class="stringliteral">"2"</span>));
|
|
00132 }
|
|
00133 <span class="keywordflow">else</span> <span class="comment">// parameter passed by user as DetTour(T)</span>
|
|
00134 detSize = atoi(ppSelect.second[0].c_str());
|
|
00135 select = <span class="keyword">new</span> <a class="code" href="classeo_det_tournament_worth_select.html">eoDetTournamentWorthSelect<EOT></a>(*p2w, detSize);
|
|
00136 }
|
|
00137 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (ppSelect.first == std::string(<span class="stringliteral">"StochTour"</span>))
|
|
00138 {
|
|
00139 <span class="keywordtype">double</span> p;
|
|
00140 <span class="keywordflow">if</span> (!ppSelect.second.size()) <span class="comment">// no parameter added</span>
|
|
00141 {
|
|
00142 std::cerr << <span class="stringliteral">"WARNING, no parameter passed to StochTour, using 1"</span> << std::endl;
|
|
00143 p = 1;
|
|
00144 <span class="comment">// put back p in parameter for consistency (and status file)</span>
|
|
00145 ppSelect.second.push_back(std::string(<span class="stringliteral">"1"</span>));
|
|
00146 }
|
|
00147 <span class="keywordflow">else</span> <span class="comment">// parameter passed by user as DetTour(T)</span>
|
|
00148 p = atof(ppSelect.second[0].c_str());
|
|
00149
|
|
00150 select = <span class="keyword">new</span> <a class="code" href="classeo_stoch_tournament_worth_select.html">eoStochTournamentWorthSelect<EOT></a>(*p2w, p);
|
|
00151 }
|
|
00152 <span class="comment">// else if (ppSelect.first == std::string("Sequential")) // one after the other</span>
|
|
00153 <span class="comment">// {</span>
|
|
00154 <span class="comment">// bool b;</span>
|
|
00155 <span class="comment">// if (ppSelect.second.size() == 0) // no argument -> default = ordered</span>
|
|
00156 <span class="comment">// {</span>
|
|
00157 <span class="comment">// b=true;</span>
|
|
00158 <span class="comment">// // put back in parameter for consistency (and status file)</span>
|
|
00159 <span class="comment">// ppSelect.second.push_back(std::string("ordered"));</span>
|
|
00160 <span class="comment">// }</span>
|
|
00161 <span class="comment">// else</span>
|
|
00162 <span class="comment">// b = !(ppSelect.second[0] == std::string("unordered"));</span>
|
|
00163 <span class="comment">// select = new eoSequentialWorthSelect<EOT>(b);</span>
|
|
00164 <span class="comment">// }</span>
|
|
00165 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (ppSelect.first == std::string(<span class="stringliteral">"Roulette"</span>)) <span class="comment">// no argument (yet)</span>
|
|
00166 {
|
|
00167 select = <span class="keyword">new</span> <a class="code" href="classeo_roulette_worth_select.html">eoRouletteWorthSelect<EOT></a>(*p2w);
|
|
00168 }
|
|
00169 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (ppSelect.first == std::string(<span class="stringliteral">"Random"</span>)) <span class="comment">// no argument, no perf2Worth</span>
|
|
00170 {
|
|
00171 select = <span class="keyword">new</span> <a class="code" href="classeo_random_select.html">eoRandomSelect<EOT></a>;
|
|
00172 }
|
|
00173 <span class="keywordflow">else</span>
|
|
00174 {
|
|
00175 std::string stmp = std::string(<span class="stringliteral">"Invalid selection: "</span>) + ppSelect.first;
|
|
00176 <span class="keywordflow">throw</span> std::runtime_error(stmp.c_str());
|
|
00177 }
|
|
00178
|
|
00179 _state.<a class="code" href="classeo_functor_store.html#a2">storeFunctor</a>(select);
|
|
00180
|
|
00181
|
|
00182 <span class="comment">// the number of offspring </span>
|
|
00183 <a class="code" href="classeo_value_param.html">eoValueParam<eoHowMany></a>& offspringRateParam = _parser.<a class="code" href="classeo_parameter_loader.html#a3">createParam</a>(<a class="code" href="classeo_how_many.html">eoHowMany</a>(1.0), <span class="stringliteral">"nbOffspring"</span>, <span class="stringliteral">"Nb of offspring (percentage or absolute)"</span>, <span class="charliteral">'O'</span>, <span class="stringliteral">"Evolution Engine"</span>);
|
|
00184
|
|
00185 <span class="comment">// the replacement</span>
|
|
00186 <span class="comment">// actually limited to eoNDPlusReplacement</span>
|
|
00187 <a class="code" href="classeo_replacement.html">eoReplacement<EOT></a> & replace = _state.<a class="code" href="classeo_functor_store.html#a2">storeFunctor</a>(
|
|
00188 <span class="keyword">new</span> <a class="code" href="classeo_n_d_plus_replacement.html">eoNDPlusReplacement<EOT, double></a>(*p2w)
|
|
00189 );
|
|
00190
|
|
00191 <span class="comment">// the general breeder</span>
|
|
00192 <a class="code" href="classeo_general_breeder.html">eoGeneralBreeder<EOT></a> *breed =
|
|
00193 <span class="keyword">new</span> <a class="code" href="classeo_general_breeder.html">eoGeneralBreeder<EOT></a>(*select, _op, offspringRateParam.<a class="code" href="classeo_value_param.html#a2">value</a>());
|
|
00194 _state.<a class="code" href="classeo_functor_store.html#a2">storeFunctor</a>(breed);
|
|
00195
|
|
00196 <span class="comment">// now the eoEasyEA</span>
|
|
00197 <a class="code" href="classeo_algo.html">eoAlgo<EOT></a> *algo = <span class="keyword">new</span> <a class="code" href="classeo_easy_e_a.html">eoEasyEA<EOT></a>(_continue, _eval, *breed, replace);
|
|
00198 _state.<a class="code" href="classeo_functor_store.html#a2">storeFunctor</a>(algo);
|
|
00199 <span class="comment">// that's it!</span>
|
|
00200 <span class="keywordflow">return</span> *algo;
|
|
00201 }
|
|
00202
|
|
00203 <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>
|