Sophie

Sophie

distrib > Fedora > 15 > i386 > by-pkgid > 54cac1c2268db633d66eeff1b4faa585 > files > 491

frepple-doc-0.8.1-3.fc15.noarch.rpm

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>C++ API frePPLe: forecast.cpp Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
<link href="tabs.css" rel="stylesheet" type="text/css">
<link href="../styles.css" rel="stylesheet"  type="text/css">
</head>
<body>
<div id="container">

<div id="menubar"> 
<div id="logo" align="center">
<br/><img src='../frepple.bmp' alt="frepple" /><br/>
<a href='http://www.frepple.com/'>
<strong>a Free<br/>Production Planning<br/>Library</strong>
</a>
</div>
<div id="menu">
<br/>
<h3><a href='../Main/HomePage.html'>Main</a></h3>
<h3><a href='../UI/Main.html'>User Manual</a></h3>
<h3><a href='../Tutorial/Main.html'>Tutorial</a></h3>
<h3><a href='../Frepple/Main.html'>Reference Manual</a></h3>
<h3><a href='../Main/FAQ.html'>FAQ</a></h3>
<h3><a href='index.html'>C++ API</a></h3>
<br/>
</div>  
</div>

<div id="content">
<br/>
<!-- Generated by Doxygen 1.6.1 -->
<div class="navigation" id="top">
  <div class="tabs">
    <ul>
      <li><a href="index.html"><span>Main&nbsp;Page</span></a></li>
      <li><a href="pages.html"><span>Related&nbsp;Pages</span></a></li>
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li><a href="dirs.html"><span>Directories</span></a></li>
    </ul>
  </div>
  <div class="tabs">
    <ul>
      <li><a href="files.html"><span>File&nbsp;List</span></a></li>
      <li><a href="globals.html"><span>File&nbsp;Members</span></a></li>
    </ul>
  </div>
  <div class="navpath"><a class="el" href="dir_cfc6129efafb4deb1379318d01a4b532.html">modules</a>&nbsp;&raquo&nbsp;<a class="el" href="dir_4a975c66df64d91ea50e31e1c6371883.html">forecast</a>
  </div>
