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
153
trunk/paradiseo-eo/doc/html/mastermind_8cpp-source.html
Normal file
153
trunk/paradiseo-eo/doc/html/mastermind_8cpp-source.html
Normal file
|
|
@ -0,0 +1,153 @@
|
|||
<!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: mastermind.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_000020.html">app</a> / <a class="el" href="dir_000027.html">mastermind</a></div>
|
||||
<h1>mastermind.cpp</h1><div class="fragment"><pre class="fragment">00001 <span class="comment">//-----------------------------------------------------------------------------</span>
|
||||
00002 <span class="comment">// mastermind</span>
|
||||
00003 <span class="comment">//-----------------------------------------------------------------------------</span>
|
||||
00004
|
||||
00005 <span class="preprocessor">#include <stdlib.h></span> <span class="comment">// EXIT_SUCCESS EXIT_FAILURE</span>
|
||||
00006 <span class="preprocessor">#include <stdexcept></span> <span class="comment">// exception</span>
|
||||
00007 <span class="preprocessor">#include <iostream></span> <span class="comment">// cerr cout</span>
|
||||
00008 <span class="preprocessor">#include <fstream></span> <span class="comment">// ifstream</span>
|
||||
00009 <span class="preprocessor">#include <string></span> <span class="comment">// string</span>
|
||||
00010 <span class="preprocessor">#include <eo></span> <span class="comment">// all usefull eo stuff</span>
|
||||
00011
|
||||
00012 <span class="preprocessor">#include "mastermind.h"</span> <span class="comment">// Chrom eoChromInit eoChromMutation eoChromXover eoChromEvaluator</span>
|
||||
00013
|
||||
00014 <span class="keyword">using</span> <span class="keyword">namespace </span>std;
|
||||
00015
|
||||
00016 <span class="comment">//-----------------------------------------------------------------------------</span>
|
||||
00017 <span class="comment">// global variables</span>
|
||||
00018 <span class="comment">//-----------------------------------------------------------------------------</span>
|
||||
00019
|
||||
00020 <span class="keywordtype">unsigned</span> in, out, hidden;
|
||||
00021
|
||||
00022 <span class="comment">//-----------------------------------------------------------------------------</span>
|
||||
00023 <span class="comment">// parameters</span>
|
||||
00024 <span class="comment">//-----------------------------------------------------------------------------</span>
|
||||
00025
|
||||
00026 <a class="code" href="classeo_value_param.html">eoValueParam<unsigned></a> pop_size(16, <span class="stringliteral">"pop_size"</span>, <span class="stringliteral">"population size"</span>, <span class="charliteral">'p'</span>);
|
||||
00027 <a class="code" href="classeo_value_param.html">eoValueParam<unsigned></a> generations(100, <span class="stringliteral">"generations"</span>, <span class="stringliteral">"number of generation"</span>, <span class="charliteral">'g'</span>);
|
||||
00028 <a class="code" href="classeo_value_param.html">eoValueParam<double></a> mut_rate(0.1, <span class="stringliteral">"mut_rate"</span>, <span class="stringliteral">"mutation rate"</span>, <span class="charliteral">'m'</span>);
|
||||
00029 <a class="code" href="classeo_value_param.html">eoValueParam<double></a> xover_rate(0.5, <span class="stringliteral">"xover_rate"</span>, <span class="stringliteral">"default crossover rate"</span>, <span class="charliteral">'x'</span>);
|
||||
00030 <a class="code" href="classeo_value_param.html">eoValueParam<unsigned></a> col_p(default_colors, <span class="stringliteral">"colors"</span>, <span class="stringliteral">"number of colors"</span>, <span class="charliteral">'c'</span>);
|
||||
00031 <a class="code" href="classeo_value_param.html">eoValueParam<unsigned></a> len_p(default_length, <span class="stringliteral">"legth"</span>, <span class="stringliteral">"solution legth"</span>, <span class="charliteral">'l'</span>);
|
||||
00032 <a class="code" href="classeo_value_param.html">eoValueParam<string></a> sol_p(default_solution, <span class="stringliteral">"solution"</span>, <span class="stringliteral">"problem solution"</span>, <span class="charliteral">'s'</span>);
|
||||
00033
|
||||
00034 <span class="comment">//-----------------------------------------------------------------------------</span>
|
||||
00035 <span class="comment">// auxiliar functions</span>
|
||||
00036 <span class="comment">//-----------------------------------------------------------------------------</span>
|
||||
00037
|
||||
00038 <span class="keywordtype">void</span> arg(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span>** argv);
|
||||
00039 <span class="keywordtype">void</span> ga();
|
||||
00040
|
||||
00041 <span class="comment">//-----------------------------------------------------------------------------</span>
|
||||
00042 <span class="comment">// main</span>
|
||||
00043 <span class="comment">//-----------------------------------------------------------------------------</span>
|
||||
00044
|
||||
00045 <span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span>** argv)
|
||||
00046 {
|
||||
00047 <span class="keywordflow">try</span>
|
||||
00048 {
|
||||
00049 arg(argc, argv);
|
||||
00050 ga();
|
||||
00051 }
|
||||
00052 <span class="keywordflow">catch</span> (exception& e)
|
||||
00053 {
|
||||
00054 cerr << argv[0] << <span class="stringliteral">": "</span> << e.what() << endl;
|
||||
00055 exit(EXIT_FAILURE);
|
||||
00056 }
|
||||
00057
|
||||
00058 <span class="keywordflow">return</span> 0;
|
||||
00059 }
|
||||
00060
|
||||
00061 <span class="comment">//-----------------------------------------------------------------------------</span>
|
||||
00062 <span class="comment">// implementation</span>
|
||||
00063 <span class="comment">//-----------------------------------------------------------------------------</span>
|
||||
00064
|
||||
00065 <span class="keywordtype">void</span> arg(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span>** argv)
|
||||
00066 {
|
||||
00067 eoParser parser(argc, argv);
|
||||
00068
|
||||
00069 parser.processParam(pop_size, <span class="stringliteral">"genetic operators"</span>);
|
||||
00070 parser.processParam(generations, <span class="stringliteral">"genetic operators"</span>);
|
||||
00071 parser.processParam(mut_rate, <span class="stringliteral">"genetic operators"</span>);
|
||||
00072 parser.processParam(xover_rate, <span class="stringliteral">"genetic operators"</span>);
|
||||
00073 parser.processParam(col_p, <span class="stringliteral">"problem"</span>);
|
||||
00074 parser.processParam(len_p, <span class="stringliteral">"problem"</span>);
|
||||
00075 parser.processParam(sol_p, <span class="stringliteral">"problem"</span>);
|
||||
00076
|
||||
00077 <span class="keywordflow">if</span> (parser.userNeedsHelp())
|
||||
00078 {
|
||||
00079 parser.printHelp(cout);
|
||||
00080 exit(EXIT_SUCCESS);
|
||||
00081 }
|
||||
00082
|
||||
00083 init_eoChromEvaluator(col_p.<a class="code" href="classeo_value_param.html#a2">value</a>(), len_p.<a class="code" href="classeo_value_param.html#a2">value</a>(), sol_p.<a class="code" href="classeo_value_param.html#a2">value</a>());
|
||||
00084 }
|
||||
00085
|
||||
00086 <span class="comment">//-----------------------------------------------------------------------------</span>
|
||||
00087
|
||||
00088 <span class="keywordtype">void</span> ga()
|
||||
00089 {
|
||||
00090 <span class="comment">// create population</span>
|
||||
00091 eoInitChrom init;
|
||||
00092 <a class="code" href="classeo_pop.html">eoPop<Chrom></a> pop(pop_size.<a class="code" href="classeo_value_param.html#a2">value</a>(), init);
|
||||
00093
|
||||
00094 <span class="comment">// evaluate population</span>
|
||||
00095 <a class="code" href="structeo_eval_func_ptr.html">eoEvalFuncPtr<Chrom></a> evaluator(eoChromEvaluator);
|
||||
00096 apply<Chrom>(evaluator, pop);
|
||||
00097
|
||||
00098 <span class="comment">// selector</span>
|
||||
00099 <a class="code" href="classeo_proportional_select.html">eoProportionalSelect<Chrom></a> select(pop);
|
||||
00100
|
||||
00101 <span class="comment">// genetic operators</span>
|
||||
00102 eoChromMutation mutation;
|
||||
00103 eoChromXover xover;
|
||||
00104
|
||||
00105 <span class="comment">// stop condition</span>
|
||||
00106 <a class="code" href="classeo_gen_continue.html">eoGenContinue<Chrom></a> continuator1(generations.<a class="code" href="classeo_value_param.html#a2">value</a>());
|
||||
00107 <a class="code" href="classeo_fit_continue.html">eoFitContinue<Chrom></a> continuator2(solution.fitness());
|
||||
00108 <a class="code" href="classeo_combined_continue.html">eoCombinedContinue<Chrom></a> continuator(continuator1, continuator2);
|
||||
00109
|
||||
00110 <span class="comment">// checkpoint</span>
|
||||
00111 <a class="code" href="classeo_check_point.html">eoCheckPoint<Chrom></a> checkpoint(continuator);
|
||||
00112
|
||||
00113 <span class="comment">// monitor</span>
|
||||
00114 <a class="code" href="classeo_stdout_monitor.html">eoStdoutMonitor</a> monitor;
|
||||
00115 checkpoint.add(monitor);
|
||||
00116
|
||||
00117 <span class="comment">// statistics</span>
|
||||
00118 <a class="code" href="classeo_best_fitness_stat.html">eoBestFitnessStat<Chrom></a> stats;
|
||||
00119 checkpoint.add(stats);
|
||||
00120 monitor.<a class="code" href="classeo_monitor.html#a1">add</a>(stats);
|
||||
00121
|
||||
00122 <span class="comment">// genetic algorithm</span>
|
||||
00123 <a class="code" href="classeo_s_g_a.html">eoSGA<Chrom></a> sga(select,
|
||||
00124 xover, xover_rate.<a class="code" href="classeo_value_param.html#a2">value</a>(),
|
||||
00125 mutation, mut_rate.<a class="code" href="classeo_value_param.html#a2">value</a>(),
|
||||
00126 evaluator,
|
||||
00127 checkpoint);
|
||||
00128 sga(pop);
|
||||
00129
|
||||
00130 cout << <span class="stringliteral">"solution = "</span> << solution << endl
|
||||
00131 << <span class="stringliteral">"best = "</span> << *max_element(pop.begin(), pop.end()) << endl;
|
||||
00132 }
|
||||
00133
|
||||
00134 <span class="comment">//-----------------------------------------------------------------------------</span>
|
||||
00135
|
||||
00136 <span class="comment">// Local Variables:</span>
|
||||
00137 <span class="comment">// mode:C++</span>
|
||||
00138 <span class="comment">// End:</span>
|
||||
</pre></div><hr size="1"><address style="align: right;"><small>Generated on Thu Oct 19 05:06:41 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