git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@40 331e1502-861f-0410-8da2-ba01fb791d7f
166 lines
11 KiB
HTML
166 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>EO: eoParseTree.h 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_000000.html">src</a> / <a class="el" href="dir_000017.html">gp</a></div>
|
|
<h1>eoParseTree.h</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">// eoParseTree.h : eoParseTree class (for Tree-based Genetic Programming)</span>
|
|
00005 <span class="comment">// (c) Maarten Keijzer 2000</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: todos@geneura.ugr.es, http://geneura.ugr.es</span>
|
|
00022 <span class="comment"> mak@dhi.dk</span>
|
|
00023 <span class="comment"></span>
|
|
00024 <span class="comment"> */</span>
|
|
00025 <span class="comment">//-----------------------------------------------------------------------------</span>
|
|
00026
|
|
00027 <span class="preprocessor">#ifndef eoParseTree_h</span>
|
|
00028 <span class="preprocessor"></span><span class="preprocessor">#define eoParseTree_h</span>
|
|
00029 <span class="preprocessor"></span>
|
|
00030 <span class="preprocessor">#include <iterator></span>
|
|
00031 <span class="preprocessor">#include <list></span>
|
|
00032
|
|
00033 <span class="preprocessor">#include <EO.h></span>
|
|
00034 <span class="preprocessor">#include <eoInit.h></span>
|
|
00035 <span class="preprocessor">#include <eoOp.h></span>
|
|
00036 <span class="preprocessor">#include <gp/parse_tree.h></span>
|
|
00037
|
|
00038 <span class="keyword">using</span> <span class="keyword">namespace </span>gp_parse_tree;
|
|
00039
|
|
00053 <span class="keyword">template</span> <<span class="keyword">class</span> FType, <span class="keyword">class</span> Node>
|
|
<a name="l00054"></a><a class="code" href="classeo_parse_tree.html">00054</a> <span class="keyword">class </span><a class="code" href="classeo_parse_tree.html">eoParseTree</a> : <span class="keyword">public</span> EO<FType>, <span class="keyword">public</span> parse_tree<Node>
|
|
00055 {
|
|
00056 <span class="keyword">public</span>:
|
|
00057
|
|
00058 <span class="keyword">using</span> parse_tree<Node>::back;
|
|
00059 <span class="keyword">using</span> parse_tree<Node>::ebegin;
|
|
00060 <span class="keyword">using</span> parse_tree<Node>::eend;
|
|
00061 <span class="keyword">using</span> parse_tree<Node>::size;
|
|
00062
|
|
00063
|
|
00064 <span class="keyword">typedef</span> <span class="keyword">typename</span> parse_tree<Node>::subtree Subtree;
|
|
00065
|
|
00066 <span class="comment">/* For Compatibility with the intel C++ compiler for Linux 5.x */</span>
|
|
00067 <span class="keyword">typedef</span> Node reference;
|
|
00068 <span class="keyword">typedef</span> <span class="keyword">const</span> reference const_reference;
|
|
00069
|
|
<a name="l00073"></a><a class="code" href="classeo_parse_tree.html#a0">00073</a> <a class="code" href="classeo_parse_tree.html#a0">eoParseTree</a>(<span class="keywordtype">void</span>) {}
|
|
00074
|
|
<a name="l00079"></a><a class="code" href="classeo_parse_tree.html#a1">00079</a> <a class="code" href="classeo_parse_tree.html#a0">eoParseTree</a>(<span class="keyword">const</span> parse_tree<Node>& tree) : parse_tree<Node>(tree) {}
|
|
00080
|
|
00081 <span class="comment">// eoParseTree(const eoParseTree<FType, Node>& tree) : parse_tree<Node>(tree) {}</span>
|
|
<a name="l00086"></a><a class="code" href="classeo_parse_tree.html#a2">00086</a> <span class="comment"></span> <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classeo_parse_tree.html#a2">pruneTree</a>(<span class="keywordtype">unsigned</span> _size)
|
|
00087 {
|
|
00088 <span class="keywordflow">if</span> (_size < 1)
|
|
00089 <span class="keywordflow">return</span>;
|
|
00090
|
|
00091 <span class="keywordflow">while</span> (size() > _size)
|
|
00092 {
|
|
00093 back() = operator[](size()-2);
|
|
00094 }
|
|
00095 }
|
|
00096
|
|
<a name="l00102"></a><a class="code" href="classeo_parse_tree.html#a3">00102</a> <a class="code" href="classeo_parse_tree.html#a0">eoParseTree</a>(std::istream& is) : EO<FType>(), parse_tree<Node>()
|
|
00103 {
|
|
00104 <a class="code" href="classeo_parse_tree.html#a6">readFrom</a>(is);
|
|
00105 }
|
|
00106
|
|
<a name="l00108"></a><a class="code" href="classeo_parse_tree.html#a4">00108</a> std::string <a class="code" href="classeo_parse_tree.html#a4">className</a>(<span class="keywordtype">void</span>)<span class="keyword"> const </span>{ <span class="keywordflow">return</span> <span class="stringliteral">"eoParseTree"</span>; }
|
|
00109
|
|
<a name="l00114"></a><a class="code" href="classeo_parse_tree.html#a5">00114</a> <span class="keywordtype">void</span> <a class="code" href="classeo_parse_tree.html#a5">printOn</a>(std::ostream& os)<span class="keyword"> const</span>
|
|
00115 <span class="keyword"> </span>{
|
|
00116 <a class="code" href="class_e_o.html#z10_2">EO<FType>::printOn</a>(os);
|
|
00117 os << <span class="charliteral">' '</span>;
|
|
00118
|
|
00119 os << size() << <span class="charliteral">' '</span>;
|
|
00120
|
|
00121 std::copy(ebegin(), eend(), std::ostream_iterator<Node>(os, <span class="stringliteral">" "</span>));
|
|
00122 }
|
|
00123
|
|
<a name="l00128"></a><a class="code" href="classeo_parse_tree.html#a6">00128</a> <span class="keywordtype">void</span> <a class="code" href="classeo_parse_tree.html#a6">readFrom</a>(std::istream& is)
|
|
00129 {
|
|
00130
|
|
00131
|
|
00132 <a class="code" href="class_e_o.html#z10_1">EO<FType>::readFrom</a>(is);
|
|
00133
|
|
00134 <span class="keywordtype">unsigned</span> sz;
|
|
00135 is >> sz;
|
|
00136
|
|
00137
|
|
00138 std::vector<Node> v(sz);
|
|
00139
|
|
00140 <span class="keywordtype">unsigned</span> i;
|
|
00141
|
|
00142 <span class="keywordflow">for</span> (i = 0; i < sz; ++i)
|
|
00143 {
|
|
00144 Node node;
|
|
00145 is >> node;
|
|
00146 v[i] = node;
|
|
00147 }
|
|
00148 parse_tree<Node> tmp(v.begin(), v.end());
|
|
00149 swap(tmp);
|
|
00150
|
|
00151 <span class="comment">/*</span>
|
|
00152 <span class="comment"> * old code which caused problems for paradisEO</span>
|
|
00153 <span class="comment"> *</span>
|
|
00154 <span class="comment"> * this can be removed once it has proved itself</span>
|
|
00155 <span class="comment"> EO<FType>::readFrom(is);</span>
|
|
00156 <span class="comment"></span>
|
|
00157 <span class="comment"> // even older code</span>
|
|
00158 <span class="comment"> FType fit;</span>
|
|
00159 <span class="comment"> is >> fit;</span>
|
|
00160 <span class="comment"></span>
|
|
00161 <span class="comment"> fitness(fit);</span>
|
|
00162 <span class="comment"></span>
|
|
00163 <span class="comment"></span>
|
|
00164 <span class="comment"> std::copy(std::istream_iterator<Node>(is), std::istream_iterator<Node>(), back_inserter(*this));</span>
|
|
00165 <span class="comment"> */</span>
|
|
00166 }
|
|
00167 };
|
|
00168
|
|
00169 <span class="comment">// friend function to print eoParseTree</span>
|
|
00170 <span class="keyword">template</span> <<span class="keyword">class</span> FType, <span class="keyword">class</span> Node>
|
|
00171 std::ostream& operator<<(std::ostream& os, const eoParseTree<FType, Node>& eot)
|
|
00172 {
|
|
00173 eot.printOn(os);
|
|
00174 <span class="keywordflow">return</span> os;
|
|
00175 }
|
|
00176
|
|
00177 <span class="comment">// friend function to read eoParseTree</span>
|
|
00178 <span class="keyword">template</span> <<span class="keyword">class</span> FType, <span class="keyword">class</span> Node>
|
|
00179 std::istream& operator>>(std::istream& is, <a class="code" href="classeo_parse_tree.html">eoParseTree<FType, Node></a>& eot)
|
|
00180 {
|
|
00181 eot.<a class="code" href="classeo_parse_tree.html#a6">readFrom</a>(is);
|
|
00182 <span class="keywordflow">return</span> is;
|
|
00183 }
|
|
00184
|
|
00185 <span class="comment">// for backward compatibility</span>
|
|
00186 <span class="preprocessor">#include <gp/eoParseTreeOp.h></span>
|
|
00187 <span class="preprocessor">#include <gp/eoParseTreeDepthInit.h></span>
|
|
00188
|
|
00189 <span class="preprocessor">#endif</span>
|
|
</pre></div><hr size="1"><address style="align: right;"><small>Generated on Thu Oct 19 05:06:36 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>
|