Sophie

Sophie

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

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: solverflow.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_f53ab566a495928d11ba5681eabceaaf.html">solver</a>
  </div>
</div>
<div class="contents">
<h1>solverflow.cpp</h1><a href="a00242.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/solver/solverflow.cpp $</span>
<a name="l00003"></a>00003 <span class="comment">  version : $LastChangedRevision: 1315 $  $LastChangedBy: jdetaeye $</span>
<a name="l00004"></a>00004 <span class="comment">  date : $LastChangedDate: 2010-07-17 18:08:53 +0200 (Sat, 17 Jul 2010) $</span>
<a name="l00005"></a>00005 <span class="comment"> ***************************************************************************/</span>
<a name="l00006"></a>00006 
<a name="l00007"></a>00007 <span class="comment">/***************************************************************************</span>
<a name="l00008"></a>00008 <span class="comment"> *                                                                         *</span>
<a name="l00009"></a>00009 <span class="comment"> * Copyright (C) 2007-2010 by Johan De Taeye                               *</span>
<a name="l00010"></a>00010 <span class="comment"> *                                                                         *</span>
<a name="l00011"></a>00011 <span class="comment"> * This library is free software; you can redistribute it and/or modify it *</span>
<a name="l00012"></a>00012 <span class="comment"> * under the terms of the GNU Lesser General Public License as published   *</span>
<a name="l00013"></a>00013 <span class="comment"> * by the Free Software Foundation; either version 2.1 of the License, or  *</span>
<a name="l00014"></a>00014 <span class="comment"> * (at your option) any later version.                                     *</span>
<a name="l00015"></a>00015 <span class="comment"> *                                                                         *</span>
<a name="l00016"></a>00016 <span class="comment"> * This library is distributed in the hope that it will be useful,         *</span>
<a name="l00017"></a>00017 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of          *</span>
<a name="l00018"></a>00018 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser *</span>
<a name="l00019"></a>00019 <span class="comment"> * General Public License for more details.                                *</span>
<a name="l00020"></a>00020 <span class="comment"> *                                                                         *</span>
<a name="l00021"></a>00021 <span class="comment"> * You should have received a copy of the GNU Lesser General Public        *</span>
<a name="l00022"></a>00022 <span class="comment"> * License along with this library; if not, write to the Free Software     *</span>
<a name="l00023"></a>00023 <span class="comment"> * Foundation Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 *</span>
<a name="l00024"></a>00024 <span class="comment"> * USA                                                                     *</span>
<a name="l00025"></a>00025 <span class="comment"> *                                                                         *</span>
<a name="l00026"></a>00026 <span class="comment"> ***************************************************************************/</span>
<a name="l00027"></a>00027 
<a name="l00028"></a><a class="code" href="a00242.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="a00239.html">frepple/solver.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><a class="code" href="a00256.html#aaa4ca701ce60388c7cb7afaa635d8e50">00034</a> <span class="keywordtype">bool</span> <a class="code" href="a00256.html#aaa4ca701ce60388c7cb7afaa635d8e50">sortFlow</a>(<span class="keyword">const</span> <a class="code" href="a00065.html" title="This class defines a material flow to/from a buffer, linked with an operation. This...">Flow</a>* lhs, <span class="keyword">const</span> <a class="code" href="a00065.html" title="This class defines a material flow to/from a buffer, linked with an operation. This...">Flow</a>* rhs)
<a name="l00035"></a>00035 {
<a name="l00036"></a>00036   <span class="keywordflow">return</span> lhs-&gt;<a class="code" href="a00065.html#a8cac1ed580a00c11f797bf0eae77330e">getPriority</a>() &lt; rhs-&gt;<a class="code" href="a00065.html#a8cac1ed580a00c11f797bf0eae77330e">getPriority</a>();
<a name="l00037"></a>00037 }
<a name="l00038"></a>00038 
<a name="l00039"></a>00039 
<a name="l00040"></a><a class="code" href="a00173.html#a07bb4bc46446999572f77d94b8c33b35">00040</a> <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> <span class="keywordtype">void</span> <a class="code" href="a00173.html#aed1d08dd6ece530ed9229d463e31cca3">SolverMRP::solve</a>(<span class="keyword">const</span> <a class="code" href="a00065.html" title="This class defines a material flow to/from a buffer, linked with an operation. This...">Flow</a>* fl, <span class="keywordtype">void</span>* v)  <span class="comment">// @todo implement search mode</span>
<a name="l00041"></a>00041 {
<a name="l00042"></a>00042   <span class="comment">// Note: This method is only called for consuming flows and for the leading</span>
<a name="l00043"></a>00043   <span class="comment">// flow of an alternate group. See SolverMRP::checkOperation</span>
<a name="l00044"></a>00044 
<a name="l00045"></a>00045   <a class="code" href="a00174.html" title="This class is a helper class of the SolverMRP class.">SolverMRPdata</a>* data = <span class="keyword">static_cast&lt;</span><a class="code" href="a00174.html" title="This class is a helper class of the SolverMRP class.">SolverMRPdata</a>*<span class="keyword">&gt;</span>(v);
<a name="l00046"></a>00046   <span class="keywordflow">if</span> (fl-&gt;<a class="code" href="a00065.html#af014c60036fa0d54295e2a179e146c11">hasAlternates</a>())
<a name="l00047"></a>00047   {
<a name="l00048"></a>00048     <span class="comment">// CASE I: It is an alternate flow.</span>
<a name="l00049"></a>00049     <span class="comment">// We ask each alternate flow in order of priority till we find a flow</span>
<a name="l00050"></a>00050     <span class="comment">// that has a non-zero reply.</span>
<a name="l00051"></a>00051 
<a name="l00052"></a>00052     <span class="comment">// 1) collect a list of alternates</span>
<a name="l00053"></a>00053     list&lt;const Flow*&gt; thealternates;
<a name="l00054"></a>00054     <span class="keyword">const</span> <a class="code" href="a00065.html" title="This class defines a material flow to/from a buffer, linked with an operation. This...">Flow</a> *x = fl-&gt;<a class="code" href="a00065.html#af014c60036fa0d54295e2a179e146c11">hasAlternates</a>() ? fl : fl-&gt;<a class="code" href="a00065.html#a24a2afc7eb0ad57edf20f87e9ce2de96">getAlternate</a>();
<a name="l00055"></a>00055     <span class="keywordflow">for</span> (<a class="code" href="a00040.html" title="An iterator over the associated objects.">Operation::flowlist::const_iterator</a> i = fl-&gt;<a class="code" href="a00065.html#af7649182aaa0020e9684ccd337a357ad">getOperation</a>()-&gt;<a class="code" href="a00121.html#ac6b2f299c5939e2c61b2724ac58a2326">getFlows</a>().begin();
<a name="l00056"></a>00056       i != fl-&gt;<a class="code" href="a00065.html#af7649182aaa0020e9684ccd337a357ad">getOperation</a>()-&gt;<a class="code" href="a00121.html#ac6b2f299c5939e2c61b2724ac58a2326">getFlows</a>().end(); ++i)
<a name="l00057"></a>00057       <span class="keywordflow">if</span> ((i-&gt;getAlternate() == x || &amp;*i == x)
<a name="l00058"></a>00058         &amp;&amp; i-&gt;getEffective().within(data-&gt;<a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-&gt;<a class="code" href="a00175.html#a012238f00ed4e3db77e711848f257f74">q_flowplan</a>-&gt;<a class="code" href="a00058.html#a965645e70dd9f99b0bd4f1325fb382aa">getDate</a>()))
<a name="l00059"></a>00059         thealternates.push_front(&amp;*i);
<a name="l00060"></a>00060 
<a name="l00061"></a>00061     <span class="comment">// 2) Sort the list</span>
<a name="l00062"></a>00062     thealternates.sort(<a class="code" href="a00256.html#aaa4ca701ce60388c7cb7afaa635d8e50">sortFlow</a>);
<a name="l00063"></a>00063 
<a name="l00064"></a>00064     <span class="comment">// 3) Control the planning mode</span>
<a name="l00065"></a>00065     <span class="keywordtype">bool</span> originalPlanningMode = data-&gt;constrainedPlanning;
<a name="l00066"></a>00066     data-&gt;constrainedPlanning = <span class="keyword">true</span>;
<a name="l00067"></a>00067     <span class="keyword">const</span> <a class="code" href="a00065.html" title="This class defines a material flow to/from a buffer, linked with an operation. This...">Flow</a> *firstAlternate = NULL;
<a name="l00068"></a>00068     <span class="keywordtype">double</span> firstQuantity = 0.0;
<a name="l00069"></a>00069 
<a name="l00070"></a>00070     <span class="comment">// Remember the top constraint</span>
<a name="l00071"></a>00071     <span class="keywordtype">bool</span> originalLogConstraints = data-&gt;logConstraints;
<a name="l00072"></a>00072     <a class="code" href="a00134.html" title="A problem represents infeasibilities, alerts and warnings in the plan.">Problem</a>* topConstraint = data-&gt;planningDemand-&gt;<a class="code" href="a00051.html#acd06be46dd32eb121e408c5b9e035965">getConstraints</a>().<a class="code" href="a00100.html#a0391e63b3596b7820946776182f7bd7f">top</a>();
<a name="l00073"></a>00073 
<a name="l00074"></a>00074     <span class="comment">// 4) Loop through the alternates till we find a non-zero reply</span>
<a name="l00075"></a>00075     <a class="code" href="a00049.html" title="This class represents a date and time with an accuracy of one second.">Date</a> min_next_date(Date::infiniteFuture);
<a name="l00076"></a>00076     <span class="keywordtype">double</span> ask_qty;
<a name="l00077"></a>00077     <a class="code" href="a00068.html" title="A flowplan represents a planned material flow in or out of a buffer.">FlowPlan</a> *flplan = data-&gt;<a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-&gt;<a class="code" href="a00175.html#a012238f00ed4e3db77e711848f257f74">q_flowplan</a>;
<a name="l00078"></a>00078     <span class="keywordflow">for</span> (list&lt;const Flow*&gt;::const_iterator i = thealternates.begin();
<a name="l00079"></a>00079       i != thealternates.end();)
<a name="l00080"></a>00080     {
<a name="l00081"></a>00081       <span class="keyword">const</span> <a class="code" href="a00065.html" title="This class defines a material flow to/from a buffer, linked with an operation. This...">Flow</a> *curflow = *i;
<a name="l00082"></a>00082       data-&gt;<a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-&gt;<a class="code" href="a00175.html#a012238f00ed4e3db77e711848f257f74">q_flowplan</a> = flplan; <span class="comment">// because q_flowplan can change</span>
<a name="l00083"></a>00083 
<a name="l00084"></a>00084       <span class="comment">// 4a) Switch to this flow</span>
<a name="l00085"></a>00085       <span class="keywordflow">if</span> (data-&gt;<a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-&gt;<a class="code" href="a00175.html#a012238f00ed4e3db77e711848f257f74">q_flowplan</a>-&gt;<a class="code" href="a00068.html#afad8d8ad9e551d7abb012bf1383b18c8">getFlow</a>() != curflow)
<a name="l00086"></a>00086         data-&gt;<a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-&gt;<a class="code" href="a00175.html#a012238f00ed4e3db77e711848f257f74">q_flowplan</a>-&gt;<a class="code" href="a00068.html#aaa7771a21e573b2a9981ff1c9bab321d">setFlow</a>(curflow);
<a name="l00087"></a>00087 
<a name="l00088"></a>00088       <span class="comment">// 4b) Call the Python user exit if there is one</span>
<a name="l00089"></a>00089       <span class="keywordflow">if</span> (userexit_flow)
<a name="l00090"></a>00090       {
<a name="l00091"></a>00091         <a class="code" href="a00154.html" title="This class handles two-way translation between the data types in C++ and Python.">PythonObject</a> result = userexit_flow.<a class="code" href="a00152.html#a7f199c39019f133986783dfc6017b640">call</a>(data-&gt;<a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-&gt;<a class="code" href="a00175.html#a012238f00ed4e3db77e711848f257f74">q_flowplan</a>, <a class="code" href="a00154.html" title="This class handles two-way translation between the data types in C++ and Python.">PythonObject</a>(data-&gt;constrainedPlanning));
<a name="l00092"></a>00092         <span class="keywordflow">if</span> (!result.<a class="code" href="a00154.html#a804b478fb76759d334882ee468fc84f9">getBool</a>())
<a name="l00093"></a>00093         {
<a name="l00094"></a>00094           <span class="comment">// Return value is false, alternate rejected</span>
<a name="l00095"></a>00095           <span class="keywordflow">if</span> (data-&gt;<a class="code" href="a00174.html#a1d6f62b1c53725b796ea1c4f8843b85d">getSolver</a>()-&gt;<a class="code" href="a00171.html#a7331226cd4ef515184dff2d118c43423">getLogLevel</a>()&gt;1)
<a name="l00096"></a>00096             <a class="code" href="a00257.html#a4af9f241e955122820c5e81ceb33edb5">logger</a> &lt;&lt; <a class="code" href="a00087.html">indent</a>(curflow-&gt;<a class="code" href="a00065.html#af7649182aaa0020e9684ccd337a357ad">getOperation</a>()-&gt;<a class="code" href="a00084.html#a44c879fcf3b6ae9193c393630e25fd13">getLevel</a>())
<a name="l00097"></a>00097               &lt;&lt; <span class="stringliteral">&quot;   User exit disallows consumption from &apos;&quot;</span>
<a name="l00098"></a>00098               &lt;&lt; (*i)-&gt;getBuffer()-&gt;getName() &lt;&lt; <span class="stringliteral">&quot;&apos;&quot;</span> &lt;&lt; endl;
<a name="l00099"></a>00099           <span class="comment">// Move to the next alternate</span>
<a name="l00100"></a>00100           <span class="keywordflow">if</span> (++i != thealternates.end() &amp;&amp; data-&gt;<a class="code" href="a00174.html#a1d6f62b1c53725b796ea1c4f8843b85d">getSolver</a>()-&gt;<a class="code" href="a00171.html#a7331226cd4ef515184dff2d118c43423">getLogLevel</a>()&gt;1)
<a name="l00101"></a>00101             <a class="code" href="a00257.html#a4af9f241e955122820c5e81ceb33edb5">logger</a> &lt;&lt; <a class="code" href="a00087.html">indent</a>(curflow-&gt;<a class="code" href="a00065.html#af7649182aaa0020e9684ccd337a357ad">getOperation</a>()-&gt;<a class="code" href="a00084.html#a44c879fcf3b6ae9193c393630e25fd13">getLevel</a>()) &lt;&lt; <span class="stringliteral">&quot;   Alternate flow switches from &apos;&quot;</span>
<a name="l00102"></a>00102                   &lt;&lt; curflow-&gt;<a class="code" href="a00065.html#a3034ea6d121f86338faeab26ec7464d4">getBuffer</a>()-&gt;<a class="code" href="a00182.html#a7416ca220c55147bc1276becc5b9de01">getName</a>() &lt;&lt; <span class="stringliteral">&quot;&apos; to &apos;&quot;</span>
<a name="l00103"></a>00103                   &lt;&lt; (*i)-&gt;getBuffer()-&gt;getName() &lt;&lt; <span class="stringliteral">&quot;&apos;&quot;</span> &lt;&lt; endl;
<a name="l00104"></a>00104           <span class="keywordflow">continue</span>;
<a name="l00105"></a>00105         }
<a name="l00106"></a>00106       }
<a name="l00107"></a>00107 
<a name="l00108"></a>00108       <span class="comment">// Remember the first alternate</span>
<a name="l00109"></a>00109       <span class="keywordflow">if</span> (!firstAlternate)
<a name="l00110"></a>00110       {
<a name="l00111"></a>00111         firstAlternate = *i;
<a name="l00112"></a>00112         firstQuantity = data-&gt;<a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-&gt;<a class="code" href="a00175.html#a012238f00ed4e3db77e711848f257f74">q_flowplan</a>-&gt;<a class="code" href="a00059.html#a665af7bb916d05a8c9a06f1a8170090f">getQuantity</a>();
<a name="l00113"></a>00113       }
<a name="l00114"></a>00114 
<a name="l00115"></a>00115       <span class="comment">// Constraint tracking</span>
<a name="l00116"></a>00116       <span class="keywordflow">if</span> (*i != firstAlternate)
<a name="l00117"></a>00117         <span class="comment">// Only enabled on first alternate</span>
<a name="l00118"></a>00118         data-&gt;logConstraints = <span class="keyword">false</span>;
<a name="l00119"></a>00119       <span class="keywordflow">else</span> 
<a name="l00120"></a>00120         <span class="comment">// Keep track of constraints, if enabled</span>
<a name="l00121"></a>00121         data-&gt;logConstraints = originalLogConstraints;
<a name="l00122"></a>00122 
<a name="l00123"></a>00123       <span class="comment">// 4c) Ask the buffer</span>
<a name="l00124"></a>00124       data-&gt;<a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-&gt;<a class="code" href="a00175.html#adf7c858a404b725f2f2c67648300f89b">q_qty</a> = ask_qty = - data-&gt;<a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-&gt;<a class="code" href="a00175.html#a012238f00ed4e3db77e711848f257f74">q_flowplan</a>-&gt;<a class="code" href="a00059.html#a665af7bb916d05a8c9a06f1a8170090f">getQuantity</a>();
<a name="l00125"></a>00125       data-&gt;<a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-&gt;<a class="code" href="a00175.html#a658c5379af8ec535090a96dd969f1fc3">q_date</a> = data-&gt;<a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-&gt;<a class="code" href="a00175.html#a012238f00ed4e3db77e711848f257f74">q_flowplan</a>-&gt;<a class="code" href="a00058.html#a965645e70dd9f99b0bd4f1325fb382aa">getDate</a>();
<a name="l00126"></a>00126       <a class="code" href="a00025.html" title="Abstract base class for all commands.">Command</a>* topcommand = data-&gt;<a class="code" href="a00029.html#a392f247416814b845c086ff1f7196ad9">getLastCommand</a>();
<a name="l00127"></a>00127       curflow-&gt;<a class="code" href="a00065.html#a3034ea6d121f86338faeab26ec7464d4">getBuffer</a>()-&gt;<a class="code" href="a00008.html#a312e9f46eeab928dd58a3418376af2ea">solve</a>(*<span class="keyword">this</span>,data);
<a name="l00128"></a>00128 
<a name="l00129"></a>00129       <span class="comment">// 4d) A positive reply: exit the loop</span>
<a name="l00130"></a>00130       <span class="keywordflow">if</span> (data-&gt;<a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-&gt;<a class="code" href="a00175.html#af34ccc319ed0bd6bb387353e0968e622">a_qty</a> &gt; <a class="code" href="a00252.html#a42d90a6275119e1b4ce73c50f1867e60">ROUNDING_ERROR</a>) 
<a name="l00131"></a>00131       {
<a name="l00132"></a>00132         <span class="comment">// Update the opplan, which is required to (1) update the flowplans</span>
<a name="l00133"></a>00133         <span class="comment">// and to (2) take care of lot sizing constraints of this operation.</span>
<a name="l00134"></a>00134         <span class="keywordflow">if</span> (data-&gt;<a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-&gt;<a class="code" href="a00175.html#af34ccc319ed0bd6bb387353e0968e622">a_qty</a> &lt; ask_qty - <a class="code" href="a00252.html#a42d90a6275119e1b4ce73c50f1867e60">ROUNDING_ERROR</a>)
<a name="l00135"></a>00135         {
<a name="l00136"></a>00136           flplan-&gt;<a class="code" href="a00068.html#a0b5b8438e4f952d0ae4d50a9b5e1d68a">setQuantity</a>(-data-&gt;<a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-&gt;<a class="code" href="a00175.html#af34ccc319ed0bd6bb387353e0968e622">a_qty</a>, <span class="keyword">true</span>);
<a name="l00137"></a>00137           data-&gt;<a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-&gt;<a class="code" href="a00175.html#af34ccc319ed0bd6bb387353e0968e622">a_qty</a> = -flplan-&gt;<a class="code" href="a00059.html#a665af7bb916d05a8c9a06f1a8170090f">getQuantity</a>();
<a name="l00138"></a>00138         }
<a name="l00139"></a>00139         <span class="keywordflow">if</span> (data-&gt;<a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-&gt;<a class="code" href="a00175.html#af34ccc319ed0bd6bb387353e0968e622">a_qty</a> &gt; <a class="code" href="a00252.html#a42d90a6275119e1b4ce73c50f1867e60">ROUNDING_ERROR</a>)
<a name="l00140"></a>00140         {
<a name="l00141"></a>00141           data-&gt;constrainedPlanning = originalPlanningMode;
<a name="l00142"></a>00142           data-&gt;logConstraints = originalLogConstraints;
<a name="l00143"></a>00143           <span class="keywordflow">return</span>;
<a name="l00144"></a>00144         }
<a name="l00145"></a>00145       }
<a name="l00146"></a>00146 
<a name="l00147"></a>00147       <span class="comment">// 4e) Undo the plan on the alternate</span>
<a name="l00148"></a>00148       data-&gt;<a class="code" href="a00029.html#a6f38f9a190b88a29f63b58a478cbe982">undo</a>(topcommand);
<a name="l00149"></a>00149 
<a name="l00150"></a>00150       <span class="comment">// 4f) Prepare for the next alternate</span>
<a name="l00151"></a>00151       <span class="keywordflow">if</span> (data-&gt;<a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-&gt;<a class="code" href="a00175.html#ab56b3877ddc206e8817f04186c0e47a8">a_date</a> &lt; min_next_date)
<a name="l00152"></a>00152         min_next_date = data-&gt;<a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-&gt;<a class="code" href="a00175.html#ab56b3877ddc206e8817f04186c0e47a8">a_date</a>;
<a name="l00153"></a>00153       <span class="keywordflow">if</span> (++i != thealternates.end() &amp;&amp; data-&gt;<a class="code" href="a00174.html#a1d6f62b1c53725b796ea1c4f8843b85d">getSolver</a>()-&gt;<a class="code" href="a00171.html#a7331226cd4ef515184dff2d118c43423">getLogLevel</a>()&gt;1)
<a name="l00154"></a>00154         <a class="code" href="a00257.html#a4af9f241e955122820c5e81ceb33edb5">logger</a> &lt;&lt; <a class="code" href="a00087.html">indent</a>(curflow-&gt;<a class="code" href="a00065.html#af7649182aaa0020e9684ccd337a357ad">getOperation</a>()-&gt;<a class="code" href="a00084.html#a44c879fcf3b6ae9193c393630e25fd13">getLevel</a>()) &lt;&lt; <span class="stringliteral">&quot;   Alternate flow switches from &apos;&quot;</span>
<a name="l00155"></a>00155               &lt;&lt; curflow-&gt;<a class="code" href="a00065.html#a3034ea6d121f86338faeab26ec7464d4">getBuffer</a>()-&gt;<a class="code" href="a00182.html#a7416ca220c55147bc1276becc5b9de01">getName</a>() &lt;&lt; <span class="stringliteral">&quot;&apos; to &apos;&quot;</span>
<a name="l00156"></a>00156               &lt;&lt; (*i)-&gt;getBuffer()-&gt;getName() &lt;&lt; <span class="stringliteral">&quot;&apos;&quot;</span> &lt;&lt; endl;
<a name="l00157"></a>00157     }
<a name="l00158"></a>00158 
<a name="l00159"></a>00159     <span class="comment">// 5) No reply found, all alternates are infeasible</span>
<a name="l00160"></a>00160     <span class="keywordflow">if</span> (!originalPlanningMode)
<a name="l00161"></a>00161     {
<a name="l00162"></a>00162       assert(firstAlternate);
<a name="l00163"></a>00163       <span class="comment">// Unconstrained plan: Plan on the primary alternate</span>
<a name="l00164"></a>00164       <span class="comment">// Switch to this flow</span>
<a name="l00165"></a>00165       <span class="keywordflow">if</span> (flplan-&gt;<a class="code" href="a00068.html#afad8d8ad9e551d7abb012bf1383b18c8">getFlow</a>() != firstAlternate)
<a name="l00166"></a>00166         flplan-&gt;<a class="code" href="a00068.html#aaa7771a21e573b2a9981ff1c9bab321d">setFlow</a>(firstAlternate);
<a name="l00167"></a>00167       <span class="comment">// Message</span>
<a name="l00168"></a>00168       <span class="keywordflow">if</span> (data-&gt;<a class="code" href="a00174.html#a1d6f62b1c53725b796ea1c4f8843b85d">getSolver</a>()-&gt;<a class="code" href="a00171.html#a7331226cd4ef515184dff2d118c43423">getLogLevel</a>()&gt;1)
<a name="l00169"></a>00169         <a class="code" href="a00257.html#a4af9f241e955122820c5e81ceb33edb5">logger</a> &lt;&lt; <a class="code" href="a00087.html">indent</a>(fl-&gt;<a class="code" href="a00065.html#af7649182aaa0020e9684ccd337a357ad">getOperation</a>()-&gt;<a class="code" href="a00084.html#a44c879fcf3b6ae9193c393630e25fd13">getLevel</a>()) 
<a name="l00170"></a>00170           &lt;&lt; <span class="stringliteral">&quot;   Alternate flow plans unconstrained on alternate &apos;&quot;</span>
<a name="l00171"></a>00171           &lt;&lt; firstAlternate-&gt;<a class="code" href="a00065.html#a3034ea6d121f86338faeab26ec7464d4">getBuffer</a>()-&gt;<a class="code" href="a00182.html#a7416ca220c55147bc1276becc5b9de01">getName</a>() &lt;&lt; <span class="stringliteral">&quot;&apos;&quot;</span> &lt;&lt; endl;
<a name="l00172"></a>00172       <span class="comment">// Plan unconstrained</span>
<a name="l00173"></a>00173       data-&gt;constrainedPlanning = <span class="keyword">false</span>;
<a name="l00174"></a>00174       data-&gt;<a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-&gt;<a class="code" href="a00175.html#a012238f00ed4e3db77e711848f257f74">q_flowplan</a> = flplan; <span class="comment">// because q_flowplan can change</span>
<a name="l00175"></a>00175       flplan-&gt;<a class="code" href="a00068.html#a0b5b8438e4f952d0ae4d50a9b5e1d68a">setQuantity</a>(firstQuantity, <span class="keyword">true</span>);
<a name="l00176"></a>00176       data-&gt;<a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-&gt;<a class="code" href="a00175.html#adf7c858a404b725f2f2c67648300f89b">q_qty</a> = ask_qty = - flplan-&gt;<a class="code" href="a00059.html#a665af7bb916d05a8c9a06f1a8170090f">getQuantity</a>();
<a name="l00177"></a>00177       data-&gt;<a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-&gt;<a class="code" href="a00175.html#a658c5379af8ec535090a96dd969f1fc3">q_date</a> = flplan-&gt;<a class="code" href="a00058.html#a965645e70dd9f99b0bd4f1325fb382aa">getDate</a>();
<a name="l00178"></a>00178       <a class="code" href="a00025.html" title="Abstract base class for all commands.">Command</a>* topcommand = data-&gt;<a class="code" href="a00029.html#a392f247416814b845c086ff1f7196ad9">getLastCommand</a>();
<a name="l00179"></a>00179       firstAlternate-&gt;<a class="code" href="a00065.html#a3034ea6d121f86338faeab26ec7464d4">getBuffer</a>()-&gt;<a class="code" href="a00008.html#a312e9f46eeab928dd58a3418376af2ea">solve</a>(*<span class="keyword">this</span>,data);
<a name="l00180"></a>00180       data-&gt;<a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-&gt;<a class="code" href="a00175.html#af34ccc319ed0bd6bb387353e0968e622">a_qty</a> = -flplan-&gt;<a class="code" href="a00059.html#a665af7bb916d05a8c9a06f1a8170090f">getQuantity</a>();
<a name="l00181"></a>00181       <span class="comment">// Restore original planning mode</span>
<a name="l00182"></a>00182       data-&gt;constrainedPlanning = originalPlanningMode;
<a name="l00183"></a>00183     }
<a name="l00184"></a>00184     <span class="keywordflow">else</span>
<a name="l00185"></a>00185     {
<a name="l00186"></a>00186       <span class="comment">// Constrained plan: Return 0</span>
<a name="l00187"></a>00187       data-&gt;<a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-&gt;<a class="code" href="a00175.html#ab56b3877ddc206e8817f04186c0e47a8">a_date</a> = min_next_date;
<a name="l00188"></a>00188       data-&gt;<a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-&gt;<a class="code" href="a00175.html#af34ccc319ed0bd6bb387353e0968e622">a_qty</a> = 0;
<a name="l00189"></a>00189       <span class="keywordflow">if</span> (data-&gt;<a class="code" href="a00174.html#a1d6f62b1c53725b796ea1c4f8843b85d">getSolver</a>()-&gt;<a class="code" href="a00171.html#a7331226cd4ef515184dff2d118c43423">getLogLevel</a>()&gt;1)
<a name="l00190"></a>00190         <a class="code" href="a00257.html#a4af9f241e955122820c5e81ceb33edb5">logger</a> &lt;&lt; <a class="code" href="a00087.html">indent</a>(fl-&gt;<a class="code" href="a00065.html#af7649182aaa0020e9684ccd337a357ad">getOperation</a>()-&gt;<a class="code" href="a00084.html#a44c879fcf3b6ae9193c393630e25fd13">getLevel</a>()) &lt;&lt;
<a name="l00191"></a>00191           <span class="stringliteral">&quot;   Alternate flow doesn&apos;t find supply on any alternate : &quot;</span>
<a name="l00192"></a>00192           &lt;&lt; data-&gt;<a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-&gt;<a class="code" href="a00175.html#af34ccc319ed0bd6bb387353e0968e622">a_qty</a> &lt;&lt; <span class="stringliteral">&quot;  &quot;</span> &lt;&lt; data-&gt;<a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-&gt;<a class="code" href="a00175.html#ab56b3877ddc206e8817f04186c0e47a8">a_date</a> &lt;&lt; endl;
<a name="l00193"></a>00193     }
<a name="l00194"></a>00194   }
<a name="l00195"></a>00195   <span class="keywordflow">else</span>
<a name="l00196"></a>00196   {
<a name="l00197"></a>00197     <span class="comment">// CASE II: Not an alternate flow.</span>
<a name="l00198"></a>00198     <span class="comment">// In this case, this method is passing control on to the buffer.</span>
<a name="l00199"></a>00199     data-&gt;<a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-&gt;<a class="code" href="a00175.html#adf7c858a404b725f2f2c67648300f89b">q_qty</a> = - data-&gt;<a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-&gt;<a class="code" href="a00175.html#a012238f00ed4e3db77e711848f257f74">q_flowplan</a>-&gt;<a class="code" href="a00059.html#a665af7bb916d05a8c9a06f1a8170090f">getQuantity</a>();
<a name="l00200"></a>00200     data-&gt;<a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-&gt;<a class="code" href="a00175.html#a658c5379af8ec535090a96dd969f1fc3">q_date</a> = data-&gt;<a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-&gt;<a class="code" href="a00175.html#a012238f00ed4e3db77e711848f257f74">q_flowplan</a>-&gt;<a class="code" href="a00058.html#a965645e70dd9f99b0bd4f1325fb382aa">getDate</a>();
<a name="l00201"></a>00201     <span class="keywordflow">if</span> (data-&gt;<a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-&gt;<a class="code" href="a00175.html#adf7c858a404b725f2f2c67648300f89b">q_qty</a> != 0.0)
<a name="l00202"></a>00202     {
<a name="l00203"></a>00203       fl-&gt;<a class="code" href="a00065.html#a3034ea6d121f86338faeab26ec7464d4">getBuffer</a>()-&gt;<a class="code" href="a00008.html#a312e9f46eeab928dd58a3418376af2ea">solve</a>(*<span class="keyword">this</span>,data);
<a name="l00204"></a>00204       <span class="keywordflow">if</span> (data-&gt;<a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-&gt;<a class="code" href="a00175.html#ab56b3877ddc206e8817f04186c0e47a8">a_date</a> &gt; fl-&gt;<a class="code" href="a00118.html#a3056abd641cadca725336059b9e91b1b">getEffective</a>().<a class="code" href="a00050.html#a165a8f748d8468e5ba8331c0e06bd3a2">getEnd</a>())
<a name="l00205"></a>00205       {
<a name="l00206"></a>00206         <span class="comment">// The reply date must be less than the effectivity end date: after</span>
<a name="l00207"></a>00207         <span class="comment">// that date the flow in question won&apos;t consume any material any more.</span>
<a name="l00208"></a>00208         <span class="keywordflow">if</span> (data-&gt;<a class="code" href="a00174.html#a1d6f62b1c53725b796ea1c4f8843b85d">getSolver</a>()-&gt;<a class="code" href="a00171.html#a7331226cd4ef515184dff2d118c43423">getLogLevel</a>()&gt;1
<a name="l00209"></a>00209           &amp;&amp; data-&gt;<a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-&gt;<a class="code" href="a00175.html#af34ccc319ed0bd6bb387353e0968e622">a_qty</a> &lt; <a class="code" href="a00252.html#a42d90a6275119e1b4ce73c50f1867e60">ROUNDING_ERROR</a>)
<a name="l00210"></a>00210           <a class="code" href="a00257.html#a4af9f241e955122820c5e81ceb33edb5">logger</a> &lt;&lt; <a class="code" href="a00087.html">indent</a>(fl-&gt;<a class="code" href="a00065.html#a3034ea6d121f86338faeab26ec7464d4">getBuffer</a>()-&gt;<a class="code" href="a00084.html#a44c879fcf3b6ae9193c393630e25fd13">getLevel</a>()) &lt;&lt; <span class="stringliteral">&quot;  Buffer &apos;&quot;</span>
<a name="l00211"></a>00211             &lt;&lt; fl-&gt;<a class="code" href="a00065.html#a3034ea6d121f86338faeab26ec7464d4">getBuffer</a>()-&gt;<a class="code" href="a00182.html#a7416ca220c55147bc1276becc5b9de01">getName</a>() &lt;&lt; <span class="stringliteral">&quot;&apos; answer date is adjusted to &quot;</span>
<a name="l00212"></a>00212             &lt;&lt; fl-&gt;<a class="code" href="a00118.html#a3056abd641cadca725336059b9e91b1b">getEffective</a>().<a class="code" href="a00050.html#a165a8f748d8468e5ba8331c0e06bd3a2">getEnd</a>()
<a name="l00213"></a>00213             &lt;&lt; <span class="stringliteral">&quot; because of a date effective flow&quot;</span> &lt;&lt; endl;
<a name="l00214"></a>00214         data-&gt;<a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-&gt;<a class="code" href="a00175.html#ab56b3877ddc206e8817f04186c0e47a8">a_date</a> = fl-&gt;<a class="code" href="a00118.html#a3056abd641cadca725336059b9e91b1b">getEffective</a>().<a class="code" href="a00050.html#a165a8f748d8468e5ba8331c0e06bd3a2">getEnd</a>();
<a name="l00215"></a>00215       }
<a name="l00216"></a>00216     }
<a name="l00217"></a>00217     <span class="keywordflow">else</span>
<a name="l00218"></a>00218     {
<a name="l00219"></a>00219       <span class="comment">// It&apos;s a zero quantity flowplan.</span>
<a name="l00220"></a>00220       <span class="comment">// E.g. because it is not effective.</span>
<a name="l00221"></a>00221       data-&gt;<a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-&gt;<a class="code" href="a00175.html#ab56b3877ddc206e8817f04186c0e47a8">a_date</a> = data-&gt;<a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-&gt;<a class="code" href="a00175.html#a658c5379af8ec535090a96dd969f1fc3">q_date</a>;
<a name="l00222"></a>00222       data-&gt;<a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-&gt;<a class="code" href="a00175.html#af34ccc319ed0bd6bb387353e0968e622">a_qty</a> = 0.0;
<a name="l00223"></a>00223     }
<a name="l00224"></a>00224   }
<a name="l00225"></a>00225 }
<a name="l00226"></a>00226 
<a name="l00227"></a>00227 
<a name="l00228"></a>00228 }
</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>