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
267
trunk/paradiseo-eo/doc/html/eo_real_bounds_8cpp-source.html
Normal file
267
trunk/paradiseo-eo/doc/html/eo_real_bounds_8cpp-source.html
Normal file
|
|
@ -0,0 +1,267 @@
|
|||
<!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: eoRealBounds.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_000000.html">src</a> / <a class="el" href="dir_000011.html">utils</a></div>
|
||||
<h1>eoRealBounds.cpp</h1><div class="fragment"><pre class="fragment">00001 <span class="preprocessor">#ifdef _MSC_VER</span>
|
||||
00002 <span class="preprocessor"></span><span class="comment">// to avoid long name warnings</span>
|
||||
00003 <span class="preprocessor">#pragma warning(disable:4786)</span>
|
||||
00004 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
|
||||
00005 <span class="preprocessor"></span>
|
||||
00006 <span class="preprocessor">#ifdef HAVE_CONFIG_H</span>
|
||||
00007 <span class="preprocessor"></span><span class="preprocessor">#include <config.h></span>
|
||||
00008 <span class="preprocessor">#endif</span>
|
||||
00009 <span class="preprocessor"></span>
|
||||
00010 <span class="preprocessor">#include <ctime></span>
|
||||
00011 <span class="preprocessor">#include <sstream></span>
|
||||
00012
|
||||
00013 <span class="preprocessor">#include "eoRealBounds.h"</span>
|
||||
00014 <span class="preprocessor">#include "eoRealVectorBounds.h"</span>
|
||||
00015
|
||||
00016
|
||||
00017 <span class="comment">// the global dummy bounds</span>
|
||||
00018 <span class="comment">// (used for unbounded variables when bounds are required)</span>
|
||||
00019 <a class="code" href="classeo_real_no_bounds.html">eoRealNoBounds</a> eoDummyRealNoBounds;
|
||||
00020 <a class="code" href="classeo_real_vector_no_bounds.html">eoRealVectorNoBounds</a> eoDummyVectorNoBounds(0);
|
||||
00021
|
||||
00023
|
||||
00024 <span class="comment">// removes leading delimiters - return false if nothing else left</span>
|
||||
00025 <span class="keywordtype">bool</span> remove_leading(std::string & _s, <span class="keyword">const</span> std::string _delim)
|
||||
00026 {
|
||||
00027 size_t posDebToken = _s.find_first_not_of(_delim);
|
||||
00028 <span class="keywordflow">if</span> (posDebToken >= _s.size())
|
||||
00029 <span class="keywordflow">return</span> <span class="keyword">false</span>;
|
||||
00030 _s = _s.substr(posDebToken);
|
||||
00031 <span class="keywordflow">return</span> <span class="keyword">true</span>;
|
||||
00032 }
|
||||
00033
|
||||
00034 <span class="keywordtype">double</span> read_double(std::string _s)
|
||||
00035 {
|
||||
00036 std::istringstream is(_s);
|
||||
00037 <span class="keywordtype">double</span> r;
|
||||
00038 is >> r;
|
||||
00039 <span class="keywordflow">return</span> r;
|
||||
00040 }
|
||||
00041
|
||||
00042 <span class="keywordtype">long</span> <span class="keywordtype">int</span> read_int(std::string _s)
|
||||
00043 {
|
||||
00044 std::istringstream is(_s);
|
||||
00045 <span class="keywordtype">long</span> <span class="keywordtype">int</span> i;
|
||||
00046 is >> i;
|
||||
00047 <span class="keywordflow">return</span> i;
|
||||
00048 }
|
||||
00049
|
||||
00050 <span class="comment">// need to rewrite copy ctor and assignement operator because of ownedBounds</span>
|
||||
<a name="l00051"></a><a class="code" href="classeo_real_vector_bounds.html#a11">00051</a> <a class="code" href="classeo_real_vector_bounds.html#a0">eoRealVectorBounds::eoRealVectorBounds</a>(<span class="keyword">const</span> <a class="code" href="classeo_real_vector_bounds.html">eoRealVectorBounds</a> & _b):
|
||||
00052 <a class="code" href="classeo_real_base_vector_bounds.html">eoRealBaseVectorBounds</a>(_b)
|
||||
00053 {
|
||||
00054 factor = _b.<a class="code" href="classeo_real_vector_bounds.html#r0">factor</a>;
|
||||
00055 ownedBounds = _b.<a class="code" href="classeo_real_vector_bounds.html#r1">ownedBounds</a>;
|
||||
00056 <span class="comment">// duplicate all pointers!</span>
|
||||
00057 <span class="keywordflow">if</span> (ownedBounds.size()>0)
|
||||
00058 <span class="keywordflow">for</span> (<span class="keywordtype">unsigned</span> i=0; i<ownedBounds.size(); i++)
|
||||
00059 ownedBounds[i] = ownedBounds[i]->dup();
|
||||
00060 }
|
||||
00061
|
||||
00062
|
||||
00063 <span class="comment">// the readFrom method of eoRealVectorNoBounds:</span>
|
||||
00064 <span class="comment">// only calls the readFrom(string) - for param reading</span>
|
||||
<a name="l00065"></a><a class="code" href="classeo_real_vector_bounds.html#a7">00065</a> <span class="keywordtype">void</span> <a class="code" href="classeo_real_vector_bounds.html#a7">eoRealVectorBounds::readFrom</a>(std::istream& _is)
|
||||
00066 {
|
||||
00067 std::string value;
|
||||
00068 _is >> value;
|
||||
00069 <a class="code" href="classeo_real_vector_bounds.html#a7">readFrom</a>(value);
|
||||
00070 <span class="keywordflow">return</span>;
|
||||
00071 }
|
||||
00072
|
||||
<a name="l00073"></a><a class="code" href="classeo_real_vector_bounds.html#a8">00073</a> <span class="keywordtype">void</span> <a class="code" href="classeo_real_vector_bounds.html#a7">eoRealVectorBounds::readFrom</a>(std::string _value)
|
||||
00074 {
|
||||
00075 <span class="comment">// keep track of old size - to adjust in the end</span>
|
||||
00076 <span class="keywordtype">unsigned</span> oldSize = size();
|
||||
00077 <span class="comment">// clean-up before filling in</span>
|
||||
00078 <span class="keywordflow">if</span> (ownedBounds.size()>0)
|
||||
00079 <span class="keywordflow">for</span> (<span class="keywordtype">unsigned</span> i = 0; i < ownedBounds.size(); ++i)
|
||||
00080 {
|
||||
00081 <span class="keyword">delete</span> ownedBounds[i];
|
||||
00082 }
|
||||
00083 ownedBounds.resize(0);
|
||||
00084 factor.resize(0);
|
||||
00085 resize(0);
|
||||
00086
|
||||
00087 <span class="comment">// now read</span>
|
||||
00088 std::string delim(<span class="stringliteral">",; "</span>);
|
||||
00089 <span class="keywordflow">while</span> (_value.size()>0)
|
||||
00090 {
|
||||
00091 <span class="keywordflow">if</span> (!remove_leading(_value, delim)) <span class="comment">// only delimiters were left</span>
|
||||
00092 <span class="keywordflow">break</span>;
|
||||
00093 <span class="comment">// look for opening char</span>
|
||||
00094 size_t posDeb = _value.find_first_of(<span class="stringliteral">"[("</span>);
|
||||
00095 <span class="keywordflow">if</span> (posDeb >= _value.size()) <span class="comment">// nothing left to read (though probably a syntax error there)</span>
|
||||
00096 {
|
||||
00097 <span class="keywordflow">break</span>;
|
||||
00098 }
|
||||
00099 <span class="comment">// ending char</span>
|
||||
00100 std::string closeChar = (_value[posDeb] == <span class="charliteral">'('</span> ? std::string(<span class="stringliteral">")"</span>) : std::string(<span class="stringliteral">"]"</span>) );
|
||||
00101
|
||||
00102 size_t posFin = _value.find_first_of(std::string(closeChar));
|
||||
00103 <span class="keywordflow">if</span> (posFin >= _value.size())
|
||||
00104 <span class="keywordflow">throw</span> std::runtime_error(<span class="stringliteral">"Syntax error when reading bounds"</span>);
|
||||
00105
|
||||
00106 <span class="comment">// y a-t-il un nbre devant</span>
|
||||
00107 <span class="keywordtype">unsigned</span> count = 1;
|
||||
00108 <span class="keywordflow">if</span> (posDeb > 0) <span class="comment">// something before opening</span>
|
||||
00109 {
|
||||
00110 std::string sCount = _value.substr(0, posDeb);
|
||||
00111 count = read_int(sCount);
|
||||
00112 <span class="keywordflow">if</span> (count <= 0)
|
||||
00113 <span class="keywordflow">throw</span> std::runtime_error(<span class="stringliteral">"Syntax error when reading bounds"</span>);
|
||||
00114 }
|
||||
00115
|
||||
00116 <span class="comment">// the bounds</span>
|
||||
00117 std::string sBounds = _value.substr(posDeb+1, posFin-posDeb-1);
|
||||
00118 <span class="comment">// and remove from original string</span>
|
||||
00119 _value = _value.substr(posFin+1);
|
||||
00120
|
||||
00121 remove_leading(sBounds, delim);
|
||||
00122 size_t posDelim = sBounds.find_first_of(delim);
|
||||
00123 <span class="keywordflow">if</span> (posDelim >= sBounds.size())
|
||||
00124 <span class="keywordflow">throw</span> std::runtime_error(<span class="stringliteral">"Syntax error when reading bounds"</span>);
|
||||
00125
|
||||
00126 <span class="keywordtype">bool</span> minBounded=<span class="keyword">false</span>, maxBounded=<span class="keyword">false</span>;
|
||||
00127 <span class="keywordtype">double</span> minBound=0, maxBound=0;
|
||||
00128
|
||||
00129 <span class="comment">// min bound</span>
|
||||
00130 std::string sMinBounds = sBounds.substr(0,posDelim);
|
||||
00131 <span class="keywordflow">if</span> (sMinBounds != std::string(<span class="stringliteral">"-inf"</span>))
|
||||
00132 {
|
||||
00133 minBounded = <span class="keyword">true</span>;
|
||||
00134 minBound = read_double(sMinBounds);
|
||||
00135 }
|
||||
00136
|
||||
00137 <span class="comment">// max bound</span>
|
||||
00138 size_t posEndDelim = sBounds.find_first_not_of(delim,posDelim);
|
||||
00139
|
||||
00140 std::string sMaxBounds = sBounds.substr(posEndDelim);
|
||||
00141 <span class="keywordflow">if</span> (sMaxBounds != std::string(<span class="stringliteral">"+inf"</span>))
|
||||
00142 {
|
||||
00143 maxBounded = <span class="keyword">true</span>;
|
||||
00144 maxBound = read_double(sMaxBounds);
|
||||
00145 }
|
||||
00146
|
||||
00147 <span class="comment">// now create the eoRealBounds objects</span>
|
||||
00148 <a class="code" href="classeo_real_bounds.html">eoRealBounds</a> *ptBounds;
|
||||
00149 <span class="keywordflow">if</span> (minBounded && maxBounded)
|
||||
00150 ptBounds = <span class="keyword">new</span> <a class="code" href="classeo_real_interval.html">eoRealInterval</a>(minBound, maxBound);
|
||||
00151 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (!minBounded && !maxBounded) <span class="comment">// no bound at all</span>
|
||||
00152 ptBounds = <span class="keyword">new</span> <a class="code" href="classeo_real_no_bounds.html">eoRealNoBounds</a>;
|
||||
00153 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (!minBounded && maxBounded)
|
||||
00154 ptBounds = <span class="keyword">new</span> <a class="code" href="classeo_real_above_bound.html">eoRealAboveBound</a>(maxBound);
|
||||
00155 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (minBounded && !maxBounded)
|
||||
00156 ptBounds = <span class="keyword">new</span> <a class="code" href="classeo_real_below_bound.html">eoRealBelowBound</a>(minBound);
|
||||
00157 <span class="comment">// store it for memory management</span>
|
||||
00158 ownedBounds.push_back(ptBounds);
|
||||
00159 <span class="comment">// push the count</span>
|
||||
00160 factor.push_back(count);
|
||||
00161 <span class="comment">// and add count of it to the actual bounds</span>
|
||||
00162 <span class="keywordflow">for</span> (<span class="keywordtype">unsigned</span> i=0; i<count; i++)
|
||||
00163 push_back(ptBounds);
|
||||
00164 }
|
||||
00165 <span class="comment">// now adjust the size to the initial value</span>
|
||||
00166 <a class="code" href="classeo_real_vector_bounds.html#a10">adjust_size</a>(oldSize);
|
||||
00167 }
|
||||
00168
|
||||
<a name="l00170"></a><a class="code" href="classeo_real_vector_bounds.html#a10">00170</a> <span class="keywordtype">void</span> <a class="code" href="classeo_real_vector_bounds.html#a10">eoRealVectorBounds::adjust_size</a>(<span class="keywordtype">unsigned</span> _dim)
|
||||
00171 {
|
||||
00172 <span class="keywordflow">if</span> ( size() < _dim )
|
||||
00173 {
|
||||
00174 <span class="comment">// duplicate last bound</span>
|
||||
00175 <span class="keywordtype">unsigned</span> missing = _dim-size();
|
||||
00176 <a class="code" href="classeo_real_bounds.html">eoRealBounds</a> * ptBounds = back();
|
||||
00177 <span class="keywordflow">for</span> (<span class="keywordtype">unsigned</span> i=0; i<missing; i++)
|
||||
00178 push_back(ptBounds);
|
||||
00179 <span class="comment">// update last factor (warning: can be > 1 already!)</span>
|
||||
00180 factor[factor.size()-1] += missing;
|
||||
00181 }
|
||||
00182 }
|
||||
00183
|
||||
<a name="l00189"></a><a class="code" href="classeo_general_real_bounds.html#d0">00189</a> <a class="code" href="classeo_real_bounds.html">eoRealBounds</a>* <a class="code" href="classeo_general_real_bounds.html#d0">eoGeneralRealBounds::getBoundsFromString</a>(std::string _value)
|
||||
00190 {
|
||||
00191 <span class="comment">// now read</span>
|
||||
00192 std::string delim(<span class="stringliteral">",; "</span>);
|
||||
00193 std::string beginOrClose(<span class="stringliteral">"[(])"</span>);
|
||||
00194 <span class="keywordflow">if</span> (!remove_leading(_value, delim)) <span class="comment">// only delimiters were left</span>
|
||||
00195 <span class="keywordflow">throw</span> std::runtime_error(<span class="stringliteral">"Syntax error in eoGeneralRealBounds Ctor"</span>);
|
||||
00196
|
||||
00197 <span class="comment">// look for opening char</span>
|
||||
00198 size_t posDeb = _value.find_first_of(beginOrClose); <span class="comment">// allow ]a,b]</span>
|
||||
00199 <span class="keywordflow">if</span> (posDeb >= _value.size()) <span class="comment">// nothing left to read</span>
|
||||
00200 <span class="keywordflow">throw</span> std::runtime_error(<span class="stringliteral">"Syntax error in eoGeneralRealBounds Ctor"</span>);
|
||||
00201
|
||||
00202 <span class="comment">// ending char: next {}() after posDeb</span>
|
||||
00203 size_t posFin = _value.find_first_of(beginOrClose,posDeb+1);
|
||||
00204 <span class="keywordflow">if</span> (posFin >= _value.size()) <span class="comment">// not found</span>
|
||||
00205 <span class="keywordflow">throw</span> std::runtime_error(<span class="stringliteral">"Syntax error in eoGeneralRealBounds Ctor"</span>);
|
||||
00206
|
||||
00207 <span class="comment">// the bounds</span>
|
||||
00208 std::string sBounds = _value.substr(posDeb+1, posFin-posDeb-1);
|
||||
00209 <span class="comment">// and remove from original string</span>
|
||||
00210 _value = _value.substr(posFin+1);
|
||||
00211
|
||||
00212 remove_leading(sBounds, delim);
|
||||
00213 size_t posDelim = sBounds.find_first_of(delim);
|
||||
00214 <span class="keywordflow">if</span> (posDelim >= sBounds.size())
|
||||
00215 <span class="keywordflow">throw</span> std::runtime_error(<span class="stringliteral">"Syntax error in eoGeneralRealBounds Ctor"</span>);
|
||||
00216
|
||||
00217 <span class="keywordtype">bool</span> minBounded=<span class="keyword">false</span>, maxBounded=<span class="keyword">false</span>;
|
||||
00218 <span class="keywordtype">double</span> minBound=0, maxBound=0;
|
||||
00219
|
||||
00220 <span class="comment">// min bound</span>
|
||||
00221 std::string sMinBounds = sBounds.substr(0,posDelim);
|
||||
00222
|
||||
00223 <span class="keywordflow">if</span> ( (sMinBounds != std::string(<span class="stringliteral">"-inf"</span>)) &&
|
||||
00224 (sMinBounds != std::string(<span class="stringliteral">"-infinity"</span>))
|
||||
00225 )
|
||||
00226 {
|
||||
00227 minBounded = <span class="keyword">true</span>;
|
||||
00228 minBound = read_double(sMinBounds);
|
||||
00229 }
|
||||
00230
|
||||
00231 <span class="comment">// max bound</span>
|
||||
00232 size_t posEndDelim = sBounds.find_first_not_of(delim,posDelim);
|
||||
00233
|
||||
00234 std::string sMaxBounds = sBounds.substr(posEndDelim);
|
||||
00235
|
||||
00236 <span class="keywordflow">if</span> ( (sMaxBounds != std::string(<span class="stringliteral">"+inf"</span>)) &&
|
||||
00237 (sMaxBounds != std::string(<span class="stringliteral">"+infinity"</span>))
|
||||
00238 )
|
||||
00239 {
|
||||
00240 maxBounded = <span class="keyword">true</span>;
|
||||
00241 maxBound = read_double(sMaxBounds);
|
||||
00242 }
|
||||
00243
|
||||
00244 <span class="comment">// now create the embedded eoRealBounds object</span>
|
||||
00245 <a class="code" href="classeo_real_bounds.html">eoRealBounds</a> * locBound;
|
||||
00246 <span class="keywordflow">if</span> (minBounded && maxBounded)
|
||||
00247 {
|
||||
00248 <span class="keywordflow">if</span> (maxBound <= minBound)
|
||||
00249 <span class="keywordflow">throw</span> std::runtime_error(<span class="stringliteral">"Syntax error in eoGeneralRealBounds Ctor"</span>);
|
||||
00250 locBound = <span class="keyword">new</span> <a class="code" href="classeo_real_interval.html">eoRealInterval</a>(minBound, maxBound);
|
||||
00251 }
|
||||
00252 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (!minBounded && !maxBounded) <span class="comment">// no bound at all</span>
|
||||
00253 locBound = <span class="keyword">new</span> <a class="code" href="classeo_real_no_bounds.html">eoRealNoBounds</a>;
|
||||
00254 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (!minBounded && maxBounded)
|
||||
00255 locBound = <span class="keyword">new</span> <a class="code" href="classeo_real_above_bound.html">eoRealAboveBound</a>(maxBound);
|
||||
00256 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (minBounded && !maxBounded)
|
||||
00257 locBound = <span class="keyword">new</span> <a class="code" href="classeo_real_below_bound.html">eoRealBelowBound</a>(minBound);
|
||||
00258 <span class="keywordflow">return</span> locBound;
|
||||
00259 }
|
||||
</pre></div><hr size="1"><address style="align: right;"><small>Generated on Thu Oct 19 05:06:37 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