git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@40 331e1502-861f-0410-8da2-ba01fb791d7f
207 lines
10 KiB
HTML
207 lines
10 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: t-eoParetoFitness.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-eoParetoFitness.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
|
|
00003 <span class="comment">//-----------------------------------------------------------------------------</span>
|
|
00004 <span class="comment">// t-eoParetoFitness.cpp</span>
|
|
00005 <span class="comment">// (c) Maarten Keijzer</span>
|
|
00006 <span class="comment">/*</span>
|
|
00007 <span class="comment"> This library is free software; you can redistribute it and/or</span>
|
|
00008 <span class="comment"> modify it under the terms of the GNU Lesser General Public</span>
|
|
00009 <span class="comment"> License as published by the Free Software Foundation; either</span>
|
|
00010 <span class="comment"> version 2 of the License, or (at your option) any later version.</span>
|
|
00011 <span class="comment"></span>
|
|
00012 <span class="comment"> This library 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 GNU</span>
|
|
00015 <span class="comment"> Lesser 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 Lesser General Public</span>
|
|
00018 <span class="comment"> License along with this library; 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: mak@dhi.dk</span>
|
|
00022 <span class="comment"></span>
|
|
00023 <span class="comment">30/01/02 - MS - Added the eoVariableParetoTraits - and the compare Fn</span>
|
|
00024 <span class="comment"> */</span>
|
|
00025 <span class="comment">//-----------------------------------------------------------------------------</span>
|
|
00026
|
|
00027 <span class="preprocessor">#include <cassert></span>
|
|
00028 <span class="preprocessor">#include <iostream></span>
|
|
00029
|
|
00030 <span class="preprocessor">#include "eoParetoFitness.h"</span>
|
|
00031
|
|
00032 <span class="keyword">using</span> <span class="keyword">namespace </span>std;
|
|
00033
|
|
<a name="l00036"></a><a class="code" href="class_minimizing_traits.html">00036</a> <span class="keyword">class </span><a class="code" href="class_minimizing_traits.html">MinimizingTraits</a> : <span class="keyword">public</span> <a class="code" href="classeo_pareto_fitness_traits.html">eoParetoFitnessTraits</a>
|
|
00037 {
|
|
00038 <span class="keyword">public</span> :
|
|
00039
|
|
00040 <span class="keyword">static</span> <span class="keywordtype">bool</span> maximizing(<span class="keywordtype">int</span>) { <span class="keywordflow">return</span> <span class="keyword">false</span>; }
|
|
00041 };
|
|
00042
|
|
00043 <span class="keyword">template</span> <<span class="keyword">class</span> F>
|
|
00044 <span class="keywordtype">void</span> compare(F & _eo1, F & _eo2)
|
|
00045 {
|
|
00046 <span class="keywordflow">if</span> (_eo1.dominates(_eo2))
|
|
00047 std::cout << _eo1 << <span class="stringliteral">" dominates "</span> << _eo2 << std::endl;
|
|
00048 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (_eo2.dominates(_eo1))
|
|
00049 std::cout << _eo2 << <span class="stringliteral">" dominates "</span> << _eo1 << std::endl;
|
|
00050 <span class="keywordflow">else</span>
|
|
00051 std::cout << <span class="stringliteral">"None of "</span> << _eo1 << <span class="stringliteral">" and "</span> << _eo2 << <span class="stringliteral">"dominates the other"</span> << std::endl;
|
|
00052 <span class="keywordflow">return</span>;
|
|
00053 }
|
|
00054
|
|
00055 <span class="keywordtype">int</span> main()
|
|
00056 {
|
|
00057 <span class="keyword">typedef</span> <a class="code" href="classeo_pareto_fitness.html">eoParetoFitness<></a> MaxFitness;
|
|
00058 <span class="keyword">typedef</span> <a class="code" href="classeo_pareto_fitness.html">eoParetoFitness<MinimizingTraits></a> MinFitness;
|
|
00059
|
|
00060 <span class="keyword">typedef</span> <a class="code" href="classeo_pareto_fitness.html">eoParetoFitness<eoVariableParetoTraits></a> VarFitness;
|
|
00061
|
|
00062 <span class="keywordflow">try</span>{
|
|
00063
|
|
00064 MaxFitness f0;
|
|
00065 f0[0] = 0.0;
|
|
00066 f0[1] = 1.0;
|
|
00067
|
|
00068 MaxFitness f1;
|
|
00069 f1[0] = 1.0;
|
|
00070 f1[1] = 0.0;
|
|
00071
|
|
00072 MaxFitness f2;
|
|
00073 f2[0] = 0.0;
|
|
00074 f2[1] = 0.5;
|
|
00075
|
|
00076 <span class="comment">// now f0 should dominate f2;</span>
|
|
00077
|
|
00078 <span class="keywordflow">if</span> (!f0.dominates(f2))
|
|
00079 {
|
|
00080 std::cout << f2 << <span class="stringliteral">" not dominated by "</span> << f0;
|
|
00081 <span class="keywordflow">throw</span>;
|
|
00082 }
|
|
00083
|
|
00084 <span class="comment">// f0 and f1 should not dominate each other</span>
|
|
00085
|
|
00086 <span class="keywordflow">if</span> (f0.dominates(f1) || f1.dominates(f0))
|
|
00087 {
|
|
00088 std::cout << f0 << <span class="stringliteral">" and "</span> << f1 << <span class="stringliteral">" dominate"</span>;
|
|
00089 <span class="keywordflow">throw</span>;
|
|
00090 }
|
|
00091
|
|
00092 <span class="keywordflow">if</span> (! (f0 == f0))
|
|
00093 {
|
|
00094 std::cout << <span class="stringliteral">"f0 == f0 failed"</span> << std::endl;
|
|
00095 <span class="keywordflow">throw</span>;
|
|
00096 }
|
|
00097
|
|
00098 <span class="comment">// test ctors and such</span>
|
|
00099 MaxFitness f3 = f0;
|
|
00100 f3[0] += 1e-9;
|
|
00101
|
|
00102 <span class="comment">// test tolerance</span>
|
|
00103 assert(f3 == f0);
|
|
00104
|
|
00105 MinFitness m0;
|
|
00106 MinFitness m1;
|
|
00107 MinFitness m2;
|
|
00108 MinFitness m3;
|
|
00109
|
|
00110 m0[0] = 0.0;
|
|
00111 m0[1] = 1.0;
|
|
00112
|
|
00113 m1[0] = 1.0;
|
|
00114 m1[1] = 0.0;
|
|
00115
|
|
00116 m2[0] = 0.0;
|
|
00117 m2[1] = 0.5;
|
|
00118
|
|
00119 m3[0] = 0.5;
|
|
00120 m3[1] = 0.5;
|
|
00121
|
|
00122 <span class="comment">//m2 should dominate m0</span>
|
|
00123 assert(m2.dominates(m0));
|
|
00124
|
|
00125 assert(!m1.dominates(m0));
|
|
00126 assert(!m0.dominates(m1));
|
|
00127 assert(!m0.dominates(m2)); <span class="comment">// (m2 < m0));</span>
|
|
00128 assert(m2.dominates(m3)); <span class="comment">//m3 < m2);</span>
|
|
00129 assert(!m3.dominates(m2)); <span class="comment">// (m2 < m3));</span>
|
|
00130 assert(m2.dominates(m3)); <span class="comment">//m2 > m3);</span>
|
|
00131
|
|
00132
|
|
00134 <span class="comment">// now the run-time set-able number of objectives</span>
|
|
00136 <span class="comment"></span>
|
|
00137 std::cout << <span class="stringliteral">"On y va"</span> << std::endl;
|
|
00138
|
|
00139
|
|
00140 <span class="comment">// setup fitness WARNING do not try to allocate any EO before that (runtime error)</span>
|
|
00141 vector<bool> b(2, <span class="keyword">true</span>);
|
|
00142 b[0]=<span class="keyword">true</span>;
|
|
00143 b[1]=<span class="keyword">false</span>;
|
|
00144 VarFitness::setUp(2, b);
|
|
00145 std::cout << <span class="stringliteral">"\nMAXimizing on Obj 0 and MINimizing on Obj 1\n"</span>;
|
|
00146
|
|
00147 VarFitness mv0;
|
|
00148 VarFitness mv1;
|
|
00149 VarFitness mv2;
|
|
00150 VarFitness mv3;
|
|
00151
|
|
00152 mv0[0] = 0.0;
|
|
00153 mv0[1] = 1.0;
|
|
00154
|
|
00155 mv1[0] = 1.0;
|
|
00156 mv1[1] = 0.0;
|
|
00157
|
|
00158 mv2[0] = 0.0;
|
|
00159 mv2[1] = 0.5;
|
|
00160
|
|
00161 mv3[0] = 0.5;
|
|
00162 mv3[1] = 0.5;
|
|
00163
|
|
00164 compare <VarFitness>(mv0,mv1);
|
|
00165 compare <VarFitness>(mv0,mv2);
|
|
00166 compare <VarFitness>(mv0,mv3);
|
|
00167 compare <VarFitness>(mv1,mv2);
|
|
00168 compare <VarFitness>(mv1,mv3);
|
|
00169 compare <VarFitness>(mv2,mv3);
|
|
00170
|
|
00171 std::cout << <span class="stringliteral">"\nChanging now the min <-> max\n"</span>;
|
|
00172 b[0]=<span class="keyword">false</span>;
|
|
00173 b[1]=<span class="keyword">true</span>;
|
|
00174 VarFitness::setUp(2, b);
|
|
00175 std::cout << <span class="stringliteral">"\nMINimizing on Obj 0 and MAXimizing on Obj 1\n"</span>;
|
|
00176 compare <VarFitness>(mv0,mv1);
|
|
00177 compare <VarFitness>(mv0,mv2);
|
|
00178 compare <VarFitness>(mv0,mv3);
|
|
00179 compare <VarFitness>(mv1,mv2);
|
|
00180 compare <VarFitness>(mv1,mv3);
|
|
00181 compare <VarFitness>(mv2,mv3);
|
|
00182
|
|
00183 std::cout << <span class="stringliteral">"\nTesting WARNING\n"</span>;
|
|
00184 b.resize(3);
|
|
00185 b[0]=<span class="keyword">false</span>;
|
|
00186 b[1]=<span class="keyword">true</span>;
|
|
00187 b[2]=<span class="keyword">true</span>;
|
|
00188 VarFitness::setUp(3, b);
|
|
00189
|
|
00190 }
|
|
00191 <span class="keywordflow">catch</span>(std::exception& e)
|
|
00192 {
|
|
00193 std::cout << e.what() << std::endl;
|
|
00194 }
|
|
00195
|
|
00196 }
|
|
</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>
|