git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@40 331e1502-861f-0410-8da2-ba01fb791d7f
128 lines
9.7 KiB
HTML
128 lines
9.7 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: eoSequentialSelect.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>eoSequentialSelect.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">// eoSequential.h</span>
|
|
00005 <span class="comment">// (c) GeNeura Team, 1998 - Maarten Keijzer 2000, Marc Schoenauer, 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@polytechnique.fr</span>
|
|
00023 <span class="comment"> mak@dhi.dk</span>
|
|
00024 <span class="comment"> */</span>
|
|
00025 <span class="comment">//-----------------------------------------------------------------------------</span>
|
|
00026
|
|
00027 <span class="preprocessor">#ifndef eoSequential_h</span>
|
|
00028 <span class="preprocessor"></span><span class="preprocessor">#define eoSequential_h</span>
|
|
00029 <span class="preprocessor"></span>
|
|
00030 <span class="preprocessor">#include <limits></span>
|
|
00031
|
|
00032 <span class="preprocessor">#include "utils/eoData.h"</span>
|
|
00033 <span class="preprocessor">#include "utils/eoRNG.h"</span>
|
|
00034 <span class="preprocessor">#include "eoSelectOne.h"</span>
|
|
00035
|
|
<a name="l00052"></a><a class="code" href="classeo_sequential_select.html">00052</a> <span class="keyword">template</span> <<span class="keyword">class</span> EOT> <span class="keyword">class </span><a class="code" href="classeo_sequential_select.html">eoSequentialSelect</a>: <span class="keyword">public</span> <a class="code" href="classeo_select_one.html">eoSelectOne</a><EOT>
|
|
00053 {
|
|
00054 <span class="keyword">public</span>:
|
|
<a name="l00058"></a><a class="code" href="classeo_sequential_select.html#a0">00058</a> <a class="code" href="classeo_sequential_select.html#a0">eoSequentialSelect</a>(<span class="keywordtype">bool</span> _ordered = <span class="keyword">true</span>)
|
|
00059 : ordered(_ordered), current(std::numeric_limits<unsigned>::max()) {}
|
|
00060
|
|
<a name="l00061"></a><a class="code" href="classeo_sequential_select.html#a1">00061</a> <span class="keywordtype">void</span> <a class="code" href="classeo_sequential_select.html#a1">setup</a>(<span class="keyword">const</span> <a class="code" href="classeo_pop.html">eoPop<EOT></a>& _pop)
|
|
00062 {
|
|
00063 eoPters.resize(_pop.size());
|
|
00064 <span class="keywordflow">if</span> (ordered) <span class="comment">// probably we could have a marker to avoid re-sorting</span>
|
|
00065 _pop.<a class="code" href="classeo_pop.html#a5">sort</a>(eoPters);
|
|
00066 <span class="keywordflow">else</span>
|
|
00067 _pop.<a class="code" href="classeo_pop.html#a7">shuffle</a>(eoPters);
|
|
00068 current=0;
|
|
00069 }
|
|
00070
|
|
<a name="l00071"></a><a class="code" href="classeo_sequential_select.html#a2">00071</a> <span class="keyword">virtual</span> <span class="keyword">const</span> <a class="code" href="struct_dummy.html">EOT</a>& <a class="code" href="classeo_sequential_select.html#a2">operator()</a>(<span class="keyword">const</span> <a class="code" href="classeo_pop.html">eoPop<EOT></a>& _pop)
|
|
00072 {
|
|
00073 <span class="keywordflow">if</span> (current >= _pop.size())
|
|
00074 <a class="code" href="classeo_sequential_select.html#a1">setup</a>(_pop);
|
|
00075
|
|
00076 <span class="keywordtype">unsigned</span> eoN = current;
|
|
00077 current++;
|
|
00078 <span class="keywordflow">return</span> *eoPters[eoN] ;
|
|
00079 }
|
|
00080 <span class="keyword">private</span>:
|
|
00081 <span class="keywordtype">bool</span> ordered;
|
|
00082 <span class="keywordtype">unsigned</span> current;
|
|
00083 std::vector<const EOT*> eoPters;
|
|
00084 };
|
|
00085
|
|
00086
|
|
00087
|
|
<a name="l00097"></a><a class="code" href="classeo_elite_sequential_select.html">00097</a> <span class="keyword">template</span> <<span class="keyword">class</span> EOT> <span class="keyword">class </span><a class="code" href="classeo_elite_sequential_select.html">eoEliteSequentialSelect</a>: <span class="keyword">public</span> <a class="code" href="classeo_select_one.html">eoSelectOne</a><EOT>
|
|
00098 {
|
|
00099 <span class="keyword">public</span>:
|
|
00100
|
|
<a name="l00104"></a><a class="code" href="classeo_elite_sequential_select.html#a0">00104</a> <a class="code" href="classeo_elite_sequential_select.html#a0">eoEliteSequentialSelect</a>(): current(std::numeric_limits<unsigned>::max()) {}
|
|
00105
|
|
<a name="l00106"></a><a class="code" href="classeo_elite_sequential_select.html#a1">00106</a> <span class="keywordtype">void</span> <a class="code" href="classeo_elite_sequential_select.html#a1">setup</a>(<span class="keyword">const</span> <a class="code" href="classeo_pop.html">eoPop<EOT></a>& _pop)
|
|
00107 {
|
|
00108 eoPters.resize(_pop.size());
|
|
00109 _pop.<a class="code" href="classeo_pop.html#a7">shuffle</a>(eoPters);
|
|
00110 <span class="comment">// now get the best</span>
|
|
00111 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> ibest = 0;
|
|
00112 <span class="keyword">const</span> <a class="code" href="struct_dummy.html">EOT</a> * best = eoPters[0];
|
|
00113 <span class="keywordflow">if</span> (_pop.size() == 1)
|
|
00114 <span class="keywordflow">throw</span> std::runtime_error(<span class="stringliteral">"Trying eoEliteSequentialSelect with only one individual!"</span>);
|
|
00115 <span class="keywordflow">for</span> (<span class="keywordtype">unsigned</span> i=1; i<_pop.size(); i++)
|
|
00116 <span class="keywordflow">if</span> (*eoPters[i]>*best)
|
|
00117 {
|
|
00118 ibest = i;
|
|
00119 best = eoPters[ibest];
|
|
00120 }
|
|
00121 <span class="comment">// and put it upfront</span>
|
|
00122 <span class="keyword">const</span> <a class="code" href="struct_dummy.html">EOT</a> *ptmp = eoPters[0];
|
|
00123 eoPters[0]=best;
|
|
00124 eoPters[ibest] = ptmp;
|
|
00125 <span class="comment">// exit after setting current</span>
|
|
00126 current=0;
|
|
00127 }
|
|
00128
|
|
<a name="l00129"></a><a class="code" href="classeo_elite_sequential_select.html#a2">00129</a> <span class="keyword">virtual</span> <span class="keyword">const</span> <a class="code" href="struct_dummy.html">EOT</a>& <a class="code" href="classeo_elite_sequential_select.html#a2">operator()</a>(<span class="keyword">const</span> <a class="code" href="classeo_pop.html">eoPop<EOT></a>& _pop)
|
|
00130 {
|
|
00131 <span class="keywordflow">if</span> (current >= _pop.size())
|
|
00132 <a class="code" href="classeo_elite_sequential_select.html#a1">setup</a>(_pop);
|
|
00133
|
|
00134 <span class="keywordtype">unsigned</span> eoN = current;
|
|
00135 current++;
|
|
00136 <span class="keywordflow">return</span> *eoPters[eoN] ;
|
|
00137 }
|
|
00138 <span class="keyword">private</span>:
|
|
00139 <span class="keywordtype">unsigned</span> current;
|
|
00140 std::vector<const EOT*> eoPters;
|
|
00141 };
|
|
00142
|
|
00143
|
|
00144 <span class="preprocessor">#endif</span>
|
|
</pre></div><hr size="1"><address style="align: right;"><small>Generated on Thu Oct 19 05:06:38 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>
|