git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@40 331e1502-861f-0410-8da2-ba01fb791d7f
128 lines
9.5 KiB
HTML
128 lines
9.5 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: eoMerge.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></div>
|
|
<h1>eoMerge.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">// eoMerge.h</span>
|
|
00005 <span class="comment">// Base class for elitist-merging classes</span>
|
|
00006 <span class="comment">// (c) GeNeura Team, 1998</span>
|
|
00007 <span class="comment">/* </span>
|
|
00008 <span class="comment"> This library is free software; you can redistribute it and/or</span>
|
|
00009 <span class="comment"> modify it under the terms of the GNU Lesser General Public</span>
|
|
00010 <span class="comment"> License as published by the Free Software Foundation; either</span>
|
|
00011 <span class="comment"> version 2 of the License, or (at your option) any later version.</span>
|
|
00012 <span class="comment"></span>
|
|
00013 <span class="comment"> This library is distributed in the hope that it will be useful,</span>
|
|
00014 <span class="comment"> but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
|
|
00015 <span class="comment"> MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU</span>
|
|
00016 <span class="comment"> Lesser General Public License for more details.</span>
|
|
00017 <span class="comment"></span>
|
|
00018 <span class="comment"> You should have received a copy of the GNU Lesser General Public</span>
|
|
00019 <span class="comment"> License along with this library; if not, write to the Free Software</span>
|
|
00020 <span class="comment"> Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA</span>
|
|
00021 <span class="comment"></span>
|
|
00022 <span class="comment"> Contact: todos@geneura.ugr.es, http://geneura.ugr.es</span>
|
|
00023 <span class="comment"> */</span>
|
|
00024 <span class="comment">//-----------------------------------------------------------------------------</span>
|
|
00025
|
|
00026 <span class="preprocessor">#ifndef eoMerge_h</span>
|
|
00027 <span class="preprocessor"></span><span class="preprocessor">#define eoMerge_h</span>
|
|
00028 <span class="preprocessor"></span>
|
|
00029 <span class="comment">//-----------------------------------------------------------------------------</span>
|
|
00030
|
|
00031 <span class="preprocessor">#include <stdexcept></span>
|
|
00032
|
|
00033 <span class="comment">// EO includes</span>
|
|
00034 <span class="preprocessor">#include <eoPop.h></span> <span class="comment">// eoPop</span>
|
|
00035 <span class="preprocessor">#include <eoFunctor.h></span> <span class="comment">// eoMerge</span>
|
|
00036
|
|
<a name="l00048"></a><a class="code" href="classeo_merge.html">00048</a> <span class="keyword">template</span><<span class="keyword">class</span> Chrom> <span class="keyword">class </span><a class="code" href="classeo_merge.html">eoMerge</a>: <span class="keyword">public</span> <a class="code" href="classeo_b_f.html">eoBF</a><const eoPop<Chrom>&, eoPop<Chrom>&, void>
|
|
00049 {};
|
|
00050
|
|
<a name="l00055"></a><a class="code" href="classeo_elitism.html">00055</a> <span class="keyword">template</span> <<span class="keyword">class</span> EOT> <span class="keyword">class </span><a class="code" href="classeo_elitism.html">eoElitism</a> : <span class="keyword">public</span> <a class="code" href="classeo_merge.html">eoMerge</a><EOT>
|
|
00056 {
|
|
00057 <span class="keyword">public</span> :
|
|
00058 <a class="code" href="classeo_elitism.html">eoElitism</a>(<span class="keywordtype">double</span> _rate, <span class="keywordtype">bool</span> _interpret_as_rate = <span class="keyword">true</span>):
|
|
00059 rate(0), combien(0)
|
|
00060 {
|
|
00061 <span class="keywordflow">if</span> (_interpret_as_rate)
|
|
00062 {
|
|
00063 <span class="keywordflow">if</span> ( (_rate<0) || (_rate>1) )
|
|
00064 <span class="keywordflow">throw</span> std::logic_error(<span class="stringliteral">"eoElitism: rate shoud be in [0,1]"</span>);
|
|
00065 rate = _rate;
|
|
00066 }
|
|
00067 <span class="keywordflow">else</span>
|
|
00068 {
|
|
00069 <span class="keywordflow">if</span> (_rate<0)
|
|
00070 <span class="keywordflow">throw</span> std::logic_error(<span class="stringliteral">"Negative number of offspring in eoElitism!"</span>);
|
|
00071 combien = (<span class="keywordtype">unsigned</span> int)_rate;
|
|
00072 <span class="keywordflow">if</span> (combien != _rate)
|
|
00073 std::cout << <span class="stringliteral">"Warning: Number of guys to merge in eoElitism was rounded"</span>;
|
|
00074 }
|
|
00075 }
|
|
00076
|
|
<a name="l00077"></a><a class="code" href="classeo_elitism.html#a1">00077</a> <span class="keywordtype">void</span> <a class="code" href="classeo_elitism.html#a1">operator()</a>(<span class="keyword">const</span> <a class="code" href="classeo_pop.html">eoPop<EOT></a>& _pop, <a class="code" href="classeo_pop.html">eoPop<EOT></a>& _offspring)
|
|
00078 {
|
|
00079 <span class="keywordflow">if</span> ((combien == 0) && (rate == 0.0))
|
|
00080 <span class="keywordflow">return</span>;
|
|
00081 <span class="keywordtype">unsigned</span> combienLocal;
|
|
00082 <span class="keywordflow">if</span> (combien == 0) <span class="comment">// rate is specified</span>
|
|
00083 combienLocal = (<span class="keywordtype">unsigned</span> int) (rate * _pop.size());
|
|
00084 <span class="keywordflow">else</span>
|
|
00085 combienLocal = combien;
|
|
00086
|
|
00087 <span class="keywordflow">if</span> (combienLocal > _pop.size())
|
|
00088 <span class="keywordflow">throw</span> std::logic_error(<span class="stringliteral">"Elite larger than population"</span>);
|
|
00089
|
|
00090 std::vector<const EOT*> result;
|
|
00091 _pop.<a class="code" href="classeo_pop.html#a13">nth_element</a>(combienLocal, result);
|
|
00092
|
|
00093 <span class="keywordflow">for</span> (size_t i = 0; i < result.size(); ++i)
|
|
00094 {
|
|
00095 _offspring.push_back(*result[i]);
|
|
00096 }
|
|
00097 }
|
|
00098
|
|
00099 <span class="keyword">private</span> :
|
|
00100 <span class="keywordtype">double</span> rate;
|
|
00101 <span class="keywordtype">unsigned</span> combien;
|
|
00102 };
|
|
00103
|
|
<a name="l00107"></a><a class="code" href="classeo_no_elitism.html">00107</a> <span class="keyword">template</span> <<span class="keyword">class</span> EOT> <span class="keyword">class </span><a class="code" href="classeo_no_elitism.html">eoNoElitism</a> : <span class="keyword">public</span> <a class="code" href="classeo_elitism.html">eoElitism</a><EOT>
|
|
00108 {
|
|
00109 <span class="keyword">public</span> :
|
|
00110 <a class="code" href="classeo_no_elitism.html">eoNoElitism</a>() : <a class="code" href="classeo_elitism.html">eoElitism<EOT></a>(0) {}
|
|
00111 };
|
|
00112
|
|
<a name="l00116"></a><a class="code" href="classeo_plus.html">00116</a> <span class="keyword">template</span> <<span class="keyword">class</span> EOT> <span class="keyword">class </span><a class="code" href="classeo_plus.html">eoPlus</a> : <span class="keyword">public</span> <a class="code" href="classeo_merge.html">eoMerge</a><EOT>
|
|
00117 {
|
|
00118 <span class="keyword">public</span> :
|
|
<a name="l00119"></a><a class="code" href="classeo_plus.html#a0">00119</a> <span class="keywordtype">void</span> <a class="code" href="classeo_plus.html#a0">operator()</a>(<span class="keyword">const</span> <a class="code" href="classeo_pop.html">eoPop<EOT></a>& _pop, <a class="code" href="classeo_pop.html">eoPop<EOT></a>& _offspring)
|
|
00120 {
|
|
00121 _offspring.reserve(_offspring.size() + _pop.size());
|
|
00122
|
|
00123 <span class="keywordflow">for</span> (size_t i = 0; i < _pop.size(); ++i)
|
|
00124 {
|
|
00125 _offspring.push_back(_pop[i]);
|
|
00126 }
|
|
00127 }
|
|
00128
|
|
00129 <span class="keyword">private</span> :
|
|
00130 };
|
|
00131
|
|
00132 <span class="comment">//-----------------------------------------------------------------------------</span>
|
|
00133
|
|
00134 <span class="preprocessor">#endif </span>
|
|
</pre></div><hr size="1"><address style="align: right;"><small>Generated on Thu Oct 19 05:06:36 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>
|