paradiseo/trunk/paradiseo-moeo/doc/html/moeoIteratedIBMOLS_8h-source.html
legrand 04b12455d0 added good doc files
git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@683 331e1502-861f-0410-8da2-ba01fb791d7f
2007-10-08 14:49:10 +00:00

206 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>ParadisEO-MOEOMovingObjects: moeoIteratedIBMOLS.h Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
<link href="tabs.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.4.7 -->
<div class="tabs">
<ul>
<li><a href="main.html"><span>Main&nbsp;Page</span></a></li>
<li><a href="classes.html"><span>Classes</span></a></li>
<li id="current"><a href="files.html"><span>Files</span></a></li>
<li>
<form action="search.php" method="get">
<table cellspacing="0" cellpadding="0" border="0">
<tr>
<td><label>&nbsp;<u>S</u>earch&nbsp;for&nbsp;</label></td>
<td><input type="text" name="query" value="" size="20" accesskey="s"/></td>
</tr>
</table>
</form>
</li>
</ul></div>
<h1>moeoIteratedIBMOLS.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-</span>
<a name="l00002"></a>00002
<a name="l00003"></a>00003 <span class="comment">//-----------------------------------------------------------------------------</span>
<a name="l00004"></a>00004 <span class="comment">// moeoIteratedIBMOLS.h</span>
<a name="l00005"></a>00005 <span class="comment">// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007</span>
<a name="l00006"></a>00006 <span class="comment">/*</span>
<a name="l00007"></a>00007 <span class="comment"> This library...</span>
<a name="l00008"></a>00008 <span class="comment"></span>
<a name="l00009"></a>00009 <span class="comment"> Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr</span>
<a name="l00010"></a>00010 <span class="comment"> */</span>
<a name="l00011"></a>00011 <span class="comment">//-----------------------------------------------------------------------------</span>
<a name="l00012"></a>00012
<a name="l00013"></a>00013 <span class="preprocessor">#ifndef MOEOITERATEDIBMOLS_H_</span>
<a name="l00014"></a>00014 <span class="preprocessor"></span><span class="preprocessor">#define MOEOITERATEDIBMOLS_H_</span>
<a name="l00015"></a>00015 <span class="preprocessor"></span>
<a name="l00016"></a>00016 <span class="preprocessor">#include &lt;eoContinue.h&gt;</span>
<a name="l00017"></a>00017 <span class="preprocessor">#include &lt;eoEvalFunc.h&gt;</span>
<a name="l00018"></a>00018 <span class="preprocessor">#include &lt;eoOp.h&gt;</span>
<a name="l00019"></a>00019 <span class="preprocessor">#include &lt;eoPop.h&gt;</span>
<a name="l00020"></a>00020 <span class="preprocessor">#include &lt;utils/rnd_generators.h&gt;</span>
<a name="l00021"></a>00021 <span class="preprocessor">#include &lt;moMove.h&gt;</span>
<a name="l00022"></a>00022 <span class="preprocessor">#include &lt;moMoveInit.h&gt;</span>
<a name="l00023"></a>00023 <span class="preprocessor">#include &lt;moNextMove.h&gt;</span>
<a name="l00024"></a>00024 <span class="preprocessor">#include &lt;algo/moeoIBMOLS.h&gt;</span>
<a name="l00025"></a>00025 <span class="preprocessor">#include &lt;algo/moeoLS.h&gt;</span>
<a name="l00026"></a>00026 <span class="preprocessor">#include &lt;archive/moeoArchive.h&gt;</span>
<a name="l00027"></a>00027 <span class="preprocessor">#include &lt;fitness/moeoBinaryIndicatorBasedFitnessAssignment.h&gt;</span>
<a name="l00028"></a>00028 <span class="preprocessor">#include &lt;move/moeoMoveIncrEval.h&gt;</span>
<a name="l00029"></a>00029
<a name="l00030"></a>00030
<a name="l00031"></a>00031
<a name="l00032"></a>00032 <span class="comment">//#include &lt;rsCrossQuad.h&gt;</span>
<a name="l00033"></a>00033
<a name="l00034"></a>00034
<a name="l00035"></a>00035
<a name="l00040"></a>00040 <span class="keyword">template</span> &lt; <span class="keyword">class</span> MOEOT, <span class="keyword">class</span> Move &gt;
<a name="l00041"></a><a class="code" href="classmoeoIteratedIBMOLS.html">00041</a> <span class="keyword">class </span><a class="code" href="classmoeoIteratedIBMOLS.html">moeoIteratedIBMOLS</a> : <span class="keyword">public</span> <a class="code" href="classmoeoLS.html">moeoLS</a> &lt; MOEOT, eoPop &lt; MOEOT &gt; &amp; &gt;
<a name="l00042"></a>00042 {
<a name="l00043"></a>00043 <span class="keyword">public</span>:
<a name="l00044"></a>00044
<a name="l00046"></a><a class="code" href="classmoeoIteratedIBMOLS.html#bc0f8dff81be56b23376995aace92a01">00046</a> <span class="keyword">typedef</span> <span class="keyword">typename</span> MOEOT::ObjectiveVector <a class="code" href="classmoeoIteratedIBMOLS.html#bc0f8dff81be56b23376995aace92a01">ObjectiveVector</a>;
<a name="l00047"></a>00047
<a name="l00048"></a>00048
<a name="l00061"></a><a class="code" href="classmoeoIteratedIBMOLS.html#67352bb5d797f20e767a4f0fa6d80f93">00061</a> <a class="code" href="classmoeoIteratedIBMOLS.html#67352bb5d797f20e767a4f0fa6d80f93">moeoIteratedIBMOLS</a>(
<a name="l00062"></a>00062 moMoveInit &lt; Move &gt; &amp; _moveInit,
<a name="l00063"></a>00063 moNextMove &lt; Move &gt; &amp; _nextMove,
<a name="l00064"></a>00064 eoEvalFunc &lt; MOEOT &gt; &amp; _eval,
<a name="l00065"></a>00065 moeoMoveIncrEval &lt; Move &gt; &amp; _moveIncrEval,
<a name="l00066"></a>00066 moeoBinaryIndicatorBasedFitnessAssignment &lt; MOEOT &gt; &amp; _fitnessAssignment,
<a name="l00067"></a>00067 eoContinue &lt; MOEOT &gt; &amp; _continuator,
<a name="l00068"></a>00068 eoMonOp &lt; MOEOT &gt; &amp; _monOp,
<a name="l00069"></a>00069 eoMonOp &lt; MOEOT &gt; &amp; _randomMonOp,
<a name="l00070"></a>00070 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> _nNoiseIterations=1
<a name="l00071"></a>00071 ) :
<a name="l00072"></a>00072 <a class="code" href="classmoeoIteratedIBMOLS.html#6b1351f1faa391a1f095d1f9d4dba915">ibmols</a>(_moveInit, _nextMove, _eval, _moveIncrEval, _fitnessAssignment, _continuator),
<a name="l00073"></a>00073 <a class="code" href="classmoeoIteratedIBMOLS.html#7abdd0c1433ec4671522c8d5edc9fe61">eval</a>(_eval),
<a name="l00074"></a>00074 <a class="code" href="classmoeoIteratedIBMOLS.html#964e5df65c7aa33dd84eed3180d5e0a3">continuator</a>(_continuator),
<a name="l00075"></a>00075 <a class="code" href="classmoeoIteratedIBMOLS.html#77851daa2f2230000c0012beef3b8558">monOp</a>(_monOp),
<a name="l00076"></a>00076 <a class="code" href="classmoeoIteratedIBMOLS.html#89df3bfa7069c06c7e7cf4b30ccc5535">randomMonOp</a>(_randomMonOp),
<a name="l00077"></a>00077 <a class="code" href="classmoeoIteratedIBMOLS.html#a50f25daf2847fb9d299ef65baf3bda7">nNoiseIterations</a>(_nNoiseIterations)
<a name="l00078"></a>00078 {}
<a name="l00079"></a>00079
<a name="l00080"></a>00080
<a name="l00086"></a><a class="code" href="classmoeoIteratedIBMOLS.html#52d4aa19a93c69ed0c2246c62821e76e">00086</a> <span class="keywordtype">void</span> <a class="code" href="classmoeoIteratedIBMOLS.html#52d4aa19a93c69ed0c2246c62821e76e">operator() </a>(eoPop &lt; MOEOT &gt; &amp; _pop, moeoArchive &lt; MOEOT &gt; &amp; _arch)
<a name="l00087"></a>00087 {
<a name="l00088"></a>00088 _arch.<a class="code" href="classmoeoArchive.html#6df0acd84cab4cb53682f2e6ca850e9a">update</a>(_pop);
<a name="l00089"></a>00089 <a class="code" href="classmoeoIteratedIBMOLS.html#6b1351f1faa391a1f095d1f9d4dba915">ibmols</a>(_pop, _arch);
<a name="l00090"></a>00090 <span class="keywordflow">while</span> (<a class="code" href="classmoeoIteratedIBMOLS.html#964e5df65c7aa33dd84eed3180d5e0a3">continuator</a>(_arch))
<a name="l00091"></a>00091 {
<a name="l00092"></a>00092 <span class="comment">// generate new solutions from the archive</span>
<a name="l00093"></a>00093 <a class="code" href="classmoeoIteratedIBMOLS.html#2826cf283f6670b3c46da5ac6b6def18">generateNewSolutions</a>(_pop, _arch);
<a name="l00094"></a>00094 <span class="comment">// apply the local search (the global archive is updated in the sub-function)</span>
<a name="l00095"></a>00095 <a class="code" href="classmoeoIteratedIBMOLS.html#6b1351f1faa391a1f095d1f9d4dba915">ibmols</a>(_pop, _arch);
<a name="l00096"></a>00096 }
<a name="l00097"></a>00097 }
<a name="l00098"></a>00098
<a name="l00099"></a>00099
<a name="l00100"></a>00100 <span class="keyword">private</span>:
<a name="l00101"></a>00101
<a name="l00103"></a><a class="code" href="classmoeoIteratedIBMOLS.html#6b1351f1faa391a1f095d1f9d4dba915">00103</a> moeoIBMOLS &lt; MOEOT, Move &gt; <a class="code" href="classmoeoIteratedIBMOLS.html#6b1351f1faa391a1f095d1f9d4dba915">ibmols</a>;
<a name="l00105"></a><a class="code" href="classmoeoIteratedIBMOLS.html#7abdd0c1433ec4671522c8d5edc9fe61">00105</a> eoEvalFunc &lt; MOEOT &gt; &amp; <a class="code" href="classmoeoIteratedIBMOLS.html#7abdd0c1433ec4671522c8d5edc9fe61">eval</a>;
<a name="l00107"></a><a class="code" href="classmoeoIteratedIBMOLS.html#964e5df65c7aa33dd84eed3180d5e0a3">00107</a> eoContinue &lt; MOEOT &gt; &amp; <a class="code" href="classmoeoIteratedIBMOLS.html#964e5df65c7aa33dd84eed3180d5e0a3">continuator</a>;
<a name="l00109"></a><a class="code" href="classmoeoIteratedIBMOLS.html#77851daa2f2230000c0012beef3b8558">00109</a> eoMonOp &lt; MOEOT &gt; &amp; <a class="code" href="classmoeoIteratedIBMOLS.html#77851daa2f2230000c0012beef3b8558">monOp</a>;
<a name="l00111"></a><a class="code" href="classmoeoIteratedIBMOLS.html#89df3bfa7069c06c7e7cf4b30ccc5535">00111</a> eoMonOp &lt; MOEOT &gt; &amp; <a class="code" href="classmoeoIteratedIBMOLS.html#89df3bfa7069c06c7e7cf4b30ccc5535">randomMonOp</a>;
<a name="l00113"></a><a class="code" href="classmoeoIteratedIBMOLS.html#a50f25daf2847fb9d299ef65baf3bda7">00113</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="classmoeoIteratedIBMOLS.html#a50f25daf2847fb9d299ef65baf3bda7">nNoiseIterations</a>;
<a name="l00114"></a>00114
<a name="l00115"></a>00115
<a name="l00121"></a><a class="code" href="classmoeoIteratedIBMOLS.html#2826cf283f6670b3c46da5ac6b6def18">00121</a> <span class="keywordtype">void</span> <a class="code" href="classmoeoIteratedIBMOLS.html#2826cf283f6670b3c46da5ac6b6def18">generateNewSolutions</a>(eoPop &lt; MOEOT &gt; &amp; _pop, <span class="keyword">const</span> moeoArchive &lt; MOEOT &gt; &amp; _arch)
<a name="l00122"></a>00122 {
<a name="l00123"></a>00123 <span class="comment">// shuffle vector for the random selection of individuals</span>
<a name="l00124"></a>00124 vector&lt;unsigned int&gt; shuffle;
<a name="l00125"></a>00125 shuffle.resize(std::max(_pop.size(), _arch.size()));
<a name="l00126"></a>00126 <span class="comment">// init shuffle</span>
<a name="l00127"></a>00127 <span class="keywordflow">for</span> (<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i=0; i&lt;shuffle.size(); i++)
<a name="l00128"></a>00128 {
<a name="l00129"></a>00129 shuffle[i] = i;
<a name="l00130"></a>00130 }
<a name="l00131"></a>00131 <span class="comment">// randomize shuffle</span>
<a name="l00132"></a>00132 UF_random_generator &lt;unsigned int&gt; gen;
<a name="l00133"></a>00133 std::random_shuffle(shuffle.begin(), shuffle.end(), gen);
<a name="l00134"></a>00134 <span class="comment">// start the creation of new solutions</span>
<a name="l00135"></a>00135 <span class="keywordflow">for</span> (<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i=0; i&lt;_pop.size(); i++)
<a name="l00136"></a>00136 {
<a name="l00137"></a>00137 <span class="keywordflow">if</span> (shuffle[i] &lt; _arch.size()) <span class="comment">// the given archive contains the individual i</span>
<a name="l00138"></a>00138 {
<a name="l00139"></a>00139 <span class="comment">// add it to the resulting pop</span>
<a name="l00140"></a>00140 _pop[i] = _arch[shuffle[i]];
<a name="l00141"></a>00141 <span class="comment">// apply noise</span>
<a name="l00142"></a>00142 <span class="keywordflow">for</span> (<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> j=0; j&lt;<a class="code" href="classmoeoIteratedIBMOLS.html#a50f25daf2847fb9d299ef65baf3bda7">nNoiseIterations</a>; j++)
<a name="l00143"></a>00143 {
<a name="l00144"></a>00144 <a class="code" href="classmoeoIteratedIBMOLS.html#77851daa2f2230000c0012beef3b8558">monOp</a>(_pop[i]);
<a name="l00145"></a>00145 }
<a name="l00146"></a>00146 }
<a name="l00147"></a>00147 <span class="keywordflow">else</span> <span class="comment">// a random solution needs to be added</span>
<a name="l00148"></a>00148 {
<a name="l00149"></a>00149 <span class="comment">// random initialization</span>
<a name="l00150"></a>00150 <a class="code" href="classmoeoIteratedIBMOLS.html#89df3bfa7069c06c7e7cf4b30ccc5535">randomMonOp</a>(_pop[i]);
<a name="l00151"></a>00151 }
<a name="l00152"></a>00152 <span class="comment">// evaluation of the new individual</span>
<a name="l00153"></a>00153 _pop[i].<a class="codeRef" doxygen="eo.doxytag:http://eodev.sourceforge.net/eo/doc/html/" href="http://eodev.sourceforge.net/eo/doc/html/classeo_pop.html#94ff8afbb4bad67b48f04165b1170e67">invalidate</a>();
<a name="l00154"></a>00154 <a class="code" href="classmoeoIteratedIBMOLS.html#7abdd0c1433ec4671522c8d5edc9fe61">eval</a>(_pop[i]);
<a name="l00155"></a>00155 }
<a name="l00156"></a>00156 }
<a name="l00157"></a>00157
<a name="l00158"></a>00158
<a name="l00159"></a>00159
<a name="l00160"></a>00160
<a name="l00161"></a>00161
<a name="l00163"></a>00163 <span class="comment">// A DEVELOPPER RAPIDEMENT POUR TESTER AVEC CROSSOVER //</span>
<a name="l00164"></a>00164 <span class="comment">/*</span>
<a name="l00165"></a>00165 <span class="comment"> void generateNewSolutions2(eoPop &lt; MOEOT &gt; &amp; _pop, const moeoArchive &lt; MOEOT &gt; &amp; _arch)</span>
<a name="l00166"></a>00166 <span class="comment"> {</span>
<a name="l00167"></a>00167 <span class="comment"> // here, we must have a QuadOp !</span>
<a name="l00168"></a>00168 <span class="comment"> //eoQuadOp &lt; MOEOT &gt; quadOp;</span>
<a name="l00169"></a>00169 <span class="comment"> rsCrossQuad quadOp;</span>
<a name="l00170"></a>00170 <span class="comment"> // shuffle vector for the random selection of individuals</span>
<a name="l00171"></a>00171 <span class="comment"> vector&lt;unsigned int&gt; shuffle;</span>
<a name="l00172"></a>00172 <span class="comment"> shuffle.resize(_arch.size());</span>
<a name="l00173"></a>00173 <span class="comment"> // init shuffle</span>
<a name="l00174"></a>00174 <span class="comment"> for (unsigned int i=0; i&lt;shuffle.size(); i++)</span>
<a name="l00175"></a>00175 <span class="comment"> {</span>
<a name="l00176"></a>00176 <span class="comment"> shuffle[i] = i;</span>
<a name="l00177"></a>00177 <span class="comment"> }</span>
<a name="l00178"></a>00178 <span class="comment"> // randomize shuffle</span>
<a name="l00179"></a>00179 <span class="comment"> UF_random_generator &lt;unsigned int int&gt; gen;</span>
<a name="l00180"></a>00180 <span class="comment"> std::random_shuffle(shuffle.begin(), shuffle.end(), gen);</span>
<a name="l00181"></a>00181 <span class="comment"> // start the creation of new solutions</span>
<a name="l00182"></a>00182 <span class="comment"> unsigned int i=0;</span>
<a name="l00183"></a>00183 <span class="comment"> while ((i&lt;_pop.size()-1) &amp;&amp; (i&lt;_arch.size()-1))</span>
<a name="l00184"></a>00184 <span class="comment"> {</span>
<a name="l00185"></a>00185 <span class="comment"> _pop[i] = _arch[shuffle[i]];</span>
<a name="l00186"></a>00186 <span class="comment"> _pop[i+1] = _arch[shuffle[i+1]];</span>
<a name="l00187"></a>00187 <span class="comment"> // then, apply the operator nIterationsNoise times</span>
<a name="l00188"></a>00188 <span class="comment"> for (unsigned int j=0; j&lt;nNoiseIterations; j++)</span>
<a name="l00189"></a>00189 <span class="comment"> {</span>
<a name="l00190"></a>00190 <span class="comment"> quadOp(_pop[i], _pop[i+1]);</span>
<a name="l00191"></a>00191 <span class="comment"> }</span>
<a name="l00192"></a>00192 <span class="comment"> eval(_pop[i]);</span>
<a name="l00193"></a>00193 <span class="comment"> eval(_pop[i+1]);</span>
<a name="l00194"></a>00194 <span class="comment"> i=i+2;</span>
<a name="l00195"></a>00195 <span class="comment"> }</span>
<a name="l00196"></a>00196 <span class="comment"> // do we have to add some random solutions ?</span>
<a name="l00197"></a>00197 <span class="comment"> while (i&lt;_pop.size())</span>
<a name="l00198"></a>00198 <span class="comment"> {</span>
<a name="l00199"></a>00199 <span class="comment"> randomMonOp(_pop[i]);</span>
<a name="l00200"></a>00200 <span class="comment"> eval(_pop[i]);</span>
<a name="l00201"></a>00201 <span class="comment"> i++;</span>
<a name="l00202"></a>00202 <span class="comment"> }</span>
<a name="l00203"></a>00203 <span class="comment"> }</span>
<a name="l00204"></a>00204 <span class="comment"> */</span>
<a name="l00206"></a>00206
<a name="l00207"></a>00207
<a name="l00208"></a>00208
<a name="l00209"></a>00209
<a name="l00210"></a>00210
<a name="l00211"></a>00211 };
<a name="l00212"></a>00212
<a name="l00213"></a>00213 <span class="preprocessor">#endif </span><span class="comment">/*MOEOITERATEDIBMOLS_H_*/</span>
</pre></div><hr size="1"><address style="align: right;"><small>Generated on Mon Oct 8 10:35:51 2007 for ParadisEO-MOEOMovingObjects by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.7 </small></address>
</body>
</html>