Paradiseo-eo sources added
git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@40 331e1502-861f-0410-8da2-ba01fb791d7f
This commit is contained in:
parent
bc1f453978
commit
c3aec878e5
3609 changed files with 342772 additions and 0 deletions
233
trunk/paradiseo-eo/doc/html/t-eobin_8cpp-source.html
Normal file
233
trunk/paradiseo-eo/doc/html/t-eobin_8cpp-source.html
Normal file
|
|
@ -0,0 +1,233 @@
|
|||
<!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: t-eobin.cpp 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_000002.html">test</a></div>
|
||||
<h1>t-eobin.cpp</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 <span class="comment"></span>
|
||||
00003 <span class="comment"> t-eobin.cpp</span>
|
||||
00004 <span class="comment"> This program tests the the binary cromosomes and several genetic operators</span>
|
||||
00005 <span class="comment"> (c) GeNeura Team, 1999</span>
|
||||
00006 <span class="comment"></span>
|
||||
00007 <span class="comment"> This program is free software; you can redistribute it and/or modify</span>
|
||||
00008 <span class="comment"> it under the terms of the GNU General Public License as published by</span>
|
||||
00009 <span class="comment"> the Free Software Foundation; either version 2 of the License, or</span>
|
||||
00010 <span class="comment"> (at your option) any later version.</span>
|
||||
00011 <span class="comment"></span>
|
||||
00012 <span class="comment"> This program 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</span>
|
||||
00015 <span class="comment"> GNU 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 General Public License</span>
|
||||
00018 <span class="comment"> along with this program; 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"></span>
|
||||
00023 <span class="comment">*/</span>
|
||||
00024 <span class="comment">//-----------------------------------------------------------------------------</span>
|
||||
00025 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
|
||||
00026 <span class="preprocessor"></span><span class="preprocessor">#include <config.h></span>
|
||||
00027 <span class="preprocessor">#endif</span>
|
||||
00028 <span class="preprocessor"></span>
|
||||
00029 <span class="preprocessor">#include <iostream></span> <span class="comment">// std::cout</span>
|
||||
00030 <span class="preprocessor">#include <sstream></span>
|
||||
00031
|
||||
00032 <span class="preprocessor">#include <eo></span> <span class="comment">// general EO</span>
|
||||
00033 <span class="preprocessor">#include <ga.h></span> <span class="comment">// bitstring representation & operators</span>
|
||||
00034 <span class="preprocessor">#include <utils/eoRndGenerators.h></span>
|
||||
00035 <span class="preprocessor">#include "binary_value.h"</span>
|
||||
00036
|
||||
00037 <span class="comment">//-----------------------------------------------------------------------------</span>
|
||||
00038
|
||||
00039 <span class="keyword">typedef</span> <a class="code" href="classeo_bit.html">eoBit<double></a> Chrom;
|
||||
00040
|
||||
00041 <span class="comment">//-----------------------------------------------------------------------------</span>
|
||||
00042
|
||||
00043 <span class="keywordtype">void</span> main_function()
|
||||
00044 {
|
||||
00045 <span class="keyword">const</span> <span class="keywordtype">unsigned</span> SIZE = 8;
|
||||
00046 <span class="keywordtype">unsigned</span> i, j;
|
||||
00047 <a class="code" href="classeo_boolean_generator.html">eoBooleanGenerator</a> gen;
|
||||
00048
|
||||
00049 Chrom chrom(SIZE), chrom2;
|
||||
00050 chrom.<a class="code" href="class_e_o.html#a2">fitness</a>(binary_value(chrom)); chrom2.<a class="code" href="class_e_o.html#a2">fitness</a>(binary_value(chrom2));
|
||||
00051
|
||||
00052 std::cout << <span class="stringliteral">"chrom: "</span> << chrom << std::endl;
|
||||
00053 chrom[0] = chrom[SIZE - 1] = <span class="keyword">true</span>; chrom.<a class="code" href="class_e_o.html#a2">fitness</a>(binary_value(chrom));
|
||||
00054 std::cout << <span class="stringliteral">"chrom: "</span> << chrom << std::endl;
|
||||
00055 chrom[0] = chrom[SIZE - 1] = <span class="keyword">false</span>; chrom.<a class="code" href="class_e_o.html#a2">fitness</a>(binary_value(chrom));
|
||||
00056 std::cout << <span class="stringliteral">"chrom: "</span> << chrom << std::endl;
|
||||
00057 chrom[0] = chrom[SIZE - 1] = <span class="keyword">true</span>; chrom.<a class="code" href="class_e_o.html#a2">fitness</a>(binary_value(chrom));
|
||||
00058
|
||||
00059 std::cout << <span class="stringliteral">"chrom.className() = "</span> << chrom.<a class="code" href="classeo_bit.html#a1">className</a>() << std::endl;
|
||||
00060
|
||||
00061 std::cout << <span class="stringliteral">"chrom: "</span> << chrom << std::endl
|
||||
00062 << <span class="stringliteral">"chrom2: "</span> << chrom2 << std::endl;
|
||||
00063
|
||||
00064 std::ostringstream os;
|
||||
00065 os << chrom;
|
||||
00066 std::istringstream is(os.str());
|
||||
00067 is >> chrom2; chrom.<a class="code" href="class_e_o.html#a2">fitness</a>(binary_value(chrom2));
|
||||
00068
|
||||
00069 std::cout << <span class="stringliteral">"\nTesting reading, writing\n"</span>;
|
||||
00070 std::cout << <span class="stringliteral">"chrom: "</span> << chrom << <span class="stringliteral">"\nchrom2: "</span> << chrom2 << <span class="charliteral">'\n'</span>;
|
||||
00071
|
||||
00072 std::fill(chrom.begin(), chrom.end(), <span class="keyword">false</span>);
|
||||
00073 std::cout << <span class="stringliteral">"--------------------------------------------------"</span>
|
||||
00074 << std::endl << <span class="stringliteral">"eoMonOp's aplied to .......... "</span> << chrom << std::endl;
|
||||
00075
|
||||
00076 <a class="code" href="classeo_init_fixed_length.html">eoInitFixedLength<Chrom></a>
|
||||
00077 random(chrom.size(), gen);
|
||||
00078
|
||||
00079 random(chrom); chrom.<a class="code" href="class_e_o.html#a2">fitness</a>(binary_value(chrom));
|
||||
00080 std::cout << <span class="stringliteral">"after eoBinRandom ............ "</span> << chrom << std::endl;
|
||||
00081
|
||||
00082 eoOneBitFlip<Chrom> bitflip;
|
||||
00083 bitflip(chrom); chrom.<a class="code" href="class_e_o.html#a2">fitness</a>(binary_value(chrom));
|
||||
00084 std::cout << <span class="stringliteral">"after eoBitFlip .............. "</span> << chrom << std::endl;
|
||||
00085
|
||||
00086 <a class="code" href="classeo_bit_mutation.html">eoBitMutation<Chrom></a> mutation(0.5);
|
||||
00087 mutation(chrom); chrom.<a class="code" href="class_e_o.html#a2">fitness</a>(binary_value(chrom));
|
||||
00088 std::cout << <span class="stringliteral">"after eoBinMutation(0.5) ..... "</span> << chrom << std::endl;
|
||||
00089
|
||||
00090 <a class="code" href="classeo_bit_inversion.html">eoBitInversion<Chrom></a> inversion;
|
||||
00091 inversion(chrom); chrom.fitness(binary_value(chrom));
|
||||
00092 std::cout << <span class="stringliteral">"after eoBinInversion ......... "</span> << chrom << std::endl;
|
||||
00093
|
||||
00094 <a class="code" href="classeo_bit_next.html">eoBitNext<Chrom></a> next;
|
||||
00095 next(chrom); chrom.fitness(binary_value(chrom));
|
||||
00096 std::cout << <span class="stringliteral">"after eoBinNext .............. "</span> << chrom << std::endl;
|
||||
00097
|
||||
00098 <a class="code" href="classeo_bit_prev.html">eoBitPrev<Chrom></a> prev;
|
||||
00099 prev(chrom); chrom.fitness(binary_value(chrom));
|
||||
00100 std::cout << <span class="stringliteral">"after eoBinPrev .............. "</span> << chrom << std::endl;
|
||||
00101
|
||||
00102 std::fill(chrom.begin(), chrom.end(), <span class="keyword">false</span>); chrom.fitness(binary_value(chrom));
|
||||
00103 std::fill(chrom2.begin(), chrom2.end(), <span class="keyword">true</span>); chrom2.fitness(binary_value(chrom2));
|
||||
00104 std::cout << <span class="stringliteral">"--------------------------------------------------"</span>
|
||||
00105 << std::endl << <span class="stringliteral">"eoBinOp's aplied to ... "</span>
|
||||
00106 << chrom << <span class="stringliteral">" "</span> << chrom2 << std::endl;
|
||||
00107
|
||||
00108 eo1PtBitXover<Chrom> xover;
|
||||
00109 std::fill(chrom.begin(), chrom.end(), <span class="keyword">false</span>);
|
||||
00110 std::fill(chrom2.begin(), chrom2.end(), <span class="keyword">true</span>);
|
||||
00111 xover(chrom, chrom2);
|
||||
00112 chrom.fitness(binary_value(chrom)); chrom2.fitness(binary_value(chrom2));
|
||||
00113 std::cout << <span class="stringliteral">"eoBinCrossover ........ "</span> << chrom << <span class="stringliteral">" "</span> << chrom2 << std::endl;
|
||||
00114
|
||||
00115 <span class="keywordflow">for</span> (i = 1; i < SIZE; i++)
|
||||
00116 {
|
||||
00117 <a class="code" href="classeo_n_pts_bit_xover.html">eoNPtsBitXover<Chrom></a> nxover(i);
|
||||
00118 std::fill(chrom.begin(), chrom.end(), <span class="keyword">false</span>);
|
||||
00119 std::fill(chrom2.begin(), chrom2.end(), <span class="keyword">true</span>);
|
||||
00120 nxover(chrom, chrom2);
|
||||
00121 chrom.fitness(binary_value(chrom)); chrom2.fitness(binary_value(chrom2));
|
||||
00122 std::cout << <span class="stringliteral">"eoBinNxOver("</span> << i << <span class="stringliteral">") ........ "</span>
|
||||
00123 << chrom << <span class="stringliteral">" "</span> << chrom2 << std::endl;
|
||||
00124 }
|
||||
00125
|
||||
00126 <span class="keywordflow">for</span> (i = 1; i < SIZE / 2; i++)
|
||||
00127 <span class="keywordflow">for</span> (j = 1; j < SIZE / 2; j++)
|
||||
00128 {
|
||||
00129 <a class="code" href="classeo_bit_gx_over.html">eoBitGxOver<Chrom></a> gxover(i, j);
|
||||
00130 std::fill(chrom.begin(), chrom.end(), <span class="keyword">false</span>);
|
||||
00131 std::fill(chrom2.begin(), chrom2.end(), <span class="keyword">true</span>);
|
||||
00132 gxover(chrom, chrom2);
|
||||
00133 chrom.fitness(binary_value(chrom)); chrom2.fitness(binary_value(chrom2));
|
||||
00134 std::cout << <span class="stringliteral">"eoBinGxOver("</span> << i << <span class="stringliteral">", "</span> << j << <span class="stringliteral">") ..... "</span>
|
||||
00135 << chrom << <span class="stringliteral">" "</span> << chrom2 << std::endl;
|
||||
00136 }
|
||||
00137
|
||||
00138 <span class="comment">// test SGA algorithm</span>
|
||||
00139 <a class="code" href="classeo_gen_continue.html">eoGenContinue<Chrom></a> continuator1(50);
|
||||
00140 <a class="code" href="classeo_fit_continue.html">eoFitContinue<Chrom></a> continuator2(65535.f);
|
||||
00141
|
||||
00142 <a class="code" href="classeo_combined_continue.html">eoCombinedContinue<Chrom></a> continuator(continuator1, continuator2);
|
||||
00143
|
||||
00144 <a class="code" href="classeo_check_point.html">eoCheckPoint<Chrom></a> checkpoint(continuator);
|
||||
00145
|
||||
00146 <a class="code" href="classeo_stdout_monitor.html">eoStdoutMonitor</a> monitor;
|
||||
00147
|
||||
00148 checkpoint.add(monitor);
|
||||
00149
|
||||
00150 <a class="code" href="classeo_second_moment_stats.html">eoSecondMomentStats<Chrom></a> stats;
|
||||
00151
|
||||
00152 monitor.<a class="code" href="classeo_monitor.html#a1">add</a>(stats);
|
||||
00153 checkpoint.<a class="code" href="classeo_monitor.html#a1">add</a>(stats);
|
||||
00154
|
||||
00155 <a class="code" href="classeo_proportional_select.html">eoProportionalSelect<Chrom></a> select;
|
||||
00156 <a class="code" href="structeo_eval_func_ptr.html">eoEvalFuncPtr<Chrom></a> eval(binary_value);
|
||||
00157
|
||||
00158 <a class="code" href="classeo_s_g_a.html">eoSGA<Chrom></a> sga(select, xover, 0.8f, bitflip, 0.1f, eval, checkpoint);
|
||||
00159
|
||||
00160 <a class="code" href="classeo_init_fixed_length.html">eoInitFixedLength<Chrom></a> init(16, gen);
|
||||
00161 <a class="code" href="classeo_pop.html">eoPop<Chrom></a> pop(100, init);
|
||||
00162
|
||||
00163 apply<Chrom>(eval, pop);
|
||||
00164
|
||||
00165 sga(pop);
|
||||
00166
|
||||
00167 pop.sort();
|
||||
00168
|
||||
00169 std::cout << <span class="stringliteral">"Population "</span> << pop << std::endl;
|
||||
00170
|
||||
00171 std::cout << <span class="stringliteral">"\nBest: "</span> << pop[0].fitness() << <span class="charliteral">'\n'</span>;
|
||||
00172
|
||||
00173 <span class="comment">/*</span>
|
||||
00174 <span class="comment"></span>
|
||||
00175 <span class="comment"> Commented this out, waiting for a definite decision what to do with the mOp's</span>
|
||||
00176 <span class="comment"></span>
|
||||
00177 <span class="comment"> // Check multiOps</span>
|
||||
00178 <span class="comment"> eoMultiMonOp<Chrom> mOp( &next );</span>
|
||||
00179 <span class="comment"> mOp.adOp( &bitflip );</span>
|
||||
00180 <span class="comment"> std::cout << "before multiMonOp............ " << chrom << std::endl;</span>
|
||||
00181 <span class="comment"> mOp( chrom );</span>
|
||||
00182 <span class="comment"> std::cout << "after multiMonOp .............. " << chrom << std::endl;</span>
|
||||
00183 <span class="comment"></span>
|
||||
00184 <span class="comment"> eoBinGxOver<Chrom> gxover(2, 4);</span>
|
||||
00185 <span class="comment"> eoMultiBinOp<Chrom> mbOp( &gxover );</span>
|
||||
00186 <span class="comment"> mOp.adOp( &bitflip );</span>
|
||||
00187 <span class="comment"> std::cout << "before multiBinOp............ " << chrom << " " << chrom2 << std::endl;</span>
|
||||
00188 <span class="comment"> mbOp( chrom, chrom2 );</span>
|
||||
00189 <span class="comment"> std::cout << "after multiBinOp .............. " << chrom << " " << chrom2 <<std::endl;</span>
|
||||
00190 <span class="comment"> */</span>
|
||||
00191 }
|
||||
00192
|
||||
00193 <span class="comment">//-----------------------------------------------------------------------------</span>
|
||||
00194 <span class="comment">// For MSVC memory lead detection</span>
|
||||
00195 <span class="preprocessor">#ifdef _MSC_VER</span>
|
||||
00196 <span class="preprocessor"></span><span class="preprocessor">#include <crtdbg.h></span>
|
||||
00197 <span class="preprocessor">#endif</span>
|
||||
00198 <span class="preprocessor"></span>
|
||||
00199 <span class="keywordtype">int</span> main()
|
||||
00200 {
|
||||
00201 <span class="preprocessor">#ifdef _MSC_VER</span>
|
||||
00202 <span class="preprocessor"></span> <span class="comment">// rng.reseed(42);</span>
|
||||
00203 <span class="keywordtype">int</span> flag = _CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF);
|
||||
00204 flag |= _CRTDBG_LEAK_CHECK_DF;
|
||||
00205 _CrtSetDbgFlag(flag);
|
||||
00206 <span class="comment">// _CrtSetBreakAlloc(100);</span>
|
||||
00207 <span class="preprocessor">#endif</span>
|
||||
00208 <span class="preprocessor"></span>
|
||||
00209 <span class="keywordflow">try</span>
|
||||
00210 {
|
||||
00211 main_function();
|
||||
00212 }
|
||||
00213 <span class="keywordflow">catch</span>(std::exception& e)
|
||||
00214 {
|
||||
00215 std::cout << <span class="stringliteral">"Exception: "</span> << e.what() << <span class="charliteral">'\n'</span>;
|
||||
00216 }
|
||||
00217
|
||||
00218 }
|
||||
</pre></div><hr size="1"><address style="align: right;"><small>Generated on Thu Oct 19 05:06:43 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>
|
||||
Loading…
Add table
Add a link
Reference in a new issue