paradiseo/trunk/paradiseo-moeo/doc/html/Sch1_8cpp-source.html
legrand 04b12455d0 added good doc files
git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@683 331e1502-861f-0410-8da2-ba01fb791d7f
2007-10-08 14:49:10 +00:00

135 lines
11 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>ParadisEO-MOEOMovingObjects: Sch1.cpp Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
<link href="tabs.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.4.7 -->
<div class="tabs">
<ul>
<li><a href="main.html"><span>Main&nbsp;Page</span></a></li>
<li><a href="classes.html"><span>Classes</span></a></li>
<li id="current"><a href="files.html"><span>Files</span></a></li>
<li>
<form action="search.php" method="get">
<table cellspacing="0" cellpadding="0" border="0">
<tr>
<td><label>&nbsp;<u>S</u>earch&nbsp;for&nbsp;</label></td>
<td><input type="text" name="query" value="" size="20" accesskey="s"/></td>
</tr>
</table>
</form>
</li>
</ul></div>
<h1>Sch1.cpp</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-</span>
<a name="l00002"></a>00002
<a name="l00003"></a>00003 <span class="comment">//-----------------------------------------------------------------------------</span>
<a name="l00004"></a>00004 <span class="comment">// Sch1.cpp</span>
<a name="l00005"></a>00005 <span class="comment">// (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007</span>
<a name="l00006"></a>00006 <span class="comment">/*</span>
<a name="l00007"></a>00007 <span class="comment"> This library...</span>
<a name="l00008"></a>00008 <span class="comment"></span>
<a name="l00009"></a>00009 <span class="comment"> Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr</span>
<a name="l00010"></a>00010 <span class="comment"> */</span>
<a name="l00011"></a>00011 <span class="comment">//-----------------------------------------------------------------------------</span>
<a name="l00012"></a>00012
<a name="l00013"></a>00013 <span class="preprocessor">#include &lt;stdio.h&gt;</span>
<a name="l00014"></a>00014 <span class="preprocessor">#include &lt;moeo&gt;</span>
<a name="l00015"></a>00015 <span class="preprocessor">#include &lt;es/eoRealInitBounded.h&gt;</span>
<a name="l00016"></a>00016 <span class="preprocessor">#include &lt;es/eoRealOp.h&gt;</span>
<a name="l00017"></a>00017
<a name="l00018"></a>00018 <span class="keyword">using namespace </span>std;
<a name="l00019"></a>00019
<a name="l00020"></a>00020 <span class="comment">// the moeoObjectiveVectorTraits : minimizing 2 objectives</span>
<a name="l00021"></a><a class="code" href="classSch1ObjectiveVectorTraits.html">00021</a> <span class="keyword">class </span><a class="code" href="classSch1ObjectiveVectorTraits.html">Sch1ObjectiveVectorTraits</a> : <span class="keyword">public</span> <a class="code" href="classmoeoObjectiveVectorTraits.html">moeoObjectiveVectorTraits</a>
<a name="l00022"></a>00022 {
<a name="l00023"></a>00023 <span class="keyword">public</span>:
<a name="l00024"></a><a class="code" href="classSch1ObjectiveVectorTraits.html#455ac35e419ad21c0a4ba4bbd2768ca5">00024</a> <span class="keyword">static</span> <span class="keywordtype">bool</span> <a class="code" href="classSch1ObjectiveVectorTraits.html#455ac35e419ad21c0a4ba4bbd2768ca5">minimizing</a> (<span class="keywordtype">int</span> i)
<a name="l00025"></a>00025 {
<a name="l00026"></a>00026 <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00027"></a>00027 }
<a name="l00028"></a><a class="code" href="classSch1ObjectiveVectorTraits.html#a7de212f3346dde550757e8a412baa4d">00028</a> <span class="keyword">static</span> <span class="keywordtype">bool</span> <a class="code" href="classSch1ObjectiveVectorTraits.html#a7de212f3346dde550757e8a412baa4d">maximizing</a> (<span class="keywordtype">int</span> i)
<a name="l00029"></a>00029 {
<a name="l00030"></a>00030 <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00031"></a>00031 }
<a name="l00032"></a><a class="code" href="classSch1ObjectiveVectorTraits.html#54ae04aa8eb052223778ecae175be95b">00032</a> <span class="keyword">static</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="classSch1ObjectiveVectorTraits.html#54ae04aa8eb052223778ecae175be95b">nObjectives</a> ()
<a name="l00033"></a>00033 {
<a name="l00034"></a>00034 <span class="keywordflow">return</span> 2;
<a name="l00035"></a>00035 }
<a name="l00036"></a>00036 };
<a name="l00037"></a>00037
<a name="l00038"></a>00038
<a name="l00039"></a>00039 <span class="comment">// objective vector of real values</span>
<a name="l00040"></a>00040 <span class="keyword">typedef</span> moeoRealObjectiveVector &lt; Sch1ObjectiveVectorTraits &gt; <a class="code" href="classmoeoRealObjectiveVector.html">Sch1ObjectiveVector</a>;
<a name="l00041"></a>00041
<a name="l00042"></a>00042
<a name="l00043"></a>00043 <span class="comment">// multi-objective evolving object for the Sch1 problem</span>
<a name="l00044"></a><a class="code" href="classSch1.html">00044</a> <span class="keyword">class </span><a class="code" href="classSch1.html">Sch1</a> : <span class="keyword">public</span> <a class="code" href="classmoeoRealVector.html">moeoRealVector</a> &lt; Sch1ObjectiveVector, double, double &gt;
<a name="l00045"></a>00045 {
<a name="l00046"></a>00046 <span class="keyword">public</span>:
<a name="l00047"></a><a class="code" href="classSch1.html#3ddc72f40539bfe0d5bb8d977b6655c0">00047</a> <a class="code" href="classSch1.html#3ddc72f40539bfe0d5bb8d977b6655c0">Sch1</a>() : <a class="code" href="classmoeoRealVector.html">moeoRealVector</a> &lt; <a class="code" href="classmoeoRealObjectiveVector.html">Sch1ObjectiveVector</a>, double, double &gt; (1) {}
<a name="l00048"></a>00048 };
<a name="l00049"></a>00049
<a name="l00050"></a>00050
<a name="l00051"></a>00051 <span class="comment">// evaluation of objective functions</span>
<a name="l00052"></a><a class="code" href="classSch1Eval.html">00052</a> <span class="keyword">class </span><a class="code" href="classSch1Eval.html">Sch1Eval</a> : <span class="keyword">public</span> <a class="code" href="classmoeoEvalFunc.html">moeoEvalFunc</a> &lt; Sch1 &gt;
<a name="l00053"></a>00053 {
<a name="l00054"></a>00054 <span class="keyword">public</span>:
<a name="l00055"></a><a class="code" href="classSch1Eval.html#4f806a964f7bafa9e4fcca45da458c98">00055</a> <span class="keywordtype">void</span> <a class="code" href="classSch1Eval.html#4f806a964f7bafa9e4fcca45da458c98">operator () </a>(<a class="code" href="classSch1.html">Sch1</a> &amp; _sch1)
<a name="l00056"></a>00056 {
<a name="l00057"></a>00057 <span class="keywordflow">if</span> (_sch1.<a class="code" href="classMOEO.html#c8e93beabdab8c2f79f17c7e39efdd05">invalidObjectiveVector</a>())
<a name="l00058"></a>00058 {
<a name="l00059"></a>00059 <a class="code" href="classmoeoRealObjectiveVector.html">Sch1ObjectiveVector</a> objVec;
<a name="l00060"></a>00060 <span class="keywordtype">double</span> x = _sch1[0];
<a name="l00061"></a>00061 objVec[0] = x * x;
<a name="l00062"></a>00062 objVec[1] = (x - 2.0) * (x - 2.0);
<a name="l00063"></a>00063 _sch1.<a class="code" href="classMOEO.html#7509143b0f18644e7d3183a039cece7b">objectiveVector</a>(objVec);
<a name="l00064"></a>00064 }
<a name="l00065"></a>00065 }
<a name="l00066"></a>00066 };
<a name="l00067"></a>00067
<a name="l00068"></a>00068
<a name="l00069"></a>00069 <span class="comment">// main</span>
<a name="l00070"></a>00070 <span class="keywordtype">int</span> main (<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span> *argv[])
<a name="l00071"></a>00071 {
<a name="l00072"></a>00072 <span class="comment">// parameters</span>
<a name="l00073"></a>00073 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> POP_SIZE = 20;
<a name="l00074"></a>00074 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> MAX_GEN = 100;
<a name="l00075"></a>00075 <span class="keywordtype">double</span> M_EPSILON = 0.01;
<a name="l00076"></a>00076 <span class="keywordtype">double</span> P_CROSS = 0.25;
<a name="l00077"></a>00077 <span class="keywordtype">double</span> P_MUT = 0.35;
<a name="l00078"></a>00078
<a name="l00079"></a>00079 <span class="comment">// objective functions evaluation</span>
<a name="l00080"></a>00080 <a class="code" href="classSch1Eval.html">Sch1Eval</a> eval;
<a name="l00081"></a>00081
<a name="l00082"></a>00082 <span class="comment">// crossover and mutation</span>
<a name="l00083"></a>00083 eoQuadCloneOp &lt; Sch1 &gt; xover;
<a name="l00084"></a>00084 eoUniformMutation &lt; Sch1 &gt; mutation (M_EPSILON);
<a name="l00085"></a>00085
<a name="l00086"></a>00086 <span class="comment">// generate initial population</span>
<a name="l00087"></a>00087 <a class="codeRef" doxygen="eo.doxytag:http://eodev.sourceforge.net/eo/doc/html/" href="http://eodev.sourceforge.net/eo/doc/html/classeo_real_vector_bounds.html">eoRealVectorBounds</a> bounds (1, 0.0, 2.0); <span class="comment">// [0, 2]</span>
<a name="l00088"></a>00088 eoRealInitBounded &lt; Sch1 &gt; init (bounds);
<a name="l00089"></a>00089 eoPop &lt; Sch1 &gt; pop (POP_SIZE, init);
<a name="l00090"></a>00090
<a name="l00091"></a>00091 <span class="comment">// build NSGA-II</span>
<a name="l00092"></a>00092 moeoNSGAII &lt; Sch1 &gt; nsgaII (MAX_GEN, eval, xover, P_CROSS, mutation, P_MUT);
<a name="l00093"></a>00093
<a name="l00094"></a>00094 <span class="comment">// run the algo</span>
<a name="l00095"></a>00095 nsgaII (pop);
<a name="l00096"></a>00096
<a name="l00097"></a>00097 <span class="comment">// extract first front of the final population using an moeoArchive (this is the output of nsgaII)</span>
<a name="l00098"></a>00098 moeoArchive &lt; Sch1 &gt; arch;
<a name="l00099"></a>00099 arch.<a class="code" href="classmoeoArchive.html#6df0acd84cab4cb53682f2e6ca850e9a">update</a> (pop);
<a name="l00100"></a>00100
<a name="l00101"></a>00101 <span class="comment">// printing of the final archive</span>
<a name="l00102"></a>00102 cout &lt;&lt; <span class="stringliteral">"Final Archive"</span> &lt;&lt; endl;
<a name="l00103"></a>00103 arch.<a class="codeRef" doxygen="eo.doxytag:http://eodev.sourceforge.net/eo/doc/html/" href="http://eodev.sourceforge.net/eo/doc/html/classeo_pop.html#b6572898562eebe5bab105c4475a9a64">sortedPrintOn</a> (cout);
<a name="l00104"></a>00104 cout &lt;&lt; endl;
<a name="l00105"></a>00105
<a name="l00106"></a>00106 <span class="keywordflow">return</span> EXIT_SUCCESS;
<a name="l00107"></a>00107 }
</pre></div><hr size="1"><address style="align: right;"><small>Generated on Mon Oct 8 10:35:52 2007 for ParadisEO-MOEOMovingObjects by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.7 </small></address>
</body>
</html>