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:
legrand 2006-12-12 14:49:08 +00:00
commit c3aec878e5
3609 changed files with 342772 additions and 0 deletions

View file

@ -0,0 +1,187 @@
<!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: main.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&nbsp;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&nbsp;Hierarchy</a> | <a class="qindex" href="classes.html">Alphabetical&nbsp;List</a> | <a class="qindex" href="annotated.html">Class&nbsp;List</a> | <a class="qindex" href="files.html">File&nbsp;List</a> | <a class="qindex" href="namespacemembers.html">Namespace&nbsp;Members</a> | <a class="qindex" href="functions.html">Class&nbsp;Members</a> | <a class="qindex" href="pages.html">Related&nbsp;Pages</a> | <span class="search"><u>S</u>earch&nbsp;for&nbsp;<input class="search" type="text" name="query" value="" size="20" accesskey="s"/></span></form></div>
<div class="nav">
<a class="el" href="dir_000020.html">app</a>&nbsp;/&nbsp;<a class="el" href="dir_000021.html">gpsymreg</a></div>
<h1>main.cpp</h1><div class="fragment"><pre class="fragment">00001 <span class="comment">/*</span>
00002 <span class="comment"> This program is free software; you can redistribute it and/or modify</span>
00003 <span class="comment"> it under the terms of the GNU General Public License as published by</span>
00004 <span class="comment"> the Free Software Foundation; either version 2 of the License, or</span>
00005 <span class="comment"> (at your option) any later version.</span>
00006 <span class="comment"></span>
00007 <span class="comment"> This library is distributed in the hope that it will be useful,</span>
00008 <span class="comment"> but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
00009 <span class="comment"> MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU</span>
00010 <span class="comment"> Lesser General Public License for more details.</span>
00011 <span class="comment"></span>
00012 <span class="comment"> You should have received a copy of the GNU General Public License</span>
00013 <span class="comment"> along with this library; if not, write to the Free Software</span>
00014 <span class="comment"> Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA</span>
00015 <span class="comment"></span>
00016 <span class="comment"> Contact: todos@geneura.ugr.es, http://geneura.ugr.es</span>
00017 <span class="comment"> jeggermo@liacs.nl</span>
00018 <span class="comment">*/</span>
00019
00020 <span class="preprocessor">#ifdef _MSC_VER</span>
00021 <span class="preprocessor"></span><span class="preprocessor">#pragma warning(disable:4786)</span>
00022 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
00023 <span class="preprocessor"></span>
00024 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
00025 <span class="preprocessor"></span><span class="preprocessor">#include &lt;config.h&gt;</span>
00026 <span class="preprocessor">#endif</span>
00027 <span class="preprocessor"></span>
00028 <span class="preprocessor">#include &lt;iostream&gt;</span>
00029 <span class="preprocessor">#include "gp/eoParseTree.h"</span>
00030 <span class="preprocessor">#include "eo"</span>
00031
00032 <span class="keyword">using</span> <span class="keyword">namespace </span>gp_parse_tree;
00033 <span class="keyword">using</span> <span class="keyword">namespace </span>std;
00034
00035 <span class="comment">//-----------------------------------------------------------------------------</span>
00036
00037 <span class="preprocessor">#include "node.h"</span>
00038 <span class="preprocessor">#include "parameters.h"</span>
00039 <span class="preprocessor">#include "fitness.h"</span>
00040
00041
00042 <span class="comment">// TYPE DECLARATIONS FOR GP</span>
00043
00044
00045 <span class="keyword">typedef</span> <a class="code" href="classeo_parse_tree.html">eoParseTree&lt;FitnessType, Node &gt;</a> <a class="code" href="classeo_parse_tree.html">EoType</a>;
00046 <span class="keyword">typedef</span> <a class="code" href="classeo_pop.html">eoPop&lt;EoType&gt;</a> <a class="code" href="classeo_pop.html">Pop</a>;
00047
00048 <span class="comment">//-----------------------------------------------------------------------------</span>
00049
00050 <span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> *argv[])
00051 {
00052
00053 <span class="comment">// the vector containing the possible nodes</span>
00054 vector&lt;Node&gt; initSequence;
00055
00056 <span class="comment">// initialise parameters</span>
00057 Parameters parameter(argc, argv);
00058
00059 <span class="comment">// set the randomseed</span>
00060 rng.<a class="code" href="classeo_rng.html#a2">reseed</a>(parameter.randomseed);
00061
00062 <span class="comment">// Create a generation counter</span>
00063 <a class="code" href="classeo_value_param.html">eoValueParam&lt;unsigned&gt;</a> generationCounter(0, <span class="stringliteral">"Gen."</span>);
00064
00065 <span class="comment">// Create an incrementor (sub-class of eoUpdater). Note that the</span>
00066 <span class="comment">// parameter's value is passed by reference,</span>
00067 <span class="comment">// so every time the incrementer is updated (every generation),</span>
00068 <span class="comment">// the data in generationCounter will change.</span>
00069 <a class="code" href="classeo_incrementor.html">eoIncrementor&lt;unsigned&gt;</a> increment(generationCounter.value());
00070
00071
00072 <span class="comment">// create an instantiation of the fitness/evaluation function</span>
00073 <span class="comment">// it initializes the initSequence vector</span>
00074 <span class="comment">// the parameters are passed on as well</span>
00075 RegFitness eval(generationCounter, initSequence, parameter);
00076
00077 <span class="comment">// Depth Initializor, set for Ramped Half and Half Initialization</span>
00078 <a class="code" href="classeo_parse_tree_depth_init.html">eoParseTreeDepthInit&lt;FitnessType, Node&gt;</a> initializer(parameter.InitMaxDepth, initSequence, <span class="keyword">true</span>, <span class="keyword">true</span>);
00079
00080 <span class="comment">// create the initial population</span>
00081 Pop pop(parameter.population_size, initializer);
00082
00083 <span class="comment">// and evaluate the individuals</span>
00084 apply&lt;EoType&gt;(eval, pop);
00085
00086 generationCounter.value()++; <span class="comment">// set the generationCounter to 1</span>
00087
00088
00089 <span class="comment">// define X-OVER</span>
00090
00091 <a class="code" href="classeo_subtree_x_over.html">eoSubtreeXOver&lt;FitnessType, Node&gt;</a> xover(parameter.MaxSize);
00092
00093 <span class="comment">// define MUTATION</span>
00094 <a class="code" href="classeo_branch_mutation.html">eoBranchMutation&lt;FitnessType, Node&gt;</a> mutation(initializer, parameter.MaxSize);
00095 <span class="comment">// eoExpansionMutation&lt;FitnessType, Node&gt; mutation(initializer, parameter.MaxSize);</span>
00096 <span class="comment">// eoCollapseSubtreeMutation&lt;FitnessType, Node&gt; mutation(initializer, parameter.MaxSize);</span>
00097 <span class="comment">// eoPointMutation&lt;FitnessType, Node&gt; mutation(initSequence);</span>
00098 <span class="comment">// eoHoistMutation&lt;FitnessType, Node&gt; mutation;</span>
00099
00100 <span class="comment">// The operators are encapsulated into an eoTRansform object,</span>
00101 <span class="comment">// that performs sequentially crossover and mutation</span>
00102 <a class="code" href="classeo_s_g_a_transform.html">eoSGATransform&lt;EoType&gt;</a> transform(xover, parameter.xover_rate, mutation, parameter.mutation_rate);
00103
00104 <span class="comment">// The robust tournament selection</span>
00105 <span class="comment">// in our case 5-tournament selection</span>
00106 <a class="code" href="classeo_det_tournament_select.html">eoDetTournamentSelect&lt;EoType&gt;</a> selectOne(parameter.tournamentsize);
00107 <span class="comment">// is now encapsulated in a eoSelectMany</span>
00108 <a class="code" href="classeo_select_many.html">eoSelectMany&lt;EoType&gt;</a> select(selectOne, parameter.offspring_size, eo_is_an_integer);
00109
00110 <span class="comment">// and the generational replacement</span>
00111 <span class="comment">//eoGenerationalReplacement&lt;EoType&gt; replace;</span>
00112 <span class="comment">// or the SteadtState replacment</span>
00113 <span class="comment">//eoSSGAWorseReplacement&lt;EoType&gt; replace;</span>
00114 <span class="comment">// or comma selection</span>
00115 <a class="code" href="classeo_comma_replacement.html">eoCommaReplacement&lt;EoType&gt;</a> replace;
00116
00117 <span class="comment">// Terminators</span>
00118 <a class="code" href="classeo_gen_continue.html">eoGenContinue&lt;EoType&gt;</a> term(parameter.nGenerations);
00119
00120 <a class="code" href="classeo_check_point.html">eoCheckPoint&lt;EoType&gt;</a> checkPoint(term);
00121
00122 <span class="comment">// STATISTICS</span>
00123 <a class="code" href="classeo_average_stat.html">eoAverageStat&lt;EoType&gt;</a> avg;
00124 <a class="code" href="classeo_best_fitness_stat.html">eoBestFitnessStat&lt;EoType&gt;</a> best;
00125
00126
00127 <span class="comment">// Add it to the checkpoint,</span>
00128 <span class="comment">// so the counter is updated (here, incremented) every generation</span>
00129 checkPoint.add(increment);
00130 checkPoint.add(avg);
00131 checkPoint.add(best);
00132
00133 <span class="preprocessor">#ifdef HAVE_GNUPLOT</span>
00134 <span class="preprocessor"></span> <a class="code" href="classeo_gnuplot1_d_monitor.html">eoGnuplot1DMonitor</a> gnuplotmonitor(<span class="stringliteral">"gnuplotBestStats"</span>);
00135 gnuplotmonitor.add(generationCounter);
00136 gnuplotmonitor.add(best);
00137 <span class="comment">// we need to add a empty string variable if we want to seed the second fitness value</span>
00138 <a class="code" href="classeo_value_param.html">eoValueParam&lt;string&gt;</a> dummy1(<span class="stringliteral">""</span>, <span class="stringliteral">"Smallest Tree Size"</span>);
00139 gnuplotmonitor.add(dummy1);
00140
00141 <a class="code" href="classeo_gnuplot1_d_monitor.html">eoGnuplot1DMonitor</a> gnuplotAvgmonitor(<span class="stringliteral">"gnuplotAvgStats"</span>);
00142 gnuplotAvgmonitor.add(generationCounter);
00143 gnuplotAvgmonitor.add(avg);
00144 <span class="comment">// we need to add a empty string variable if we want to seed the second fitness value</span>
00145 <a class="code" href="classeo_value_param.html">eoValueParam&lt;string&gt;</a> dummy2(<span class="stringliteral">""</span>, <span class="stringliteral">"Average Tree Size"</span>);
00146 gnuplotAvgmonitor.add(dummy2);
00147
00148 checkPoint.add(gnuplotmonitor);
00149 checkPoint.add(gnuplotAvgmonitor);
00150 <span class="preprocessor">#endif</span>
00151 <span class="preprocessor"></span> <span class="comment">// GP Generation</span>
00152 <a class="code" href="classeo_easy_e_a.html">eoEasyEA&lt;EoType&gt;</a> gp(checkPoint, eval, select, transform, replace);
00153
00154 cout &lt;&lt; <span class="stringliteral">"Initialization done"</span> &lt;&lt; endl;
00155
00156
00157 <span class="keywordflow">try</span>
00158 {
00159 gp(pop);
00160 }
00161 <span class="keywordflow">catch</span> (exception&amp; e)
00162 {
00163 cout &lt;&lt; <span class="stringliteral">"exception: "</span> &lt;&lt; e.what() &lt;&lt; endl;;
00164 exit(EXIT_FAILURE);
00165 }
00166
00167 <span class="keywordflow">return</span> 1;
00168
00169 };
00170
00171
00172
</pre></div><hr size="1"><address style="align: right;"><small>Generated on Thu Oct 19 05:06:40 2006 for EO by&nbsp;
<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>