paradiseo/eo/tutorial/html/eoOneMax_complete.html

192 lines
8.3 KiB
HTML

<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="GENERATOR" content="Mozilla/4.78 [en] (X11; U; Linux 2.4.7-10 i686) [Netscape]">
<title>Templates/eoOneMax_complete.h</title>
</head>
<body text="#000000" bgcolor="#C3C2B4" link="#0000EE" vlink="#551A8B" alink="#FF0000">
<a href="eoLesson5.html">Back to Lesson 5</a>
- <a href="eoTutorial.html">Tutorial main page </a>- <a href="eoTopDown.html">Top-Down
page</a> - <a href="eoBottomUp.html">Bottom-up page</a> - <a href="eoProgramming.html">Programming
hints</a> - <font face="Arial,Helvetica"><a href="doc/html/index.html">EO
documentation</a></font>
<br>
<hr WIDTH="100%"><!-- -------------- End of header ------------------ --><!-- ----------------------------------------------- -->
<center>
<h1>
<font color="#FF0000">Templates/eoOneMax_complete.h</font></h1></center>
The user-defined code is on <b><font color="#FF6666">pink background</font></b>..
Only the the <a href="eoTutorial.html#colors">character colors have the
usual meaning</a>.
<p><a NAME="start"></a>
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE >
<tr NOSAVE>
<td NOSAVE><tt><font color="#993300">/** -*- mode: c++; c-indent-level:
4; c++-member-init-indent: 8; comment-column: 35; -*-</font></tt>
<br><tt><font color="#993300">The above line is usefulin Emacs-like editors</font></tt>
<br><tt><font color="#993300">*/</font></tt>
<p><tt><font color="#993300">/*</font></tt>
<br><tt><font color="#993300">Template for creating a new representation
in EO</font></tt>
<br><tt><font color="#993300">================================================</font></tt>
<br><tt><font color="#993300">*/</font></tt>
<p><b><tt><font color="#993300">#ifndef _eoOneMax_h</font></tt></b>
<br><b><tt><font color="#993300">#define _eoOneMax_h</font></tt></b>
<br>&nbsp;</td>
</tr>
</table>
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCCC" NOSAVE >
<tr>
<td><tt><font color="#000000">/**&nbsp;</font></tt>
<br><tt><font color="#000000">* A simple example class for bitstring (is
NOT supposed to be used :-)</font></tt>
<br><tt><font color="#000000">*/</font></tt></td>
</tr>
</table>
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE >
<tr>
<td></td>
</tr>
</table>
<a NAME="representation"></a>
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE >
<tr>
<td><b><tt><font color="#999900">template&lt; class FitT></font></tt></b>
<br><b><tt><font color="#999900">class eoOneMax: public EO&lt;FitT> {</font></tt></b>
<br><b><tt><font color="#999900">public:</font></tt></b>
<br><tt><font color="#999900"><b>&nbsp;</b> /** Deafult Ctor: nothing to
be done */</font></tt>
<br><b><tt><font color="#999900">&nbsp;eoOneMax() {}</font></tt></b>
<p><b><tt><font color="#999900">&nbsp;virtual string className() const
{ return "eoOneMax"; }</font></tt></b>
<br>&nbsp;</td>
</tr>
</table>
<a NAME="output"></a>
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE >
<tr>
<td><tt><font color="#3366FF"><b>&nbsp;</b> /** printing... */</font></tt>
<br><b><tt><font color="#3366FF">&nbsp;&nbsp;&nbsp;&nbsp; void printOn(ostream&amp;
_os) const</font></tt></b>
<br><b><tt><font color="#3366FF">&nbsp;&nbsp;&nbsp;&nbsp; {</font></tt></b>
<br><tt><font color="#3366FF"><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</b>
// First write the fitness</font></tt>
<br><b><tt><font color="#3366FF">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
EO&lt;FitT>::printOn(_os);</font></tt></b>
<br><b><tt><font color="#3366FF">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
_os &lt;&lt; ' ';</font></tt></b></td>
</tr>
</table>
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCCC" NOSAVE >
<tr>
<td><b><tt><font color="#3366FF">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
_os &lt;&lt; b.size() &lt;&lt; ' ' ;</font></tt></b>
<br><b><tt><font color="#3366FF">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
for (unsigned i=0; i&lt;b.size(); i++)</font></tt></b>
<br><b><tt><font color="#3366FF">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
_os &lt;&lt; b[i] &lt;&lt; ' ' ;</font></tt></b></td>
</tr>
</table>
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE >
<tr>
<td><b><tt><font color="#3366FF">&nbsp;&nbsp;&nbsp;&nbsp; }</font></tt></b>
<p><tt><font color="#3366FF"><b>&nbsp;</b> /** reading...&nbsp;</font></tt>
<br><tt><font color="#3366FF">&nbsp;&nbsp; * of course, your readFrom must
be able to read what printOn writes!!!</font></tt>
<br><tt><font color="#3366FF">&nbsp;&nbsp; */</font></tt>
<br><b><tt><font color="#3366FF">&nbsp;void readFrom(istream&amp; _is)</font></tt></b>
<br><b><tt><font color="#3366FF">&nbsp;{</font></tt></b>
<br><tt><font color="#3366FF"><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</b> //
of course you should read the fitness first!</font></tt>
<br><b><tt><font color="#3366FF">&nbsp;&nbsp;&nbsp;&nbsp; EO&lt;FitT>::readFrom(_is);</font></tt></b></td>
</tr>
</table>
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCCC" NOSAVE >
<tr>
<td><b><tt><font color="#3366FF">&nbsp;&nbsp;&nbsp;&nbsp; unsigned s;</font></tt></b>
<br><b><tt><font color="#3366FF">&nbsp;&nbsp;&nbsp;&nbsp; _is >> s;</font></tt></b>
<br><b><tt><font color="#3366FF">&nbsp;&nbsp;&nbsp;&nbsp; b.resize(s);</font></tt></b>
<br><b><tt><font color="#3366FF">&nbsp;&nbsp;&nbsp;&nbsp; for (unsigned
i=0; i&lt;s; i++)</font></tt></b>
<br><b><tt><font color="#3366FF">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
{</font></tt></b>
<br><b><tt><font color="#3366FF">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
bool bTmp;</font></tt></b>
<br><b><tt><font color="#3366FF">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
_is >> bTmp;</font></tt></b>
<br><b><tt><font color="#3366FF">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
b[i] = bTmp;</font></tt></b>
<br><b><tt><font color="#3366FF">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
}&nbsp;</font></tt></b></td>
</tr>
</table>
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE >
<tr>
<td><b><tt><font color="#3366FF">&nbsp;}</font></tt></b></td>
</tr>
</table>
<a NAME="representation"></a>
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE >
<tr>
<td></td>
</tr>
</table>
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCCC" NOSAVE >
<tr>
<td><tt><font color="#999900"><b>&nbsp;</b> // brute setting (we could
also have defined a Ctor from a vector&lt;bool>)</font></tt>
<br><b><tt><font color="#999900">&nbsp;void setB(vector&lt;bool> &amp;
_b)</font></tt></b>
<br><b><tt><font color="#999900">&nbsp;{</font></tt></b>
<br><b><tt><font color="#999900">&nbsp;&nbsp;&nbsp;&nbsp; b=_b;</font></tt></b>
<br><b><tt><font color="#999900">&nbsp;}</font></tt></b>
<p><tt><font color="#999900"><b>&nbsp;</b> // brute accessing (we could
also define operator[] ...)</font></tt>
<br><b><tt><font color="#999900">&nbsp;const vector&lt;bool> &amp; B()</font></tt></b>
<br><b><tt><font color="#999900">&nbsp;{</font></tt></b>
<br><b><tt><font color="#999900">&nbsp;&nbsp;&nbsp;&nbsp; return b;</font></tt></b>
<br><b><tt><font color="#999900">&nbsp;}</font></tt></b></td>
</tr>
</table>
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE >
<tr>
<td>
<br><tt><font color="#999900"><b>private:&nbsp;&nbsp;&nbsp;&nbsp;</b> //
put all data here</font></tt></td>
</tr>
</table>
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#FFCCCC" NOSAVE >
<tr>
<td><b><tt><font color="#999900">&nbsp;std::vector&lt;bool> b;</font></tt></b></td>
</tr>
</table>
<table BORDER=0 CELLSPACING=0 COLS=1 WIDTH="100%" BGCOLOR="#CCCCCC" NOSAVE >
<tr>
<td><b><tt><font color="#999900">};</font></tt></b>
<p><b><tt><font color="#999900">#endif</font></tt></b></td>
</tr>
</table>
<hr WIDTH="100%"><a href="eoLesson5.html">Back to Lesson 5</a> - <a href="eoTutorial.html">Tutorial
main page </a>- <a href="eoTopDown.html">Top-Down page</a> - <a href="eoBottomUp.html">Bottom-up
page</a> - <a href="eoProgramming.html">Programming hints</a> - <font face="Arial,Helvetica"><a href="doc/html/index.html">EO
documentation</a></font>
<hr>
<address>
<a href="mailto:marc.schoenauer@inria.fr">Marc Schoenauer</a></address>
<br><!-- Created: Nov 2000 --><!-- hhmts start -->Last modified: Sat May
4 06:02:46 2002<!-- hhmts end -->
</body>
</html>