paradiseo/trunk/paradiseo-moeo/docs/html/moeoParetoSharing_8h-source.html
liefooga b0351ae298 doc update
git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@157 331e1502-861f-0410-8da2-ba01fb791d7f
2007-01-15 14:01:11 +00:00

185 lines
17 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-MOEO: moeoParetoSharing.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.5.1 -->
<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>moeoParetoSharing.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">// moeoParetoSharing.h</span>
<a name="l00005"></a>00005 <span class="comment">// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2006</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">#include &lt;EO.h&gt;</span>
<a name="l00014"></a>00014 <span class="preprocessor">#include &lt;eoPerf2Worth.h&gt;</span>
<a name="l00015"></a>00015 <span class="preprocessor">#include &lt;old/moeoParetoPhenDist.h&gt;</span>
<a name="l00016"></a>00016 <span class="preprocessor">#include &lt;eoParetoRanking.h&gt;</span>
<a name="l00017"></a>00017
<a name="l00018"></a>00018 <span class="keyword">template</span> &lt; <span class="keyword">class </span>EOT, <span class="keyword">class </span>worthT =
<a name="l00019"></a><a class="code" href="classmoeoParetoSharing.html">00019</a> <span class="keywordtype">double</span> &gt;<span class="keyword">class </span><a class="code" href="classmoeoParetoSharing.html">moeoParetoSharing</a>:<span class="keyword">public</span> <a class="codeRef" doxygen="eo.doxytag:../../../workspace/paradiseo-eo/doc/doc/html/" href="../../../workspace/paradiseo-eo/doc/doc/html/classeo_perf2_worth.html">eoPerf2Worth</a> &lt; EOT, worthT &gt;
<a name="l00020"></a>00020 {
<a name="l00021"></a>00021 <span class="keyword">public</span>:
<a name="l00022"></a>00022
<a name="l00023"></a><a class="code" href="classmoeoParetoSharing.html#e2bb92004d3ec5193c7c3efcd499c489">00023</a> <a class="code" href="classmoeoParetoSharing.html#e2bb92004d3ec5193c7c3efcd499c489">moeoParetoSharing</a> (<span class="keywordtype">double</span> _nicheSize):<a class="codeRef" doxygen="eo.doxytag:../../../workspace/paradiseo-eo/doc/doc/html/" href="../../../workspace/paradiseo-eo/doc/doc/html/classeo_perf2_worth.html">eoPerf2Worth</a> &lt; EOT,
<a name="l00024"></a>00024 worthT &gt; (<span class="stringliteral">"ParetoSharing"</span>), <a class="code" href="classmoeoParetoSharing.html#b5519750a3f30747cbabf67df9b4afd8">nicheSize</a> (_nicheSize), <a class="code" href="classmoeoParetoSharing.html#329d7d08f06988fcb0f03059c88ed209">dist</a> (<a class="code" href="classmoeoParetoSharing.html#42bc90da2e7f3f7d3837484c771f638e">euc_dist</a>),
<a name="l00025"></a>00025 <a class="code" href="classmoeoParetoSharing.html#0219625f2dd8bfd9ae7cb3039084059f">Dmax</a> (_nicheSize)
<a name="l00026"></a>00026 {
<a name="l00027"></a>00027 }
<a name="l00028"></a>00028
<a name="l00029"></a>00029
<a name="l00030"></a><a class="code" href="classmoeoParetoSharing.html#757d64059315641796855d5adc48cce9">00030</a> <a class="code" href="classmoeoParetoSharing.html#e2bb92004d3ec5193c7c3efcd499c489">moeoParetoSharing</a> (<span class="keywordtype">double</span> _nicheSize, <a class="code" href="classmoeoParetoPhenDist.html">moeoParetoPhenDist</a> &lt; EOT,
<a name="l00031"></a>00031 worthT &gt; &amp;_dist):<a class="codeRef" doxygen="eo.doxytag:../../../workspace/paradiseo-eo/doc/doc/html/" href="../../../workspace/paradiseo-eo/doc/doc/html/classeo_perf2_worth.html">eoPerf2Worth</a> &lt; EOT,
<a name="l00032"></a>00032 worthT &gt; (<span class="stringliteral">"ParetoSharing"</span>), <a class="code" href="classmoeoParetoSharing.html#b5519750a3f30747cbabf67df9b4afd8">nicheSize</a> (_nicheSize), <a class="code" href="classmoeoParetoSharing.html#329d7d08f06988fcb0f03059c88ed209">dist</a> (_dist),
<a name="l00033"></a>00033 <a class="code" href="classmoeoParetoSharing.html#0219625f2dd8bfd9ae7cb3039084059f">Dmax</a> (_nicheSize)
<a name="l00034"></a>00034 {
<a name="l00035"></a>00035 }
<a name="l00036"></a>00036
<a name="l00037"></a>00037
<a name="l00038"></a>00038
<a name="l00039"></a>00039
<a name="l00040"></a><a class="code" href="classmoeoParetoSharing.html#67f211b508194562903dae15989ab515">00040</a> <span class="keywordtype">void</span> <a class="code" href="classmoeoParetoSharing.html#67f211b508194562903dae15989ab515">operator </a>() <span class="comment">/*calculate_worths */</span> (<span class="keyword">const</span> eoPop &lt; EOT &gt; &amp;_pop)
<a name="l00041"></a>00041 {
<a name="l00042"></a>00042
<a name="l00043"></a>00043 <span class="keywordtype">unsigned</span> i, j, pSize = _pop.size ();
<a name="l00044"></a>00044 <span class="comment">//cout&lt;&lt;"**************************************************************************************\n";</span>
<a name="l00045"></a>00045 <span class="comment">// std :: cout &lt;&lt; "psize = " &lt;&lt; pSize &lt;&lt; std :: endl ;</span>
<a name="l00046"></a>00046 <span class="keywordflow">if</span> (pSize &lt;= 1)
<a name="l00047"></a>00047 <span class="keywordflow">throw</span> std::
<a name="l00048"></a>00048 runtime_error (<span class="stringliteral">"Apptempt to do sharing with population of size 1"</span>);
<a name="l00049"></a>00049 <a class="codeRef" doxygen="eo.doxytag:../../../workspace/paradiseo-eo/doc/doc/html/" href="../../../workspace/paradiseo-eo/doc/doc/html/classeo_value_param.html#a2">eoPerf2Worth &lt; EOT, worthT &gt;::value</a> ().<a class="codeRef" doxygen="eo.doxytag:../../../workspace/paradiseo-eo/doc/doc/html/" href="../../../workspace/paradiseo-eo/doc/doc/html/classeo_perf2_worth.html#a2">resize</a> (pSize);
<a name="l00050"></a>00050 std::vector &lt; double &gt;sim (pSize); <span class="comment">// to hold the similarities</span>
<a name="l00051"></a>00051
<a name="l00052"></a>00052 <a class="code" href="classmoeoParetoSharing_1_1dMatrix.html">dMatrix</a> distMatrix (pSize);
<a name="l00053"></a>00053
<a name="l00054"></a>00054 <span class="comment">// compute the distance</span>
<a name="l00055"></a>00055 distMatrix[0][0] = 0;
<a name="l00056"></a>00056 <span class="keywordflow">for</span> (i = 1; i &lt; pSize; i++)
<a name="l00057"></a>00057 {
<a name="l00058"></a>00058 distMatrix[i][i] = 0;
<a name="l00059"></a>00059 <span class="keywordflow">for</span> (j = 0; j &lt; i; j++)
<a name="l00060"></a>00060 {
<a name="l00061"></a>00061 <span class="comment">//if</span>
<a name="l00062"></a>00062 distMatrix[i][j] = distMatrix[j][i] = <a class="code" href="classmoeoParetoSharing.html#329d7d08f06988fcb0f03059c88ed209">dist</a> (_pop[i], _pop[j]);
<a name="l00063"></a>00063 <span class="comment">//cout&lt;&lt;" "&lt;&lt;distMatrix[j][i]&lt;&lt;" "&lt;&lt;dist(_pop[i],_pop[j])&lt;&lt;"\n";</span>
<a name="l00064"></a>00064 }
<a name="l00065"></a>00065
<a name="l00066"></a>00066 }
<a name="l00067"></a>00067
<a name="l00068"></a>00068 <span class="comment">//compute the similarities</span>
<a name="l00069"></a>00069 <span class="keywordflow">for</span> (i = 0; i &lt; pSize; i++)
<a name="l00070"></a>00070 {
<a name="l00071"></a>00071 <span class="keywordtype">double</span> sum = 0.0;
<a name="l00072"></a>00072 <span class="keywordflow">for</span> (j = 0; j &lt; pSize; j++)
<a name="l00073"></a>00073
<a name="l00074"></a>00074 sum += <a class="code" href="classmoeoParetoSharing.html#002e355f0df0ad242cdf171207b592ac">sh</a> (distMatrix[i][j], <a class="code" href="classmoeoParetoSharing.html#0219625f2dd8bfd9ae7cb3039084059f">Dmax</a>);
<a name="l00075"></a>00075 sim[i] = sum;
<a name="l00076"></a>00076
<a name="l00077"></a>00077 <span class="comment">//cout&lt;&lt;"\n i -----&gt;"&lt;&lt;sim[i]&lt;&lt;"\n";</span>
<a name="l00078"></a>00078 }
<a name="l00079"></a>00079
<a name="l00080"></a>00080 eoDominanceMap &lt; EOT &gt; Dmap1;
<a name="l00081"></a>00081 Dmap1.<a class="codeRef" doxygen="eo.doxytag:../../../workspace/paradiseo-eo/doc/doc/html/" href="../../../workspace/paradiseo-eo/doc/doc/html/classeo_dominance_map.html#a3">setup</a> (_pop);
<a name="l00082"></a>00082
<a name="l00083"></a>00083 eoParetoRanking &lt; EOT &gt; rnk1 (Dmap1);
<a name="l00084"></a>00084 rnk1.<a class="codeRef" doxygen="eo.doxytag:../../../workspace/paradiseo-eo/doc/doc/html/" href="../../../workspace/paradiseo-eo/doc/doc/html/classeo_pareto_ranking.html#a1">calculate_worths</a> (_pop);
<a name="l00085"></a>00085 <span class="comment">// now set the worthes values</span>
<a name="l00086"></a>00086 <span class="keywordflow">for</span> (i = 0; i &lt; pSize; ++i)
<a name="l00087"></a>00087 {
<a name="l00088"></a>00088 <span class="keyword">typename</span> EOT::Fitness v;
<a name="l00089"></a>00089
<a name="l00090"></a>00090
<a name="l00091"></a>00091
<a name="l00092"></a>00092 <span class="comment">//cout&lt;&lt;"voila: "&lt;&lt;</span>
<a name="l00093"></a>00093 <span class="comment">//rnk1.value().operator[](i);</span>
<a name="l00094"></a>00094
<a name="l00095"></a>00095 <span class="comment">//vector&lt;double&gt; v;</span>
<a name="l00096"></a>00096 <span class="comment">//v.resize(_pop[i].fitness().size());</span>
<a name="l00097"></a>00097 <span class="comment">//for(unsigned k=0;k&lt;_pop[i].fitness().size();++k)</span>
<a name="l00098"></a>00098 <span class="comment">//v[k]=_pop[i].fitness().operator[](k)/sim[i];</span>
<a name="l00099"></a>00099 <span class="comment">//_pop[i].fitness(v);//.operator[](k)=0;//_pop[i].fitness().operator[](k)/sim[i];</span>
<a name="l00100"></a>00100 <a class="codeRef" doxygen="eo.doxytag:../../../workspace/paradiseo-eo/doc/doc/html/" href="../../../workspace/paradiseo-eo/doc/doc/html/classeo_value_param.html#a2">eoPerf2Worth &lt; EOT, worthT &gt;::value</a> ()[i] = rnk1.<a class="codeRef" doxygen="eo.doxytag:../../../workspace/paradiseo-eo/doc/doc/html/" href="../../../workspace/paradiseo-eo/doc/doc/html/classeo_value_param.html#a2">value</a> ().operator[](i) / sim[i]; <span class="comment">//*_pop[i].fitness().operator[](1)*_pop[i].fitness().operator[](1));</span>
<a name="l00101"></a>00101 <span class="comment">//cout&lt;&lt;"\n__________"&lt;&lt;pSize&lt;&lt;" "&lt;&lt;value()[i]&lt;&lt;" "&lt;&lt;i;</span>
<a name="l00102"></a>00102 }
<a name="l00103"></a>00103
<a name="l00104"></a>00104 }
<a name="l00105"></a>00105
<a name="l00106"></a>00106
<a name="l00107"></a>00107
<a name="l00108"></a>00108
<a name="l00109"></a><a class="code" href="classmoeoParetoSharing_1_1dMatrix.html">00109</a> <span class="keyword">class </span><a class="code" href="classmoeoParetoSharing_1_1dMatrix.html">dMatrix</a>:<span class="keyword">public</span> std::vector &lt; std::vector &lt; double &gt; &gt;
<a name="l00110"></a>00110 {
<a name="l00111"></a>00111 <span class="keyword">public</span>:
<a name="l00112"></a><a class="code" href="classmoeoParetoSharing_1_1dMatrix.html#97aa4b1596be7ddba2b52a43ebc4cb6a">00112</a> <a class="code" href="classmoeoParetoSharing_1_1dMatrix.html#97aa4b1596be7ddba2b52a43ebc4cb6a">dMatrix</a> (<span class="keywordtype">unsigned</span> _s):<a class="code" href="classmoeoParetoSharing_1_1dMatrix.html#792b8a45e222a0daecad1ed344fc9a4f">rSize</a> (_s)
<a name="l00113"></a>00113 {
<a name="l00114"></a>00114 this-&gt;<a class="codeRef" doxygen="eo.doxytag:../../../workspace/paradiseo-eo/doc/doc/html/" href="../../../workspace/paradiseo-eo/doc/doc/html/classeo_perf2_worth.html#a2">resize</a> (_s);
<a name="l00115"></a>00115 <span class="keywordflow">for</span> (<span class="keywordtype">unsigned</span> i = 0; i &lt; _s; ++i)
<a name="l00116"></a>00116 this-&gt;operator[] (i).resize (_s);
<a name="l00117"></a>00117 }
<a name="l00118"></a>00118
<a name="l00119"></a><a class="code" href="classmoeoParetoSharing_1_1dMatrix.html#e63c5e6d70866a31eff53fab563922d7">00119</a> <span class="keywordtype">void</span> <a class="code" href="classmoeoParetoSharing_1_1dMatrix.html#e63c5e6d70866a31eff53fab563922d7">printOn</a> (std::ostream &amp; _os)
<a name="l00120"></a>00120 {
<a name="l00121"></a>00121 <span class="keywordflow">for</span> (<span class="keywordtype">unsigned</span> i = 0; i &lt; <a class="code" href="classmoeoParetoSharing_1_1dMatrix.html#792b8a45e222a0daecad1ed344fc9a4f">rSize</a>; i++)
<a name="l00122"></a>00122 <span class="keywordflow">for</span> (<span class="keywordtype">unsigned</span> j = 0; j &lt; rSize; ++j)
<a name="l00123"></a>00123 {
<a name="l00124"></a>00124 _os &lt;&lt; this-&gt;operator[](i)[j] &lt;&lt; <span class="stringliteral">" "</span>;
<a name="l00125"></a>00125 _os &lt;&lt; endl;
<a name="l00126"></a>00126 }
<a name="l00127"></a>00127 _os &lt;&lt; endl;
<a name="l00128"></a>00128 }
<a name="l00129"></a>00129 <span class="comment">//public:</span>
<a name="l00130"></a>00130 <span class="comment">//std::vector&lt;double&gt;v;</span>
<a name="l00131"></a>00131
<a name="l00132"></a>00132 <span class="keyword">private</span>:
<a name="l00133"></a>00133
<a name="l00134"></a>00134
<a name="l00135"></a>00135
<a name="l00136"></a>00136
<a name="l00137"></a><a class="code" href="classmoeoParetoSharing_1_1dMatrix.html#792b8a45e222a0daecad1ed344fc9a4f">00137</a> <span class="keywordtype">unsigned</span> <a class="code" href="classmoeoParetoSharing_1_1dMatrix.html#792b8a45e222a0daecad1ed344fc9a4f">rSize</a>;
<a name="l00138"></a>00138 };
<a name="l00139"></a>00139
<a name="l00140"></a>00140 <span class="keyword">private</span>:
<a name="l00141"></a>00141
<a name="l00142"></a>00142 ;
<a name="l00143"></a>00143
<a name="l00144"></a><a class="code" href="classmoeoParetoSharing.html#002e355f0df0ad242cdf171207b592ac">00144</a> <span class="keywordtype">double</span> <a class="code" href="classmoeoParetoSharing.html#002e355f0df0ad242cdf171207b592ac">sh</a> (<span class="keywordtype">double</span> <a class="code" href="classmoeoParetoSharing.html#329d7d08f06988fcb0f03059c88ed209">dist</a>, <span class="keywordtype">double</span> <a class="code" href="classmoeoParetoSharing.html#0219625f2dd8bfd9ae7cb3039084059f">Dmax</a>)
<a name="l00145"></a>00145 {
<a name="l00146"></a>00146 <span class="keywordflow">if</span> (dist &lt; Dmax)
<a name="l00147"></a>00147 <span class="keywordflow">return</span> (1.0 - dist / Dmax);
<a name="l00148"></a>00148 <span class="keywordflow">else</span>
<a name="l00149"></a>00149 <span class="keywordflow">return</span> (0.0);
<a name="l00150"></a>00150 }
<a name="l00151"></a>00151
<a name="l00152"></a><a class="code" href="classmoeoParetoSharing.html#b5519750a3f30747cbabf67df9b4afd8">00152</a> <span class="keywordtype">double</span> <a class="code" href="classmoeoParetoSharing.html#b5519750a3f30747cbabf67df9b4afd8">nicheSize</a>;
<a name="l00153"></a><a class="code" href="classmoeoParetoSharing.html#329d7d08f06988fcb0f03059c88ed209">00153</a> moeoParetoPhenDist &lt; EOT, worthT &gt; &amp;<a class="code" href="classmoeoParetoSharing.html#329d7d08f06988fcb0f03059c88ed209">dist</a>;
<a name="l00154"></a><a class="code" href="classmoeoParetoSharing.html#42bc90da2e7f3f7d3837484c771f638e">00154</a> moeoParetoEuclidDist &lt; EOT &gt; <a class="code" href="classmoeoParetoSharing.html#42bc90da2e7f3f7d3837484c771f638e">euc_dist</a>;
<a name="l00155"></a><a class="code" href="classmoeoParetoSharing.html#0219625f2dd8bfd9ae7cb3039084059f">00155</a> <span class="keywordtype">double</span> <a class="code" href="classmoeoParetoSharing.html#0219625f2dd8bfd9ae7cb3039084059f">Dmax</a>;
<a name="l00156"></a>00156
<a name="l00157"></a>00157 };
</pre></div><hr size="1"><address style="align: right;"><small>Generated on Mon Jan 15 14:19:18 2007 for ParadisEO-MOEO by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.1 </small></address>
</body>
</html>