Sophie

Sophie

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

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: operationplan.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_88117dff2735251a69c8eb9084477714.html">src</a>&nbsp;&raquo&nbsp;<a class="el" href="dir_25032d30b6d615a661c02e2ac1394b01.html">model</a>
  </div>
</div>
<div class="contents">
<h1>operationplan.cpp</h1><a href="a00224.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/src/model/operationplan.cpp $</span>
<a name="l00003"></a>00003 <span class="comment">  version : $LastChangedRevision: 1341 $  $LastChangedBy: jdetaeye $</span>
<a name="l00004"></a>00004 <span class="comment">  date : $LastChangedDate: 2010-08-21 07:17:25 +0200 (Sat, 21 Aug 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><a class="code" href="a00224.html#a342983a479ae7a921be5face83fdb029">00028</a> <span class="preprocessor">#define FREPPLE_CORE</span>
<a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#include &quot;<a class="code" href="a00218.html">frepple/model.h</a>&quot;</span>
<a name="l00030"></a>00030 
<a name="l00031"></a>00031 <span class="keyword">namespace </span>frepple
<a name="l00032"></a>00032 {
<a name="l00033"></a>00033 
<a name="l00034"></a>00034 <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> <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="a00125.html#a31cde691d7cdf2ce2db1fb0eb595e34a">OperationPlan::metadata</a>;
<a name="l00035"></a>00035 <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> <span class="keyword">const</span> <a class="code" href="a00114.html" title="A MetaCategory instance represents metadata for a category of object.">MetaCategory</a>* <a class="code" href="a00125.html#ad32c559f9ca421acae969bb0c5a194b6">OperationPlan::metacategory</a>;
<a name="l00036"></a>00036 <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> OperationPlan::counterMin = 1;
<a name="l00037"></a>00037 <span class="comment">// The value of the max counter is hard-coded to 2^31 - 1. This value is the </span>
<a name="l00038"></a>00038 <span class="comment">// highest positive integer number that can safely be used on 32-bit platforms.</span>
<a name="l00039"></a>00039 <span class="comment">// An alternative approach is to use the value ULONG_MAX, but this has the </span>
<a name="l00040"></a>00040 <span class="comment">// disadvantage of not being portable across platforms and tools.</span>
<a name="l00041"></a>00041 <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> OperationPlan::counterMax = 2147483647;
<a name="l00042"></a>00042 
<a name="l00043"></a>00043 
<a name="l00044"></a><a class="code" href="a00125.html#acd5cce9abe40ac2c14cde0f5f0d1d05d">00044</a> <span class="keywordtype">int</span> <a class="code" href="a00125.html#acd5cce9abe40ac2c14cde0f5f0d1d05d">OperationPlan::initialize</a>()
<a name="l00045"></a>00045 {
<a name="l00046"></a>00046   <span class="comment">// Initialize the metadata</span>
<a name="l00047"></a>00047   <a class="code" href="a00125.html#ad32c559f9ca421acae969bb0c5a194b6">OperationPlan::metacategory</a> = <span class="keyword">new</span> <a class="code" href="a00114.html" title="A MetaCategory instance represents metadata for a category of object.">MetaCategory</a>(<span class="stringliteral">&quot;operationplan&quot;</span>, <span class="stringliteral">&quot;operationplans&quot;</span>,
<a name="l00048"></a>00048     <a class="code" href="a00125.html#acabc6d5f06b157c155355d04b3e2e4ef">OperationPlan::createOperationPlan</a>, <a class="code" href="a00125.html#a6e290be8218f038b5c3613def7442c1a">OperationPlan::writer</a>);
<a name="l00049"></a>00049   <a class="code" href="a00125.html#a31cde691d7cdf2ce2db1fb0eb595e34a">OperationPlan::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;operationplan&quot;</span>, <span class="stringliteral">&quot;operationplan&quot;</span>);
<a name="l00050"></a>00050 
<a name="l00051"></a>00051   <span class="comment">// Initialize the Python type</span>
<a name="l00052"></a>00052   <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="a00125.html#ac605151cc6cb3d9cd76ff1e6b627f949">FreppleCategory&lt;OperationPlan&gt;::getType</a>();
<a name="l00053"></a>00053   x.<a class="code" href="a00155.html#af9217b67c7c60e8e87c703066d6970d5">setName</a>(<span class="stringliteral">&quot;operationplan&quot;</span>);
<a name="l00054"></a>00054   x.<a class="code" href="a00155.html#aaafe003660694b2cf497a89815d7fe49">setDoc</a>(<span class="stringliteral">&quot;frePPLe operationplan&quot;</span>);
<a name="l00055"></a>00055   x.<a class="code" href="a00155.html#a8d3f24e0357f41ac3bc0be78bd2ab268">supportgetattro</a>();
<a name="l00056"></a>00056   x.<a class="code" href="a00155.html#a83866bef191c69cf8506426fe38b8d19">supportsetattro</a>();
<a name="l00057"></a>00057   x.<a class="code" href="a00155.html#a23a670ed39c26ab20ec400cbe3618e6c">supportstr</a>();
<a name="l00058"></a>00058   x.<a class="code" href="a00155.html#a001dc53b2dd832c001aee4d21bc7bf09">supportcreate</a>(<a class="code" href="a00125.html#a9011cb69db2094761747475bfe760a5f">create</a>);
<a name="l00059"></a>00059   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="l00060"></a>00060   <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="a00125.html#a31cde691d7cdf2ce2db1fb0eb595e34a">metadata</a>)-&gt;pythonClass = x.<a class="code" href="a00155.html#aed0915f1cc32c0c1e12e209abfedf615">type_object</a>();
<a name="l00061"></a>00061   <span class="keywordflow">return</span> x.<a class="code" href="a00155.html#a5b2be5d75982b077b2d694c269d43778">typeReady</a>();
<a name="l00062"></a>00062 }
<a name="l00063"></a>00063 
<a name="l00064"></a>00064 
<a name="l00065"></a><a class="code" href="a00125.html#abf77895a64e6ddfffc99f290df38750d">00065</a> <span class="keywordtype">void</span> <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> <a class="code" href="a00125.html#abf77895a64e6ddfffc99f290df38750d">OperationPlan::setChanged</a>(<span class="keywordtype">bool</span> b)
<a name="l00066"></a>00066 {
<a name="l00067"></a>00067   <span class="keywordflow">if</span> (owner)
<a name="l00068"></a>00068     owner-&gt;<a class="code" href="a00125.html#abf77895a64e6ddfffc99f290df38750d">setChanged</a>(b);
<a name="l00069"></a>00069   <span class="keywordflow">else</span>
<a name="l00070"></a>00070   {
<a name="l00071"></a>00071     oper-&gt;<a class="code" href="a00133.html#a11a86a6e020664a337325a96a64f6d2c">setChanged</a>(b);
<a name="l00072"></a>00072     <span class="keywordflow">if</span> (dmd) dmd-&gt;<a class="code" href="a00133.html#a11a86a6e020664a337325a96a64f6d2c">setChanged</a>();
<a name="l00073"></a>00073   }
<a name="l00074"></a>00074 }
<a name="l00075"></a>00075 
<a name="l00076"></a>00076 
<a name="l00077"></a>00077 <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> <a class="code" href="a00120.html" title="Object is the abstract base class for the main entities.">Object</a>* <a class="code" href="a00125.html#acabc6d5f06b157c155355d04b3e2e4ef">OperationPlan::createOperationPlan</a>
<a name="l00078"></a><a class="code" href="a00125.html#acabc6d5f06b157c155355d04b3e2e4ef">00078</a> (<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>* cat, <span class="keyword">const</span> <a class="code" href="a00003.html" title="This class represents a dictionary of keyword + value pairs.">AttributeList</a>&amp; in)
<a name="l00079"></a>00079 {
<a name="l00080"></a>00080   <span class="comment">// Pick up the action attribute</span>
<a name="l00081"></a>00081   <a class="code" href="a00257.html#a07f97ddf3e649a4d2aa13cb900b5dcf4">Action</a> action = MetaClass::decodeAction(in);
<a name="l00082"></a>00082 
<a name="l00083"></a>00083   <span class="comment">// Decode the attributes</span>
<a name="l00084"></a>00084   <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>* opnameElement = in.<a class="code" href="a00003.html#afc79347bc21694cedfe218f8d023235f">get</a>(<a class="code" href="a00177.html#ad70b79a1c1f3f6d13539207da4f19609">Tags::tag_operation</a>);
<a name="l00085"></a>00085   <span class="keywordflow">if</span> (!*opnameElement &amp;&amp; action!=<a class="code" href="a00257.html#a07f97ddf3e649a4d2aa13cb900b5dcf4a6b9fb19e9a6595385dec31b63e0054e1">REMOVE</a>)
<a name="l00086"></a>00086     <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 operation attribute&quot;</span>);
<a name="l00087"></a>00087   <span class="keywordtype">string</span> opname = *opnameElement ? opnameElement-&gt;<a class="code" href="a00047.html#a053aa4cde35b21a399f26bca0132ab3f">getString</a>() : <span class="stringliteral">&quot;&quot;</span>;
<a name="l00088"></a>00088 
<a name="l00089"></a>00089   <span class="comment">// Decode the operationplan identifier</span>
<a name="l00090"></a>00090   <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> <span class="keywordtype">id</span> = 0;
<a name="l00091"></a>00091   <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>* idfier = in.<a class="code" href="a00003.html#afc79347bc21694cedfe218f8d023235f">get</a>(<a class="code" href="a00177.html#a9a660b4455888adc9ad733f07826840f">Tags::tag_id</a>);
<a name="l00092"></a>00092   <span class="keywordflow">if</span> (*idfier) <span class="keywordtype">id</span> = idfier-&gt;<a class="code" href="a00047.html#a5c309a5660770ea024a6ae6057d71c28">getUnsignedLong</a>();
<a name="l00093"></a>00093 
<a name="l00094"></a>00094   <span class="comment">// If an ID is specified, we look up this operation plan</span>
<a name="l00095"></a>00095   <a class="code" href="a00125.html" title="An operationplan is the key dynamic element of a plan. It represents a certain quantity...">OperationPlan</a>* opplan = NULL;
<a name="l00096"></a>00096   <span class="keywordflow">if</span> (idfier)
<a name="l00097"></a>00097   {
<a name="l00098"></a>00098     opplan = <a class="code" href="a00125.html#a35f7c280c07d3e019e2bcdf99e4d9d3f">OperationPlan::findId</a>(<span class="keywordtype">id</span>);
<a name="l00099"></a>00099     <span class="keywordflow">if</span> (opplan &amp;&amp; !opname.<a class="code" href="a00125.html#a1b67f83c0a010a76f9d481cdf1474774">empty</a>()
<a name="l00100"></a>00100         &amp;&amp; opplan-&gt;<a class="code" href="a00125.html#a2f5ae1046cd50f98e59520ed8910c458">getOperation</a>()-&gt;<a class="code" href="a00182.html#a7416ca220c55147bc1276becc5b9de01">getName</a>()==opname)
<a name="l00101"></a>00101     {
<a name="l00102"></a>00102       <span class="comment">// Previous and current operations don&apos;t match.</span>
<a name="l00103"></a>00103       ostringstream ch;
<a name="l00104"></a>00104       ch &lt;&lt; <span class="stringliteral">&quot;Operationplan id &quot;</span> &lt;&lt; <span class="keywordtype">id</span>
<a name="l00105"></a>00105       &lt;&lt; <span class="stringliteral">&quot; defined multiple times with different operations: &apos;&quot;</span>
<a name="l00106"></a>00106       &lt;&lt; opplan-&gt;<a class="code" href="a00125.html#a2f5ae1046cd50f98e59520ed8910c458">getOperation</a>() &lt;&lt; <span class="stringliteral">&quot;&apos; &amp; &apos;&quot;</span> &lt;&lt; opname &lt;&lt; <span class="stringliteral">&quot;&apos;&quot;</span>;
<a name="l00107"></a>00107       <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>(ch.str());
<a name="l00108"></a>00108     }
<a name="l00109"></a>00109   }
<a name="l00110"></a>00110 
<a name="l00111"></a>00111   <span class="comment">// Execute the proper action</span>
<a name="l00112"></a>00112   <span class="keywordflow">switch</span> (action)
<a name="l00113"></a>00113   {
<a name="l00114"></a>00114     <span class="keywordflow">case</span> <a class="code" href="a00257.html#a07f97ddf3e649a4d2aa13cb900b5dcf4a6b9fb19e9a6595385dec31b63e0054e1">REMOVE</a>:
<a name="l00115"></a>00115       <span class="keywordflow">if</span> (opplan)
<a name="l00116"></a>00116       {
<a name="l00117"></a>00117         <span class="comment">// Send out the notification to subscribers</span>
<a name="l00118"></a>00118         <span class="keywordflow">if</span> (opplan-&gt;<a class="code" href="a00125.html#ac605151cc6cb3d9cd76ff1e6b627f949">getType</a>().<a class="code" href="a00115.html#ae3e00d415acf61ed63fe0854ebc55ee3">raiseEvent</a>(opplan, <a class="code" href="a00257.html#aec6d4a238b0cd9ffc8be8f10fd9b652fa6a5f44a606844db345f7c98cd402ecfb">SIG_REMOVE</a>))
<a name="l00119"></a>00119           <span class="comment">// Delete it</span>
<a name="l00120"></a>00120           <span class="keyword">delete</span> opplan;
<a name="l00121"></a>00121         <span class="keywordflow">else</span>
<a name="l00122"></a>00122         {
<a name="l00123"></a>00123           <span class="comment">// The callbacks disallowed the deletion!</span>
<a name="l00124"></a>00124           ostringstream ch;
<a name="l00125"></a>00125           ch &lt;&lt; <span class="stringliteral">&quot;Can&apos;t delete operationplan with id &quot;</span> &lt;&lt; id;
<a name="l00126"></a>00126           <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>(ch.str());
<a name="l00127"></a>00127         }
<a name="l00128"></a>00128       }
<a name="l00129"></a>00129       <span class="keywordflow">else</span>
<a name="l00130"></a>00130       {
<a name="l00131"></a>00131         ostringstream ch;
<a name="l00132"></a>00132         ch &lt;&lt; <span class="stringliteral">&quot;Can&apos;t find operationplan with identifier &quot;</span>
<a name="l00133"></a>00133         &lt;&lt; <span class="keywordtype">id</span> &lt;&lt; <span class="stringliteral">&quot; for removal&quot;</span>;
<a name="l00134"></a>00134         <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>(ch.str());
<a name="l00135"></a>00135       }
<a name="l00136"></a>00136       <span class="keywordflow">return</span> NULL;
<a name="l00137"></a>00137     <span class="keywordflow">case</span> <a class="code" href="a00257.html#a07f97ddf3e649a4d2aa13cb900b5dcf4a8f6183fcf54ca6985ff2b5ef80673a25">ADD</a>:
<a name="l00138"></a>00138       <span class="keywordflow">if</span> (opplan)
<a name="l00139"></a>00139       {
<a name="l00140"></a>00140         ostringstream ch;
<a name="l00141"></a>00141         ch &lt;&lt; <span class="stringliteral">&quot;Operationplan with identifier &quot;</span> &lt;&lt; <span class="keywordtype">id</span>
<a name="l00142"></a>00142         &lt;&lt; <span class="stringliteral">&quot; already exists and can&apos;t be added again&quot;</span>;
<a name="l00143"></a>00143         <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>(ch.str());
<a name="l00144"></a>00144       }
<a name="l00145"></a>00145       <span class="keywordflow">if</span> (opname.empty())
<a name="l00146"></a>00146         <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="l00147"></a>00147           (<span class="stringliteral">&quot;Operation name missing for creating an operationplan&quot;</span>);
<a name="l00148"></a>00148       <span class="keywordflow">break</span>;
<a name="l00149"></a>00149     <span class="keywordflow">case</span> <a class="code" href="a00257.html#a07f97ddf3e649a4d2aa13cb900b5dcf4a1b9888c025bb8f78e322471fd5e14423">CHANGE</a>:
<a name="l00150"></a>00150       <span class="keywordflow">if</span> (!opplan)
<a name="l00151"></a>00151       {
<a name="l00152"></a>00152         ostringstream ch;
<a name="l00153"></a>00153         ch &lt;&lt; <span class="stringliteral">&quot;Operationplan with identifier &quot;</span> &lt;&lt; <span class="keywordtype">id</span> &lt;&lt; <span class="stringliteral">&quot; doesn&apos;t exist&quot;</span>;
<a name="l00154"></a>00154         <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>(ch.str());
<a name="l00155"></a>00155       }
<a name="l00156"></a>00156       <span class="keywordflow">break</span>;
<a name="l00157"></a>00157     <span class="keywordflow">case</span> <a class="code" href="a00257.html#a07f97ddf3e649a4d2aa13cb900b5dcf4a75b4aab762127e8083e16661b4021a00">ADD_CHANGE</a>: ;
<a name="l00158"></a>00158   }
<a name="l00159"></a>00159 
<a name="l00160"></a>00160   <span class="comment">// Return the existing operationplan</span>
<a name="l00161"></a>00161   <span class="keywordflow">if</span> (opplan) <span class="keywordflow">return</span> opplan;
<a name="l00162"></a>00162 
<a name="l00163"></a>00163   <span class="comment">// Create a new operation plan</span>
<a name="l00164"></a>00164   <a class="code" href="a00121.html" title="An operation represents an activity: these consume and produce material, take time...">Operation</a>* oper = <a class="code" href="a00085.html#aad19dfc63a16f3fb30f7bda2e00f3cdc">Operation::find</a>(opname);
<a name="l00165"></a>00165   <span class="keywordflow">if</span> (!oper)
<a name="l00166"></a>00166   {
<a name="l00167"></a>00167     <span class="comment">// Can&apos;t create operationplan because the operation doesn&apos;t exist</span>
<a name="l00168"></a>00168     <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;Operation &apos;&quot;</span> + opname + <span class="stringliteral">&quot;&apos; doesn&apos;t exist&quot;</span>);
<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">// Create an operationplan</span>
<a name="l00173"></a>00173     opplan = oper-&gt;<a class="code" href="a00121.html#ad183a2e72b75cdd83f9e71f6bc235424">createOperationPlan</a>(0.0,Date::infinitePast,Date::infinitePast,NULL,NULL,<span class="keywordtype">id</span>,<span class="keyword">false</span>);
<a name="l00174"></a>00174     <span class="keywordflow">if</span> (!opplan-&gt;<a class="code" href="a00125.html#ac605151cc6cb3d9cd76ff1e6b627f949">getType</a>().<a class="code" href="a00115.html#ae3e00d415acf61ed63fe0854ebc55ee3">raiseEvent</a>(opplan, <a class="code" href="a00257.html#aec6d4a238b0cd9ffc8be8f10fd9b652fa0002e13b1bc824daa2f7eba569780247">SIG_ADD</a>))
<a name="l00175"></a>00175     {
<a name="l00176"></a>00176       <span class="keyword">delete</span> opplan;
<a name="l00177"></a>00177       <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;Can&apos;t create operationplan&quot;</span>);
<a name="l00178"></a>00178     }
<a name="l00179"></a>00179     <span class="keywordflow">return</span> opplan;
<a name="l00180"></a>00180   }
<a name="l00181"></a>00181 }
<a name="l00182"></a>00182 
<a name="l00183"></a>00183 
<a name="l00184"></a><a class="code" href="a00125.html#a35f7c280c07d3e019e2bcdf99e4d9d3f">00184</a> <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> <a class="code" href="a00125.html" title="An operationplan is the key dynamic element of a plan. It represents a certain quantity...">OperationPlan</a>* <a class="code" href="a00125.html#a35f7c280c07d3e019e2bcdf99e4d9d3f">OperationPlan::findId</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> l)
<a name="l00185"></a>00185 {
<a name="l00186"></a>00186   <span class="comment">// We are garantueed that there are no operationplans that have an id equal</span>
<a name="l00187"></a>00187   <span class="comment">// or higher than the current counter. This is garantueed by the</span>
<a name="l00188"></a>00188   <span class="comment">// instantiate() method.</span>
<a name="l00189"></a>00189   <span class="keywordflow">if</span> (l &gt;= counterMin &amp;&amp; l &lt;= counterMax) <span class="keywordflow">return</span> NULL;
<a name="l00190"></a>00190 
<a name="l00191"></a>00191   <span class="comment">// Loop through all operationplans.</span>
<a name="l00192"></a>00192   <span class="keywordflow">for</span> (<a class="code" href="a00093.html" title="This class models an STL-like iterator that allows us to iterate over the operationplans...">OperationPlan::iterator</a> i = <a class="code" href="a00125.html#a8bd5449992e056b2d637cfe65ac7da1f">begin</a>(); i != <a class="code" href="a00125.html#a0f9f6ba7d4fe7e20e9b88c765fe24f25">end</a>(); ++i)
<a name="l00193"></a>00193     <span class="keywordflow">if</span> (i-&gt;id == l) <span class="keywordflow">return</span> &amp;*i;
<a name="l00194"></a>00194 
<a name="l00195"></a>00195   <span class="comment">// This ID was not found</span>
<a name="l00196"></a>00196   <span class="keywordflow">return</span> NULL;
<a name="l00197"></a>00197 }
<a name="l00198"></a>00198 
<a name="l00199"></a>00199 
<a name="l00200"></a><a class="code" href="a00125.html#a13fe13cfa3f0b8dc229b9f115172c9c5">00200</a> <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> <span class="keywordtype">bool</span> <a class="code" href="a00125.html#a13fe13cfa3f0b8dc229b9f115172c9c5">OperationPlan::instantiate</a>(<span class="keywordtype">bool</span> useMinCounter)
<a name="l00201"></a>00201 {
<a name="l00202"></a>00202   <span class="comment">// At least a valid operation pointer must exist</span>
<a name="l00203"></a>00203   <span class="keywordflow">if</span> (!oper) <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;Initializing an invalid operationplan&quot;</span>);
<a name="l00204"></a>00204 
<a name="l00205"></a>00205   <span class="comment">// Avoid zero quantity on top-operationplans</span>
<a name="l00206"></a>00206   <span class="keywordflow">if</span> (<a class="code" href="a00125.html#aa32661a65b2309ba7c35576940274687">getQuantity</a>() &lt;= 0.0 &amp;&amp; !owner)
<a name="l00207"></a>00207   {
<a name="l00208"></a>00208     <span class="keyword">delete</span> <span class="keyword">this</span>;
<a name="l00209"></a>00209     <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00210"></a>00210   }
<a name="l00211"></a>00211 
<a name="l00212"></a>00212   <span class="comment">// Call any operation specific initialisation logic</span>
<a name="l00213"></a>00213   <span class="keywordflow">if</span> (!oper-&gt;<a class="code" href="a00121.html#a281dbc14aa516838b895c352bd388bda">extraInstantiate</a>(<span class="keyword">this</span>))
<a name="l00214"></a>00214   {
<a name="l00215"></a>00215     <span class="keyword">delete</span> <span class="keyword">this</span>;
<a name="l00216"></a>00216     <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00217"></a>00217   }
<a name="l00218"></a>00218 
<a name="l00219"></a>00219   <span class="comment">// Instantiate all suboperationplans as well</span>
<a name="l00220"></a>00220   <span class="keywordflow">for</span> (<a class="code" href="a00093.html" title="This class models an STL-like iterator that allows us to iterate over the operationplans...">OperationPlan::iterator</a> x(<span class="keyword">this</span>); x != <a class="code" href="a00125.html#a0f9f6ba7d4fe7e20e9b88c765fe24f25">end</a>(); ++x)
<a name="l00221"></a>00221     x-&gt;instantiate();
<a name="l00222"></a>00222 
<a name="l00223"></a>00223   <span class="comment">// Create unique identifier</span>
<a name="l00224"></a>00224   <span class="comment">// Having an identifier assigned is an important flag.</span>
<a name="l00225"></a>00225   <span class="comment">// Only operation plans with an id :</span>
<a name="l00226"></a>00226   <span class="comment">//   - can be linked in the global operation plan list.</span>
<a name="l00227"></a>00227   <span class="comment">//   - can have problems (this results from the previous point).</span>
<a name="l00228"></a>00228   <span class="comment">//   - can be linked with a demand.</span>
<a name="l00229"></a>00229   <span class="comment">// These properties allow us to delete operation plans without an id faster.</span>
<a name="l00230"></a>00230   <span class="keyword">static</span> <a class="code" href="a00117.html" title="This class is a wrapper around platform specific mutex functions.">Mutex</a> onlyOne;
<a name="l00231"></a>00231   {
<a name="l00232"></a>00232   <a class="code" href="a00163.html" title="This is a convenience class that makes it easy (and exception-safe) to lock a mutex...">ScopeMutexLock</a> l(onlyOne);  <span class="comment">// Need to assure that ids are unique!</span>
<a name="l00233"></a>00233   <span class="keywordflow">if</span> (<span class="keywordtype">id</span>)
<a name="l00234"></a>00234   {
<a name="l00235"></a>00235     <span class="comment">// An identifier was read in from input</span>
<a name="l00236"></a>00236     <span class="keywordflow">if</span> (id &lt; counterMin || id &gt; counterMax)
<a name="l00237"></a>00237     {
<a name="l00238"></a>00238       <span class="comment">// The assigned id potentially clashes with an existing operationplan.</span>
<a name="l00239"></a>00239       <span class="comment">// Check whether it clashes with existing operationplans</span>
<a name="l00240"></a>00240       <a class="code" href="a00125.html" title="An operationplan is the key dynamic element of a plan. It represents a certain quantity...">OperationPlan</a>* opplan = <a class="code" href="a00125.html#a35f7c280c07d3e019e2bcdf99e4d9d3f">findId</a>(<span class="keywordtype">id</span>);
<a name="l00241"></a>00241       <span class="keywordflow">if</span> (opplan &amp;&amp; opplan-&gt;<a class="code" href="a00125.html#a2f5ae1046cd50f98e59520ed8910c458">getOperation</a>()!=oper)
<a name="l00242"></a>00242       {
<a name="l00243"></a>00243         ostringstream ch;
<a name="l00244"></a>00244         ch &lt;&lt; <span class="stringliteral">&quot;Operationplan id &quot;</span> &lt;&lt; <span class="keywordtype">id</span>
<a name="l00245"></a>00245           &lt;&lt; <span class="stringliteral">&quot; defined multiple times with different operations: &apos;&quot;</span>
<a name="l00246"></a>00246           &lt;&lt; opplan-&gt;<a class="code" href="a00125.html#a2f5ae1046cd50f98e59520ed8910c458">getOperation</a>() &lt;&lt; <span class="stringliteral">&quot;&apos; &amp; &apos;&quot;</span> &lt;&lt; oper &lt;&lt; <span class="stringliteral">&quot;&apos;&quot;</span>;
<a name="l00247"></a>00247         <span class="keyword">delete</span> <span class="keyword">this</span>;
<a name="l00248"></a>00248         <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>(ch.str());
<a name="l00249"></a>00249       }
<a name="l00250"></a>00250     }
<a name="l00251"></a>00251     <span class="comment">// The new operationplan definately doesn&apos;t clash with existing id&apos;s.</span>
<a name="l00252"></a>00252     <span class="comment">// The counter need updating to garantuee that counter is always</span>
<a name="l00253"></a>00253     <span class="comment">// a safe starting point for tagging new operationplans.</span>
<a name="l00254"></a>00254     <span class="keywordflow">else</span> <span class="keywordflow">if</span> (useMinCounter)
<a name="l00255"></a>00255       counterMin = <span class="keywordtype">id</span>+1;
<a name="l00256"></a>00256     <span class="keywordflow">else</span> 
<a name="l00257"></a>00257       counterMax = <span class="keywordtype">id</span>-1;
<a name="l00258"></a>00258   }
<a name="l00259"></a>00259   <span class="comment">// Fresh operationplan with blank id</span>
<a name="l00260"></a>00260   <span class="keywordflow">else</span> <span class="keywordflow">if</span> (useMinCounter)
<a name="l00261"></a>00261     <span class="keywordtype">id</span> = counterMin++;
<a name="l00262"></a>00262   <span class="keywordflow">else</span> 
<a name="l00263"></a>00263     <span class="keywordtype">id</span> = counterMax--;
<a name="l00264"></a>00264   <span class="comment">// Check whether the counters are still okay</span>
<a name="l00265"></a>00265   <span class="keywordflow">if</span> (counterMin &gt;= counterMax)
<a name="l00266"></a>00266     <span class="keywordflow">throw</span> <a class="code" href="a00162.html" title="An exception of this type is thrown when the library runs into problems that are...">RuntimeException</a>(<span class="stringliteral">&quot;Exhausted the range of available operationplan identifiers&quot;</span>);
<a name="l00267"></a>00267   }
<a name="l00268"></a>00268 
<a name="l00269"></a>00269   <span class="comment">// Insert into the doubly linked list of operationplans.</span>
<a name="l00270"></a>00270   <a class="code" href="a00125.html#a8d6318b95bb6095572c645b0f77162ce">insertInOperationplanList</a>();
<a name="l00271"></a>00271 
<a name="l00272"></a>00272   <span class="comment">// If we used the lazy creator, the flow- and loadplans have not been</span>
<a name="l00273"></a>00273   <span class="comment">// created yet. We do it now...</span>
<a name="l00274"></a>00274   <a class="code" href="a00125.html#a1c0ab58f6d41e2fd26e50f09158042ee">createFlowLoads</a>();
<a name="l00275"></a>00275 
<a name="l00276"></a>00276   <span class="comment">// Extra registration step if this is a delivery operation</span>
<a name="l00277"></a>00277   <span class="keywordflow">if</span> (<a class="code" href="a00125.html#a4cd571d01df7194dd232d07f7cbba03f">getDemand</a>() &amp;&amp; <a class="code" href="a00125.html#a4cd571d01df7194dd232d07f7cbba03f">getDemand</a>()-&gt;getDeliveryOperation() == oper)
<a name="l00278"></a>00278     dmd-&gt;<a class="code" href="a00051.html#abd37a48b6cbd9de6d32f4443c1e82841">addDelivery</a>(<span class="keyword">this</span>);
<a name="l00279"></a>00279 
<a name="l00280"></a>00280   <span class="comment">// Mark the operation to detect its problems</span>
<a name="l00281"></a>00281   <span class="comment">// Note that a single operationplan thus retriggers the problem computation</span>
<a name="l00282"></a>00282   <span class="comment">// for all operationplans of this operation. For models with 1) a large</span>
<a name="l00283"></a>00283   <span class="comment">// number of operationplans per operation and 2) very frequent problem</span>
<a name="l00284"></a>00284   <span class="comment">// detection, this could constitute a scalability problem. This combination</span>
<a name="l00285"></a>00285   <span class="comment">// is expected to be unusual and rare, justifying this design choice.</span>
<a name="l00286"></a>00286   oper-&gt;<a class="code" href="a00133.html#a11a86a6e020664a337325a96a64f6d2c">setChanged</a>();
<a name="l00287"></a>00287 
<a name="l00288"></a>00288   <span class="comment">// The operationplan is valid</span>
<a name="l00289"></a>00289   <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00290"></a>00290 }
<a name="l00291"></a>00291 
<a name="l00292"></a>00292 
<a name="l00293"></a><a class="code" href="a00125.html#a8d6318b95bb6095572c645b0f77162ce">00293</a> <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> <span class="keywordtype">void</span> <a class="code" href="a00125.html#a8d6318b95bb6095572c645b0f77162ce">OperationPlan::insertInOperationplanList</a>()
<a name="l00294"></a>00294 {
<a name="l00295"></a>00295 
<a name="l00296"></a>00296   <span class="comment">// Check if already linked</span>
<a name="l00297"></a>00297   <span class="keywordflow">if</span> (prev || oper-&gt;first_opplan == <span class="keyword">this</span>) <span class="keywordflow">return</span>;
<a name="l00298"></a>00298 
<a name="l00299"></a>00299   <span class="keywordflow">if</span> (!oper-&gt;first_opplan)
<a name="l00300"></a>00300   {
<a name="l00301"></a>00301     <span class="comment">// First operationplan in the list</span>
<a name="l00302"></a>00302     oper-&gt;first_opplan = <span class="keyword">this</span>;
<a name="l00303"></a>00303     oper-&gt;last_opplan = <span class="keyword">this</span>;
<a name="l00304"></a>00304   }
<a name="l00305"></a>00305   <span class="keywordflow">else</span> <span class="keywordflow">if</span> (*<span class="keyword">this</span> &lt; *(oper-&gt;first_opplan))
<a name="l00306"></a>00306   {
<a name="l00307"></a>00307     <span class="comment">// First in the list</span>
<a name="l00308"></a>00308     next = oper-&gt;first_opplan;
<a name="l00309"></a>00309     next-&gt;prev = <span class="keyword">this</span>;
<a name="l00310"></a>00310     oper-&gt;first_opplan = <span class="keyword">this</span>;
<a name="l00311"></a>00311   }
<a name="l00312"></a>00312   <span class="keywordflow">else</span> <span class="keywordflow">if</span> (*(oper-&gt;last_opplan) &lt; *<span class="keyword">this</span>)
<a name="l00313"></a>00313   {
<a name="l00314"></a>00314     <span class="comment">// Last in the list</span>
<a name="l00315"></a>00315     prev = oper-&gt;last_opplan;
<a name="l00316"></a>00316     prev-&gt;next = <span class="keyword">this</span>;
<a name="l00317"></a>00317     oper-&gt;last_opplan = <span class="keyword">this</span>;
<a name="l00318"></a>00318   }
<a name="l00319"></a>00319   <span class="keywordflow">else</span>
<a name="l00320"></a>00320   {
<a name="l00321"></a>00321     <span class="comment">// Insert in the middle of the list</span>
<a name="l00322"></a>00322     <a class="code" href="a00125.html" title="An operationplan is the key dynamic element of a plan. It represents a certain quantity...">OperationPlan</a> *x = oper-&gt;last_opplan;
<a name="l00323"></a>00323     <a class="code" href="a00125.html" title="An operationplan is the key dynamic element of a plan. It represents a certain quantity...">OperationPlan</a> *y = NULL;
<a name="l00324"></a>00324     <span class="keywordflow">while</span> (!(*x &lt; *<span class="keyword">this</span>))
<a name="l00325"></a>00325     {
<a name="l00326"></a>00326       y = x;
<a name="l00327"></a>00327       x = x-&gt;prev;
<a name="l00328"></a>00328     }
<a name="l00329"></a>00329     next = y;
<a name="l00330"></a>00330     prev = x;
<a name="l00331"></a>00331     <span class="keywordflow">if</span> (x) x-&gt;next = <span class="keyword">this</span>;
<a name="l00332"></a>00332     <span class="keywordflow">if</span> (y) y-&gt;prev = <span class="keyword">this</span>;
<a name="l00333"></a>00333   }
<a name="l00334"></a>00334 }
<a name="l00335"></a>00335 
<a name="l00336"></a>00336 
<a name="l00337"></a><a class="code" href="a00125.html#acc8852654a67b2108f49f83472698f63">00337</a> <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> <span class="keywordtype">void</span> <a class="code" href="a00125.html#acc8852654a67b2108f49f83472698f63">OperationPlan::addSubOperationPlan</a>(<a class="code" href="a00125.html" title="An operationplan is the key dynamic element of a plan. It represents a certain quantity...">OperationPlan</a>* o)
<a name="l00338"></a>00338 {
<a name="l00339"></a>00339   <span class="comment">// Check</span>
<a name="l00340"></a>00340   <span class="keywordflow">if</span> (!o) <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;Adding null suboperationplan&quot;</span>);
<a name="l00341"></a>00341 
<a name="l00342"></a>00342   <span class="comment">// Adding a suboperationplan that was already added</span>
<a name="l00343"></a>00343   <span class="keywordflow">if</span> (o-&gt;owner == <span class="keyword">this</span>)  <span class="keywordflow">return</span>;
<a name="l00344"></a>00344 
<a name="l00345"></a>00345   <span class="comment">// Clear the previous owner, if there is one</span>
<a name="l00346"></a>00346   <span class="keywordflow">if</span> (o-&gt;owner) o-&gt;owner-&gt;<a class="code" href="a00125.html#a229e9661189af68191319f759f3021a5">eraseSubOperationPlan</a>(o);
<a name="l00347"></a>00347 
<a name="l00348"></a>00348   <span class="comment">// Link in the list, keeping the right ordering</span>
<a name="l00349"></a>00349   <span class="keywordflow">if</span> (!firstsubopplan)
<a name="l00350"></a>00350   {
<a name="l00351"></a>00351     <span class="comment">// First element</span>
<a name="l00352"></a>00352     firstsubopplan = o;
<a name="l00353"></a>00353     lastsubopplan = o;
<a name="l00354"></a>00354   }
<a name="l00355"></a>00355   <span class="keywordflow">else</span> <span class="keywordflow">if</span> (firstsubopplan-&gt;<a class="code" href="a00125.html#a2f5ae1046cd50f98e59520ed8910c458">getOperation</a>() != <a class="code" href="a00129.html#add35ebccc253401c86cc40dc2fed3f04">OperationSetup::setupoperation</a>)    
<a name="l00356"></a>00356   {
<a name="l00357"></a>00357     <span class="comment">// New head</span>
<a name="l00358"></a>00358     o-&gt;nextsubopplan = firstsubopplan;
<a name="l00359"></a>00359     firstsubopplan-&gt;prevsubopplan = o;
<a name="l00360"></a>00360     firstsubopplan = o;
<a name="l00361"></a>00361   }
<a name="l00362"></a>00362   <span class="keywordflow">else</span>
<a name="l00363"></a>00363   {
<a name="l00364"></a>00364     <span class="comment">// Insert right after the setup operationplan</span>
<a name="l00365"></a>00365     <a class="code" href="a00125.html" title="An operationplan is the key dynamic element of a plan. It represents a certain quantity...">OperationPlan</a> *s = firstsubopplan-&gt;nextsubopplan;
<a name="l00366"></a>00366     o-&gt;nextsubopplan = s;
<a name="l00367"></a>00367     <span class="keywordflow">if</span> (s) s-&gt;nextsubopplan = o;
<a name="l00368"></a>00368     <span class="keywordflow">else</span> lastsubopplan = o;
<a name="l00369"></a>00369   }
<a name="l00370"></a>00370 
<a name="l00371"></a>00371   o-&gt;owner = <span class="keyword">this</span>;
<a name="l00372"></a>00372 
<a name="l00373"></a>00373   <span class="comment">// Update the flow and loadplans</span>
<a name="l00374"></a>00374   update();
<a name="l00375"></a>00375 }
<a name="l00376"></a>00376 
<a name="l00377"></a>00377 
<a name="l00378"></a><a class="code" href="a00125.html#a229e9661189af68191319f759f3021a5">00378</a> <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> <span class="keywordtype">void</span> <a class="code" href="a00125.html#a229e9661189af68191319f759f3021a5">OperationPlan::eraseSubOperationPlan</a>(<a class="code" href="a00125.html" title="An operationplan is the key dynamic element of a plan. It represents a certain quantity...">OperationPlan</a>* o)
<a name="l00379"></a>00379 {
<a name="l00380"></a>00380   <span class="comment">// Check</span>
<a name="l00381"></a>00381   <span class="keywordflow">if</span> (!o) <span class="keywordflow">return</span>;
<a name="l00382"></a>00382 
<a name="l00383"></a>00383   <span class="comment">// Adding a suboperationplan that was already added</span>
<a name="l00384"></a>00384   <span class="keywordflow">if</span> (o-&gt;owner != <span class="keyword">this</span>)
<a name="l00385"></a>00385     <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;Operationplan isn&apos;t a suboperationplan&quot;</span>);
<a name="l00386"></a>00386 
<a name="l00387"></a>00387   <span class="comment">// Clear owner field</span>
<a name="l00388"></a>00388   o-&gt;owner = NULL;
<a name="l00389"></a>00389 
<a name="l00390"></a>00390   <span class="comment">// Remove from the list</span>
<a name="l00391"></a>00391   <span class="keywordflow">if</span> (o-&gt;prevsubopplan)
<a name="l00392"></a>00392     o-&gt;prevsubopplan-&gt;nextsubopplan = o-&gt;nextsubopplan;
<a name="l00393"></a>00393   <span class="keywordflow">else</span>
<a name="l00394"></a>00394     firstsubopplan = o-&gt;nextsubopplan;
<a name="l00395"></a>00395   <span class="keywordflow">if</span> (o-&gt;nextsubopplan)
<a name="l00396"></a>00396     o-&gt;nextsubopplan-&gt;prevsubopplan = o-&gt;prevsubopplan;
<a name="l00397"></a>00397   <span class="keywordflow">else</span>
<a name="l00398"></a>00398     lastsubopplan = o-&gt;prevsubopplan;
<a name="l00399"></a>00399 };
<a name="l00400"></a>00400 
<a name="l00401"></a>00401 
<a name="l00402"></a><a class="code" href="a00125.html#afb462df2932218d71293488010585cf8">00402</a> <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> <span class="keywordtype">bool</span> <a class="code" href="a00125.html#afb462df2932218d71293488010585cf8">OperationPlan::operator &lt; </a>(<span class="keyword">const</span> <a class="code" href="a00125.html" title="An operationplan is the key dynamic element of a plan. It represents a certain quantity...">OperationPlan</a>&amp; a)<span class="keyword"> const</span>
<a name="l00403"></a>00403 <span class="keyword"></span>{
<a name="l00404"></a>00404   <span class="comment">// Different operations</span>
<a name="l00405"></a>00405   <span class="keywordflow">if</span> (oper != a.oper)
<a name="l00406"></a>00406     <span class="keywordflow">return</span> *oper &lt; *(a.oper);
<a name="l00407"></a>00407 
<a name="l00408"></a>00408   <span class="comment">// Different start date</span>
<a name="l00409"></a>00409   <span class="keywordflow">if</span> (dates.<a class="code" href="a00050.html#a73e574de7fbf5df8ebc4c5190e7d49c3">getStart</a>() != a.dates.<a class="code" href="a00050.html#a73e574de7fbf5df8ebc4c5190e7d49c3">getStart</a>())
<a name="l00410"></a>00410     <span class="keywordflow">return</span> dates.<a class="code" href="a00050.html#a73e574de7fbf5df8ebc4c5190e7d49c3">getStart</a>() &lt; a.dates.<a class="code" href="a00050.html#a73e574de7fbf5df8ebc4c5190e7d49c3">getStart</a>();
<a name="l00411"></a>00411 
<a name="l00412"></a>00412   <span class="comment">// Sort based on quantity</span>
<a name="l00413"></a>00413   <span class="keywordflow">return</span> quantity &gt;= a.quantity;
<a name="l00414"></a>00414 }
<a name="l00415"></a>00415 
<a name="l00416"></a>00416 
<a name="l00417"></a><a class="code" href="a00125.html#a1c0ab58f6d41e2fd26e50f09158042ee">00417</a> <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> <span class="keywordtype">void</span> <a class="code" href="a00125.html#a1c0ab58f6d41e2fd26e50f09158042ee">OperationPlan::createFlowLoads</a>()
<a name="l00418"></a>00418 {
<a name="l00419"></a>00419   <span class="comment">// Has been initialized already, it seems</span>
<a name="l00420"></a>00420   <span class="keywordflow">if</span> (firstflowplan || firstloadplan) <span class="keywordflow">return</span>;
<a name="l00421"></a>00421 
<a name="l00422"></a>00422   <span class="comment">// Create setup suboperationplans and loadplans</span>
<a name="l00423"></a>00423   <span class="keywordflow">for</span> (Operation::loadlist::const_iterator g=oper-&gt;<a class="code" href="a00121.html#a7b95131f687f60ec30165e14876dac7c">getLoads</a>().begin();
<a name="l00424"></a>00424       g!=oper-&gt;<a class="code" href="a00121.html#a7b95131f687f60ec30165e14876dac7c">getLoads</a>().end(); ++g)
<a name="l00425"></a>00425     <span class="keywordflow">if</span> (!g-&gt;getAlternate())
<a name="l00426"></a>00426     {
<a name="l00427"></a>00427       <span class="keyword">new</span> <a class="code" href="a00125.html#a5e110698e5fb838ff5f374bd47196b7e">LoadPlan</a>(<span class="keyword">this</span>, &amp;*g);
<a name="l00428"></a>00428       <span class="keywordflow">if</span> (!g-&gt;getSetup().empty() &amp;&amp; g-&gt;getResource()-&gt;getSetupMatrix())
<a name="l00429"></a>00429         <a class="code" href="a00129.html#add35ebccc253401c86cc40dc2fed3f04">OperationSetup::setupoperation</a>-&gt;<a class="code" href="a00125.html#acabc6d5f06b157c155355d04b3e2e4ef">createOperationPlan</a>(
<a name="l00430"></a>00430           1, <a class="code" href="a00125.html#a9f19aec0a96f30616f2ee06e3c8f371a">getDates</a>().<a class="code" href="a00050.html#a73e574de7fbf5df8ebc4c5190e7d49c3">getStart</a>(), <a class="code" href="a00125.html#a9f19aec0a96f30616f2ee06e3c8f371a">getDates</a>().<a class="code" href="a00050.html#a73e574de7fbf5df8ebc4c5190e7d49c3">getStart</a>(), NULL, <span class="keyword">this</span>);
<a name="l00431"></a>00431     }
<a name="l00432"></a>00432 
<a name="l00433"></a>00433   <span class="comment">// Create flowplans for flows that are not alternates of another one</span>
<a name="l00434"></a>00434   <span class="keywordflow">for</span> (<a class="code" href="a00040.html" title="An iterator over the associated objects.">Operation::flowlist::const_iterator</a> h=oper-&gt;<a class="code" href="a00121.html#ac6b2f299c5939e2c61b2724ac58a2326">getFlows</a>().begin();
<a name="l00435"></a>00435       h!=oper-&gt;<a class="code" href="a00121.html#ac6b2f299c5939e2c61b2724ac58a2326">getFlows</a>().end(); ++h)
<a name="l00436"></a>00436     <span class="keywordflow">if</span> (!h-&gt;getAlternate()) <span class="keyword">new</span> <a class="code" href="a00125.html#a59711ad93b304e7c02ef52f39e010ebf">FlowPlan</a>(<span class="keyword">this</span>, &amp;*h);
<a name="l00437"></a>00437 }
<a name="l00438"></a>00438 
<a name="l00439"></a>00439 
<a name="l00440"></a><a class="code" href="a00125.html#ae91afde7a26188acdb6e499b8a5b93fc">00440</a> <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> <a class="code" href="a00125.html#ae91afde7a26188acdb6e499b8a5b93fc">OperationPlan::~OperationPlan</a>()
<a name="l00441"></a>00441 {
<a name="l00442"></a>00442   <span class="comment">// Initialize</span>
<a name="l00443"></a>00443   <a class="code" href="a00069.html" title="An iterator class to go through all flowplans of an operationplan.">FlowPlanIterator</a> e = <a class="code" href="a00125.html#a4fb68598ded2db1ae3a9f5f975dd09c6">beginFlowPlans</a>();
<a name="l00444"></a>00444   <a class="code" href="a00106.html" title="An iterator class to go through all loadplans of an operationplan.">LoadPlanIterator</a> f = <a class="code" href="a00125.html#af14047934961e9c5f04c0ecc70df649c">beginLoadPlans</a>(); 
<a name="l00445"></a>00445   <a class="code" href="a00125.html" title="An operationplan is the key dynamic element of a plan. It represents a certain quantity...">OperationPlan</a> *x = firstsubopplan;
<a name="l00446"></a>00446 
<a name="l00447"></a>00447   <span class="comment">// Reset to avoid extra updates during the destruction</span>
<a name="l00448"></a>00448   firstflowplan = NULL;
<a name="l00449"></a>00449   firstloadplan = NULL;
<a name="l00450"></a>00450   firstsubopplan = NULL;
<a name="l00451"></a>00451   lastsubopplan = NULL;
<a name="l00452"></a>00452 
<a name="l00453"></a>00453   <span class="comment">// Delete the flowplans and loadplan</span>
<a name="l00454"></a>00454   <span class="keywordflow">while</span> (e != <a class="code" href="a00125.html#a1b421f000d0a136fa3f9dc3abd5b76cc">endFlowPlans</a>()) <span class="keyword">delete</span> &amp;*(e++);
<a name="l00455"></a>00455   <span class="keywordflow">while</span> (f != <a class="code" href="a00125.html#af4b4401df92ad9e292edd56d3272b79c">endLoadPlans</a>()) <span class="keyword">delete</span> &amp;*(f++);
<a name="l00456"></a>00456 
<a name="l00457"></a>00457   <span class="comment">// Delete the sub operationplans</span>
<a name="l00458"></a>00458   <span class="keywordflow">while</span> (x)
<a name="l00459"></a>00459   {
<a name="l00460"></a>00460     <a class="code" href="a00125.html" title="An operationplan is the key dynamic element of a plan. It represents a certain quantity...">OperationPlan</a> *y = x-&gt;nextsubopplan;
<a name="l00461"></a>00461     x-&gt;owner = NULL; <span class="comment">// Need to clear before destroying the suboperationplan</span>
<a name="l00462"></a>00462     <span class="keyword">delete</span> x;
<a name="l00463"></a>00463     x = y;
<a name="l00464"></a>00464   }
<a name="l00465"></a>00465 
<a name="l00466"></a>00466   <span class="comment">// Delete also the owner</span>
<a name="l00467"></a>00467   <span class="keywordflow">if</span> (owner)
<a name="l00468"></a>00468   {
<a name="l00469"></a>00469     <span class="keyword">const</span> <a class="code" href="a00125.html" title="An operationplan is the key dynamic element of a plan. It represents a certain quantity...">OperationPlan</a>* o = owner;
<a name="l00470"></a>00470     <a class="code" href="a00125.html#a1a08b007136515186cc22cd95007f122">setOwner</a>(NULL);
<a name="l00471"></a>00471     <span class="keyword">delete</span> o;
<a name="l00472"></a>00472   }
<a name="l00473"></a>00473 
<a name="l00474"></a>00474   <span class="comment">// Delete from the list of deliveries</span>
<a name="l00475"></a>00475   <span class="keywordflow">if</span> (<span class="keywordtype">id</span> &amp;&amp; dmd) dmd-&gt;<a class="code" href="a00051.html#ad7b6e76943e7774d10538fe21039430d">removeDelivery</a>(<span class="keyword">this</span>);
<a name="l00476"></a>00476 
<a name="l00477"></a>00477   <span class="comment">// Delete from the operationplan list</span>
<a name="l00478"></a>00478   <span class="keywordflow">if</span> (prev)
<a name="l00479"></a>00479     <span class="comment">// In the middle</span>
<a name="l00480"></a>00480     prev-&gt;next = next;
<a name="l00481"></a>00481   <span class="keywordflow">else</span> <span class="keywordflow">if</span> (oper-&gt;first_opplan == <span class="keyword">this</span>)
<a name="l00482"></a>00482     <span class="comment">// First opplan in the list of this operation</span>
<a name="l00483"></a>00483     oper-&gt;first_opplan = next;
<a name="l00484"></a>00484   <span class="keywordflow">if</span> (next)
<a name="l00485"></a>00485     <span class="comment">// In the middle</span>
<a name="l00486"></a>00486     next-&gt;prev = prev;
<a name="l00487"></a>00487   <span class="keywordflow">else</span> <span class="keywordflow">if</span> (oper-&gt;last_opplan == <span class="keyword">this</span>)
<a name="l00488"></a>00488     <span class="comment">// Last opplan in the list of this operation</span>
<a name="l00489"></a>00489     oper-&gt;last_opplan = prev;
<a name="l00490"></a>00490 }
<a name="l00491"></a>00491 
<a name="l00492"></a>00492 
<a name="l00493"></a><a class="code" href="a00125.html#a1a08b007136515186cc22cd95007f122">00493</a> <span class="keywordtype">void</span> <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> <a class="code" href="a00125.html#a1a08b007136515186cc22cd95007f122">OperationPlan::setOwner</a>(<a class="code" href="a00125.html" title="An operationplan is the key dynamic element of a plan. It represents a certain quantity...">OperationPlan</a>* o)
<a name="l00494"></a>00494 {
<a name="l00495"></a>00495   <span class="comment">// Special case: the same owner is set twice</span>
<a name="l00496"></a>00496   <span class="keywordflow">if</span> (owner == o) <span class="keywordflow">return</span>;
<a name="l00497"></a>00497   <span class="comment">// Erase the previous owner if there is one</span>
<a name="l00498"></a>00498   <span class="keywordflow">if</span> (owner) owner-&gt;<a class="code" href="a00125.html#a229e9661189af68191319f759f3021a5">eraseSubOperationPlan</a>(<span class="keyword">this</span>);
<a name="l00499"></a>00499   <span class="comment">// Register with the new owner</span>
<a name="l00500"></a>00500   <span class="keywordflow">if</span> (o) o-&gt;<a class="code" href="a00125.html#acc8852654a67b2108f49f83472698f63">addSubOperationPlan</a>(<span class="keyword">this</span>);
<a name="l00501"></a>00501 }
<a name="l00502"></a>00502 
<a name="l00503"></a>00503 
<a name="l00504"></a><a class="code" href="a00125.html#a2265d1554215f7185b8556f53c5805f2">00504</a> <span class="keywordtype">void</span> <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> <a class="code" href="a00125.html#a2265d1554215f7185b8556f53c5805f2">OperationPlan::setStart</a> (<a class="code" href="a00049.html" title="This class represents a date and time with an accuracy of one second.">Date</a> d)
<a name="l00505"></a>00505 {
<a name="l00506"></a>00506   <span class="comment">// Locked opplans don&apos;t move</span>
<a name="l00507"></a>00507   <span class="keywordflow">if</span> (<a class="code" href="a00125.html#ad76b43eab48c2587255ec1b460f91093">getLocked</a>()) <span class="keywordflow">return</span>;
<a name="l00508"></a>00508 
<a name="l00509"></a>00509   <span class="keywordflow">if</span> (!lastsubopplan || lastsubopplan-&gt;<a class="code" href="a00125.html#a2f5ae1046cd50f98e59520ed8910c458">getOperation</a>() == <a class="code" href="a00129.html#add35ebccc253401c86cc40dc2fed3f04">OperationSetup::setupoperation</a>)
<a name="l00510"></a>00510     <span class="comment">// No sub operationplans</span>
<a name="l00511"></a>00511     oper-&gt;<a class="code" href="a00121.html#a744480cdd80e70a2b0a7606114e1ab73">setOperationPlanParameters</a>(<span class="keyword">this</span>,quantity,d,Date::infinitePast);
<a name="l00512"></a>00512   <span class="keywordflow">else</span>
<a name="l00513"></a>00513   {
<a name="l00514"></a>00514     <span class="comment">// Move all sub-operationplans in an orderly fashion</span>
<a name="l00515"></a>00515     <span class="keywordtype">bool</span> firstMove = <span class="keyword">true</span>;
<a name="l00516"></a>00516     <span class="keywordflow">for</span> (<a class="code" href="a00125.html" title="An operationplan is the key dynamic element of a plan. It represents a certain quantity...">OperationPlan</a>* i = firstsubopplan; i; i = i-&gt;nextsubopplan)
<a name="l00517"></a>00517     {
<a name="l00518"></a>00518       <span class="keywordflow">if</span> (i-&gt;getOperation() == <a class="code" href="a00129.html#add35ebccc253401c86cc40dc2fed3f04">OperationSetup::setupoperation</a>) <span class="keywordflow">continue</span>;
<a name="l00519"></a>00519       <span class="keywordflow">if</span> (i-&gt;getDates().getStart() &lt; d || firstMove)
<a name="l00520"></a>00520       {
<a name="l00521"></a>00521         i-&gt;setStart(d);
<a name="l00522"></a>00522         <span class="comment">// Comment out the next line to leave slack in the routing.</span>
<a name="l00523"></a>00523         <span class="comment">// With the line commented out routing slack is cleaned up aggressively.</span>
<a name="l00524"></a>00524         <span class="comment">//@todo firstMove = false;  </span>
<a name="l00525"></a>00525         d = i-&gt;getDates().getEnd();
<a name="l00526"></a>00526       }
<a name="l00527"></a>00527       <span class="keywordflow">else</span>
<a name="l00528"></a>00528         <span class="comment">// There is sufficient slack between the suboperation plans</span>
<a name="l00529"></a>00529         <span class="keywordflow">break</span>;
<a name="l00530"></a>00530     }
<a name="l00531"></a>00531   }
<a name="l00532"></a>00532 
<a name="l00533"></a>00533   <span class="comment">// Update flow and loadplans</span>
<a name="l00534"></a>00534   update();
<a name="l00535"></a>00535 }
<a name="l00536"></a>00536 
<a name="l00537"></a>00537 
<a name="l00538"></a><a class="code" href="a00125.html#af70f6b33dcda3739d1c090a632408cd4">00538</a> <span class="keywordtype">void</span> <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> <a class="code" href="a00125.html#af70f6b33dcda3739d1c090a632408cd4">OperationPlan::setEnd</a>(<a class="code" href="a00049.html" title="This class represents a date and time with an accuracy of one second.">Date</a> d)
<a name="l00539"></a>00539 {
<a name="l00540"></a>00540   <span class="comment">// Locked opplans don&apos;t move</span>
<a name="l00541"></a>00541   <span class="keywordflow">if</span> (<a class="code" href="a00125.html#ad76b43eab48c2587255ec1b460f91093">getLocked</a>()) <span class="keywordflow">return</span>;
<a name="l00542"></a>00542 
<a name="l00543"></a>00543   <span class="keywordflow">if</span> (!lastsubopplan || lastsubopplan-&gt;<a class="code" href="a00125.html#a2f5ae1046cd50f98e59520ed8910c458">getOperation</a>() == <a class="code" href="a00129.html#add35ebccc253401c86cc40dc2fed3f04">OperationSetup::setupoperation</a>)
<a name="l00544"></a>00544     <span class="comment">// No sub operationplans</span>
<a name="l00545"></a>00545     oper-&gt;<a class="code" href="a00121.html#a744480cdd80e70a2b0a7606114e1ab73">setOperationPlanParameters</a>(<span class="keyword">this</span>,quantity,Date::infinitePast,d);
<a name="l00546"></a>00546   <span class="keywordflow">else</span>
<a name="l00547"></a>00547   {
<a name="l00548"></a>00548     <span class="comment">// Move all sub-operationplans in an orderly fashion</span>
<a name="l00549"></a>00549     <span class="keywordtype">bool</span> firstMove = <span class="keyword">true</span>;
<a name="l00550"></a>00550     <span class="keywordflow">for</span> (<a class="code" href="a00125.html" title="An operationplan is the key dynamic element of a plan. It represents a certain quantity...">OperationPlan</a>* i = lastsubopplan; i; i = i-&gt;prevsubopplan)
<a name="l00551"></a>00551     {
<a name="l00552"></a>00552       <span class="keywordflow">if</span> (i-&gt;getOperation() == <a class="code" href="a00129.html#add35ebccc253401c86cc40dc2fed3f04">OperationSetup::setupoperation</a>) <span class="keywordflow">break</span>;
<a name="l00553"></a>00553       <span class="keywordflow">if</span> (i-&gt;getDates().getEnd() &gt; d || firstMove)
<a name="l00554"></a>00554       {
<a name="l00555"></a>00555         i-&gt;setEnd(d);
<a name="l00556"></a>00556         <span class="comment">// Comment out the next line to leave slack in the routing.</span>
<a name="l00557"></a>00557         <span class="comment">// With the line commented out routing slack is cleaned up aggressively.</span>
<a name="l00558"></a>00558         <span class="comment">// @todo firstMove = false;</span>
<a name="l00559"></a>00559         d = i-&gt;getDates().getStart();
<a name="l00560"></a>00560       }
<a name="l00561"></a>00561       <span class="keywordflow">else</span>
<a name="l00562"></a>00562         <span class="comment">// There is sufficient slack between the suboperations</span>
<a name="l00563"></a>00563         <span class="keywordflow">break</span>;
<a name="l00564"></a>00564     }
<a name="l00565"></a>00565   }
<a name="l00566"></a>00566 
<a name="l00567"></a>00567   <span class="comment">// Update flow and loadplans</span>
<a name="l00568"></a>00568   update();
<a name="l00569"></a>00569 }
<a name="l00570"></a>00570 
<a name="l00571"></a>00571 
<a name="l00572"></a><a class="code" href="a00125.html#aa33a70a23ad111e4b2a35ec96757a1fb">00572</a> <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> <span class="keywordtype">double</span> <a class="code" href="a00125.html#aa33a70a23ad111e4b2a35ec96757a1fb">OperationPlan::setQuantity</a> (<span class="keywordtype">double</span> f, <span class="keywordtype">bool</span> roundDown, <span class="keywordtype">bool</span> upd, <span class="keywordtype">bool</span> execute)
<a name="l00573"></a>00573 {
<a name="l00574"></a>00574   <span class="comment">// No impact on locked operationplans</span>
<a name="l00575"></a>00575   <span class="keywordflow">if</span> (<a class="code" href="a00125.html#ad76b43eab48c2587255ec1b460f91093">getLocked</a>()) <span class="keywordflow">return</span> quantity;
<a name="l00576"></a>00576 
<a name="l00577"></a>00577   <span class="comment">// Invalid operationplan: the quantity must be &gt;= 0.</span>
<a name="l00578"></a>00578   <span class="keywordflow">if</span> (f &lt; 0)
<a name="l00579"></a>00579     <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;Operationplans can&apos;t have negative quantities&quot;</span>);
<a name="l00580"></a>00580 
<a name="l00581"></a>00581   <span class="comment">// Setting a quantity is only allowed on a top operationplan.</span>
<a name="l00582"></a>00582   <span class="comment">// One exception: on alternate operations the sizing on the sub-operations is</span>
<a name="l00583"></a>00583   <span class="comment">// respected.</span>
<a name="l00584"></a>00584   <span class="keywordflow">if</span> (owner &amp;&amp; owner-&gt;<a class="code" href="a00125.html#a2f5ae1046cd50f98e59520ed8910c458">getOperation</a>()-&gt;<a class="code" href="a00120.html#a2e5ff5e5d9c32647f692abd04a0d72d2">getType</a>() != *<a class="code" href="a00122.html#af55e7f4c9ea99a222e7433756f001d4a">OperationAlternate::metadata</a>)
<a name="l00585"></a>00585     <span class="keywordflow">return</span> owner-&gt;<a class="code" href="a00125.html#aa33a70a23ad111e4b2a35ec96757a1fb">setQuantity</a>(f,roundDown,upd,execute);
<a name="l00586"></a>00586 
<a name="l00587"></a>00587   <span class="comment">// Compute the correct size for the operationplan</span>
<a name="l00588"></a>00588   <span class="keywordflow">if</span> (f!=0.0 &amp;&amp; <a class="code" href="a00125.html#a2f5ae1046cd50f98e59520ed8910c458">getOperation</a>()-&gt;getSizeMinimum()&gt;0.0
<a name="l00589"></a>00589       &amp;&amp; f &lt; <a class="code" href="a00125.html#a2f5ae1046cd50f98e59520ed8910c458">getOperation</a>()-&gt;getSizeMinimum())
<a name="l00590"></a>00590   {
<a name="l00591"></a>00591     <span class="keywordflow">if</span> (roundDown)
<a name="l00592"></a>00592     {
<a name="l00593"></a>00593       <span class="comment">// Smaller than the minimum quantity, rounding down means... nothing</span>
<a name="l00594"></a>00594       <span class="keywordflow">if</span> (!execute) <span class="keywordflow">return</span> 0.0;
<a name="l00595"></a>00595       quantity = 0.0;
<a name="l00596"></a>00596       <span class="comment">// Update the flow and loadplans, and mark for problem detection</span>
<a name="l00597"></a>00597       <span class="keywordflow">if</span> (upd) update();
<a name="l00598"></a>00598       <span class="keywordflow">return</span> 0.0;
<a name="l00599"></a>00599     }
<a name="l00600"></a>00600     f = <a class="code" href="a00125.html#a2f5ae1046cd50f98e59520ed8910c458">getOperation</a>()-&gt;<a class="code" href="a00121.html#ae1ef1417d3f6b89561e6c0909f772782">getSizeMinimum</a>();
<a name="l00601"></a>00601   }
<a name="l00602"></a>00602   <span class="keywordflow">if</span> (f != 0.0 &amp;&amp; f &gt;= <a class="code" href="a00125.html#a2f5ae1046cd50f98e59520ed8910c458">getOperation</a>()-&gt;getSizeMaximum())
<a name="l00603"></a>00603   {
<a name="l00604"></a>00604     roundDown = <span class="keyword">true</span>; <span class="comment">// force rounddown to stay below the limit</span>
<a name="l00605"></a>00605     f = <a class="code" href="a00125.html#a2f5ae1046cd50f98e59520ed8910c458">getOperation</a>()-&gt;<a class="code" href="a00121.html#af720f657b00a661e76f3ba7304053071">getSizeMaximum</a>();
<a name="l00606"></a>00606   }
<a name="l00607"></a>00607   <span class="keywordflow">if</span> (f!=0.0 &amp;&amp; <a class="code" href="a00125.html#a2f5ae1046cd50f98e59520ed8910c458">getOperation</a>()-&gt;getSizeMultiple()&gt;0.0)
<a name="l00608"></a>00608   {
<a name="l00609"></a>00609     <span class="keywordtype">int</span> mult = <span class="keyword">static_cast&lt;</span><span class="keywordtype">int</span><span class="keyword">&gt;</span> (f / <a class="code" href="a00125.html#a2f5ae1046cd50f98e59520ed8910c458">getOperation</a>()-&gt;<a class="code" href="a00121.html#a3b55372755baff92fa8fcc0d47ed717f">getSizeMultiple</a>()
<a name="l00610"></a>00610         + (roundDown ? 0.0 : 0.99999999));
<a name="l00611"></a>00611     <span class="keywordflow">if</span> (!execute) <span class="keywordflow">return</span> mult * <a class="code" href="a00125.html#a2f5ae1046cd50f98e59520ed8910c458">getOperation</a>()-&gt;<a class="code" href="a00121.html#a3b55372755baff92fa8fcc0d47ed717f">getSizeMultiple</a>();
<a name="l00612"></a>00612     quantity = mult * <a class="code" href="a00125.html#a2f5ae1046cd50f98e59520ed8910c458">getOperation</a>()-&gt;<a class="code" href="a00121.html#a3b55372755baff92fa8fcc0d47ed717f">getSizeMultiple</a>();
<a name="l00613"></a>00613   }
<a name="l00614"></a>00614   <span class="keywordflow">else</span>
<a name="l00615"></a>00615   {
<a name="l00616"></a>00616     <span class="keywordflow">if</span> (!execute) <span class="keywordflow">return</span> f;
<a name="l00617"></a>00617     quantity = f;
<a name="l00618"></a>00618   }
<a name="l00619"></a>00619 
<a name="l00620"></a>00620   <span class="comment">// Update the parent of an alternate operationplan</span>
<a name="l00621"></a>00621   <span class="keywordflow">if</span> (execute &amp;&amp; owner
<a name="l00622"></a>00622     &amp;&amp; owner-&gt;<a class="code" href="a00125.html#a2f5ae1046cd50f98e59520ed8910c458">getOperation</a>()-&gt;<a class="code" href="a00120.html#a2e5ff5e5d9c32647f692abd04a0d72d2">getType</a>() == *<a class="code" href="a00122.html#af55e7f4c9ea99a222e7433756f001d4a">OperationAlternate::metadata</a>)
<a name="l00623"></a>00623   {
<a name="l00624"></a>00624     owner-&gt;quantity = quantity;
<a name="l00625"></a>00625     <span class="keywordflow">if</span> (upd) owner-&gt;resizeFlowLoadPlans();
<a name="l00626"></a>00626   }
<a name="l00627"></a>00627 
<a name="l00628"></a>00628   <span class="comment">// Apply the same size also to its children</span>
<a name="l00629"></a>00629   <span class="keywordflow">if</span> (execute &amp;&amp; firstsubopplan)
<a name="l00630"></a>00630     <span class="keywordflow">for</span> (<a class="code" href="a00125.html" title="An operationplan is the key dynamic element of a plan. It represents a certain quantity...">OperationPlan</a> *i = firstsubopplan; i; i = i-&gt;nextsubopplan)
<a name="l00631"></a>00631       <span class="keywordflow">if</span> (i-&gt;getOperation() != <a class="code" href="a00129.html#add35ebccc253401c86cc40dc2fed3f04">OperationSetup::setupoperation</a>)
<a name="l00632"></a>00632       {
<a name="l00633"></a>00633         i-&gt;quantity = quantity;
<a name="l00634"></a>00634         <span class="keywordflow">if</span> (upd) i-&gt;resizeFlowLoadPlans();
<a name="l00635"></a>00635       }
<a name="l00636"></a>00636 
<a name="l00637"></a>00637   <span class="comment">// Update the flow and loadplans, and mark for problem detection</span>
<a name="l00638"></a>00638   <span class="keywordflow">if</span> (upd) update();
<a name="l00639"></a>00639   <span class="keywordflow">return</span> quantity;
<a name="l00640"></a>00640 }
<a name="l00641"></a>00641 
<a name="l00642"></a>00642 
<a name="l00643"></a>00643 <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> <span class="keywordtype">void</span> OperationPlan::resizeFlowLoadPlans()
<a name="l00644"></a>00644 {
<a name="l00645"></a>00645   <span class="comment">// Update all flowplans</span>
<a name="l00646"></a>00646   <span class="keywordflow">for</span> (<a class="code" href="a00070.html">FlowPlanIterator</a> ee = <a class="code" href="a00125.html#a4fb68598ded2db1ae3a9f5f975dd09c6">beginFlowPlans</a>(); ee != <a class="code" href="a00125.html#a1b421f000d0a136fa3f9dc3abd5b76cc">endFlowPlans</a>(); ++ee)
<a name="l00647"></a>00647     ee-&gt;update();
<a name="l00648"></a>00648 
<a name="l00649"></a>00649   <span class="comment">// Update all loadplans</span>
<a name="l00650"></a>00650   <span class="keywordflow">for</span> (<a class="code" href="a00107.html">LoadPlanIterator</a> e = <a class="code" href="a00125.html#af14047934961e9c5f04c0ecc70df649c">beginLoadPlans</a>(); e != <a class="code" href="a00125.html#af4b4401df92ad9e292edd56d3272b79c">endLoadPlans</a>(); ++e)
<a name="l00651"></a>00651     e-&gt;update();
<a name="l00652"></a>00652 
<a name="l00653"></a>00653   <span class="comment">// Align the end of the setup operationplan with the start of the operation</span>
<a name="l00654"></a>00654   <span class="keywordflow">if</span> (firstsubopplan &amp;&amp; firstsubopplan-&gt;<a class="code" href="a00125.html#a2f5ae1046cd50f98e59520ed8910c458">getOperation</a>() == <a class="code" href="a00129.html#add35ebccc253401c86cc40dc2fed3f04">OperationSetup::setupoperation</a>
<a name="l00655"></a>00655     &amp;&amp; firstsubopplan-&gt;<a class="code" href="a00125.html#a9f19aec0a96f30616f2ee06e3c8f371a">getDates</a>().<a class="code" href="a00050.html#a165a8f748d8468e5ba8331c0e06bd3a2">getEnd</a>() != <a class="code" href="a00125.html#a9f19aec0a96f30616f2ee06e3c8f371a">getDates</a>().<a class="code" href="a00050.html#a73e574de7fbf5df8ebc4c5190e7d49c3">getStart</a>()) 
<a name="l00656"></a>00656     firstsubopplan-&gt;<a class="code" href="a00125.html#af70f6b33dcda3739d1c090a632408cd4">setEnd</a>(<a class="code" href="a00125.html#a9f19aec0a96f30616f2ee06e3c8f371a">getDates</a>().getStart());
<a name="l00657"></a>00657   <span class="keywordflow">else</span> <span class="keywordflow">if</span> (<a class="code" href="a00125.html#a2f5ae1046cd50f98e59520ed8910c458">getOperation</a>() == <a class="code" href="a00129.html#add35ebccc253401c86cc40dc2fed3f04">OperationSetup::setupoperation</a>
<a name="l00658"></a>00658     &amp;&amp; <a class="code" href="a00125.html#a9f19aec0a96f30616f2ee06e3c8f371a">getDates</a>().getEnd() != <a class="code" href="a00125.html#a5d8b863740c3c1a948442c470e603393">getOwner</a>()-&gt;<a class="code" href="a00125.html#a9f19aec0a96f30616f2ee06e3c8f371a">getDates</a>().getStart())
<a name="l00659"></a>00659     <a class="code" href="a00125.html#a5d8b863740c3c1a948442c470e603393">getOwner</a>()-&gt;<a class="code" href="a00125.html#a2265d1554215f7185b8556f53c5805f2">setStart</a>(<a class="code" href="a00125.html#a9f19aec0a96f30616f2ee06e3c8f371a">getDates</a>().getEnd());
<a name="l00660"></a>00660 
<a name="l00661"></a>00661   <span class="comment">// Allow the operation length to be changed now that the quantity has changed</span>
<a name="l00662"></a>00662   <span class="comment">// Note that we assume that the end date remains fixed. This assumption makes</span>
<a name="l00663"></a>00663   <span class="comment">// sense if the operationplan was created to satisfy a demand.</span>
<a name="l00664"></a>00664   <span class="comment">// It is not valid though when the purpose of the operationplan was to push</span>
<a name="l00665"></a>00665   <span class="comment">// some material downstream.</span>
<a name="l00666"></a>00666         
<a name="l00667"></a>00667   <span class="comment">// Resize children </span>
<a name="l00668"></a>00668   <span class="keywordflow">for</span> (<a class="code" href="a00125.html" title="An operationplan is the key dynamic element of a plan. It represents a certain quantity...">OperationPlan</a> *j = firstsubopplan; j; j = j-&gt;nextsubopplan)
<a name="l00669"></a>00669     <span class="keywordflow">if</span> (j-&gt;getOperation() != <a class="code" href="a00129.html#add35ebccc253401c86cc40dc2fed3f04">OperationSetup::setupoperation</a>)
<a name="l00670"></a>00670     {
<a name="l00671"></a>00671       j-&gt;quantity = quantity;
<a name="l00672"></a>00672       j-&gt;resizeFlowLoadPlans();
<a name="l00673"></a>00673     }
<a name="l00674"></a>00674 
<a name="l00675"></a>00675   <span class="comment">// Notify the demand of the changed delivery</span>
<a name="l00676"></a>00676   <span class="keywordflow">if</span> (dmd) dmd-&gt;setChanged();
<a name="l00677"></a>00677 }
<a name="l00678"></a>00678 
<a name="l00679"></a>00679 
<a name="l00680"></a>00680 <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> <span class="keywordtype">void</span> OperationPlan::update()
<a name="l00681"></a>00681 {
<a name="l00682"></a>00682   <span class="keywordflow">if</span> (lastsubopplan &amp;&amp; lastsubopplan-&gt;getOperation() != <a class="code" href="a00129.html#add35ebccc253401c86cc40dc2fed3f04">OperationSetup::setupoperation</a>)  
<a name="l00683"></a>00683   {
<a name="l00684"></a>00684     <span class="comment">// Inherit the start and end date of the child operationplans</span>
<a name="l00685"></a>00685     OperationPlan *tmp = firstsubopplan;
<a name="l00686"></a>00686     <span class="keywordflow">if</span> (tmp-&gt;getOperation() == <a class="code" href="a00129.html#add35ebccc253401c86cc40dc2fed3f04">OperationSetup::setupoperation</a>)
<a name="l00687"></a>00687       tmp = tmp-&gt;nextsubopplan;
<a name="l00688"></a>00688     dates.<a class="code" href="a00050.html#a380ccce1c1c9d6c030a9a87298306be5">setStartAndEnd</a>(
<a name="l00689"></a>00689       tmp-&gt;getDates().getStart(),
<a name="l00690"></a>00690       lastsubopplan-&gt;getDates().getEnd()
<a name="l00691"></a>00691     );
<a name="l00692"></a>00692     <span class="comment">// If at least 1 sub-operationplan is locked, the parent must be locked</span>
<a name="l00693"></a>00693     flags &amp;= ~IS_LOCKED; <span class="comment">// Clear is_locked flag</span>
<a name="l00694"></a>00694     <span class="keywordflow">for</span> (OperationPlan* i = firstsubopplan; i; i = i-&gt;nextsubopplan)
<a name="l00695"></a>00695       <span class="keywordflow">if</span> (i-&gt;flags &amp; IS_LOCKED)
<a name="l00696"></a>00696       {
<a name="l00697"></a>00697         flags |= IS_LOCKED;  <span class="comment">// Set is_locked flag</span>
<a name="l00698"></a>00698         <span class="keywordflow">break</span>;
<a name="l00699"></a>00699       }
<a name="l00700"></a>00700   }
<a name="l00701"></a>00701 
<a name="l00702"></a>00702   <span class="comment">// Update the flow and loadplans</span>
<a name="l00703"></a>00703   resizeFlowLoadPlans();
<a name="l00704"></a>00704 
<a name="l00705"></a>00705   <span class="comment">// Notify the owner operationplan</span>
<a name="l00706"></a>00706   <span class="keywordflow">if</span> (owner) owner-&gt;update();
<a name="l00707"></a>00707 
<a name="l00708"></a>00708   <span class="comment">// Mark as changed</span>
<a name="l00709"></a>00709   <a class="code" href="a00125.html#abf77895a64e6ddfffc99f290df38750d">setChanged</a>();
<a name="l00710"></a>00710 }
<a name="l00711"></a>00711 
<a name="l00712"></a>00712 
<a name="l00713"></a><a class="code" href="a00125.html#aebe0ba79364fcd6952413913a0bc5a92">00713</a> <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> <span class="keywordtype">void</span> <a class="code" href="a00125.html#aebe0ba79364fcd6952413913a0bc5a92">OperationPlan::deleteOperationPlans</a>(<a class="code" href="a00121.html" title="An operation represents an activity: these consume and produce material, take time...">Operation</a>* o, <span class="keywordtype">bool</span> deleteLockedOpplans)
<a name="l00714"></a>00714 {
<a name="l00715"></a>00715   <span class="keywordflow">if</span> (!o) <span class="keywordflow">return</span>;
<a name="l00716"></a>00716   <span class="keywordflow">for</span> (<a class="code" href="a00125.html" title="An operationplan is the key dynamic element of a plan. It represents a certain quantity...">OperationPlan</a> *opplan = o-&gt;first_opplan; opplan; )
<a name="l00717"></a>00717   {
<a name="l00718"></a>00718     <a class="code" href="a00125.html" title="An operationplan is the key dynamic element of a plan. It represents a certain quantity...">OperationPlan</a> *tmp = opplan;
<a name="l00719"></a>00719     opplan = opplan-&gt;next;
<a name="l00720"></a>00720     <span class="comment">// Note that the deletion of the operationplan also updates the opplan list</span>
<a name="l00721"></a>00721     <span class="keywordflow">if</span> (deleteLockedOpplans || !tmp-&gt;<a class="code" href="a00125.html#ad76b43eab48c2587255ec1b460f91093">getLocked</a>()) <span class="keyword">delete</span> tmp;
<a name="l00722"></a>00722   }
<a name="l00723"></a>00723 }
<a name="l00724"></a>00724 
<a name="l00725"></a>00725 
<a name="l00726"></a><a class="code" href="a00125.html#a87c9ad27248d07be7847f876415c42c5">00726</a> <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> <span class="keywordtype">double</span> <a class="code" href="a00125.html#a87c9ad27248d07be7847f876415c42c5">OperationPlan::getPenalty</a>()<span class="keyword"> const</span>
<a name="l00727"></a>00727 <span class="keyword"></span>{
<a name="l00728"></a>00728   <span class="keywordtype">double</span> penalty = 0;
<a name="l00729"></a>00729   <span class="keywordflow">for</span> (<a class="code" href="a00106.html" title="An iterator class to go through all loadplans of an operationplan.">OperationPlan::LoadPlanIterator</a> i = <a class="code" href="a00125.html#af14047934961e9c5f04c0ecc70df649c">beginLoadPlans</a>();
<a name="l00730"></a>00730     i != <a class="code" href="a00125.html#af4b4401df92ad9e292edd56d3272b79c">endLoadPlans</a>(); ++i)
<a name="l00731"></a>00731     <span class="keywordflow">if</span> (i-&gt;isStart() &amp;&amp; !i-&gt;getLoad()-&gt;getSetup().empty() &amp;&amp; i-&gt;getResource()-&gt;getSetupMatrix())
<a name="l00732"></a>00732     {
<a name="l00733"></a>00733       <a class="code" href="a00160.html" title="An specific changeover rule in a setup matrix.">SetupMatrix::Rule</a> *rule = i-&gt;getResource()-&gt;getSetupMatrix()
<a name="l00734"></a>00734         -&gt;calculateSetup(i-&gt;getSetup(<span class="keyword">false</span>), i-&gt;getSetup(<span class="keyword">true</span>));
<a name="l00735"></a>00735       <span class="keywordflow">if</span> (rule) penalty += rule-&gt;<a class="code" href="a00160.html#ac41cf32876b75929836777b1cc78f049">getCost</a>();
<a name="l00736"></a>00736     }
<a name="l00737"></a>00737   <span class="keywordflow">return</span> penalty;
<a name="l00738"></a>00738 }
<a name="l00739"></a>00739 
<a name="l00740"></a>00740 
<a name="l00741"></a><a class="code" href="a00125.html#ae129bfa670287a41f69687fc23e6203f">00741</a> <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> <span class="keywordtype">bool</span> <a class="code" href="a00125.html#ae129bfa670287a41f69687fc23e6203f">OperationPlan::isExcess</a>(<span class="keywordtype">bool</span> strict)<span class="keyword"> const</span>
<a name="l00742"></a>00742 <span class="keyword"></span>{
<a name="l00743"></a>00743   <span class="comment">// Delivery operationplans aren&apos;t excess</span>
<a name="l00744"></a>00744   <span class="keywordflow">if</span> (<a class="code" href="a00125.html#a4cd571d01df7194dd232d07f7cbba03f">getDemand</a>()) <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00745"></a>00745 
<a name="l00746"></a>00746   <span class="comment">// Recursive call for suboperationplans</span>
<a name="l00747"></a>00747   <span class="keywordflow">for</span> (<a class="code" href="a00125.html" title="An operationplan is the key dynamic element of a plan. It represents a certain quantity...">OperationPlan</a>* subopplan = firstsubopplan; subopplan; subopplan = subopplan-&gt;nextsubopplan)
<a name="l00748"></a>00748     <span class="keywordflow">if</span> (!subopplan-&gt;isExcess()) <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00749"></a>00749   
<a name="l00750"></a>00750   <span class="comment">// Loop over all producing flowplans </span>
<a name="l00751"></a>00751   <span class="keywordflow">for</span> (<a class="code" href="a00069.html" title="An iterator class to go through all flowplans of an operationplan.">OperationPlan::FlowPlanIterator</a> i = <a class="code" href="a00125.html#a4fb68598ded2db1ae3a9f5f975dd09c6">beginFlowPlans</a>();
<a name="l00752"></a>00752         i != <a class="code" href="a00125.html#a1b421f000d0a136fa3f9dc3abd5b76cc">endFlowPlans</a>(); ++i)
<a name="l00753"></a>00753   {
<a name="l00754"></a>00754     <span class="comment">// Skip consuming flowplans</span>
<a name="l00755"></a>00755     <span class="keywordflow">if</span> (i-&gt;getQuantity() &lt;= 0) <span class="keywordflow">continue</span>;
<a name="l00756"></a>00756       
<a name="l00757"></a>00757     <span class="comment">// Loop over all flowplans in the buffer (starting at the end) and verify</span>
<a name="l00758"></a>00758     <span class="comment">// that the onhand is bigger than the flowplan quantity</span>
<a name="l00759"></a>00759     <span class="keywordtype">double</span> current_maximum(0.0);
<a name="l00760"></a>00760     <span class="keywordtype">double</span> current_minimum(0.0);
<a name="l00761"></a>00761     Buffer::flowplanlist::const_iterator j = i-&gt;getBuffer()-&gt;getFlowPlans().rbegin();
<a name="l00762"></a>00762     <span class="keywordflow">if</span> (!strict &amp;&amp; j != i-&gt;getBuffer()-&gt;getFlowPlans().end())
<a name="l00763"></a>00763     {
<a name="l00764"></a>00764       current_maximum = i-&gt;getBuffer()-&gt;getFlowPlans().getMax(&amp;*j);
<a name="l00765"></a>00765       current_minimum = i-&gt;getBuffer()-&gt;getFlowPlans().getMin(&amp;*j);
<a name="l00766"></a>00766     }
<a name="l00767"></a>00767     <span class="keywordflow">for</span> (; j != i-&gt;getBuffer()-&gt;getFlowPlans().end(); --j)
<a name="l00768"></a>00768     {
<a name="l00769"></a>00769       <span class="keywordflow">if</span> ( (current_maximum &gt; 0  
<a name="l00770"></a>00770              &amp;&amp; j-&gt;getOnhand() &lt; i-&gt;getQuantity() + current_maximum - <a class="code" href="a00252.html#a42d90a6275119e1b4ce73c50f1867e60">ROUNDING_ERROR</a>)
<a name="l00771"></a>00771         || j-&gt;getOnhand() &lt; i-&gt;getQuantity() + current_minimum - <a class="code" href="a00252.html#a42d90a6275119e1b4ce73c50f1867e60">ROUNDING_ERROR</a> )
<a name="l00772"></a>00772         <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00773"></a>00773       <span class="keywordflow">if</span> (j-&gt;getType() == 4 &amp;&amp; !strict) current_maximum = j-&gt;getMax(<span class="keyword">false</span>);
<a name="l00774"></a>00774       <span class="keywordflow">if</span> (j-&gt;getType() == 3 &amp;&amp; !strict) current_minimum = j-&gt;getMin(<span class="keyword">false</span>);
<a name="l00775"></a>00775       <span class="keywordflow">if</span> (&amp;*j == &amp;*i) <span class="keywordflow">break</span>;
<a name="l00776"></a>00776     }
<a name="l00777"></a>00777   }
<a name="l00778"></a>00778   
<a name="l00779"></a>00779   <span class="comment">// If we remove this operationplan the onhand in all buffers remains positive.</span>
<a name="l00780"></a>00780   <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00781"></a>00781 }
<a name="l00782"></a>00782 
<a name="l00783"></a>00783   
<a name="l00784"></a><a class="code" href="a00125.html#ae1018a3fea252ffa6a35bffbbe768c45">00784</a> <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> <a class="code" href="a00179.html" title="This class represents a time duration with an accuracy of one second.">TimePeriod</a> <a class="code" href="a00125.html#ae1018a3fea252ffa6a35bffbbe768c45">OperationPlan::getUnavailable</a>()<span class="keyword"> const</span>
<a name="l00785"></a>00785 <span class="keyword"></span>{
<a name="l00786"></a>00786   <a class="code" href="a00179.html" title="This class represents a time duration with an accuracy of one second.">TimePeriod</a> x;
<a name="l00787"></a>00787   <a class="code" href="a00050.html" title="This class defines a date-range, i.e. a start-date and end-date pair.">DateRange</a> y = <a class="code" href="a00125.html#a2f5ae1046cd50f98e59520ed8910c458">getOperation</a>()-&gt;<a class="code" href="a00121.html#a53bed8ce50df21b809e1cf7d1e39fd95">calculateOperationTime</a>(dates.<a class="code" href="a00050.html#a73e574de7fbf5df8ebc4c5190e7d49c3">getStart</a>(), dates.<a class="code" href="a00050.html#a165a8f748d8468e5ba8331c0e06bd3a2">getEnd</a>(), &amp;x);
<a name="l00788"></a>00788   <span class="keywordflow">return</span> dates.<a class="code" href="a00050.html#ab3020816550bbe0fa227b5121c6697f0">getDuration</a>() - x;
<a name="l00789"></a>00789 }
<a name="l00790"></a>00790 
<a name="l00791"></a>00791 
<a name="l00792"></a><a class="code" href="a00125.html#a6e290be8218f038b5c3613def7442c1a">00792</a> <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> <span class="keywordtype">void</span> <a class="code" href="a00125.html#a6e290be8218f038b5c3613def7442c1a">OperationPlan::writer</a>(<span class="keyword">const</span> <a class="code" href="a00114.html" title="A MetaCategory instance represents metadata for a category of object.">MetaCategory</a>* c, <a class="code" href="a00189.html" title="Base class for writing XML formatted data to an output stream.">XMLOutput</a>* o)
<a name="l00793"></a>00793 {
<a name="l00794"></a>00794   <span class="keywordflow">if</span> (!<a class="code" href="a00125.html#a1b67f83c0a010a76f9d481cdf1474774">empty</a>())
<a name="l00795"></a>00795   {
<a name="l00796"></a>00796     o-&gt;<a class="code" href="a00189.html#a5c1811dae2e3eae344ad366f6441a8a5">BeginObject</a>(*c-&gt;<a class="code" href="a00114.html#abf52fd75f82c4de4091e3b1921b43ba5">grouptag</a>);
<a name="l00797"></a>00797     <span class="keywordflow">for</span> (<a class="code" href="a00093.html" title="This class models an STL-like iterator that allows us to iterate over the operationplans...">iterator</a> i=<a class="code" href="a00125.html#a8bd5449992e056b2d637cfe65ac7da1f">begin</a>(); i!=<a class="code" href="a00125.html#a0f9f6ba7d4fe7e20e9b88c765fe24f25">end</a>(); ++i)
<a name="l00798"></a>00798       o-&gt;<a class="code" href="a00189.html#a711922eea4cfe3c33b97e4188dacc7d2">writeElement</a>(*c-&gt;<a class="code" href="a00115.html#aace20f59ef5a9de3188cb9810398932b">typetag</a>, *i);
<a name="l00799"></a>00799     o-&gt;<a class="code" href="a00189.html#a05375aa593bb0514020b035411c8983c">EndObject</a>(*c-&gt;<a class="code" href="a00114.html#abf52fd75f82c4de4091e3b1921b43ba5">grouptag</a>);
<a name="l00800"></a>00800   }
<a name="l00801"></a>00801 }
<a name="l00802"></a>00802 
<a name="l00803"></a>00803 
<a name="l00804"></a><a class="code" href="a00125.html#a20a1f5c84a6ecab07fb59e69cba08e0c">00804</a> <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> <span class="keywordtype">void</span> <a class="code" href="a00125.html#a20a1f5c84a6ecab07fb59e69cba08e0c">OperationPlan::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="l00805"></a>00805 <span class="keyword"></span>{
<a name="l00806"></a>00806   <span class="comment">// Don&apos;t export operationplans of hidden operations</span>
<a name="l00807"></a>00807   <span class="keywordflow">if</span> (oper-&gt;<a class="code" href="a00121.html#a69cb37b254f41a64896a8de3076697a8">getHidden</a>()) <span class="keywordflow">return</span>;
<a name="l00808"></a>00808 
<a name="l00809"></a>00809   <span class="comment">// Writing a reference</span>
<a name="l00810"></a>00810   <span class="keywordflow">if</span> (m == <a class="code" href="a00257.html#a20c2c7e4c6b668e71c154ae3eb18f398a874240ada53cc5b608466064d86d91ae">REFERENCE</a>)
<a name="l00811"></a>00811   {
<a name="l00812"></a>00812     o-&gt;<a class="code" href="a00189.html#a711922eea4cfe3c33b97e4188dacc7d2">writeElement</a>
<a name="l00813"></a>00813       (tag, <a class="code" href="a00177.html#a9a660b4455888adc9ad733f07826840f">Tags::tag_id</a>, <span class="keywordtype">id</span>, <a class="code" href="a00177.html#ad70b79a1c1f3f6d13539207da4f19609">Tags::tag_operation</a>, oper-&gt;<a class="code" href="a00182.html#a7416ca220c55147bc1276becc5b9de01">getName</a>());
<a name="l00814"></a>00814     <span class="keywordflow">return</span>;
<a name="l00815"></a>00815   }
<a name="l00816"></a>00816 
<a name="l00817"></a>00817   <span class="keywordflow">if</span> (m != <a class="code" href="a00257.html#a20c2c7e4c6b668e71c154ae3eb18f398a2ad5e75fe119e297630882d182832243">NOHEADER</a>)
<a name="l00818"></a>00818     o-&gt;<a class="code" href="a00189.html#a5c1811dae2e3eae344ad366f6441a8a5">BeginObject</a>(tag, <a class="code" href="a00177.html#a9a660b4455888adc9ad733f07826840f">Tags::tag_id</a>, <span class="keywordtype">id</span>, <a class="code" href="a00177.html#ad70b79a1c1f3f6d13539207da4f19609">Tags::tag_operation</a>,oper-&gt;<a class="code" href="a00182.html#a7416ca220c55147bc1276becc5b9de01">getName</a>());
<a name="l00819"></a>00819 
<a name="l00820"></a>00820   <span class="comment">// The demand reference is only valid for delivery operationplans,</span>
<a name="l00821"></a>00821   <span class="comment">// and it should only be written if this tag is not being written</span>
<a name="l00822"></a>00822   <span class="comment">// as part of a demand+delivery tag.</span>
<a name="l00823"></a>00823   <span class="keywordflow">if</span> (dmd &amp;&amp; !dynamic_cast&lt;Demand*&gt;(o-&gt;<a class="code" href="a00189.html#ab1c39c9ee1016cc2d29152fa95fa769d">getPreviousObject</a>()))
<a name="l00824"></a>00824     o-&gt;<a class="code" href="a00189.html#a711922eea4cfe3c33b97e4188dacc7d2">writeElement</a>(<a class="code" href="a00177.html#af7d29c7626e86f3b5ad8303212f0f062">Tags::tag_demand</a>, dmd);
<a name="l00825"></a>00825 
<a name="l00826"></a>00826   o-&gt;<a class="code" href="a00189.html#a711922eea4cfe3c33b97e4188dacc7d2">writeElement</a>(<a class="code" href="a00177.html#ae9fda65e25c8720724e21b35138deec0">Tags::tag_start</a>, dates.<a class="code" href="a00050.html#a73e574de7fbf5df8ebc4c5190e7d49c3">getStart</a>());
<a name="l00827"></a>00827   o-&gt;<a class="code" href="a00189.html#a711922eea4cfe3c33b97e4188dacc7d2">writeElement</a>(<a class="code" href="a00177.html#ae7b833aedeada2860688b90cb947cdb2">Tags::tag_end</a>, dates.<a class="code" href="a00050.html#a165a8f748d8468e5ba8331c0e06bd3a2">getEnd</a>());
<a name="l00828"></a>00828   o-&gt;<a class="code" href="a00189.html#a711922eea4cfe3c33b97e4188dacc7d2">writeElement</a>(<a class="code" href="a00177.html#ab99ddcbeef0f5d15a8731dcdffa0dcff">Tags::tag_quantity</a>, quantity);
<a name="l00829"></a>00829   <span class="keywordflow">if</span> (<a class="code" href="a00125.html#ad76b43eab48c2587255ec1b460f91093">getLocked</a>()) o-&gt;<a class="code" href="a00189.html#a711922eea4cfe3c33b97e4188dacc7d2">writeElement</a> (<a class="code" href="a00177.html#adb2a5a2ca84be552ad475549d7fa42ac">Tags::tag_locked</a>, <a class="code" href="a00125.html#ad76b43eab48c2587255ec1b460f91093">getLocked</a>());
<a name="l00830"></a>00830   o-&gt;<a class="code" href="a00189.html#a711922eea4cfe3c33b97e4188dacc7d2">writeElement</a>(<a class="code" href="a00177.html#aaa2f978792ac2320979871ceafdc5c16">Tags::tag_owner</a>, owner);
<a name="l00831"></a>00831 
<a name="l00832"></a>00832   <span class="comment">// Write out the flowplans and their pegging</span>
<a name="l00833"></a>00833   <span class="keywordflow">if</span> (o-&gt;<a class="code" href="a00189.html#a364e86ed0671915df858bc52adadd29f">getContentType</a>() == XMLOutput::PLANDETAIL)
<a name="l00834"></a>00834   {
<a name="l00835"></a>00835     o-&gt;<a class="code" href="a00189.html#a5c1811dae2e3eae344ad366f6441a8a5">BeginObject</a>(<a class="code" href="a00177.html#aeaa2557f88702842d0f9fc54fd97fccc">Tags::tag_flowplans</a>);
<a name="l00836"></a>00836     <span class="keywordflow">for</span> (<a class="code" href="a00069.html" title="An iterator class to go through all flowplans of an operationplan.">FlowPlanIterator</a> qq = <a class="code" href="a00125.html#a4fb68598ded2db1ae3a9f5f975dd09c6">beginFlowPlans</a>(); qq != <a class="code" href="a00125.html#a1b421f000d0a136fa3f9dc3abd5b76cc">endFlowPlans</a>(); ++qq)
<a name="l00837"></a>00837       qq-&gt;writeElement(o, <a class="code" href="a00177.html#acf5f50deeeea86273b84a1f593626514">Tags::tag_flowplan</a>);
<a name="l00838"></a>00838     o-&gt;<a class="code" href="a00189.html#a05375aa593bb0514020b035411c8983c">EndObject</a>(<a class="code" href="a00177.html#aeaa2557f88702842d0f9fc54fd97fccc">Tags::tag_flowplans</a>);
<a name="l00839"></a>00839   }
<a name="l00840"></a>00840 
<a name="l00841"></a>00841   o-&gt;<a class="code" href="a00189.html#a05375aa593bb0514020b035411c8983c">EndObject</a>(tag);
<a name="l00842"></a>00842 }
<a name="l00843"></a>00843 
<a name="l00844"></a>00844 
<a name="l00845"></a><a class="code" href="a00125.html#a7cc72216b887fc019ffc29b6465e5704">00845</a> <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> <span class="keywordtype">void</span> <a class="code" href="a00125.html#a7cc72216b887fc019ffc29b6465e5704">OperationPlan::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="l00846"></a>00846 {
<a name="l00847"></a>00847   <span class="keywordflow">if</span> (pAttr.<a class="code" href="a00002.html#aebffce6c4fcf1696ca34f63f2b6ee091">isA</a> (<a class="code" href="a00177.html#af7d29c7626e86f3b5ad8303212f0f062">Tags::tag_demand</a>))
<a name="l00848"></a>00848     pIn.<a class="code" href="a00186.html#a88dd6be5af6fc605d2d420fbcb397b18">readto</a>( <a class="code" href="a00085.html#ac14340cc8781e6f2b7235d50a1d17914">Demand::reader</a>(<a class="code" href="a00051.html#ab47d40bcf25de651514118609b00362b">Demand::metadata</a>,pIn.<a class="code" href="a00186.html#adcc4751961526c0103536acd194d32a0">getAttributes</a>()) );
<a name="l00849"></a>00849   <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#aaa2f978792ac2320979871ceafdc5c16">Tags::tag_owner</a>))
<a name="l00850"></a>00850     pIn.<a class="code" href="a00186.html#a88dd6be5af6fc605d2d420fbcb397b18">readto</a>(<a class="code" href="a00125.html#acabc6d5f06b157c155355d04b3e2e4ef">createOperationPlan</a>(<a class="code" href="a00125.html#a31cde691d7cdf2ce2db1fb0eb595e34a">metadata</a>,pIn.<a class="code" href="a00186.html#adcc4751961526c0103536acd194d32a0">getAttributes</a>()));
<a name="l00851"></a>00851   <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#aeaa2557f88702842d0f9fc54fd97fccc">Tags::tag_flowplans</a>))
<a name="l00852"></a>00852     pIn.<a class="code" href="a00186.html#af1ffc5c65dd968dcb04a23e05a0da5ba">IgnoreElement</a>();
<a name="l00853"></a>00853 }
<a name="l00854"></a>00854 
<a name="l00855"></a>00855 
<a name="l00856"></a><a class="code" href="a00125.html#a66190169fabfa5d7843c2a7251d949ba">00856</a> <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> <span class="keywordtype">void</span> <a class="code" href="a00125.html#a66190169fabfa5d7843c2a7251d949ba">OperationPlan::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="l00857"></a>00857 {
<a name="l00858"></a>00858   <span class="comment">// Note that the fields have been ordered more or less in the order</span>
<a name="l00859"></a>00859   <span class="comment">// of their expected frequency.</span>
<a name="l00860"></a>00860   <span class="comment">// Note that id and operation are handled already during the</span>
<a name="l00861"></a>00861   <span class="comment">// operationplan creation. They don&apos;t need to be handled here...</span>
<a name="l00862"></a>00862   <span class="keywordflow">if</span> (pAttr.<a class="code" href="a00002.html#aebffce6c4fcf1696ca34f63f2b6ee091">isA</a>(<a class="code" href="a00177.html#ab99ddcbeef0f5d15a8731dcdffa0dcff">Tags::tag_quantity</a>))
<a name="l00863"></a>00863     pElement &gt;&gt; quantity;
<a name="l00864"></a>00864   <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="l00865"></a>00865     dates.<a class="code" href="a00050.html#a301068faa83a2a88fdb46ffb26f56502">setStart</a>(pElement.<a class="code" href="a00047.html#abe8c2019e5f79328a6a1fa1f3bb4bbae">getDate</a>());
<a name="l00866"></a>00866   <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="l00867"></a>00867     dates.<a class="code" href="a00050.html#a953ee79781eee836ae07bd389aca5515">setEnd</a>(pElement.<a class="code" href="a00047.html#abe8c2019e5f79328a6a1fa1f3bb4bbae">getDate</a>());
<a name="l00868"></a>00868   <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#aaa2f978792ac2320979871ceafdc5c16">Tags::tag_owner</a>) &amp;&amp; !pIn.<a class="code" href="a00186.html#a42fe5e4ae141efb84744b8a359e38bd9">isObjectEnd</a>())
<a name="l00869"></a>00869   {
<a name="l00870"></a>00870     <a class="code" href="a00125.html" title="An operationplan is the key dynamic element of a plan. It represents a certain quantity...">OperationPlan</a>* o = <span class="keyword">dynamic_cast&lt;</span><a class="code" href="a00125.html" title="An operationplan is the key dynamic element of a plan. It represents a certain quantity...">OperationPlan</a>*<span class="keyword">&gt;</span>(pIn.<a class="code" href="a00186.html#a98008d76b6971b2592ee5ae6f0f03d4c">getPreviousObject</a>());
<a name="l00871"></a>00871     <span class="keywordflow">if</span> (o) <a class="code" href="a00125.html#a1a08b007136515186cc22cd95007f122">setOwner</a>(o);
<a name="l00872"></a>00872   }
<a name="l00873"></a>00873   <span class="keywordflow">else</span> <span class="keywordflow">if</span> (pIn.<a class="code" href="a00186.html#a42fe5e4ae141efb84744b8a359e38bd9">isObjectEnd</a>())
<a name="l00874"></a>00874   {
<a name="l00875"></a>00875     <span class="comment">// Initialize the operationplan</span>
<a name="l00876"></a>00876     <span class="keywordflow">if</span> (!<a class="code" href="a00125.html#a13fe13cfa3f0b8dc229b9f115172c9c5">instantiate</a>())
<a name="l00877"></a>00877       <span class="comment">// Initialization failed and the operationplan is deleted</span>
<a name="l00878"></a>00878       pIn.<a class="code" href="a00186.html#a23ebdcfba82479d4cf56cf6aa4959899">invalidateCurrentObject</a>();
<a name="l00879"></a>00879   }
<a name="l00880"></a>00880   <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#af7d29c7626e86f3b5ad8303212f0f062">Tags::tag_demand</a>))
<a name="l00881"></a>00881   {
<a name="l00882"></a>00882     <a class="code" href="a00051.html" title="Represents the (independent) demand in the system. It can represent a customer order...">Demand</a> * d = <span class="keyword">dynamic_cast&lt;</span><a class="code" href="a00051.html" title="Represents the (independent) demand in the system. It can represent a customer order...">Demand</a>*<span class="keyword">&gt;</span>(pIn.<a class="code" href="a00186.html#a98008d76b6971b2592ee5ae6f0f03d4c">getPreviousObject</a>());
<a name="l00883"></a>00883     <span class="keywordflow">if</span> (d) d-&gt;<a class="code" href="a00051.html#abd37a48b6cbd9de6d32f4443c1e82841">addDelivery</a>(<span class="keyword">this</span>);
<a name="l00884"></a>00884     <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="l00885"></a>00885   }
<a name="l00886"></a>00886   <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#adb2a5a2ca84be552ad475549d7fa42ac">Tags::tag_locked</a>))
<a name="l00887"></a>00887     <a class="code" href="a00125.html#ad845e28c8e3a41fb08bfd7d47ff81e3a">setLocked</a>(pElement.<a class="code" href="a00047.html#a542b814710b3242bd4c81aad2fc269d8">getBool</a>());
<a name="l00888"></a>00888 }
<a name="l00889"></a>00889 
<a name="l00890"></a>00890 
<a name="l00891"></a><a class="code" href="a00125.html#ad845e28c8e3a41fb08bfd7d47ff81e3a">00891</a> <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> <span class="keywordtype">void</span> <a class="code" href="a00125.html#ad845e28c8e3a41fb08bfd7d47ff81e3a">OperationPlan::setLocked</a>(<span class="keywordtype">bool</span> b)
<a name="l00892"></a>00892 {
<a name="l00893"></a>00893   <span class="keywordflow">if</span> (b)
<a name="l00894"></a>00894     flags |= IS_LOCKED;
<a name="l00895"></a>00895   <span class="keywordflow">else</span>
<a name="l00896"></a>00896     flags &amp;= ~IS_LOCKED;
<a name="l00897"></a>00897   <span class="keywordflow">for</span> (<a class="code" href="a00125.html" title="An operationplan is the key dynamic element of a plan. It represents a certain quantity...">OperationPlan</a> *x = firstsubopplan; x; x = x-&gt;nextsubopplan)
<a name="l00898"></a>00898     x-&gt;setLocked(b);
<a name="l00899"></a>00899   update();
<a name="l00900"></a>00900 }
<a name="l00901"></a>00901 
<a name="l00902"></a>00902 
<a name="l00903"></a><a class="code" href="a00125.html#a94c3d23a9b1ea2a802cc58718187ef8a">00903</a> <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> <span class="keywordtype">void</span> <a class="code" href="a00125.html#a94c3d23a9b1ea2a802cc58718187ef8a">OperationPlan::setDemand</a>(<a class="code" href="a00051.html" title="Represents the (independent) demand in the system. It can represent a customer order...">Demand</a>* l)
<a name="l00904"></a>00904 {
<a name="l00905"></a>00905   <span class="comment">// No change</span>
<a name="l00906"></a>00906   <span class="keywordflow">if</span> (l==dmd) <span class="keywordflow">return</span>;
<a name="l00907"></a>00907 
<a name="l00908"></a>00908   <span class="comment">// Unregister from previous lot</span>
<a name="l00909"></a>00909   <span class="keywordflow">if</span> (dmd) dmd-&gt;<a class="code" href="a00051.html#ad7b6e76943e7774d10538fe21039430d">removeDelivery</a>(<span class="keyword">this</span>);
<a name="l00910"></a>00910 
<a name="l00911"></a>00911   <span class="comment">// Register the new demand and mark it changed</span>
<a name="l00912"></a>00912   dmd = l;
<a name="l00913"></a>00913   <span class="keywordflow">if</span> (l) l-&gt;<a class="code" href="a00133.html#a11a86a6e020664a337325a96a64f6d2c">setChanged</a>();
<a name="l00914"></a>00914 }
<a name="l00915"></a>00915 
<a name="l00916"></a>00916 
<a name="l00917"></a><a class="code" href="a00125.html#a9011cb69db2094761747475bfe760a5f">00917</a> PyObject* <a class="code" href="a00125.html#a9011cb69db2094761747475bfe760a5f">OperationPlan::create</a>(PyTypeObject* pytype, PyObject* args, PyObject* kwds)
<a name="l00918"></a>00918 {
<a name="l00919"></a>00919   <span class="keywordflow">try</span>
<a name="l00920"></a>00920   {
<a name="l00921"></a>00921     <span class="comment">// Find or create the C++ object</span>
<a name="l00922"></a>00922     <a class="code" href="a00149.html" title="This class is a wrapper around a Python dictionary.">PythonAttributeList</a> atts(kwds);
<a name="l00923"></a>00923     <a class="code" href="a00120.html" title="Object is the abstract base class for the main entities.">Object</a>* x = <a class="code" href="a00125.html#acabc6d5f06b157c155355d04b3e2e4ef">createOperationPlan</a>(<a class="code" href="a00125.html#a31cde691d7cdf2ce2db1fb0eb595e34a">OperationPlan::metadata</a>,atts);
<a name="l00924"></a>00924 
<a name="l00925"></a>00925     <span class="comment">// Iterate over extra keywords, and set attributes.   @todo move this responsability to the readers...</span>
<a name="l00926"></a>00926     <span class="keywordflow">if</span> (x)
<a name="l00927"></a>00927     {
<a name="l00928"></a>00928       PyObject *key, *value;
<a name="l00929"></a>00929       <a class="code" href="a00252.html#a47424a8953c340f500027db7e6c00173">Py_ssize_t</a> pos = 0;
<a name="l00930"></a>00930       <span class="keywordflow">while</span> (PyDict_Next(kwds, &amp;pos, &amp;key, &amp;value))
<a name="l00931"></a>00931       {
<a name="l00932"></a>00932         <a class="code" href="a00154.html" title="This class handles two-way translation between the data types in C++ and Python.">PythonObject</a> field(value);
<a name="l00933"></a>00933         <a class="code" href="a00002.html" title="A class to model keyword instances.">Attribute</a> attr(PyString_AsString(key));
<a name="l00934"></a>00934         <span class="keywordflow">if</span> (!attr.<a class="code" href="a00002.html#aebffce6c4fcf1696ca34f63f2b6ee091">isA</a>(<a class="code" href="a00177.html#ad70b79a1c1f3f6d13539207da4f19609">Tags::tag_operation</a>) &amp;&amp; !attr.<a class="code" href="a00002.html#aebffce6c4fcf1696ca34f63f2b6ee091">isA</a>(<a class="code" href="a00177.html#a9a660b4455888adc9ad733f07826840f">Tags::tag_id</a>) &amp;&amp; !attr.<a class="code" href="a00002.html#aebffce6c4fcf1696ca34f63f2b6ee091">isA</a>(<a class="code" href="a00177.html#a391c4d3fc071199c00a248d992d623dd">Tags::tag_action</a>))
<a name="l00935"></a>00935         {
<a name="l00936"></a>00936           <span class="keywordtype">int</span> result = x-&gt;<a class="code" href="a00151.html#a0a1bd051198a1b82fd23d3ca04c3ee8d">setattro</a>(attr, field);
<a name="l00937"></a>00937           <span class="keywordflow">if</span> (result &amp;&amp; !PyErr_Occurred())
<a name="l00938"></a>00938             PyErr_Format(PyExc_AttributeError,
<a name="l00939"></a>00939               <span class="stringliteral">&quot;attribute &apos;%s&apos; on &apos;%s&apos; can&apos;t be updated&quot;</span>,
<a name="l00940"></a>00940               PyString_AsString(key), x-&gt;ob_type-&gt;tp_name);
<a name="l00941"></a>00941         }
<a name="l00942"></a>00942       };
<a name="l00943"></a>00943     }
<a name="l00944"></a>00944 
<a name="l00945"></a>00945     <span class="keywordflow">if</span> (x &amp;&amp; !static_cast&lt;OperationPlan*&gt;(x)-&gt;<a class="code" href="a00125.html#a13fe13cfa3f0b8dc229b9f115172c9c5">instantiate</a>())
<a name="l00946"></a>00946       <span class="keywordflow">return</span> NULL;
<a name="l00947"></a>00947     <span class="keywordflow">return</span> x;
<a name="l00948"></a>00948   }
<a name="l00949"></a>00949   <span class="keywordflow">catch</span> (...)
<a name="l00950"></a>00950   {
<a name="l00951"></a>00951     PythonType::evalException();
<a name="l00952"></a>00952     <span class="keywordflow">return</span> NULL;
<a name="l00953"></a>00953   }
<a name="l00954"></a>00954 }
<a name="l00955"></a>00955 
<a name="l00956"></a>00956 
<a name="l00957"></a><a class="code" href="a00125.html#af0927db9852c532d8613b2aadf0caeb4">00957</a> <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> PyObject* <a class="code" href="a00125.html#af0927db9852c532d8613b2aadf0caeb4">OperationPlan::getattro</a>(<span class="keyword">const</span> <a class="code" href="a00002.html" title="A class to model keyword instances.">Attribute</a>&amp; attr)
<a name="l00958"></a>00958 {
<a name="l00959"></a>00959   <span class="keywordflow">if</span> (attr.<a class="code" href="a00002.html#aebffce6c4fcf1696ca34f63f2b6ee091">isA</a>(<a class="code" href="a00177.html#a9a660b4455888adc9ad733f07826840f">Tags::tag_id</a>))
<a name="l00960"></a>00960     <span class="keywordflow">return</span> <a class="code" href="a00154.html" title="This class handles two-way translation between the data types in C++ and Python.">PythonObject</a>(<a class="code" href="a00125.html#a2fc22f86c78b34f91bf535c742e2e740">getIdentifier</a>());
<a name="l00961"></a>00961   <span class="keywordflow">if</span> (attr.<a class="code" href="a00002.html#aebffce6c4fcf1696ca34f63f2b6ee091">isA</a>(<a class="code" href="a00177.html#ad70b79a1c1f3f6d13539207da4f19609">Tags::tag_operation</a>))
<a name="l00962"></a>00962     <span class="keywordflow">return</span> <a class="code" href="a00154.html" title="This class handles two-way translation between the data types in C++ and Python.">PythonObject</a>(<a class="code" href="a00125.html#a2f5ae1046cd50f98e59520ed8910c458">getOperation</a>());
<a name="l00963"></a>00963   <span class="keywordflow">if</span> (attr.<a class="code" href="a00002.html#aebffce6c4fcf1696ca34f63f2b6ee091">isA</a>(<a class="code" href="a00177.html#aeaa2557f88702842d0f9fc54fd97fccc">Tags::tag_flowplans</a>))
<a name="l00964"></a>00964     <span class="keywordflow">return</span> <span class="keyword">new</span> <a class="code" href="a00070.html">frepple::FlowPlanIterator</a>(<span class="keyword">this</span>);
<a name="l00965"></a>00965   <span class="keywordflow">if</span> (attr.<a class="code" href="a00002.html#aebffce6c4fcf1696ca34f63f2b6ee091">isA</a>(<a class="code" href="a00177.html#a8af77889e6092a30c9b191a28a2c79d0">Tags::tag_loadplans</a>))
<a name="l00966"></a>00966     <span class="keywordflow">return</span> <span class="keyword">new</span> <a class="code" href="a00107.html">frepple::LoadPlanIterator</a>(<span class="keyword">this</span>);
<a name="l00967"></a>00967   <span class="keywordflow">if</span> (attr.<a class="code" href="a00002.html#aebffce6c4fcf1696ca34f63f2b6ee091">isA</a>(<a class="code" href="a00177.html#ab99ddcbeef0f5d15a8731dcdffa0dcff">Tags::tag_quantity</a>))
<a name="l00968"></a>00968     <span class="keywordflow">return</span> <a class="code" href="a00154.html" title="This class handles two-way translation between the data types in C++ and Python.">PythonObject</a>(<a class="code" href="a00125.html#aa32661a65b2309ba7c35576940274687">getQuantity</a>());
<a name="l00969"></a>00969   <span class="keywordflow">if</span> (attr.<a class="code" href="a00002.html#aebffce6c4fcf1696ca34f63f2b6ee091">isA</a>(<a class="code" href="a00177.html#ae9fda65e25c8720724e21b35138deec0">Tags::tag_start</a>))
<a name="l00970"></a>00970     <span class="keywordflow">return</span> <a class="code" href="a00154.html" title="This class handles two-way translation between the data types in C++ and Python.">PythonObject</a>(<a class="code" href="a00125.html#a9f19aec0a96f30616f2ee06e3c8f371a">getDates</a>().<a class="code" href="a00050.html#a73e574de7fbf5df8ebc4c5190e7d49c3">getStart</a>());
<a name="l00971"></a>00971   <span class="keywordflow">if</span> (attr.<a class="code" href="a00002.html#aebffce6c4fcf1696ca34f63f2b6ee091">isA</a>(<a class="code" href="a00177.html#ae7b833aedeada2860688b90cb947cdb2">Tags::tag_end</a>))
<a name="l00972"></a>00972     <span class="keywordflow">return</span> <a class="code" href="a00154.html" title="This class handles two-way translation between the data types in C++ and Python.">PythonObject</a>(<a class="code" href="a00125.html#a9f19aec0a96f30616f2ee06e3c8f371a">getDates</a>().<a class="code" href="a00050.html#a165a8f748d8468e5ba8331c0e06bd3a2">getEnd</a>());
<a name="l00973"></a>00973   <span class="keywordflow">if</span> (attr.<a class="code" href="a00002.html#aebffce6c4fcf1696ca34f63f2b6ee091">isA</a>(<a class="code" href="a00177.html#af7d29c7626e86f3b5ad8303212f0f062">Tags::tag_demand</a>))
<a name="l00974"></a>00974     <span class="keywordflow">return</span> <a class="code" href="a00154.html" title="This class handles two-way translation between the data types in C++ and Python.">PythonObject</a>(<a class="code" href="a00125.html#a4cd571d01df7194dd232d07f7cbba03f">getDemand</a>());
<a name="l00975"></a>00975   <span class="keywordflow">if</span> (attr.<a class="code" href="a00002.html#aebffce6c4fcf1696ca34f63f2b6ee091">isA</a>(<a class="code" href="a00177.html#adb2a5a2ca84be552ad475549d7fa42ac">Tags::tag_locked</a>))
<a name="l00976"></a>00976     <span class="keywordflow">return</span> <a class="code" href="a00154.html" title="This class handles two-way translation between the data types in C++ and Python.">PythonObject</a>(<a class="code" href="a00125.html#ad76b43eab48c2587255ec1b460f91093">getLocked</a>());
<a name="l00977"></a>00977   <span class="keywordflow">if</span> (attr.<a class="code" href="a00002.html#aebffce6c4fcf1696ca34f63f2b6ee091">isA</a>(<a class="code" href="a00177.html#aaa2f978792ac2320979871ceafdc5c16">Tags::tag_owner</a>))
<a name="l00978"></a>00978     <span class="keywordflow">return</span> <a class="code" href="a00154.html" title="This class handles two-way translation between the data types in C++ and Python.">PythonObject</a>(<a class="code" href="a00125.html#a5d8b863740c3c1a948442c470e603393">getOwner</a>());
<a name="l00979"></a>00979   <span class="keywordflow">if</span> (attr.<a class="code" href="a00002.html#aebffce6c4fcf1696ca34f63f2b6ee091">isA</a>(<a class="code" href="a00177.html#aadee013608238a2c7309cb6960496126">Tags::tag_operationplans</a>))
<a name="l00980"></a>00980     <span class="keywordflow">return</span> <span class="keyword">new</span> <a class="code" href="a00126.html">OperationPlanIterator</a>(<span class="keyword">this</span>);
<a name="l00981"></a>00981   <span class="keywordflow">if</span> (attr.<a class="code" href="a00002.html#aebffce6c4fcf1696ca34f63f2b6ee091">isA</a>(<a class="code" href="a00177.html#ac016b995f75e5fdb50eefc35924c6503">Tags::tag_hidden</a>))
<a name="l00982"></a>00982     <span class="keywordflow">return</span> <a class="code" href="a00154.html" title="This class handles two-way translation between the data types in C++ and Python.">PythonObject</a>(<a class="code" href="a00125.html#ae4790b550a19fdd231276294d7782a1e">getHidden</a>());
<a name="l00983"></a>00983   <span class="keywordflow">if</span> (attr.<a class="code" href="a00002.html#aebffce6c4fcf1696ca34f63f2b6ee091">isA</a>(<a class="code" href="a00177.html#ad7971481367f2a2423184dc302d472f0">Tags::tag_unavailable</a>))
<a name="l00984"></a>00984     <span class="keywordflow">return</span> <a class="code" href="a00154.html" title="This class handles two-way translation between the data types in C++ and Python.">PythonObject</a>(<a class="code" href="a00125.html#ae1018a3fea252ffa6a35bffbbe768c45">getUnavailable</a>());
<a name="l00985"></a>00985   <span class="keywordflow">return</span> NULL;
<a name="l00986"></a>00986 }
<a name="l00987"></a>00987 
<a name="l00988"></a>00988 
<a name="l00989"></a><a class="code" href="a00125.html#aa8b58849f7ad109c44163e97cfb0676c">00989</a> <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> <span class="keywordtype">int</span> <a class="code" href="a00125.html#aa8b58849f7ad109c44163e97cfb0676c">OperationPlan::setattro</a>(<span class="keyword">const</span> <a class="code" href="a00002.html" title="A class to model keyword instances.">Attribute</a>&amp; attr, <span class="keyword">const</span> <a class="code" href="a00154.html" title="This class handles two-way translation between the data types in C++ and Python.">PythonObject</a>&amp; field)
<a name="l00990"></a>00990 {
<a name="l00991"></a>00991   <span class="keywordflow">if</span> (attr.<a class="code" href="a00002.html#aebffce6c4fcf1696ca34f63f2b6ee091">isA</a>(<a class="code" href="a00177.html#ab99ddcbeef0f5d15a8731dcdffa0dcff">Tags::tag_quantity</a>))
<a name="l00992"></a>00992     <a class="code" href="a00125.html#aa33a70a23ad111e4b2a35ec96757a1fb">setQuantity</a>(field.<a class="code" href="a00154.html#ad292e9b75b65eef65ff8701939ab348a">getDouble</a>());
<a name="l00993"></a>00993   <span class="keywordflow">else</span> <span class="keywordflow">if</span> (attr.<a class="code" href="a00002.html#aebffce6c4fcf1696ca34f63f2b6ee091">isA</a>(<a class="code" href="a00177.html#ae9fda65e25c8720724e21b35138deec0">Tags::tag_start</a>))
<a name="l00994"></a>00994     <a class="code" href="a00125.html#a2265d1554215f7185b8556f53c5805f2">setStart</a>(field.<a class="code" href="a00154.html#aa72c83cab5f89f71aff63f0bfad26bd1">getDate</a>());
<a name="l00995"></a>00995   <span class="keywordflow">else</span> <span class="keywordflow">if</span> (attr.<a class="code" href="a00002.html#aebffce6c4fcf1696ca34f63f2b6ee091">isA</a>(<a class="code" href="a00177.html#ae7b833aedeada2860688b90cb947cdb2">Tags::tag_end</a>))
<a name="l00996"></a>00996     <a class="code" href="a00125.html#af70f6b33dcda3739d1c090a632408cd4">setEnd</a>(field.<a class="code" href="a00154.html#aa72c83cab5f89f71aff63f0bfad26bd1">getDate</a>());
<a name="l00997"></a>00997   <span class="keywordflow">else</span> <span class="keywordflow">if</span> (attr.<a class="code" href="a00002.html#aebffce6c4fcf1696ca34f63f2b6ee091">isA</a>(<a class="code" href="a00177.html#adb2a5a2ca84be552ad475549d7fa42ac">Tags::tag_locked</a>))
<a name="l00998"></a>00998     <a class="code" href="a00125.html#ad845e28c8e3a41fb08bfd7d47ff81e3a">setLocked</a>(field.<a class="code" href="a00154.html#a804b478fb76759d334882ee468fc84f9">getBool</a>());
<a name="l00999"></a>00999   <span class="keywordflow">else</span> <span class="keywordflow">if</span> (attr.<a class="code" href="a00002.html#aebffce6c4fcf1696ca34f63f2b6ee091">isA</a>(<a class="code" href="a00177.html#af7d29c7626e86f3b5ad8303212f0f062">Tags::tag_demand</a>))
<a name="l01000"></a>01000   {
<a name="l01001"></a>01001     <span class="keywordflow">if</span> (!field.<a class="code" href="a00154.html#aa5f7a25056671e8df629cd42b0061b28">check</a>(<a class="code" href="a00051.html#ab47d40bcf25de651514118609b00362b">Demand::metadata</a>))
<a name="l01002"></a>01002     {
<a name="l01003"></a>01003       PyErr_SetString(<a class="code" href="a00257.html#a75c689d2dca4282e2ca0dad79dab1063" title="Python exception class matching with frepple::DataException.">PythonDataException</a>, <span class="stringliteral">&quot;operationplan demand must be of type demand&quot;</span>);
<a name="l01004"></a>01004       <span class="keywordflow">return</span> -1;
<a name="l01005"></a>01005     }
<a name="l01006"></a>01006     <a class="code" href="a00051.html" title="Represents the (independent) demand in the system. It can represent a customer order...">Demand</a>* y = <span class="keyword">static_cast&lt;</span><a class="code" href="a00051.html" title="Represents the (independent) demand in the system. It can represent a customer order...">Demand</a>*<span class="keyword">&gt;</span>(<span class="keyword">static_cast&lt;</span>PyObject*<span class="keyword">&gt;</span>(field));
<a name="l01007"></a>01007     <a class="code" href="a00125.html#a94c3d23a9b1ea2a802cc58718187ef8a">setDemand</a>(y);
<a name="l01008"></a>01008   }
<a name="l01009"></a>01009   <span class="keywordflow">else</span> <span class="keywordflow">if</span> (attr.<a class="code" href="a00002.html#aebffce6c4fcf1696ca34f63f2b6ee091">isA</a>(<a class="code" href="a00177.html#aaa2f978792ac2320979871ceafdc5c16">Tags::tag_owner</a>))
<a name="l01010"></a>01010   {
<a name="l01011"></a>01011     <span class="keywordflow">if</span> (!field.<a class="code" href="a00154.html#aa5f7a25056671e8df629cd42b0061b28">check</a>(<a class="code" href="a00125.html#a31cde691d7cdf2ce2db1fb0eb595e34a">OperationPlan::metadata</a>))
<a name="l01012"></a>01012     {
<a name="l01013"></a>01013       PyErr_SetString(<a class="code" href="a00257.html#a75c689d2dca4282e2ca0dad79dab1063" title="Python exception class matching with frepple::DataException.">PythonDataException</a>, <span class="stringliteral">&quot;operationplan demand must be of type demand&quot;</span>);
<a name="l01014"></a>01014       <span class="keywordflow">return</span> -1;
<a name="l01015"></a>01015     }
<a name="l01016"></a>01016     <a class="code" href="a00125.html" title="An operationplan is the key dynamic element of a plan. It represents a certain quantity...">OperationPlan</a>* y = <span class="keyword">static_cast&lt;</span><a class="code" href="a00125.html" title="An operationplan is the key dynamic element of a plan. It represents a certain quantity...">OperationPlan</a>*<span class="keyword">&gt;</span>(<span class="keyword">static_cast&lt;</span>PyObject*<span class="keyword">&gt;</span>(field));
<a name="l01017"></a>01017     <a class="code" href="a00125.html#a1a08b007136515186cc22cd95007f122">setOwner</a>(y);
<a name="l01018"></a>01018   }
<a name="l01019"></a>01019   <span class="keywordflow">else</span>
<a name="l01020"></a>01020     <span class="keywordflow">return</span> -1;
<a name="l01021"></a>01021   <span class="keywordflow">return</span> 0;
<a name="l01022"></a>01022 }
<a name="l01023"></a>01023 
<a name="l01024"></a>01024 } <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>