git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@40 331e1502-861f-0410-8da2-ba01fb791d7f
408 lines
27 KiB
HTML
408 lines
27 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: symreg.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_000007.html">contrib</a> / <a class="el" href="dir_000008.html">mathsym</a></div>
|
|
<h1>symreg.cpp</h1><div class="fragment"><pre class="fragment">00001 <span class="comment">/* </span>
|
|
00002 <span class="comment"> * Copyright (C) 2005 Maarten Keijzer</span>
|
|
00003 <span class="comment"> *</span>
|
|
00004 <span class="comment"> * This program is free software; you can redistribute it and/or modify</span>
|
|
00005 <span class="comment"> * it under the terms of version 2 of the GNU General Public License as </span>
|
|
00006 <span class="comment"> * published by the Free Software Foundation. </span>
|
|
00007 <span class="comment"> *</span>
|
|
00008 <span class="comment"> * This program is distributed in the hope that it will be useful,</span>
|
|
00009 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
|
|
00010 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span>
|
|
00011 <span class="comment"> * GNU General Public License for more details.</span>
|
|
00012 <span class="comment"> *</span>
|
|
00013 <span class="comment"> * You should have received a copy of the GNU General Public License</span>
|
|
00014 <span class="comment"> * along with this program; if not, write to the Free Software</span>
|
|
00015 <span class="comment"> * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA</span>
|
|
00016 <span class="comment"> */</span>
|
|
00017
|
|
00018
|
|
00019 <span class="preprocessor">#include <LanguageTable.h></span>
|
|
00020 <span class="preprocessor">#include <TreeBuilder.h></span>
|
|
00021 <span class="preprocessor">#include <FunDef.h></span>
|
|
00022 <span class="preprocessor">#include <Dataset.h></span>
|
|
00023
|
|
00024 <span class="preprocessor">#include <eoSymInit.h></span>
|
|
00025 <span class="preprocessor">#include <eoSym.h></span>
|
|
00026 <span class="preprocessor">#include <eoPop.h></span>
|
|
00027 <span class="preprocessor">#include <eoSymMutate.h></span>
|
|
00028 <span class="comment">//#include <eoSymLambdaMutate.h></span>
|
|
00029 <span class="preprocessor">#include <eoSymCrossover.h></span>
|
|
00030 <span class="preprocessor">#include <eoSymEval.h></span>
|
|
00031 <span class="preprocessor">#include <eoOpContainer.h></span>
|
|
00032 <span class="preprocessor">#include <eoDetTournamentSelect.h></span>
|
|
00033 <span class="preprocessor">#include <eoMergeReduce.h></span>
|
|
00034 <span class="preprocessor">#include <eoGenContinue.h></span>
|
|
00035 <span class="preprocessor">#include <eoEasyEA.h></span>
|
|
00036 <span class="preprocessor">#include <eoGeneralBreeder.h></span>
|
|
00037
|
|
00038 <span class="preprocessor">#include <utils/eoParser.h></span>
|
|
00039 <span class="preprocessor">#include <utils/eoCheckPoint.h></span>
|
|
00040 <span class="preprocessor">#include <utils/eoStat.h></span>
|
|
00041 <span class="preprocessor">#include <utils/eoStdoutMonitor.h></span>
|
|
00042 <span class="preprocessor">#include <utils/eoRNG.h></span>
|
|
00043
|
|
00044 <span class="keyword">using</span> <span class="keyword">namespace </span>std;
|
|
00045
|
|
00046 <span class="keyword">typedef</span> EoSym<eoMinimizingFitness> <a class="code" href="classeo_parse_tree.html">EoType</a>;
|
|
00047
|
|
00048 <span class="keyword">static</span> <span class="keywordtype">int</span> functions_added = 0;
|
|
00049
|
|
00050 <span class="keywordtype">void</span> add_function(LanguageTable& table, eoParser& parser, string name, <span class="keywordtype">unsigned</span> arity, token_t token, <span class="keyword">const</span> FunDef& fun);
|
|
00051 <span class="keywordtype">void</span> setup_language(LanguageTable& table, eoParser& parser);
|
|
00052
|
|
00053 <span class="keyword">template</span> <<span class="keyword">class</span> T>
|
|
00054 T& select(<span class="keywordtype">bool</span> check, T& a, T& b) { <span class="keywordflow">if</span> (check) <span class="keywordflow">return</span> a; <span class="keywordflow">return</span> b; }
|
|
00055
|
|
00056 <span class="keyword">class </span>eoBestIndividualStat : <span class="keyword">public</span> <a class="code" href="classeo_sorted_stat.html">eoSortedStat</a><EoType, string> {
|
|
00057 <span class="keyword">public</span>:
|
|
00058 eoBestIndividualStat() : <a class="code" href="classeo_sorted_stat.html">eoSortedStat</a><EoType, string>(<span class="stringliteral">""</span>, <span class="stringliteral">"best individual"</span>) {}
|
|
00059
|
|
00060 <span class="keywordtype">void</span> <a class="code" href="classeo_u_f.html#a1">operator()</a>(<span class="keyword">const</span> vector<const EoType*>& _pop) {
|
|
00061 ostringstream os;
|
|
00062 os << (Sym) *_pop[0];
|
|
00063 <a class="code" href="classeo_value_param.html#a2">value</a>() = os.str();
|
|
00064 }
|
|
00065
|
|
00066 };
|
|
00067
|
|
00068 <span class="keyword">class </span>AverageSizeStat : <span class="keyword">public</span> <a class="code" href="classeo_stat.html">eoStat</a><EoType, double> {
|
|
00069 <span class="keyword">public</span>:
|
|
00070 AverageSizeStat() : <a class="code" href="classeo_stat.html">eoStat</a><EoType, double>(0.0, <span class="stringliteral">"Average size population"</span>) {}
|
|
00071
|
|
00072 <span class="keywordtype">void</span> <a class="code" href="classeo_u_f.html#a1">operator()</a>(<span class="keyword">const</span> <a class="code" href="classeo_pop.html">eoPop<EoType></a>& _pop) {
|
|
00073 <span class="keywordtype">double</span> total = 0.0;
|
|
00074 <span class="keywordflow">for</span> (<span class="keywordtype">unsigned</span> i = 0; i < _pop.size(); ++i) {
|
|
00075 total += _pop[i].size();
|
|
00076 }
|
|
00077 <a class="code" href="classeo_value_param.html#a2">value</a>() = total/_pop.size();
|
|
00078 }
|
|
00079 };
|
|
00080
|
|
00081 <span class="keyword">class </span>SumSizeStat : <span class="keyword">public</span> <a class="code" href="classeo_stat.html">eoStat</a><EoType, unsigned> {
|
|
00082 <span class="keyword">public</span>:
|
|
00083 SumSizeStat() : <a class="code" href="classeo_stat.html">eoStat</a><EoType, unsigned>(0u, <span class="stringliteral">"Number of subtrees"</span>) {}
|
|
00084
|
|
00085 <span class="keywordtype">void</span> <a class="code" href="classeo_u_f.html#a1">operator()</a>(<span class="keyword">const</span> <a class="code" href="classeo_pop.html">eoPop<EoType></a>& _pop) {
|
|
00086 <span class="keywordtype">unsigned</span> total = 0;
|
|
00087 <span class="keywordflow">for</span> (<span class="keywordtype">unsigned</span> i = 0; i < _pop.size(); ++i) {
|
|
00088 total += _pop[i].size();
|
|
00089 }
|
|
00090 <a class="code" href="classeo_value_param.html#a2">value</a>() = total;
|
|
00091 }
|
|
00092 };
|
|
00093
|
|
00094 <span class="keyword">class </span>DagSizeStat : <span class="keyword">public</span> <a class="code" href="classeo_stat.html">eoStat</a><EoType, unsigned> {
|
|
00095 <span class="keyword">public</span>:
|
|
00096 DagSizeStat() : <a class="code" href="classeo_stat.html">eoStat</a><EoType, unsigned>(0u, <span class="stringliteral">"Number of distinct subtrees"</span>) {}
|
|
00097
|
|
00098 <span class="keywordtype">void</span> <a class="code" href="classeo_u_f.html#a1">operator()</a>(<span class="keyword">const</span> <a class="code" href="classeo_pop.html">eoPop<EoType></a>& _pop) {
|
|
00099 <a class="code" href="classeo_value_param.html#a2">value</a>() = Sym::get_dag().size();
|
|
00100 }
|
|
00101 };
|
|
00102
|
|
00103 <span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span>* argv[]) {
|
|
00104
|
|
00105 eoParser parser(argc, argv);
|
|
00106
|
|
00107 <span class="comment">/* Language */</span>
|
|
00108 LanguageTable table;
|
|
00109 setup_language(table, parser);
|
|
00110
|
|
00111 <span class="comment">/* Data */</span>
|
|
00112
|
|
00113 <a class="code" href="classeo_value_param.html">eoValueParam<string></a> datafile = parser.createParam(string(<span class="stringliteral">""</span>), <span class="stringliteral">"datafile"</span>, <span class="stringliteral">"Training data"</span>, <span class="charliteral">'d'</span>, string(<span class="stringliteral">"Regression"</span>), <span class="keyword">true</span>); <span class="comment">// mandatory </span>
|
|
00114 <span class="keywordtype">double</span> train_percentage = parser.createParam(1.0, <span class="stringliteral">"trainperc"</span>, <span class="stringliteral">"Percentage of data used for training"</span>, 0, string(<span class="stringliteral">"Regression"</span>)).value();
|
|
00115
|
|
00116 <span class="comment">/* Population */</span>
|
|
00117
|
|
00118 <span class="keywordtype">unsigned</span> pop_size = parser.createParam(1500u, <span class="stringliteral">"population-size"</span>, <span class="stringliteral">"Population Size"</span>, <span class="charliteral">'p'</span>, string(<span class="stringliteral">"Population"</span>)).<a class="code" href="classeo_value_param.html#a2">value</a>();
|
|
00119
|
|
00120 uint32_t seed = parser.createParam( uint32_t(time(0)), <span class="stringliteral">"random-seed"</span>, <span class="stringliteral">"Seed for rng"</span>, <span class="charliteral">'D'</span>).<a class="code" href="classeo_value_param.html#a2">value</a>();
|
|
00121
|
|
00122 cout << <span class="stringliteral">"Seed "</span> << seed << endl;
|
|
00123 rng.<a class="code" href="classeo_rng.html#a2">reseed</a>(seed);
|
|
00124
|
|
00125 <span class="keywordtype">double</span> var_prob = parser.createParam(
|
|
00126 0.9,
|
|
00127 <span class="stringliteral">"var-prob"</span>,
|
|
00128 <span class="stringliteral">"Probability of selecting a var vs. const when creating a terminal"</span>,
|
|
00129 0,
|
|
00130 <span class="stringliteral">"Population"</span>).value();
|
|
00131
|
|
00132
|
|
00133 <span class="keywordtype">double</span> grow_prob = parser.createParam(
|
|
00134 0.5,
|
|
00135 <span class="stringliteral">"grow-prob"</span>,
|
|
00136 <span class="stringliteral">"Probability of selecting 'grow' method instead of 'full' in initialization and mutation"</span>,
|
|
00137 0,
|
|
00138 <span class="stringliteral">"Population"</span>).value();
|
|
00139
|
|
00140 <span class="keywordtype">unsigned</span> max_depth = parser.createParam(
|
|
00141 8u,
|
|
00142 <span class="stringliteral">"max-depth"</span>,
|
|
00143 <span class="stringliteral">"Maximum depth used in initialization and mutation"</span>,
|
|
00144 0,
|
|
00145 <span class="stringliteral">"Population"</span>).value();
|
|
00146
|
|
00147
|
|
00148 <span class="keywordtype">bool</span> use_uniform = parser.createParam(
|
|
00149 <span class="keyword">false</span>,
|
|
00150 <span class="stringliteral">"use-uniform"</span>,
|
|
00151 <span class="stringliteral">"Use uniform node selection instead of bias towards internal nodes (functions)"</span>,
|
|
00152 0,
|
|
00153 <span class="stringliteral">"Population"</span>).value();
|
|
00154
|
|
00155 <span class="keywordtype">double</span> constant_mut_prob = parser.createParam(
|
|
00156 0.1,
|
|
00157 <span class="stringliteral">"constant-mut-rate"</span>,
|
|
00158 <span class="stringliteral">"Probability of performing constant mutation"</span>,
|
|
00159 0,
|
|
00160 <span class="stringliteral">"Population"</span>).value();
|
|
00161
|
|
00162
|
|
00163 <span class="keywordtype">double</span> subtree_mut_prob = parser.createParam(
|
|
00164 0.2,
|
|
00165 <span class="stringliteral">"subtree-mut-rate"</span>,
|
|
00166 <span class="stringliteral">"Probability of performing subtree mutation"</span>,
|
|
00167 0,
|
|
00168 <span class="stringliteral">"Population"</span>).value();
|
|
00169
|
|
00170 <span class="keywordtype">double</span> node_mut_prob = parser.createParam(
|
|
00171 0.2,
|
|
00172 <span class="stringliteral">"node-mut-rate"</span>,
|
|
00173 <span class="stringliteral">"Probability of performing node mutation"</span>,
|
|
00174 0,
|
|
00175 <span class="stringliteral">"Population"</span>).value();
|
|
00176
|
|
00177 <span class="comment">/* double lambda_mut_prob = parser.createParam(</span>
|
|
00178 <span class="comment"> 1.0,</span>
|
|
00179 <span class="comment"> "lambda-mut-rate",</span>
|
|
00180 <span class="comment"> "Probability of performing (neutral) lambda extraction/expansion",</span>
|
|
00181 <span class="comment"> 0,</span>
|
|
00182 <span class="comment"> "Population").value();</span>
|
|
00183 <span class="comment">*/</span>
|
|
00184 <span class="keywordtype">double</span> subtree_xover_prob = parser.createParam(
|
|
00185 0.4,
|
|
00186 <span class="stringliteral">"xover-rate"</span>,
|
|
00187 <span class="stringliteral">"Probability of performing subtree crossover"</span>,
|
|
00188 0,
|
|
00189 <span class="stringliteral">"Population"</span>).value();
|
|
00190
|
|
00191 <span class="keywordtype">double</span> homologous_prob = parser.createParam(
|
|
00192 0.4,
|
|
00193 <span class="stringliteral">"homologous-rate"</span>,
|
|
00194 <span class="stringliteral">"Probability of performing homologous crossover"</span>,
|
|
00195 0,
|
|
00196 <span class="stringliteral">"Population"</span>).value();
|
|
00197
|
|
00198 <span class="keywordtype">unsigned</span> max_gens = parser.createParam(
|
|
00199 50,
|
|
00200 <span class="stringliteral">"max-gens"</span>,
|
|
00201 <span class="stringliteral">"Maximum number of generations to run"</span>,
|
|
00202 <span class="charliteral">'g'</span>,
|
|
00203 <span class="stringliteral">"Population"</span>).value();
|
|
00204
|
|
00205 <span class="keywordtype">unsigned</span> tournamentsize = parser.createParam(
|
|
00206 5,
|
|
00207 <span class="stringliteral">"tournament-size"</span>,
|
|
00208 <span class="stringliteral">"Tournament size used for selection"</span>,
|
|
00209 <span class="charliteral">'t'</span>,
|
|
00210 <span class="stringliteral">"Population"</span>).value();
|
|
00211
|
|
00212 <span class="keywordtype">unsigned</span> maximumSize = parser.createParam(
|
|
00213 -1u,
|
|
00214 <span class="stringliteral">"maximum-size"</span>,
|
|
00215 <span class="stringliteral">"Maximum size after crossover"</span>,
|
|
00216 <span class="charliteral">'s'</span>,
|
|
00217 <span class="stringliteral">"Population"</span>).value();
|
|
00218
|
|
00219 <span class="keywordtype">unsigned</span> meas_param = parser.createParam(
|
|
00220 2u,
|
|
00221 <span class="stringliteral">"measure"</span>,
|
|
00222 <span class="stringliteral">"Error measure:\n\</span>
|
|
00223 <span class="stringliteral"> 0 -> absolute error\n\</span>
|
|
00224 <span class="stringliteral"> 1 -> mean squared error\n\</span>
|
|
00225 <span class="stringliteral"> 2 -> mean squared error scaled (equivalent with correlation)\n\</span>
|
|
00226 <span class="stringliteral"> "</span>,
|
|
00227 <span class="charliteral">'m'</span>,
|
|
00228 <span class="stringliteral">"Regression"</span>).value();
|
|
00229
|
|
00230
|
|
00231 ErrorMeasure::measure meas = ErrorMeasure::mean_squared_scaled;
|
|
00232 <span class="keywordflow">if</span> (meas_param == 0) meas = ErrorMeasure::absolute;
|
|
00233 <span class="keywordflow">if</span> (meas_param == 1) meas = ErrorMeasure::mean_squared;
|
|
00234
|
|
00235
|
|
00236 <span class="comment">/* End parsing */</span>
|
|
00237 <span class="keywordflow">if</span> (parser.userNeedsHelp())
|
|
00238 {
|
|
00239 parser.printHelp(std::cout);
|
|
00240 <span class="keywordflow">return</span> 1;
|
|
00241 }
|
|
00242
|
|
00243 <span class="keywordflow">if</span> (functions_added == 0) {
|
|
00244 cout << <span class="stringliteral">"ERROR: no functions defined"</span> << endl;
|
|
00245 exit(1);
|
|
00246 }
|
|
00247
|
|
00248
|
|
00249 Dataset dataset;
|
|
00250 dataset.load_data(datafile.<a class="code" href="classeo_value_param.html#a2">value</a>());
|
|
00251
|
|
00252 cout << <span class="stringliteral">"Data "</span> << datafile.<a class="code" href="classeo_value_param.html#a2">value</a>() << <span class="stringliteral">" loaded "</span> << endl;
|
|
00253
|
|
00254 <span class="comment">/* Add Variables */</span>
|
|
00255 <span class="keywordtype">unsigned</span> nvars = dataset.n_fields();
|
|
00256 <span class="keywordflow">for</span> (<span class="keywordtype">unsigned</span> i = 0; i < nvars; ++i) {
|
|
00257 table.add_function( SymVar(i).token(), 0);
|
|
00258 }
|
|
00259
|
|
00260 TreeBuilder builder(table, var_prob);
|
|
00261 <a class="code" href="classeo_sym_init.html">eoSymInit<EoType></a> init(builder, grow_prob, max_depth);
|
|
00262
|
|
00263 <a class="code" href="classeo_pop.html">eoPop<EoType></a> pop(pop_size, init);
|
|
00264
|
|
00265 <a class="code" href="class_biased_node_selector.html">BiasedNodeSelector</a> biased_sel;
|
|
00266 <a class="code" href="class_random_node_selector.html">RandomNodeSelector</a> random_sel;
|
|
00267
|
|
00268 <a class="code" href="class_node_selector.html">NodeSelector</a>& node_selector = select<NodeSelector>(use_uniform, random_sel, biased_sel);
|
|
00269
|
|
00270 <span class="comment">//eoProportionalOp<EoType> genetic_operator;</span>
|
|
00271 <a class="code" href="classeo_sequential_op.html">eoSequentialOp<EoType></a> genetic_operator;
|
|
00272
|
|
00273 eoSymSubtreeMutate<EoType> submutate(builder, node_selector);
|
|
00274 genetic_operator.<a class="code" href="classeo_op_container.html#a3">add</a>( submutate, subtree_mut_prob);
|
|
00275
|
|
00276 <span class="comment">// todo, make this parameter, etc</span>
|
|
00277 <span class="keywordtype">double</span> std = 0.01;
|
|
00278 eoSymConstantMutate<EoType> constmutate(std);
|
|
00279 genetic_operator.<a class="code" href="classeo_op_container.html#a3">add</a>(constmutate, constant_mut_prob);
|
|
00280
|
|
00281 eoSymNodeMutate<EoType> nodemutate(table);
|
|
00282 genetic_operator.<a class="code" href="classeo_op_container.html#a3">add</a>(nodemutate, node_mut_prob);
|
|
00283
|
|
00284 <span class="comment">// eoSymLambdaMutate<EoType> lambda_mutate(node_selector);</span>
|
|
00285 <span class="comment">// genetic_operator.add(lambda_mutate, lambda_mut_prob); // TODO: prob should be settable</span>
|
|
00286
|
|
00287 <span class="comment">//eoQuadSubtreeCrossover<EoType> quad(node_selector);</span>
|
|
00288 eoBinSubtreeCrossover<EoType> bin(node_selector);
|
|
00289 genetic_operator.<a class="code" href="classeo_op_container.html#a3">add</a>(bin, subtree_xover_prob);
|
|
00290
|
|
00291 eoBinHomologousCrossover<EoType> hom;
|
|
00292 genetic_operator.<a class="code" href="classeo_op_container.html#a3">add</a>(hom, homologous_prob);
|
|
00293
|
|
00294
|
|
00295 IntervalBoundsCheck check(dataset.input_minima(), dataset.input_maxima());
|
|
00296 ErrorMeasure measure(dataset, train_percentage, meas);
|
|
00297
|
|
00298 eoSymPopEval<EoType> evaluator(check, measure, maximumSize);
|
|
00299
|
|
00300 <a class="code" href="classeo_det_tournament_select.html">eoDetTournamentSelect<EoType></a> selectOne(tournamentsize);
|
|
00301 <a class="code" href="classeo_general_breeder.html">eoGeneralBreeder<EoType></a> breeder(selectOne, genetic_operator);
|
|
00302 <a class="code" href="classeo_plus_replacement.html">eoPlusReplacement<EoType></a> replace;
|
|
00303
|
|
00304 <span class="comment">// Terminators</span>
|
|
00305 <a class="code" href="classeo_gen_continue.html">eoGenContinue<EoType></a> term(max_gens);
|
|
00306 <a class="code" href="classeo_check_point.html">eoCheckPoint<EoType></a> checkpoint(term);
|
|
00307
|
|
00308 <a class="code" href="classeo_best_fitness_stat.html">eoBestFitnessStat<EoType></a> beststat;
|
|
00309 checkpoint.<a class="code" href="classeo_op_container.html#a3">add</a>(beststat);
|
|
00310
|
|
00311 eoBestIndividualStat printer;
|
|
00312 AverageSizeStat avgSize;
|
|
00313 DagSizeStat dagSize;
|
|
00314 SumSizeStat sumSize;
|
|
00315
|
|
00316 checkpoint.<a class="code" href="classeo_op_container.html#a3">add</a>(printer);
|
|
00317 checkpoint.<a class="code" href="classeo_op_container.html#a3">add</a>(avgSize);
|
|
00318 checkpoint.<a class="code" href="classeo_op_container.html#a3">add</a>(dagSize);
|
|
00319 checkpoint.<a class="code" href="classeo_op_container.html#a3">add</a>(sumSize);
|
|
00320
|
|
00321 <a class="code" href="classeo_stdout_monitor.html">eoStdoutMonitor</a> genmon;
|
|
00322 genmon.<a class="code" href="classeo_monitor.html#a1">add</a>(beststat);
|
|
00323 genmon.<a class="code" href="classeo_monitor.html#a1">add</a>(printer);
|
|
00324 genmon.<a class="code" href="classeo_monitor.html#a1">add</a>(avgSize);
|
|
00325 genmon.<a class="code" href="classeo_monitor.html#a1">add</a>(dagSize);
|
|
00326 genmon.<a class="code" href="classeo_monitor.html#a1">add</a>(sumSize);
|
|
00327 genmon.<a class="code" href="classeo_monitor.html#a1">add</a>(term); <span class="comment">// add generation counter</span>
|
|
00328
|
|
00329 checkpoint.<a class="code" href="classeo_monitor.html#a1">add</a>(genmon);
|
|
00330
|
|
00331 <a class="code" href="classeo_pop.html">eoPop<EoType></a> dummy;
|
|
00332 evaluator(pop, dummy);
|
|
00333
|
|
00334 <a class="code" href="classeo_easy_e_a.html">eoEasyEA<EoType></a> ea(checkpoint, evaluator, breeder, replace);
|
|
00335
|
|
00336 ea(pop); <span class="comment">// run</span>
|
|
00337
|
|
00338 }
|
|
00339
|
|
00340 <span class="keywordtype">void</span> add_function(LanguageTable& table, eoParser& parser, string name, <span class="keywordtype">unsigned</span> arity, token_t token, <span class="keyword">const</span> FunDef& fun, <span class="keywordtype">bool</span> all) {
|
|
00341 ostringstream desc;
|
|
00342 desc << <span class="stringliteral">"Enable function "</span> << name << <span class="stringliteral">" arity = "</span> << arity;
|
|
00343 <span class="keywordtype">bool</span> enabled = parser.createParam(<span class="keyword">false</span>, name, desc.str(), 0, <span class="stringliteral">"Language"</span>).value();
|
|
00344
|
|
00345 <span class="keywordflow">if</span> (enabled || all) {
|
|
00346 cout << <span class="stringliteral">"Func "</span> << name << <span class="stringliteral">" enabled"</span> << endl;
|
|
00347 table.add_function(token, arity);
|
|
00348 <span class="keywordflow">if</span> (arity > 0) functions_added++;
|
|
00349 }
|
|
00350 }
|
|
00351
|
|
00352 <span class="keywordtype">void</span> setup_language(LanguageTable& table, eoParser& parser) {
|
|
00353
|
|
00354 <span class="keywordtype">bool</span> all = parser.createParam(<span class="keyword">false</span>,<span class="stringliteral">"all"</span>, <span class="stringliteral">"Enable all functions"</span>).value();
|
|
00355 <span class="keywordtype">bool</span> ratio = parser.createParam(<span class="keyword">false</span>,<span class="stringliteral">"ratio"</span>,<span class="stringliteral">"Enable rational functions (inv,min,sum,prod)"</span>).value();
|
|
00356 <span class="keywordtype">bool</span> poly = parser.createParam(<span class="keyword">false</span>,<span class="stringliteral">"poly"</span>,<span class="stringliteral">"Enable polynomial functions (min,sum,prod)"</span>).value();
|
|
00357
|
|
00358 <span class="comment">// assumes that at this point all tokens are defined (none are zeroed out, which can happen with ERCs)</span>
|
|
00359 vector<const FunDef*> lang = get_defined_functions();
|
|
00360
|
|
00361 <span class="keywordflow">for</span> (token_t i = 0; i < lang.size(); ++i) {
|
|
00362
|
|
00363 <span class="keywordflow">if</span> (lang[i] == 0) <span class="keywordflow">continue</span>;
|
|
00364
|
|
00365 <span class="keywordtype">bool</span> is_poly = <span class="keyword">false</span>;
|
|
00366 <span class="keywordflow">if</span> (poly && (i == prod_token || i == sum_token || i == min_token) ) {
|
|
00367 is_poly = <span class="keyword">true</span>;
|
|
00368 }
|
|
00369
|
|
00370 <span class="keywordtype">bool</span> is_ratio = <span class="keyword">false</span>;
|
|
00371 <span class="keywordflow">if</span> (ratio && (is_poly || i == inv_token)) {
|
|
00372 is_ratio = <span class="keyword">true</span>;
|
|
00373 }
|
|
00374
|
|
00375 <span class="keyword">const</span> FunDef& fun = *lang[i];
|
|
00376
|
|
00377 <span class="keywordflow">if</span> (fun.has_varargs() ) {
|
|
00378
|
|
00379 <span class="keywordflow">for</span> (<span class="keywordtype">unsigned</span> j = fun.min_arity(); j < fun.min_arity() + 8; ++j) {
|
|
00380 <span class="keywordflow">if</span> (j==1) <span class="keywordflow">continue</span>; <span class="comment">// prod 1 and sum 1 are useless</span>
|
|
00381 ostringstream nm;
|
|
00382 nm << fun.name() << j;
|
|
00383 <span class="keywordtype">bool</span> addanyway = (all || is_ratio || is_poly) && j == 2;
|
|
00384 add_function(table, parser, nm.str(), j, i, fun, addanyway);
|
|
00385 }
|
|
00386 }
|
|
00387 <span class="keywordflow">else</span> {
|
|
00388 add_function(table, parser, fun.name(), fun.min_arity(), i, fun, all || is_ratio || is_poly);
|
|
00389 }
|
|
00390 }
|
|
00391 }
|
|
00392
|
|
00393
|
|
</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>
|