</div>
<div class="contents">
<h1>forecast.cpp</h1><a href="a00203.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/***************************************************************************</span>
<a name="l00002"></a>00002 <span class="comment">  file : $URL: https://frepple.svn.sourceforge.net/svnroot/frepple/trunk/modules/forecast/forecast.cpp $</span>
<a name="l00003"></a>00003 <span class="comment">  version : $LastChangedRevision: 1315 $  $LastChangedBy: jdetaeye $</span>
<a name="l00004"></a>00004 <span class="comment">  date : $LastChangedDate: 2010-07-17 18:08:53 +0200 (Sat, 17 Jul 2010) $</span>
<a name="l00005"></a>00005 <span class="comment"> ***************************************************************************/</span>
<a name="l00006"></a>00006 
<a name="l00007"></a>00007 <span class="comment">/***************************************************************************</span>
<a name="l00008"></a>00008 <span class="comment"> *                                                                         *</span>
<a name="l00009"></a>00009 <span class="comment"> * Copyright (C) 2007-2010 by Johan De Taeye                               *</span>
<a name="l00010"></a>00010 <span class="comment"> *                                                                         *</span>
<a name="l00011"></a>00011 <span class="comment"> * This library is free software; you can redistribute it and/or modify it *</span>
<a name="l00012"></a>00012 <span class="comment"> * under the terms of the GNU Lesser General Public License as published   *</span>
<a name="l00013"></a>00013 <span class="comment"> * by the Free Software Foundation; either version 2.1 of the License, or  *</span>
<a name="l00014"></a>00014 <span class="comment"> * (at your option) any later version.                                     *</span>
<a name="l00015"></a>00015 <span class="comment"> *                                                                         *</span>
<a name="l00016"></a>00016 <span class="comment"> * This library is distributed in the hope that it will be useful,         *</span>
<a name="l00017"></a>00017 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of          *</span>
<a name="l00018"></a>00018 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser *</span>
<a name="l00019"></a>00019 <span class="comment"> * General Public License for more details.                                *</span>
<a name="l00020"></a>00020 <span class="comment"> *                                                                         *</span>
<a name="l00021"></a>00021 <span class="comment"> * You should have received a copy of the GNU Lesser General Public        *</span>
<a name="l00022"></a>00022 <span class="comment"> * License along with this library; if not, write to the Free Software     *</span>
<a name="l00023"></a>00023 <span class="comment"> * Foundation Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 *</span>
<a name="l00024"></a>00024 <span class="comment"> * USA                                                                     *</span>
<a name="l00025"></a>00025 <span class="comment"> *                                                                         *</span>
<a name="l00026"></a>00026 <span class="comment"> ***************************************************************************/</span>
<a name="l00027"></a>00027 
<a name="l00028"></a>00028 <span class="preprocessor">#include &quot;<a class="code" href="a00204.html" title="Header file for the module forecast.">forecast.h</a>&quot;</span>
<a name="l00029"></a>00029 
<a name="l00030"></a><a class="code" href="a00258.html">00030</a> <span class="keyword">namespace </span>module_forecast
<a name="l00031"></a>00031 {
<a name="l00032"></a>00032 
<a name="l00033"></a>00033 <span class="keyword">const</span> <a class="code" href="a00096.html" title="This class defines a keyword for the frePPLe data model.">Keyword</a> <a class="code" href="a00072.html#a8f1b1910feb8fcaa9d2a261949cfbb67">Forecast::tag_total</a>(<span class="stringliteral">&quot;total&quot;</span>);
<a name="l00034"></a>00034 <span class="keyword">const</span> <a class="code" href="a00096.html" title="This class defines a keyword for the frePPLe data model.">Keyword</a> <a class="code" href="a00072.html#aa020a05db722fc3f85183d676e8c27c9">Forecast::tag_net</a>(<span class="stringliteral">&quot;net&quot;</span>);
<a name="l00035"></a>00035 <span class="keyword">const</span> <a class="code" href="a00096.html" title="This class defines a keyword for the frePPLe data model.">Keyword</a> <a class="code" href="a00072.html#aa00855cb99c427b85ed329cf22634431">Forecast::tag_consumed</a>(<span class="stringliteral">&quot;consumed&quot;</span>);
<a name="l00036"></a>00036 <span class="keyword">const</span> <a class="code" href="a00115.html" title="This class stores metadata about the classes in the library. The stored information...">MetaClass</a> *<a class="code" href="a00072.html#a7c19a634d92660bd4970feb92776d202">Forecast::metadata</a>;
<a name="l00037"></a>00037 <span class="keyword">const</span> <a class="code" href="a00115.html" title="This class stores metadata about the classes in the library. The stored information...">MetaClass</a> *<a class="code" href="a00073.html#ae08822e2f5a92d979c1b821666eacc9e">ForecastBucket::metadata</a>;
<a name="l00038"></a>00038 <span class="keywordtype">bool</span> ForecastBucket::DueAtEndOfBucket = <span class="keyword">false</span>;
<a name="l00039"></a>00039 
<a name="l00040"></a>00040 
<a name="l00041"></a><a class="code" href="a00072.html#a9229b49c623cbbb5fd02cdbabfd932f1">00041</a> <span class="keywordtype">int</span> <a class="code" href="a00072.html#a9229b49c623cbbb5fd02cdbabfd932f1">Forecast::initialize</a>()
<a name="l00042"></a>00042 {
<a name="l00043"></a>00043   <span class="comment">// Initialize the metadata</span>
<a name="l00044"></a>00044   <a class="code" href="a00072.html#a7c19a634d92660bd4970feb92776d202">metadata</a> = <span class="keyword">new</span> <a class="code" href="a00115.html" title="This class stores metadata about the classes in the library. The stored information...">MetaClass</a>(<span class="stringliteral">&quot;demand&quot;</span>, <span class="stringliteral">&quot;demand_forecast&quot;</span>,
<a name="l00045"></a>00045     Object::createString&lt;Forecast&gt;);
<a name="l00046"></a>00046 
<a name="l00047"></a>00047   <span class="comment">// Get notified when a calendar is deleted</span>
<a name="l00048"></a>00048   <a class="code" href="a00081.html" title="This class represents a static subscription to a signal.">FunctorStatic&lt;Calendar,Forecast&gt;::connect</a>(<a class="code" href="a00257.html#aec6d4a238b0cd9ffc8be8f10fd9b652fa6a5f44a606844db345f7c98cd402ecfb">SIG_REMOVE</a>);
<a name="l00049"></a>00049 
<a name="l00050"></a>00050   <span class="comment">// Initialize the Python class</span>
<a name="l00051"></a>00051   <a class="code" href="a00072.html#a305e46fd188147e4461826764b810146">FreppleClass&lt;Forecast,Demand&gt;::getType</a>().addMethod(<span class="stringliteral">&quot;timeseries&quot;</span>, <a class="code" href="a00072.html#a79267a1541b64718bf9136554d94441e">Forecast::timeseries</a>, METH_VARARGS,
<a name="l00052"></a>00052      <span class="stringliteral">&quot;Set the future based on the timeseries of historical data&quot;</span>);
<a name="l00053"></a>00053   <span class="keywordflow">return</span> <a class="code" href="a00072.html#a9229b49c623cbbb5fd02cdbabfd932f1">FreppleClass&lt;Forecast,Demand&gt;::initialize</a>();
<a name="l00054"></a>00054 }
<a name="l00055"></a>00055 
<a name="l00056"></a>00056 
<a name="l00057"></a><a class="code" href="a00073.html#ae569e5dc37d82f7e96a85b793965863b">00057</a> <span class="keywordtype">int</span> <a class="code" href="a00073.html#ae569e5dc37d82f7e96a85b793965863b">ForecastBucket::initialize</a>()
<a name="l00058"></a>00058 {
<a name="l00059"></a>00059   <span class="comment">// Initialize the metadata</span>
<a name="l00060"></a>00060   <span class="comment">// No factory method for this class</span>
<a name="l00061"></a>00061   <a class="code" href="a00073.html#ae08822e2f5a92d979c1b821666eacc9e">metadata</a> = <span class="keyword">new</span> <a class="code" href="a00115.html" title="This class stores metadata about the classes in the library. The stored information...">MetaClass</a>(<span class="stringliteral">&quot;demand&quot;</span>, <span class="stringliteral">&quot;demand_forecastbucket&quot;</span>);
<a name="l00062"></a>00062 
<a name="l00063"></a>00063   <span class="comment">// Initialize the Python class</span>
<a name="l00064"></a>00064   <span class="comment">// No support for creation</span>
<a name="l00065"></a>00065   <a class="code" href="a00155.html" title="This class is a thin wrapper around the type information in Python.">PythonType</a>&amp; x = <a class="code" href="a00073.html#a5cea298c43e94dfb24844c4ed8c071ba">FreppleClass&lt;ForecastBucket,Demand&gt;::getType</a>();
<a name="l00066"></a>00066   x.<a class="code" href="a00155.html#af9217b67c7c60e8e87c703066d6970d5">setName</a>(<span class="stringliteral">&quot;demand_forecastbucket&quot;</span>);
<a name="l00067"></a>00067   x.<a class="code" href="a00155.html#aaafe003660694b2cf497a89815d7fe49">setDoc</a>(<span class="stringliteral">&quot;frePPLe forecastbucket&quot;</span>);
<a name="l00068"></a>00068   x.<a class="code" href="a00155.html#a8d3f24e0357f41ac3bc0be78bd2ab268">supportgetattro</a>();
<a name="l00069"></a>00069   x.<a class="code" href="a00155.html#a83866bef191c69cf8506426fe38b8d19">supportsetattro</a>();
<a name="l00070"></a>00070   x.<a class="code" href="a00155.html#a23a670ed39c26ab20ec400cbe3618e6c">supportstr</a>();
<a name="l00071"></a>00071   x.<a class="code" href="a00155.html#ae96d28a03dbcf0e2b51100d8d2e6d621">supportcompare</a>();
<a name="l00072"></a>00072   x.<a class="code" href="a00155.html#a583846cf8dc2a5c91f5ebb9941039ae5">setBase</a>(Demand::metadata-&gt;pythonClass);
<a name="l00073"></a>00073   x.<a class="code" href="a00155.html#ab5950f891179f3ae7d31f4977580cb1d">addMethod</a>(<span class="stringliteral">&quot;toXML&quot;</span>, <a class="code" href="a00120.html#a936a4ac5b81ba4f9c9cbe54b9aeeda13">toXML</a>, METH_VARARGS, <span class="stringliteral">&quot;return a XML representation&quot;</span>);
<a name="l00074"></a>00074   <span class="keyword">const_cast&lt;</span><a class="code" href="a00115.html" title="This class stores metadata about the classes in the library. The stored information...">MetaClass</a>*<span class="keyword">&gt;</span>(<a class="code" href="a00073.html#ae08822e2f5a92d979c1b821666eacc9e">metadata</a>)-&gt;pythonClass = x.<a class="code" href="a00155.html#aed0915f1cc32c0c1e12e209abfedf615">type_object</a>();
<a name="l00075"></a>00075   <span class="keywordflow">return</span> x.<a class="code" href="a00155.html#a5b2be5d75982b077b2d694c269d43778">typeReady</a>();
<a name="l00076"></a>00076 }
<a name="l00077"></a>00077 
<a name="l00078"></a>00078 
<a name="l00079"></a><a class="code" href="a00072.html#a12d3e0aad8d9085fbc02e68dbadf7f53">00079</a> <span class="keywordtype">bool</span> <a class="code" href="a00072.html#a12d3e0aad8d9085fbc02e68dbadf7f53">Forecast::callback</a>(<a class="code" href="a00013.html" title="This is the class used to represent variables that are varying over time.">Calendar</a>* l, <span class="keyword">const</span> <a class="code" href="a00257.html#aec6d4a238b0cd9ffc8be8f10fd9b652f">Signal</a> a)
<a name="l00080"></a>00080 {
<a name="l00081"></a>00081   <span class="comment">// This function is called when a calendar is about to be deleted.</span>
<a name="l00082"></a>00082   <span class="comment">// If that calendar is being used for a forecast we reset the calendar</span>
<a name="l00083"></a>00083   <span class="comment">// pointer to null.</span>
<a name="l00084"></a>00084   <span class="keywordflow">for</span> (MapOfForecasts::iterator x = ForecastDictionary.begin();
<a name="l00085"></a>00085     x != ForecastDictionary.end(); ++x)
<a name="l00086"></a>00086     <span class="keywordflow">if</span> (x-&gt;second-&gt;calptr == l)
<a name="l00087"></a>00087       <span class="comment">// Calendar in use for this forecast</span>
<a name="l00088"></a>00088       x-&gt;second-&gt;calptr = NULL;
<a name="l00089"></a>00089   <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00090"></a>00090 }
<a name="l00091"></a>00091 
<a name="l00092"></a>00092 
<a name="l00093"></a><a class="code" href="a00072.html#a7faf92d7ccc10bd651be84bcb1269088">00093</a> <a class="code" href="a00072.html#a7faf92d7ccc10bd651be84bcb1269088">Forecast::~Forecast</a>()
<a name="l00094"></a>00094 {
<a name="l00095"></a>00095   <span class="comment">// Update the dictionary</span>
<a name="l00096"></a>00096   <span class="keywordflow">for</span> (MapOfForecasts::iterator x=
<a name="l00097"></a>00097     ForecastDictionary.lower_bound(make_pair(&amp;*<a class="code" href="a00051.html#a49f5ca2d8cf91112c41c1eaa04626889">getItem</a>(),&amp;*<a class="code" href="a00051.html#ada8b8f6e9163a3f334d9799d14c5a7ec">getCustomer</a>()));
<a name="l00098"></a>00098     x != ForecastDictionary.end(); ++x)
<a name="l00099"></a>00099     <span class="keywordflow">if</span> (x-&gt;second == <span class="keyword">this</span>)
<a name="l00100"></a>00100     {
<a name="l00101"></a>00101       ForecastDictionary.erase(x);
<a name="l00102"></a>00102       <span class="keywordflow">break</span>;
<a name="l00103"></a>00103     }
<a name="l00104"></a>00104 
<a name="l00105"></a>00105   <span class="comment">// Delete all children demands</span>
<a name="l00106"></a>00106   <span class="keywordflow">for</span>(<a class="code" href="a00083.html#af604aa38df25c5555db2cee12da24a23">memberIterator</a> i = <a class="code" href="a00083.html#a7afe3a1b114b7f7a93ecd68f56005dac">beginMember</a>(); i != <a class="code" href="a00083.html#a3861adc09dde2deb2ea0466cf46634ac">endMember</a>(); i = <a class="code" href="a00083.html#a7afe3a1b114b7f7a93ecd68f56005dac">beginMember</a>())
<a name="l00107"></a>00107     <span class="keyword">delete</span> &amp;*i;
<a name="l00108"></a>00108 }
<a name="l00109"></a>00109 
<a name="l00110"></a>00110 
<a name="l00111"></a>00111 <span class="keywordtype">void</span> Forecast::instantiate()
<a name="l00112"></a>00112 {
<a name="l00113"></a>00113   <span class="keywordflow">if</span> (!calptr) <span class="keywordflow">throw</span> <a class="code" href="a00048.html" title="An exception of this type is thrown when data errors are found.">DataException</a>(<span class="stringliteral">&quot;Missing forecast calendar&quot;</span>);
<a name="l00114"></a>00114 
<a name="l00115"></a>00115   <span class="comment">// Create a demand for every bucket. The weight value depends on the</span>
<a name="l00116"></a>00116   <span class="comment">// calendar type: double, integer, bool or other</span>
<a name="l00117"></a>00117   <span class="keyword">const</span> <a class="code" href="a00016.html" title="A calendar storing double values in its buckets.">CalendarDouble</a>* c = <span class="keyword">dynamic_cast&lt;</span><span class="keyword">const </span><a class="code" href="a00016.html" title="A calendar storing double values in its buckets.">CalendarDouble</a>*<span class="keyword">&gt;</span>(calptr);
<a name="l00118"></a>00118   <a class="code" href="a00073.html" title="This class represents a forecast value in a time bucket.">ForecastBucket</a>* prev = NULL;
<a name="l00119"></a>00119   <a class="code" href="a00049.html" title="This class represents a date and time with an accuracy of one second.">Date</a> prevDate;
<a name="l00120"></a>00120   <span class="keywordtype">double</span> prevValue(0.0);
<a name="l00121"></a>00121   <span class="keywordflow">if</span> (c)
<a name="l00122"></a>00122     <span class="comment">// Double calendar</span>
<a name="l00123"></a>00123     <span class="keywordflow">for</span> (CalendarDouble::EventIterator i(c); i.getDate()&lt;=Date::infiniteFuture; ++i)
<a name="l00124"></a>00124     {
<a name="l00125"></a>00125       <span class="keywordflow">if</span> ((prevDate || i.getDate() == Date::infiniteFuture) &amp;&amp; prevValue &gt; 0.0)
<a name="l00126"></a>00126       {
<a name="l00127"></a>00127         prev = <span class="keyword">new</span> <a class="code" href="a00073.html" title="This class represents a forecast value in a time bucket.">ForecastBucket</a>
<a name="l00128"></a>00128           (<span class="keyword">this</span>, prevDate, i.getDate(), prevValue, prev);
<a name="l00129"></a>00129         <a class="code" href="a00085.html#a63b0e8c75aecc6fde9f4053ece52fde0">Demand::add</a>(prev);
<a name="l00130"></a>00130       }
<a name="l00131"></a>00131       <span class="keywordflow">if</span> (i.getDate() == Date::infiniteFuture) <span class="keywordflow">break</span>;
<a name="l00132"></a>00132       prevDate = i.getDate();
<a name="l00133"></a>00133       prevValue = i.getValue();
<a name="l00134"></a>00134     }
<a name="l00135"></a>00135   <span class="keywordflow">else</span>
<a name="l00136"></a>00136   {
<a name="l00137"></a>00137     <span class="keyword">const</span> <a class="code" href="a00018.html" title="A calendar storing integer values in its buckets.">CalendarInt</a>* c = <span class="keyword">dynamic_cast&lt;</span><span class="keyword">const </span><a class="code" href="a00018.html" title="A calendar storing integer values in its buckets.">CalendarInt</a>*<span class="keyword">&gt;</span>(calptr);
<a name="l00138"></a>00138     <span class="keywordflow">if</span> (c)
<a name="l00139"></a>00139       <span class="comment">// Integer calendar</span>
<a name="l00140"></a>00140       <span class="keywordflow">for</span> (CalendarInt::EventIterator i(c); i.getDate()&lt;=Date::infiniteFuture; ++i)
<a name="l00141"></a>00141       {
<a name="l00142"></a>00142         <span class="keywordflow">if</span> ((prevDate || i.getDate() == Date::infiniteFuture) &amp;&amp; prevValue &gt; 0)
<a name="l00143"></a>00143         {
<a name="l00144"></a>00144           prev = <span class="keyword">new</span> ForecastBucket
<a name="l00145"></a>00145             (<span class="keyword">this</span>, prevDate, i.getDate(), prevValue, prev);
<a name="l00146"></a>00146           <a class="code" href="a00085.html#a63b0e8c75aecc6fde9f4053ece52fde0">Demand::add</a>(prev);
<a name="l00147"></a>00147         }
<a name="l00148"></a>00148         <span class="keywordflow">if</span> (i.getDate() == Date::infiniteFuture) <span class="keywordflow">break</span>;
<a name="l00149"></a>00149         prevDate = i.getDate();
<a name="l00150"></a>00150         prevValue = <span class="keyword">static_cast&lt;</span><span class="keywordtype">double</span><span class="keyword">&gt;</span>(i.getValue());
<a name="l00151"></a>00151       }
<a name="l00152"></a>00152     <span class="keywordflow">else</span>
<a name="l00153"></a>00153     {
<a name="l00154"></a>00154       <span class="keyword">const</span> <a class="code" href="a00014.html" title="A calendar storing boolean values in its buckets.">CalendarBool</a>* c = <span class="keyword">dynamic_cast&lt;</span><span class="keyword">const </span><a class="code" href="a00014.html" title="A calendar storing boolean values in its buckets.">CalendarBool</a>*<span class="keyword">&gt;</span>(calptr);
<a name="l00155"></a>00155       <span class="keywordtype">bool</span> prevValueBool = <span class="keyword">false</span>;
<a name="l00156"></a>00156       <span class="keywordflow">if</span> (c)
<a name="l00157"></a>00157         <span class="comment">// Boolean calendar</span>
<a name="l00158"></a>00158         <span class="keywordflow">for</span> (CalendarBool::EventIterator i(c); <span class="keyword">true</span>; ++i)
<a name="l00159"></a>00159         {
<a name="l00160"></a>00160           <span class="keywordflow">if</span> ((prevDate || i.getDate() == Date::infiniteFuture) &amp;&amp; prevValueBool)
<a name="l00161"></a>00161           {
<a name="l00162"></a>00162             prev = <span class="keyword">new</span> ForecastBucket
<a name="l00163"></a>00163                 (<span class="keyword">this</span>, prevDate, i.getDate(), 1.0, prev);
<a name="l00164"></a>00164             <a class="code" href="a00085.html#a63b0e8c75aecc6fde9f4053ece52fde0">Demand::add</a>(prev);
<a name="l00165"></a>00165             }
<a name="l00166"></a>00166           <span class="keywordflow">if</span> (i.getDate() == Date::infiniteFuture) <span class="keywordflow">break</span>;
<a name="l00167"></a>00167           prevDate = i.getDate();
<a name="l00168"></a>00168           prevValueBool = i.getValue();
<a name="l00169"></a>00169         }
<a name="l00170"></a>00170       <span class="keywordflow">else</span>
<a name="l00171"></a>00171       {
<a name="l00172"></a>00172         <span class="comment">// Other calendar</span>
<a name="l00173"></a>00173         <span class="keywordflow">for</span> (<a class="code" href="a00061.html" title="An iterator class to go through all dates where the calendar value changes.">Calendar::EventIterator</a> i(calptr); <span class="keyword">true</span>; ++i)
<a name="l00174"></a>00174         {
<a name="l00175"></a>00175           <span class="keywordflow">if</span> (prevDate || i.getDate() == Date::infiniteFuture)
<a name="l00176"></a>00176           {
<a name="l00177"></a>00177             prev = <span class="keyword">new</span> ForecastBucket(<span class="keyword">this</span>, prevDate, i.getDate(), 1.0, prev);
<a name="l00178"></a>00178             <a class="code" href="a00085.html#a63b0e8c75aecc6fde9f4053ece52fde0">Demand::add</a>(prev);
<a name="l00179"></a>00179             <span class="keywordflow">if</span> (i.getDate() == Date::infiniteFuture) <span class="keywordflow">break</span>;
<a name="l00180"></a>00180           }
<a name="l00181"></a>00181           prevDate = i.getDate();
<a name="l00182"></a>00182         }
<a name="l00183"></a>00183       }
<a name="l00184"></a>00184     }
<a name="l00185"></a>00185   }
<a name="l00186"></a>00186 }
<a name="l00187"></a>00187 
<a name="l00188"></a>00188 
<a name="l00189"></a><a class="code" href="a00072.html#aec4536cbcd5b29f2e64e71424957c9af">00189</a> <span class="keywordtype">void</span> <a class="code" href="a00072.html#aec4536cbcd5b29f2e64e71424957c9af">Forecast::setDiscrete</a>(<span class="keyword">const</span> <span class="keywordtype">bool</span> b)
<a name="l00190"></a>00190 {
<a name="l00191"></a>00191   <span class="comment">// Update the flag</span>
<a name="l00192"></a>00192   discrete = b;
<a name="l00193"></a>00193 
<a name="l00194"></a>00194   <span class="comment">// Round down any forecast demands that may already exist.</span>
<a name="l00195"></a>00195   <span class="keywordflow">if</span> (discrete)
<a name="l00196"></a>00196     <span class="keywordflow">for</span> (<a class="code" href="a00083.html#af604aa38df25c5555db2cee12da24a23">memberIterator</a> m = <a class="code" href="a00083.html#a7afe3a1b114b7f7a93ecd68f56005dac">beginMember</a>(); m!=<a class="code" href="a00083.html#a3861adc09dde2deb2ea0466cf46634ac">endMember</a>(); ++m)
<a name="l00197"></a>00197       m-&gt;setQuantity(floor(m-&gt;getQuantity()));
<a name="l00198"></a>00198 }
<a name="l00199"></a>00199 
<a name="l00200"></a>00200 
<a name="l00201"></a><a class="code" href="a00072.html#a6a95cdf8571fcb91179a215e40f991e2">00201</a> <span class="keywordtype">void</span> <a class="code" href="a00072.html#a6a95cdf8571fcb91179a215e40f991e2">Forecast::setTotalQuantity</a>(<span class="keyword">const</span> <a class="code" href="a00050.html" title="This class defines a date-range, i.e. a start-date and end-date pair.">DateRange</a>&amp; d, <span class="keywordtype">double</span> f)
<a name="l00202"></a>00202 {
<a name="l00203"></a>00203   <span class="comment">// Initialize, if not done yet</span>
<a name="l00204"></a>00204   <span class="keywordflow">if</span> (!<a class="code" href="a00083.html#ad4e04677c1fd0b008267a1a55225705d">isGroup</a>()) instantiate();
<a name="l00205"></a>00205 
<a name="l00206"></a>00206   <span class="comment">// Find all forecast demands, and sum their weights</span>
<a name="l00207"></a>00207   <span class="keywordtype">double</span> weights = 0.0;
<a name="l00208"></a>00208   <span class="keywordflow">for</span> (<a class="code" href="a00083.html#af604aa38df25c5555db2cee12da24a23">memberIterator</a> m = <a class="code" href="a00083.html#a7afe3a1b114b7f7a93ecd68f56005dac">beginMember</a>(); m!=<a class="code" href="a00083.html#a3861adc09dde2deb2ea0466cf46634ac">endMember</a>(); ++m)
<a name="l00209"></a>00209   {
<a name="l00210"></a>00210     <a class="code" href="a00073.html" title="This class represents a forecast value in a time bucket.">ForecastBucket</a>* x = <span class="keyword">dynamic_cast&lt;</span><a class="code" href="a00073.html" title="This class represents a forecast value in a time bucket.">ForecastBucket</a>*<span class="keyword">&gt;</span>(&amp;*m);
<a name="l00211"></a>00211     <span class="keywordflow">if</span> (!x)
<a name="l00212"></a>00212       <span class="keywordflow">throw</span> <a class="code" href="a00048.html" title="An exception of this type is thrown when data errors are found.">DataException</a>(<span class="stringliteral">&quot;Invalid subdemand of forecast &apos;&quot;</span> + <a class="code" href="a00182.html#a7416ca220c55147bc1276becc5b9de01">getName</a>() +<span class="stringliteral">&quot;&apos;&quot;</span>);
<a name="l00213"></a>00213     <span class="keywordflow">if</span> (d.<a class="code" href="a00050.html#a0bffe72b2f8c5c70a23c293349c074fd">intersect</a>(x-&gt;<a class="code" href="a00073.html#a86fcfc356492a8ad2ec2a07219331eb7">getDueRange</a>()))
<a name="l00214"></a>00214     {
<a name="l00215"></a>00215       <span class="comment">// Bucket intersects with daterange</span>
<a name="l00216"></a>00216       <span class="keywordflow">if</span> (!d.<a class="code" href="a00050.html#ab3020816550bbe0fa227b5121c6697f0">getDuration</a>())
<a name="l00217"></a>00217       {
<a name="l00218"></a>00218         <span class="comment">// Single date provided. Update that one bucket.</span>
<a name="l00219"></a>00219         x-&gt;<a class="code" href="a00073.html#a7efb5987d5d43cce60d9b36312c16b18">setTotal</a>(f);
<a name="l00220"></a>00220         <span class="keywordflow">return</span>;
<a name="l00221"></a>00221       }
<a name="l00222"></a>00222       weights += x-&gt;<a class="code" href="a00073.html#aa39b372e48be5f516cb364ed0d025635">getWeight</a>() * <span class="keyword">static_cast&lt;</span><span class="keywordtype">long</span><span class="keyword">&gt;</span>(x-&gt;<a class="code" href="a00073.html#a86fcfc356492a8ad2ec2a07219331eb7">getDueRange</a>().<a class="code" href="a00050.html#a2e274b28b08fbe066b8b7c58542f774c">overlap</a>(d));
<a name="l00223"></a>00223     }
<a name="l00224"></a>00224   }
<a name="l00225"></a>00225 
<a name="l00226"></a>00226   <span class="comment">// Expect to find at least one non-zero weight...</span>
<a name="l00227"></a>00227   <span class="keywordflow">if</span> (!weights)
<a name="l00228"></a>00228     <span class="keywordflow">throw</span> <a class="code" href="a00048.html" title="An exception of this type is thrown when data errors are found.">DataException</a>(<span class="stringliteral">&quot;No valid forecast date in range &quot;</span>
<a name="l00229"></a>00229       + <span class="keywordtype">string</span>(d) + <span class="stringliteral">&quot; of forecast &apos;&quot;</span> + <a class="code" href="a00182.html#a7416ca220c55147bc1276becc5b9de01">getName</a>() +<span class="stringliteral">&quot;&apos;&quot;</span>);
<a name="l00230"></a>00230 
<a name="l00231"></a>00231   <span class="comment">// Update the forecast quantity, respecting the weights</span>
<a name="l00232"></a>00232   f /= weights;
<a name="l00233"></a>00233   <span class="keywordtype">double</span> carryover = 0.0;
<a name="l00234"></a>00234   <span class="keywordflow">for</span> (<a class="code" href="a00083.html#af604aa38df25c5555db2cee12da24a23">memberIterator</a> m = <a class="code" href="a00083.html#a7afe3a1b114b7f7a93ecd68f56005dac">beginMember</a>(); m!=<a class="code" href="a00083.html#a3861adc09dde2deb2ea0466cf46634ac">endMember</a>(); ++m)
<a name="l00235"></a>00235   {
<a name="l00236"></a>00236     <a class="code" href="a00073.html" title="This class represents a forecast value in a time bucket.">ForecastBucket</a>* x = <span class="keyword">dynamic_cast&lt;</span><a class="code" href="a00073.html" title="This class represents a forecast value in a time bucket.">ForecastBucket</a>*<span class="keyword">&gt;</span>(&amp;*m);
<a name="l00237"></a>00237     <span class="keywordflow">if</span> (d.<a class="code" href="a00050.html#a0bffe72b2f8c5c70a23c293349c074fd">intersect</a>(x-&gt;<a class="code" href="a00073.html#a86fcfc356492a8ad2ec2a07219331eb7">getDueRange</a>()))
<a name="l00238"></a>00238     {
<a name="l00239"></a>00239       <span class="comment">// Bucket intersects with daterange</span>
<a name="l00240"></a>00240       <a class="code" href="a00179.html" title="This class represents a time duration with an accuracy of one second.">TimePeriod</a> o = x-&gt;<a class="code" href="a00073.html#a86fcfc356492a8ad2ec2a07219331eb7">getDueRange</a>().<a class="code" href="a00050.html#a2e274b28b08fbe066b8b7c58542f774c">overlap</a>(d);
<a name="l00241"></a>00241       <span class="keywordtype">double</span> percent = x-&gt;<a class="code" href="a00073.html#aa39b372e48be5f516cb364ed0d025635">getWeight</a>() * <span class="keyword">static_cast&lt;</span><span class="keywordtype">long</span><span class="keyword">&gt;</span>(o);
<a name="l00242"></a>00242       <span class="keywordflow">if</span> (<a class="code" href="a00072.html#a64b5b2b91ee5408e10d8a4e3748ec1f5">getDiscrete</a>())
<a name="l00243"></a>00243       {
<a name="l00244"></a>00244         <span class="comment">// Rounding to discrete numbers</span>
<a name="l00245"></a>00245         carryover += f * percent;
<a name="l00246"></a>00246         <span class="keywordtype">int</span> intdelta = <span class="keyword">static_cast&lt;</span><span class="keywordtype">int</span><span class="keyword">&gt;</span>(ceil(carryover - 0.5));
<a name="l00247"></a>00247         carryover -= intdelta;
<a name="l00248"></a>00248         <span class="keywordflow">if</span> (o &lt; x-&gt;getDueRange().getDuration())
<a name="l00249"></a>00249           <span class="comment">// The bucket is only partially updated</span>
<a name="l00250"></a>00250           x-&gt;<a class="code" href="a00073.html#a3f19f8587d8748ff1c922f903a743c62">incTotal</a>(static_cast&lt;double&gt;(intdelta));
<a name="l00251"></a>00251         <span class="keywordflow">else</span>
<a name="l00252"></a>00252           <span class="comment">// The bucket is completely updated</span>
<a name="l00253"></a>00253           x-&gt;<a class="code" href="a00073.html#a7efb5987d5d43cce60d9b36312c16b18">setTotal</a>(static_cast&lt;double&gt;(intdelta));
<a name="l00254"></a>00254       }
<a name="l00255"></a>00255       <span class="keywordflow">else</span>
<a name="l00256"></a>00256       {
<a name="l00257"></a>00257         <span class="comment">// No rounding</span>
<a name="l00258"></a>00258         <span class="keywordflow">if</span> (o &lt; x-&gt;getDueRange().getDuration())
<a name="l00259"></a>00259           <span class="comment">// The bucket is only partially updated</span>
<a name="l00260"></a>00260           x-&gt;<a class="code" href="a00073.html#a3f19f8587d8748ff1c922f903a743c62">incTotal</a>(f * percent);
<a name="l00261"></a>00261         <span class="keywordflow">else</span>
<a name="l00262"></a>00262           <span class="comment">// The bucket is completely updated</span>
<a name="l00263"></a>00263           x-&gt;<a class="code" href="a00073.html#a7efb5987d5d43cce60d9b36312c16b18">setTotal</a>(f * percent);
<a name="l00264"></a>00264       }
<a name="l00265"></a>00265     }
<a name="l00266"></a>00266   }
<a name="l00267"></a>00267 }
<a name="l00268"></a>00268 
<a name="l00269"></a>00269 
<a name="l00270"></a><a class="code" href="a00072.html#a0d4e1372b309d8a5d1efbe4e8049621c">00270</a> <span class="keywordtype">void</span> <a class="code" href="a00072.html#a0d4e1372b309d8a5d1efbe4e8049621c">Forecast::writeElement</a>(<a class="code" href="a00189.html" title="Base class for writing XML formatted data to an output stream.">XMLOutput</a> *o, <span class="keyword">const</span> <a class="code" href="a00096.html" title="This class defines a keyword for the frePPLe data model.">Keyword</a> &amp;tag, <a class="code" href="a00257.html#a20c2c7e4c6b668e71c154ae3eb18f398">mode</a> m)<span class="keyword"> const</span>
<a name="l00271"></a>00271 <span class="keyword"></span>{
<a name="l00272"></a>00272   <span class="comment">// Writing a reference</span>
<a name="l00273"></a>00273   <span class="keywordflow">if</span> (m == <a class="code" href="a00257.html#a20c2c7e4c6b668e71c154ae3eb18f398a874240ada53cc5b608466064d86d91ae">REFERENCE</a>)
<a name="l00274"></a>00274   {
<a name="l00275"></a>00275     o-&gt;<a class="code" href="a00189.html#a711922eea4cfe3c33b97e4188dacc7d2">writeElement</a>
<a name="l00276"></a>00276     (tag, <a class="code" href="a00177.html#aeb3841a93774dfc303e3df16304b5af2">Tags::tag_name</a>, <a class="code" href="a00182.html#a7416ca220c55147bc1276becc5b9de01">getName</a>(), <a class="code" href="a00177.html#a6745112e0237e378e2b0cbe41aa5926a">Tags::tag_type</a>, <a class="code" href="a00072.html#a305e46fd188147e4461826764b810146">getType</a>().<a class="code" href="a00051.html" title="Represents the (independent) demand in the system. It can represent a customer order...">type</a>);
<a name="l00277"></a>00277     <span class="keywordflow">return</span>;
<a name="l00278"></a>00278   }
<a name="l00279"></a>00279 
<a name="l00280"></a>00280   <span class="comment">// Write the complete object</span>
<a name="l00281"></a>00281   <span class="keywordflow">if</span> (m != <a class="code" href="a00257.html#a20c2c7e4c6b668e71c154ae3eb18f398a2ad5e75fe119e297630882d182832243">NOHEADER</a>) o-&gt;<a class="code" href="a00189.html#a5c1811dae2e3eae344ad366f6441a8a5">BeginObject</a>
<a name="l00282"></a>00282     (tag, <a class="code" href="a00177.html#aeb3841a93774dfc303e3df16304b5af2">Tags::tag_name</a>, <a class="code" href="a00182.html#a7416ca220c55147bc1276becc5b9de01">getName</a>(), <a class="code" href="a00177.html#a6745112e0237e378e2b0cbe41aa5926a">Tags::tag_type</a>, <a class="code" href="a00072.html#a305e46fd188147e4461826764b810146">getType</a>().<a class="code" href="a00051.html" title="Represents the (independent) demand in the system. It can represent a customer order...">type</a>);
<a name="l00283"></a>00283 
<a name="l00284"></a>00284   o-&gt;<a class="code" href="a00189.html#a711922eea4cfe3c33b97e4188dacc7d2">writeElement</a>(<a class="code" href="a00177.html#a9503f5b5b382603919b72bf295c6bb95">Tags::tag_item</a>, &amp;*<a class="code" href="a00051.html#a49f5ca2d8cf91112c41c1eaa04626889">getItem</a>());
<a name="l00285"></a>00285   o-&gt;<a class="code" href="a00189.html#a711922eea4cfe3c33b97e4188dacc7d2">writeElement</a>(<a class="code" href="a00177.html#ad70b79a1c1f3f6d13539207da4f19609">Tags::tag_operation</a>, &amp;*<a class="code" href="a00051.html#a34558d9117ff82e4c84cbccf99334db1">getOperation</a>());
<a name="l00286"></a>00286   <span class="keywordflow">if</span> (<a class="code" href="a00051.html#a312655c39f5d5acc4db3676c9a741a45">getPriority</a>()) o-&gt;<a class="code" href="a00189.html#a711922eea4cfe3c33b97e4188dacc7d2">writeElement</a>(<a class="code" href="a00177.html#af594a7455ab0f7ee255eab14acb44229">Tags::tag_priority</a>, <a class="code" href="a00051.html#a312655c39f5d5acc4db3676c9a741a45">getPriority</a>());
<a name="l00287"></a>00287   o-&gt;<a class="code" href="a00189.html#a711922eea4cfe3c33b97e4188dacc7d2">writeElement</a>(<a class="code" href="a00177.html#af73b7397b82ca602df4b4e35a2fa41c0">Tags::tag_calendar</a>, calptr);
<a name="l00288"></a>00288   <span class="keywordflow">if</span> (!<a class="code" href="a00072.html#a64b5b2b91ee5408e10d8a4e3748ec1f5">getDiscrete</a>()) o-&gt;<a class="code" href="a00189.html#a711922eea4cfe3c33b97e4188dacc7d2">writeElement</a>(<a class="code" href="a00177.html#aed69995b3ea237df03211c52edfe2a3e">Tags::tag_discrete</a>, <a class="code" href="a00072.html#a64b5b2b91ee5408e10d8a4e3748ec1f5">getDiscrete</a>());
<a name="l00289"></a>00289 
<a name="l00290"></a>00290   <span class="comment">// Write all entries</span>
<a name="l00291"></a>00291   o-&gt;<a class="code" href="a00189.html#a5c1811dae2e3eae344ad366f6441a8a5">BeginObject</a> (<a class="code" href="a00177.html#a30dbb2b364e7933ce57f1ba25e01d8a6">Tags::tag_buckets</a>);
<a name="l00292"></a>00292   <span class="keywordflow">for</span> (<a class="code" href="a00083.html#af604aa38df25c5555db2cee12da24a23">memberIterator</a> i = <a class="code" href="a00083.html#a7afe3a1b114b7f7a93ecd68f56005dac">beginMember</a>(); i != <a class="code" href="a00083.html#a3861adc09dde2deb2ea0466cf46634ac">endMember</a>(); ++i)
<a name="l00293"></a>00293   {
<a name="l00294"></a>00294     <a class="code" href="a00073.html" title="This class represents a forecast value in a time bucket.">ForecastBucket</a>* f = <span class="keyword">dynamic_cast&lt;</span><a class="code" href="a00073.html" title="This class represents a forecast value in a time bucket.">ForecastBucket</a>*<span class="keyword">&gt;</span>(&amp;*i);
<a name="l00295"></a>00295     o-&gt;<a class="code" href="a00189.html#a5c1811dae2e3eae344ad366f6441a8a5">BeginObject</a>(<a class="code" href="a00177.html#abf195fcbb64c846ed9c187eabbb45c94">Tags::tag_bucket</a>, <a class="code" href="a00177.html#ae9fda65e25c8720724e21b35138deec0">Tags::tag_start</a>, <span class="keywordtype">string</span>(f-&gt;<a class="code" href="a00051.html#ab21889e9a16e3701a84ba8f3aa68628b">getDue</a>()));
<a name="l00296"></a>00296     o-&gt;<a class="code" href="a00189.html#a711922eea4cfe3c33b97e4188dacc7d2">writeElement</a>(<a class="code" href="a00072.html#a8f1b1910feb8fcaa9d2a261949cfbb67">tag_total</a>, f-&gt;<a class="code" href="a00073.html#ad8b6e29264104892adfafdc78e8e17db">getTotal</a>());
<a name="l00297"></a>00297     o-&gt;<a class="code" href="a00189.html#a711922eea4cfe3c33b97e4188dacc7d2">writeElement</a>(<a class="code" href="a00177.html#ab99ddcbeef0f5d15a8731dcdffa0dcff">Tags::tag_quantity</a>, f-&gt;<a class="code" href="a00051.html#af5fe6f1b6e8f9b2c24ce3479b6546444">getQuantity</a>());
<a name="l00298"></a>00298     o-&gt;<a class="code" href="a00189.html#a711922eea4cfe3c33b97e4188dacc7d2">writeElement</a>(<a class="code" href="a00072.html#aa00855cb99c427b85ed329cf22634431">tag_consumed</a>, f-&gt;<a class="code" href="a00073.html#a501b4d69cf41b838649a50eb2aef4c9c">getConsumed</a>());
<a name="l00299"></a>00299     o-&gt;<a class="code" href="a00189.html#a05375aa593bb0514020b035411c8983c">EndObject</a>(<a class="code" href="a00177.html#abf195fcbb64c846ed9c187eabbb45c94">Tags::tag_bucket</a>);
<a name="l00300"></a>00300   }
<a name="l00301"></a>00301   o-&gt;<a class="code" href="a00189.html#a05375aa593bb0514020b035411c8983c">EndObject</a>(<a class="code" href="a00177.html#a30dbb2b364e7933ce57f1ba25e01d8a6">Tags::tag_buckets</a>);
<a name="l00302"></a>00302 
<a name="l00303"></a>00303   o-&gt;<a class="code" href="a00189.html#a05375aa593bb0514020b035411c8983c">EndObject</a>(tag);
<a name="l00304"></a>00304 }
<a name="l00305"></a>00305 
<a name="l00306"></a>00306 
<a name="l00307"></a><a class="code" href="a00072.html#a7684ca786326565eb2f7ceed1a821c5d">00307</a> <span class="keywordtype">void</span> <a class="code" href="a00072.html#a7684ca786326565eb2f7ceed1a821c5d">Forecast::endElement</a>(<a class="code" href="a00186.html" title="This class will read in an XML-file and call the appropriate handler functions of...">XMLInput</a>&amp; pIn, <span class="keyword">const</span> <a class="code" href="a00002.html" title="A class to model keyword instances.">Attribute</a>&amp; pAttr, <span class="keyword">const</span> <a class="code" href="a00047.html" title="This abstract class represents a attribute and value pair for updating objects in...">DataElement</a>&amp; pElement)
<a name="l00308"></a>00308 {
<a name="l00309"></a>00309   <span class="comment">// While reading forecast buckets, we use the userarea field on the input</span>
<a name="l00310"></a>00310   <span class="comment">// to cache the data. The temporary object is deleted when the bucket</span>
<a name="l00311"></a>00311   <span class="comment">// tag is closed.</span>
<a name="l00312"></a>00312   <span class="keywordflow">if</span> (pAttr.<a class="code" href="a00002.html#aebffce6c4fcf1696ca34f63f2b6ee091">isA</a>(<a class="code" href="a00177.html#af73b7397b82ca602df4b4e35a2fa41c0">Tags::tag_calendar</a>))
<a name="l00313"></a>00313   {
<a name="l00314"></a>00314     <a class="code" href="a00013.html" title="This is the class used to represent variables that are varying over time.">Calendar</a> *b = <span class="keyword">dynamic_cast&lt;</span><a class="code" href="a00013.html" title="This is the class used to represent variables that are varying over time.">Calendar</a>*<span class="keyword">&gt;</span>(pIn.<a class="code" href="a00186.html#a98008d76b6971b2592ee5ae6f0f03d4c">getPreviousObject</a>());
<a name="l00315"></a>00315     <span class="keywordflow">if</span> (b) <a class="code" href="a00072.html#a1cb40a614cc39d2121edba4912fd5847">setCalendar</a>(b);
<a name="l00316"></a>00316     <span class="keywordflow">else</span> <span class="keywordflow">throw</span> <a class="code" href="a00111.html" title="An exception of this type is thrown when the library gets in an inconsistent state...">LogicException</a>(<span class="stringliteral">&quot;Incorrect object type during read operation&quot;</span>);
<a name="l00317"></a>00317   }
<a name="l00318"></a>00318   <span class="keywordflow">else</span> <span class="keywordflow">if</span> (pAttr.<a class="code" href="a00002.html#aebffce6c4fcf1696ca34f63f2b6ee091">isA</a>(<a class="code" href="a00177.html#aed69995b3ea237df03211c52edfe2a3e">Tags::tag_discrete</a>))
<a name="l00319"></a>00319     <a class="code" href="a00072.html#aec4536cbcd5b29f2e64e71424957c9af">setDiscrete</a>(pElement.<a class="code" href="a00047.html#a542b814710b3242bd4c81aad2fc269d8">getBool</a>());
<a name="l00320"></a>00320   <span class="keywordflow">else</span> <span class="keywordflow">if</span> (pAttr.<a class="code" href="a00002.html#aebffce6c4fcf1696ca34f63f2b6ee091">isA</a>(<a class="code" href="a00177.html#abf195fcbb64c846ed9c187eabbb45c94">Tags::tag_bucket</a>))
<a name="l00321"></a>00321   {
<a name="l00322"></a>00322     pair&lt;DateRange,double&gt; *d =
<a name="l00323"></a>00323       <span class="keyword">static_cast&lt;</span> pair&lt;DateRange,double&gt;* <span class="keyword">&gt;</span>(pIn.<a class="code" href="a00186.html#a656f44229f4251a26773decd010caaaf">getUserArea</a>());
<a name="l00324"></a>00324     <span class="keywordflow">if</span> (d)
<a name="l00325"></a>00325     {
<a name="l00326"></a>00326       <span class="comment">// Update the forecast quantities</span>
<a name="l00327"></a>00327       <a class="code" href="a00072.html#a6a95cdf8571fcb91179a215e40f991e2">setTotalQuantity</a>(d-&gt;first, d-&gt;second);
<a name="l00328"></a>00328       <span class="comment">// Clear the read buffer</span>
<a name="l00329"></a>00329       d-&gt;first.setStart(<a class="code" href="a00049.html" title="This class represents a date and time with an accuracy of one second.">Date</a>());
<a name="l00330"></a>00330       d-&gt;first.setEnd(<a class="code" href="a00049.html" title="This class represents a date and time with an accuracy of one second.">Date</a>());
<a name="l00331"></a>00331       d-&gt;second = 0;
<a name="l00332"></a>00332     }
<a name="l00333"></a>00333   }
<a name="l00334"></a>00334   <span class="keywordflow">else</span> <span class="keywordflow">if</span> (pIn.<a class="code" href="a00186.html#a407522e9d0dde7f7eebfafe182d050cf">getParentElement</a>().first.isA(<a class="code" href="a00177.html#abf195fcbb64c846ed9c187eabbb45c94">Tags::tag_bucket</a>))
<a name="l00335"></a>00335   {
<a name="l00336"></a>00336     pair&lt;DateRange,double&gt; *d =
<a name="l00337"></a>00337       <span class="keyword">static_cast&lt;</span> pair&lt;DateRange,double&gt;* <span class="keyword">&gt;</span>(pIn.<a class="code" href="a00186.html#a656f44229f4251a26773decd010caaaf">getUserArea</a>());
<a name="l00338"></a>00338     <span class="keywordflow">if</span> (pAttr.<a class="code" href="a00002.html#aebffce6c4fcf1696ca34f63f2b6ee091">isA</a>(<a class="code" href="a00072.html#a8f1b1910feb8fcaa9d2a261949cfbb67">tag_total</a>))
<a name="l00339"></a>00339     {
<a name="l00340"></a>00340       <span class="keywordflow">if</span> (d) d-&gt;second = pElement.<a class="code" href="a00047.html#a88f1178689f984215c4bef4eb5a0d5d9">getDouble</a>();
<a name="l00341"></a>00341       <span class="keywordflow">else</span> pIn.<a class="code" href="a00186.html#af76fa6f3fe40bd167a36b4ab859e0ff6">setUserArea</a>(
<a name="l00342"></a>00342         <span class="keyword">new</span> pair&lt;DateRange,double&gt;(<a class="code" href="a00050.html" title="This class defines a date-range, i.e. a start-date and end-date pair.">DateRange</a>(),pElement.<a class="code" href="a00047.html#a88f1178689f984215c4bef4eb5a0d5d9">getDouble</a>())
<a name="l00343"></a>00343         );
<a name="l00344"></a>00344     }
<a name="l00345"></a>00345     <span class="keywordflow">else</span> <span class="keywordflow">if</span> (pAttr.<a class="code" href="a00002.html#aebffce6c4fcf1696ca34f63f2b6ee091">isA</a>(<a class="code" href="a00177.html#ae9fda65e25c8720724e21b35138deec0">Tags::tag_start</a>))
<a name="l00346"></a>00346     {
<a name="l00347"></a>00347       <a class="code" href="a00049.html" title="This class represents a date and time with an accuracy of one second.">Date</a> x = pElement.<a class="code" href="a00047.html#abe8c2019e5f79328a6a1fa1f3bb4bbae">getDate</a>();
<a name="l00348"></a>00348       <span class="keywordflow">if</span> (d)
<a name="l00349"></a>00349       {
<a name="l00350"></a>00350         <span class="keywordflow">if</span> (!d-&gt;first.getStart()) d-&gt;first.setStartAndEnd(x,x);
<a name="l00351"></a>00351         <span class="keywordflow">else</span> d-&gt;first.setStart(x);
<a name="l00352"></a>00352       }
<a name="l00353"></a>00353       <span class="keywordflow">else</span> pIn.<a class="code" href="a00186.html#af76fa6f3fe40bd167a36b4ab859e0ff6">setUserArea</a>(<span class="keyword">new</span> pair&lt;DateRange,double&gt;(<a class="code" href="a00050.html" title="This class defines a date-range, i.e. a start-date and end-date pair.">DateRange</a>(x,x),0));
<a name="l00354"></a>00354     }
<a name="l00355"></a>00355     <span class="keywordflow">else</span> <span class="keywordflow">if</span> (pAttr.<a class="code" href="a00002.html#aebffce6c4fcf1696ca34f63f2b6ee091">isA</a>(<a class="code" href="a00177.html#ae7b833aedeada2860688b90cb947cdb2">Tags::tag_end</a>))
<a name="l00356"></a>00356     {
<a name="l00357"></a>00357       <a class="code" href="a00049.html" title="This class represents a date and time with an accuracy of one second.">Date</a> x = pElement.<a class="code" href="a00047.html#abe8c2019e5f79328a6a1fa1f3bb4bbae">getDate</a>();
<a name="l00358"></a>00358       <span class="keywordflow">if</span> (d)
<a name="l00359"></a>00359       {
<a name="l00360"></a>00360         <span class="keywordflow">if</span> (!d-&gt;first.getStart()) d-&gt;first.setStartAndEnd(x,x);
<a name="l00361"></a>00361         <span class="keywordflow">else</span> d-&gt;first.setEnd(x);
<a name="l00362"></a>00362       }
<a name="l00363"></a>00363       <span class="keywordflow">else</span> pIn.<a class="code" href="a00186.html#af76fa6f3fe40bd167a36b4ab859e0ff6">setUserArea</a>(<span class="keyword">new</span> pair&lt;DateRange,double&gt;(<a class="code" href="a00050.html" title="This class defines a date-range, i.e. a start-date and end-date pair.">DateRange</a>(x,x),0));
<a name="l00364"></a>00364     }
<a name="l00365"></a>00365   }
<a name="l00366"></a>00366   <span class="keywordflow">else</span>
<a name="l00367"></a>00367     <a class="code" href="a00072.html#a7684ca786326565eb2f7ceed1a821c5d">Demand::endElement</a>(pIn, pAttr, pElement);
<a name="l00368"></a>00368 
<a name="l00369"></a>00369   <span class="keywordflow">if</span> (pIn.<a class="code" href="a00186.html#a42fe5e4ae141efb84744b8a359e38bd9">isObjectEnd</a>())
<a name="l00370"></a>00370   {
<a name="l00371"></a>00371     <span class="comment">// Delete dynamically allocated temporary read object</span>
<a name="l00372"></a>00372     <span class="keywordflow">if</span> (pIn.<a class="code" href="a00186.html#a656f44229f4251a26773decd010caaaf">getUserArea</a>())
<a name="l00373"></a>00373       <span class="keyword">delete</span> <span class="keyword">static_cast&lt;</span> pair&lt;DateRange,double&gt;* <span class="keyword">&gt;</span>(pIn.<a class="code" href="a00186.html#a656f44229f4251a26773decd010caaaf">getUserArea</a>());
<a name="l00374"></a>00374   }
<a name="l00375"></a>00375 }
<a name="l00376"></a>00376 
<a name="l00377"></a>00377 
<a name="l00378"></a><a class="code" href="a00072.html#a79b5db1db684716961db9ff9a45339b2">00378</a> <span class="keywordtype">void</span> <a class="code" href="a00072.html#a79b5db1db684716961db9ff9a45339b2">Forecast::beginElement</a>(<a class="code" href="a00186.html" title="This class will read in an XML-file and call the appropriate handler functions of...">XMLInput</a>&amp; pIn, <span class="keyword">const</span> <a class="code" href="a00002.html" title="A class to model keyword instances.">Attribute</a>&amp; pAttr)
<a name="l00379"></a>00379 {
<a name="l00380"></a>00380   <span class="keywordflow">if</span> (pAttr.<a class="code" href="a00002.html#aebffce6c4fcf1696ca34f63f2b6ee091">isA</a>(<a class="code" href="a00177.html#af73b7397b82ca602df4b4e35a2fa41c0">Tags::tag_calendar</a>))
<a name="l00381"></a>00381     pIn.<a class="code" href="a00186.html#a88dd6be5af6fc605d2d420fbcb397b18">readto</a>( Calendar::reader(Calendar::metadata, pIn.<a class="code" href="a00186.html#adcc4751961526c0103536acd194d32a0">getAttributes</a>()) );
<a name="l00382"></a>00382   <span class="keywordflow">else</span>
<a name="l00383"></a>00383     <a class="code" href="a00072.html#a79b5db1db684716961db9ff9a45339b2">Demand::beginElement</a>(pIn, pAttr);
<a name="l00384"></a>00384 }
<a name="l00385"></a>00385 
<a name="l00386"></a>00386 
<a name="l00387"></a><a class="code" href="a00072.html#a1cb40a614cc39d2121edba4912fd5847">00387</a> <span class="keywordtype">void</span> <a class="code" href="a00072.html#a1cb40a614cc39d2121edba4912fd5847">Forecast::setCalendar</a>(<a class="code" href="a00013.html" title="This is the class used to represent variables that are varying over time.">Calendar</a>* c)
<a name="l00388"></a>00388 {
<a name="l00389"></a>00389   <span class="keywordflow">if</span> (<a class="code" href="a00083.html#ad4e04677c1fd0b008267a1a55225705d">isGroup</a>())
<a name="l00390"></a>00390     <span class="keywordflow">throw</span> <a class="code" href="a00048.html" title="An exception of this type is thrown when data errors are found.">DataException</a>(
<a name="l00391"></a>00391       <span class="stringliteral">&quot;Changing the calendar of an initialized forecast isn&apos;t allowed&quot;</span>);
<a name="l00392"></a>00392   calptr = c;
<a name="l00393"></a>00393 }
<a name="l00394"></a>00394 
<a name="l00395"></a>00395 
<a name="l00396"></a><a class="code" href="a00072.html#a0ba4ffe9775982f1fc19cf83725fc92b">00396</a> <span class="keywordtype">void</span> <a class="code" href="a00072.html#a0ba4ffe9775982f1fc19cf83725fc92b">Forecast::setItem</a>(<a class="code" href="a00088.html" title="An item defines the products being planned, sold, stored and/or manufactured. Buffers...">Item</a>* i)
<a name="l00397"></a>00397 {
<a name="l00398"></a>00398   <span class="comment">// No change</span>
<a name="l00399"></a>00399   <span class="keywordflow">if</span> (<a class="code" href="a00051.html#a49f5ca2d8cf91112c41c1eaa04626889">getItem</a>() == i) <span class="keywordflow">return</span>;
<a name="l00400"></a>00400 
<a name="l00401"></a>00401   <span class="comment">// Update the dictionary</span>
<a name="l00402"></a>00402   <span class="keywordflow">for</span> (MapOfForecasts::iterator x =
<a name="l00403"></a>00403     ForecastDictionary.lower_bound(make_pair(
<a name="l00404"></a>00404       &amp;*<a class="code" href="a00051.html#a49f5ca2d8cf91112c41c1eaa04626889">getItem</a>(),&amp;*<a class="code" href="a00051.html#ada8b8f6e9163a3f334d9799d14c5a7ec">getCustomer</a>()
<a name="l00405"></a>00405       ));
<a name="l00406"></a>00406     x != ForecastDictionary.end(); ++x)
<a name="l00407"></a>00407     <span class="keywordflow">if</span> (x-&gt;second == <span class="keyword">this</span>)
<a name="l00408"></a>00408     {
<a name="l00409"></a>00409       ForecastDictionary.erase(x);
<a name="l00410"></a>00410       <span class="keywordflow">break</span>;
<a name="l00411"></a>00411     }
<a name="l00412"></a>00412   ForecastDictionary.insert(make_pair(make_pair(i,&amp;*<a class="code" href="a00051.html#ada8b8f6e9163a3f334d9799d14c5a7ec">getCustomer</a>()),<span class="keyword">this</span>));
<a name="l00413"></a>00413 
<a name="l00414"></a>00414   <span class="comment">// Update data field</span>
<a name="l00415"></a>00415   <a class="code" href="a00072.html#a0ba4ffe9775982f1fc19cf83725fc92b">Demand::setItem</a>(i);
<a name="l00416"></a>00416 
<a name="l00417"></a>00417   <span class="comment">// Update the item for all buckets/subdemands</span>
<a name="l00418"></a>00418   <span class="keywordflow">for</span> (<a class="code" href="a00083.html#af604aa38df25c5555db2cee12da24a23">memberIterator</a> m = <a class="code" href="a00083.html#a7afe3a1b114b7f7a93ecd68f56005dac">beginMember</a>(); m!=<a class="code" href="a00083.html#a3861adc09dde2deb2ea0466cf46634ac">endMember</a>(); ++m)
<a name="l00419"></a>00419     m-&gt;setItem(i);
<a name="l00420"></a>00420 }
<a name="l00421"></a>00421 
<a name="l00422"></a>00422 
<a name="l00423"></a><a class="code" href="a00072.html#a18d60ad7fca9f25a4ac128858a5d4cbb">00423</a> <span class="keywordtype">void</span> <a class="code" href="a00072.html#a18d60ad7fca9f25a4ac128858a5d4cbb">Forecast::setCustomer</a>(<a class="code" href="a00044.html" title="This abstracts class represents customers.">Customer</a>* i)
<a name="l00424"></a>00424 {
<a name="l00425"></a>00425   <span class="comment">// No change</span>
<a name="l00426"></a>00426   <span class="keywordflow">if</span> (<a class="code" href="a00051.html#ada8b8f6e9163a3f334d9799d14c5a7ec">getCustomer</a>() == i) <span class="keywordflow">return</span>;
<a name="l00427"></a>00427 
<a name="l00428"></a>00428   <span class="comment">// Update the dictionary</span>
<a name="l00429"></a>00429   <span class="keywordflow">for</span> (MapOfForecasts::iterator x =
<a name="l00430"></a>00430     ForecastDictionary.lower_bound(make_pair(
<a name="l00431"></a>00431       <a class="code" href="a00051.html#a49f5ca2d8cf91112c41c1eaa04626889">getItem</a>(), <a class="code" href="a00051.html#ada8b8f6e9163a3f334d9799d14c5a7ec">getCustomer</a>()
<a name="l00432"></a>00432       ));
<a name="l00433"></a>00433     x != ForecastDictionary.end(); ++x)
<a name="l00434"></a>00434     <span class="keywordflow">if</span> (x-&gt;second == <span class="keyword">this</span>)
<a name="l00435"></a>00435     {
<a name="l00436"></a>00436       ForecastDictionary.erase(x);
<a name="l00437"></a>00437       <span class="keywordflow">break</span>;
<a name="l00438"></a>00438     }
<a name="l00439"></a>00439   ForecastDictionary.insert(make_pair(make_pair(&amp;*<a class="code" href="a00051.html#a49f5ca2d8cf91112c41c1eaa04626889">getItem</a>(),i),<span class="keyword">this</span>));
<a name="l00440"></a>00440 
<a name="l00441"></a>00441   <span class="comment">// Update data field</span>
<a name="l00442"></a>00442   <a class="code" href="a00072.html#a18d60ad7fca9f25a4ac128858a5d4cbb">Demand::setCustomer</a>(i);
<a name="l00443"></a>00443 
<a name="l00444"></a>00444   <span class="comment">// Update the customer for all buckets/subdemands</span>
<a name="l00445"></a>00445   <span class="keywordflow">for</span> (<a class="code" href="a00083.html#af604aa38df25c5555db2cee12da24a23">memberIterator</a> m = <a class="code" href="a00083.html#a7afe3a1b114b7f7a93ecd68f56005dac">beginMember</a>(); m!=<a class="code" href="a00083.html#a3861adc09dde2deb2ea0466cf46634ac">endMember</a>(); ++m)
<a name="l00446"></a>00446     m-&gt;setCustomer(i);
<a name="l00447"></a>00447 }
<a name="l00448"></a>00448 
<a name="l00449"></a>00449 
<a name="l00450"></a><a class="code" href="a00072.html#ae193ddfac69b14a22beb71902da11855">00450</a> <span class="keywordtype">void</span> <a class="code" href="a00072.html#ae193ddfac69b14a22beb71902da11855">Forecast::setMaxLateness</a>(<a class="code" href="a00179.html" title="This class represents a time duration with an accuracy of one second.">TimePeriod</a> i)
<a name="l00451"></a>00451 {
<a name="l00452"></a>00452   <a class="code" href="a00072.html#ae193ddfac69b14a22beb71902da11855">Demand::setMaxLateness</a>(i);
<a name="l00453"></a>00453   <span class="comment">// Update the maximum lateness for all buckets/subdemands</span>
<a name="l00454"></a>00454   <span class="keywordflow">for</span> (<a class="code" href="a00083.html#af604aa38df25c5555db2cee12da24a23">memberIterator</a> m = <a class="code" href="a00083.html#a7afe3a1b114b7f7a93ecd68f56005dac">beginMember</a>(); m!=<a class="code" href="a00083.html#a3861adc09dde2deb2ea0466cf46634ac">endMember</a>(); ++m)
<a name="l00455"></a>00455     m-&gt;setMaxLateness(i);
<a name="l00456"></a>00456 }
<a name="l00457"></a>00457 
<a name="l00458"></a>00458 
<a name="l00459"></a><a class="code" href="a00072.html#a11c1179973582c27b4ecd4578fc28ec5">00459</a> <span class="keywordtype">void</span> <a class="code" href="a00072.html#a11c1179973582c27b4ecd4578fc28ec5">Forecast::setMinShipment</a>(<span class="keywordtype">double</span> i)
<a name="l00460"></a>00460 {
<a name="l00461"></a>00461   <a class="code" href="a00072.html#a11c1179973582c27b4ecd4578fc28ec5">Demand::setMinShipment</a>(i);
<a name="l00462"></a>00462   <span class="comment">// Update the minimum shipment for all buckets/subdemands</span>
<a name="l00463"></a>00463   <span class="keywordflow">for</span> (<a class="code" href="a00083.html#af604aa38df25c5555db2cee12da24a23">memberIterator</a> m = <a class="code" href="a00083.html#a7afe3a1b114b7f7a93ecd68f56005dac">beginMember</a>(); m!=<a class="code" href="a00083.html#a3861adc09dde2deb2ea0466cf46634ac">endMember</a>(); ++m)
<a name="l00464"></a>00464     m-&gt;setMinShipment(i);
<a name="l00465"></a>00465 }
<a name="l00466"></a>00466 
<a name="l00467"></a>00467 
<a name="l00468"></a><a class="code" href="a00072.html#a54b2e03e9d9ab035783713f9c97abc0c">00468</a> <span class="keywordtype">void</span> <a class="code" href="a00072.html#a54b2e03e9d9ab035783713f9c97abc0c">Forecast::setPriority</a>(<span class="keywordtype">int</span> i)
<a name="l00469"></a>00469 {
<a name="l00470"></a>00470   <a class="code" href="a00072.html#a54b2e03e9d9ab035783713f9c97abc0c">Demand::setPriority</a>(i);
<a name="l00471"></a>00471   <span class="comment">// Update the priority for all buckets/subdemands</span>
<a name="l00472"></a>00472   <span class="keywordflow">for</span> (<a class="code" href="a00083.html#af604aa38df25c5555db2cee12da24a23">memberIterator</a> m = <a class="code" href="a00083.html#a7afe3a1b114b7f7a93ecd68f56005dac">beginMember</a>(); m!=<a class="code" href="a00083.html#a3861adc09dde2deb2ea0466cf46634ac">endMember</a>(); ++m)
<a name="l00473"></a>00473     m-&gt;setPriority(i);
<a name="l00474"></a>00474 }
<a name="l00475"></a>00475 
<a name="l00476"></a>00476 
<a name="l00477"></a><a class="code" href="a00072.html#acbc8ffab042c9a6ed97c91ab2b92de3e">00477</a> <span class="keywordtype">void</span> <a class="code" href="a00072.html#acbc8ffab042c9a6ed97c91ab2b92de3e">Forecast::setOperation</a>(<a class="code" href="a00121.html" title="An operation represents an activity: these consume and produce material, take time...">Operation</a> *o)
<a name="l00478"></a>00478 {
<a name="l00479"></a>00479   <a class="code" href="a00072.html#acbc8ffab042c9a6ed97c91ab2b92de3e">Demand::setOperation</a>(o);
<a name="l00480"></a>00480   <span class="comment">// Update the priority for all buckets/subdemands</span>
<a name="l00481"></a>00481   <span class="keywordflow">for</span> (<a class="code" href="a00083.html#af604aa38df25c5555db2cee12da24a23">memberIterator</a> m = <a class="code" href="a00083.html#a7afe3a1b114b7f7a93ecd68f56005dac">beginMember</a>(); m!=<a class="code" href="a00083.html#a3861adc09dde2deb2ea0466cf46634ac">endMember</a>(); ++m)
<a name="l00482"></a>00482     m-&gt;setOperation(o);
<a name="l00483"></a>00483 }
<a name="l00484"></a>00484 
<a name="l00485"></a>00485 }       <span class="comment">// end namespace</span>
</pre></div></div>
<hr size="1"/><address style="align: right;"><small>Documentation generated for frePPLe by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"/></a></small></address>
</div>
</div>
</body>
</html>