In the TSP, the fitness has to be minimized ... with all the needed modification (for example, moSA.h)

git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@587 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
jboisson 2007-08-03 14:28:06 +00:00
commit 1d94071693
170 changed files with 748 additions and 837 deletions

View file

@ -51,75 +51,75 @@
<a name="l00030"></a><a class="code" href="classmo_s_a.html">00030</a> <span class="keyword">template</span> &lt; <span class="keyword">class</span> M &gt; <span class="keyword">class </span><a class="code" href="classmo_s_a.html" title="Simulated Annealing (SA).">moSA</a>:<span class="keyword">public</span> <a class="code" href="classmo_algo.html" title="Description of an algorithm of the paradiseo-mo library.">moAlgo</a> &lt; typename M::EOType &gt;
<a name="l00031"></a>00031 {
<a name="l00032"></a>00032
<a name="l00034"></a>00034 <span class="keyword">typedef</span>
<a name="l00035"></a>00035 <span class="keyword">typename</span>
<a name="l00036"></a>00036 M::EOType
<a name="l00037"></a><a class="code" href="classmo_s_a.html#d5d64a8797bdedc7b3af7893aded0bd5">00037</a> <a class="code" href="classmo_s_a.html#d5d64a8797bdedc7b3af7893aded0bd5" title="Alias for the type.">EOT</a>;
<a name="l00034"></a><a class="code" href="classmo_s_a.html#d5d64a8797bdedc7b3af7893aded0bd5">00034</a> <span class="keyword">typedef</span> <span class="keyword">typename</span> M::EOType <a class="code" href="classmo_s_a.html#d5d64a8797bdedc7b3af7893aded0bd5" title="Alias for the type.">EOT</a>;
<a name="l00035"></a>00035
<a name="l00037"></a><a class="code" href="classmo_s_a.html#97f1a40d5ab5a0b3f878d0347b34804b">00037</a> <span class="keyword">typedef</span> <span class="keyword">typename</span> EOT::Fitness <a class="code" href="classmo_s_a.html#97f1a40d5ab5a0b3f878d0347b34804b" title="Alias for the fitness.">Fitness</a>;
<a name="l00038"></a>00038
<a name="l00040"></a>00040 <span class="keyword">typedef</span>
<a name="l00041"></a>00041 <span class="keyword">typename</span>
<a name="l00042"></a>00042 EOT::Fitness
<a name="l00043"></a><a class="code" href="classmo_s_a.html#97f1a40d5ab5a0b3f878d0347b34804b">00043</a> <a class="code" href="classmo_s_a.html#97f1a40d5ab5a0b3f878d0347b34804b" title="Alias for the fitness.">Fitness</a>;
<a name="l00044"></a>00044
<a name="l00045"></a>00045 <span class="keyword">public</span>:
<a name="l00046"></a>00046
<a name="l00048"></a>00048
<a name="l00058"></a><a class="code" href="classmo_s_a.html#01f6a44483e5a7abbce33eb480b6a9b9">00058</a> <a class="code" href="classmo_s_a.html#01f6a44483e5a7abbce33eb480b6a9b9" title="SA constructor.">moSA</a> (moRandMove &lt; M &gt; &amp;__move_rand,
<a name="l00059"></a>00059 moMoveIncrEval &lt; M &gt; &amp;__incr_eval,
<a name="l00060"></a>00060 moSolContinue &lt; EOT &gt; &amp;__cont,
<a name="l00061"></a>00061 <span class="keywordtype">double</span> __init_temp,
<a name="l00062"></a>00062 <a class="code" href="classmo_cooling_schedule.html" title="This class gives the description of a cooling schedule.">moCoolingSchedule</a> &amp; __cool_sched, eoEvalFunc &lt; EOT &gt; &amp;__full_eval):
<a name="l00063"></a>00063 <a class="code" href="classmo_s_a.html#71c49935b63a202d25888a5f86121fec" title="A move generator (generally randomly).">move_rand</a> (__move_rand),
<a name="l00064"></a>00064 <a class="code" href="classmo_s_a.html#4c3be32e9832e465b24e6d33559356bc" title="A (generally) efficient evaluation function.">incr_eval</a> (__incr_eval),
<a name="l00065"></a>00065 <a class="code" href="classmo_s_a.html#54484c8a514866ea496e0058c2e09716" title="Stopping criterion before temperature update.">cont</a> (__cont),
<a name="l00066"></a>00066 <a class="code" href="classmo_s_a.html#f1af7636b52aa5f6b381f8187b667bd4" title="Initial temperature.">init_temp</a> (__init_temp),
<a name="l00067"></a>00067 <a class="code" href="classmo_s_a.html#11c7d0cab649b7d680dd85bb74cb4ff6" title="The cooling schedule.">cool_sched</a> (__cool_sched),
<a name="l00068"></a>00068 <a class="code" href="classmo_s_a.html#bcd6a940046f23dd741444c0b85edf2c" title="A full evaluation function.">full_eval</a> (__full_eval)
<a name="l00069"></a>00069 {
<a name="l00070"></a>00070
<a name="l00071"></a>00071 }
<a name="l00072"></a>00072
<a name="l00074"></a>00074
<a name="l00080"></a><a class="code" href="classmo_s_a.html#0e4c54b57bc13fcbd4763883b8f719e5">00080</a> <span class="keywordtype">bool</span> <a class="code" href="classmo_s_a.html#0e4c54b57bc13fcbd4763883b8f719e5" title="function that launches the SA algorithm.">operator ()</a>(<a class="code" href="classmo_s_a.html#d5d64a8797bdedc7b3af7893aded0bd5" title="Alias for the type.">EOT</a> &amp; __sol)
<a name="l00081"></a>00081 {
<a name="l00082"></a>00082
<a name="l00083"></a>00083 <span class="keywordflow">if</span> (__sol.invalid ())
<a name="l00084"></a>00084 {
<a name="l00085"></a>00085 <a class="code" href="classmo_s_a.html#bcd6a940046f23dd741444c0b85edf2c" title="A full evaluation function.">full_eval</a> (__sol);
<a name="l00086"></a>00086 }
<a name="l00039"></a>00039 <span class="keyword">public</span>:
<a name="l00040"></a>00040
<a name="l00042"></a>00042
<a name="l00052"></a><a class="code" href="classmo_s_a.html#01f6a44483e5a7abbce33eb480b6a9b9">00052</a> <a class="code" href="classmo_s_a.html#01f6a44483e5a7abbce33eb480b6a9b9" title="SA constructor.">moSA</a> (moRandMove &lt; M &gt; &amp;__move_rand,
<a name="l00053"></a>00053 moMoveIncrEval &lt; M &gt; &amp;__incr_eval,
<a name="l00054"></a>00054 moSolContinue &lt; EOT &gt; &amp;__cont,
<a name="l00055"></a>00055 <span class="keywordtype">double</span> __init_temp,
<a name="l00056"></a>00056 <a class="code" href="classmo_cooling_schedule.html" title="This class gives the description of a cooling schedule.">moCoolingSchedule</a> &amp; __cool_sched, eoEvalFunc &lt; EOT &gt; &amp;__full_eval):
<a name="l00057"></a>00057 <a class="code" href="classmo_s_a.html#71c49935b63a202d25888a5f86121fec" title="A move generator (generally randomly).">move_rand</a> (__move_rand),
<a name="l00058"></a>00058 <a class="code" href="classmo_s_a.html#4c3be32e9832e465b24e6d33559356bc" title="A (generally) efficient evaluation function.">incr_eval</a> (__incr_eval),
<a name="l00059"></a>00059 <a class="code" href="classmo_s_a.html#54484c8a514866ea496e0058c2e09716" title="Stopping criterion before temperature update.">cont</a> (__cont),
<a name="l00060"></a>00060 <a class="code" href="classmo_s_a.html#f1af7636b52aa5f6b381f8187b667bd4" title="Initial temperature.">init_temp</a> (__init_temp),
<a name="l00061"></a>00061 <a class="code" href="classmo_s_a.html#11c7d0cab649b7d680dd85bb74cb4ff6" title="The cooling schedule.">cool_sched</a> (__cool_sched),
<a name="l00062"></a>00062 <a class="code" href="classmo_s_a.html#bcd6a940046f23dd741444c0b85edf2c" title="A full evaluation function.">full_eval</a> (__full_eval)
<a name="l00063"></a>00063 {
<a name="l00064"></a>00064
<a name="l00065"></a>00065 }
<a name="l00066"></a>00066
<a name="l00068"></a>00068
<a name="l00074"></a><a class="code" href="classmo_s_a.html#0e4c54b57bc13fcbd4763883b8f719e5">00074</a> <span class="keywordtype">bool</span> <a class="code" href="classmo_s_a.html#0e4c54b57bc13fcbd4763883b8f719e5" title="function that launches the SA algorithm.">operator ()</a>(<a class="code" href="classmo_s_a.html#d5d64a8797bdedc7b3af7893aded0bd5" title="Alias for the type.">EOT</a> &amp; __sol)
<a name="l00075"></a>00075 {
<a name="l00076"></a>00076
<a name="l00077"></a>00077 <span class="keywordflow">if</span> (__sol.invalid ())
<a name="l00078"></a>00078 {
<a name="l00079"></a>00079 <a class="code" href="classmo_s_a.html#bcd6a940046f23dd741444c0b85edf2c" title="A full evaluation function.">full_eval</a> (__sol);
<a name="l00080"></a>00080 }
<a name="l00081"></a>00081
<a name="l00082"></a>00082 <span class="keywordtype">double</span> temp = <a class="code" href="classmo_s_a.html#f1af7636b52aa5f6b381f8187b667bd4" title="Initial temperature.">init_temp</a>;
<a name="l00083"></a>00083
<a name="l00084"></a>00084 M move;
<a name="l00085"></a>00085
<a name="l00086"></a>00086 <a class="code" href="classmo_s_a.html#d5d64a8797bdedc7b3af7893aded0bd5" title="Alias for the type.">EOT</a> best_sol = __sol;
<a name="l00087"></a>00087
<a name="l00088"></a>00088 <span class="keywordtype">double</span> temp = <a class="code" href="classmo_s_a.html#f1af7636b52aa5f6b381f8187b667bd4" title="Initial temperature.">init_temp</a>;
<a name="l00089"></a>00089
<a name="l00090"></a>00090 M move;
<a name="l00091"></a>00091
<a name="l00092"></a>00092 <a class="code" href="classmo_s_a.html#d5d64a8797bdedc7b3af7893aded0bd5" title="Alias for the type.">EOT</a> best_sol = __sol;
<a name="l00093"></a>00093
<a name="l00094"></a>00094 <span class="keywordflow">do</span>
<a name="l00095"></a>00095 {
<a name="l00096"></a>00096
<a name="l00097"></a>00097 <a class="code" href="classmo_s_a.html#54484c8a514866ea496e0058c2e09716" title="Stopping criterion before temperature update.">cont</a>.init ();
<a name="l00098"></a>00098 <span class="keywordflow">do</span>
<a name="l00099"></a>00099 {
<a name="l00100"></a>00100
<a name="l00101"></a>00101 <a class="code" href="classmo_s_a.html#71c49935b63a202d25888a5f86121fec" title="A move generator (generally randomly).">move_rand</a> (move);
<a name="l00102"></a>00102
<a name="l00103"></a>00103 <a class="code" href="classmo_s_a.html#97f1a40d5ab5a0b3f878d0347b34804b" title="Alias for the fitness.">Fitness</a> delta_fit = <a class="code" href="classmo_s_a.html#4c3be32e9832e465b24e6d33559356bc" title="A (generally) efficient evaluation function.">incr_eval</a> (move, __sol) - __sol.fitness ();
<a name="l00104"></a>00104
<a name="l00105"></a>00105 <span class="keywordflow">if</span> (delta_fit &gt; 0 || rng.<a class="codeRef" doxygen="eo.doxytag:http://eodev.sourceforge.net/eo/doc/html/" href="http://eodev.sourceforge.net/eo/doc/html/classeo_rng.html#50dfb052f11ae50326e552cb223d88e4">uniform</a> () &lt; exp (delta_fit / temp))
<a name="l00106"></a>00106 {
<a name="l00107"></a>00107
<a name="l00108"></a>00108 __sol.fitness (<a class="code" href="classmo_s_a.html#4c3be32e9832e465b24e6d33559356bc" title="A (generally) efficient evaluation function.">incr_eval</a> (move, __sol));
<a name="l00109"></a>00109 move (__sol);
<a name="l00110"></a>00110
<a name="l00111"></a>00111 <span class="comment">/* Updating the best solution found</span>
<a name="l00112"></a>00112 <span class="comment"> until now ? */</span>
<a name="l00088"></a>00088 <a class="code" href="classmo_s_a.html#97f1a40d5ab5a0b3f878d0347b34804b" title="Alias for the fitness.">Fitness</a> current_fitness, delta;
<a name="l00089"></a>00089 <span class="keywordtype">double</span> exp1, exp2;
<a name="l00090"></a>00090
<a name="l00091"></a>00091 <span class="keywordflow">do</span>
<a name="l00092"></a>00092 {
<a name="l00093"></a>00093 <a class="code" href="classmo_s_a.html#54484c8a514866ea496e0058c2e09716" title="Stopping criterion before temperature update.">cont</a>.init ();
<a name="l00094"></a>00094 <span class="keywordflow">do</span>
<a name="l00095"></a>00095 {
<a name="l00096"></a>00096 <a class="code" href="classmo_s_a.html#71c49935b63a202d25888a5f86121fec" title="A move generator (generally randomly).">move_rand</a> (move);
<a name="l00097"></a>00097
<a name="l00098"></a>00098 current_fitness= <a class="code" href="classmo_s_a.html#4c3be32e9832e465b24e6d33559356bc" title="A (generally) efficient evaluation function.">incr_eval</a> (move, __sol);
<a name="l00099"></a>00099
<a name="l00100"></a>00100 delta = current_fitness - __sol.fitness();
<a name="l00101"></a>00101
<a name="l00102"></a>00102 <span class="keywordflow">if</span>(((<span class="keywordtype">long</span> <span class="keywordtype">double</span>)delta) &lt; 0.0)
<a name="l00103"></a>00103 {
<a name="l00104"></a>00104 delta=-delta;
<a name="l00105"></a>00105 }
<a name="l00106"></a>00106
<a name="l00107"></a>00107 <span class="keywordflow">if</span> ((current_fitness &gt; __sol.fitness()) || ((rng.<a class="codeRef" doxygen="eo.doxytag:http://eodev.sourceforge.net/eo/doc/html/" href="http://eodev.sourceforge.net/eo/doc/html/classeo_rng.html#50dfb052f11ae50326e552cb223d88e4">uniform</a> ()) &lt; (exp (-delta/ temp))))
<a name="l00108"></a>00108 {
<a name="l00109"></a>00109 __sol.fitness (current_fitness);
<a name="l00110"></a>00110 move (__sol);
<a name="l00111"></a>00111
<a name="l00112"></a>00112 <span class="comment">/* Updating the best solution found until now ? */</span>
<a name="l00113"></a>00113 <span class="keywordflow">if</span> (__sol.fitness () &gt; best_sol.fitness ())
<a name="l00114"></a>00114 best_sol = __sol;
<a name="l00115"></a>00115 }
<a name="l00116"></a>00116
<a name="l00117"></a>00117 }
<a name="l00118"></a>00118 <span class="keywordflow">while</span> (<a class="code" href="classmo_s_a.html#54484c8a514866ea496e0058c2e09716" title="Stopping criterion before temperature update.">cont</a> (__sol));
<a name="l00119"></a>00119
<a name="l00114"></a>00114 {
<a name="l00115"></a>00115 best_sol = __sol;
<a name="l00116"></a>00116 }
<a name="l00117"></a>00117 }
<a name="l00118"></a>00118 }
<a name="l00119"></a>00119 <span class="keywordflow">while</span> (<a class="code" href="classmo_s_a.html#54484c8a514866ea496e0058c2e09716" title="Stopping criterion before temperature update.">cont</a> (__sol));
<a name="l00120"></a>00120 }
<a name="l00121"></a>00121 <span class="keywordflow">while</span> (<a class="code" href="classmo_s_a.html#11c7d0cab649b7d680dd85bb74cb4ff6" title="The cooling schedule.">cool_sched</a> (temp));
<a name="l00122"></a>00122
@ -144,7 +144,7 @@
<a name="l00147"></a>00147 };
<a name="l00148"></a>00148
<a name="l00149"></a>00149 <span class="preprocessor">#endif</span>
</pre></div><hr size="1"><address style="text-align: right;"><small>Generated on Thu Aug 2 09:02:25 2007 for PARADISEO-MO by&nbsp;
</pre></div><hr size="1"><address style="text-align: right;"><small>Generated on Fri Aug 3 16:25:56 2007 for PARADISEO-MO by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.2 </small></address>
</body>