<!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 Page</span></a></li> <li><a href="pages.html"><span>Related 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 List</span></a></li> <li><a href="globals.html"><span>File Members</span></a></li> </ul> </div> <div class="navpath"><a class="el" href="dir_88117dff2735251a69c8eb9084477714.html">src</a> » <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 "<a class="code" href="a00239.html">frepple/solver.h</a>"</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-><a class="code" href="a00065.html#a8cac1ed580a00c11f797bf0eae77330e">getPriority</a>() < rhs-><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<</span><a class="code" href="a00174.html" title="This class is a helper class of the SolverMRP class.">SolverMRPdata</a>*<span class="keyword">></span>(v); <a name="l00046"></a>00046 <span class="keywordflow">if</span> (fl-><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<const Flow*> 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-><a class="code" href="a00065.html#af014c60036fa0d54295e2a179e146c11">hasAlternates</a>() ? fl : fl-><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-><a class="code" href="a00065.html#af7649182aaa0020e9684ccd337a357ad">getOperation</a>()-><a class="code" href="a00121.html#ac6b2f299c5939e2c61b2724ac58a2326">getFlows</a>().begin(); <a name="l00056"></a>00056 i != fl-><a class="code" href="a00065.html#af7649182aaa0020e9684ccd337a357ad">getOperation</a>()-><a class="code" href="a00121.html#ac6b2f299c5939e2c61b2724ac58a2326">getFlows</a>().end(); ++i) <a name="l00057"></a>00057 <span class="keywordflow">if</span> ((i->getAlternate() == x || &*i == x) <a name="l00058"></a>00058 && i->getEffective().within(data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#a012238f00ed4e3db77e711848f257f74">q_flowplan</a>-><a class="code" href="a00058.html#a965645e70dd9f99b0bd4f1325fb382aa">getDate</a>())) <a name="l00059"></a>00059 thealternates.push_front(&*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->constrainedPlanning; <a name="l00066"></a>00066 data->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->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->planningDemand-><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-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#a012238f00ed4e3db77e711848f257f74">q_flowplan</a>; <a name="l00078"></a>00078 <span class="keywordflow">for</span> (list<const Flow*>::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-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><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-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#a012238f00ed4e3db77e711848f257f74">q_flowplan</a>-><a class="code" href="a00068.html#afad8d8ad9e551d7abb012bf1383b18c8">getFlow</a>() != curflow) <a name="l00086"></a>00086 data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#a012238f00ed4e3db77e711848f257f74">q_flowplan</a>-><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-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><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->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-><a class="code" href="a00174.html#a1d6f62b1c53725b796ea1c4f8843b85d">getSolver</a>()-><a class="code" href="a00171.html#a7331226cd4ef515184dff2d118c43423">getLogLevel</a>()>1) <a name="l00096"></a>00096 <a class="code" href="a00257.html#a4af9f241e955122820c5e81ceb33edb5">logger</a> << <a class="code" href="a00087.html">indent</a>(curflow-><a class="code" href="a00065.html#af7649182aaa0020e9684ccd337a357ad">getOperation</a>()-><a class="code" href="a00084.html#a44c879fcf3b6ae9193c393630e25fd13">getLevel</a>()) <a name="l00097"></a>00097 << <span class="stringliteral">" User exit disallows consumption from '"</span> <a name="l00098"></a>00098 << (*i)->getBuffer()->getName() << <span class="stringliteral">"'"</span> << 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() && data-><a class="code" href="a00174.html#a1d6f62b1c53725b796ea1c4f8843b85d">getSolver</a>()-><a class="code" href="a00171.html#a7331226cd4ef515184dff2d118c43423">getLogLevel</a>()>1) <a name="l00101"></a>00101 <a class="code" href="a00257.html#a4af9f241e955122820c5e81ceb33edb5">logger</a> << <a class="code" href="a00087.html">indent</a>(curflow-><a class="code" href="a00065.html#af7649182aaa0020e9684ccd337a357ad">getOperation</a>()-><a class="code" href="a00084.html#a44c879fcf3b6ae9193c393630e25fd13">getLevel</a>()) << <span class="stringliteral">" Alternate flow switches from '"</span> <a name="l00102"></a>00102 << curflow-><a class="code" href="a00065.html#a3034ea6d121f86338faeab26ec7464d4">getBuffer</a>()-><a class="code" href="a00182.html#a7416ca220c55147bc1276becc5b9de01">getName</a>() << <span class="stringliteral">"' to '"</span> <a name="l00103"></a>00103 << (*i)->getBuffer()->getName() << <span class="stringliteral">"'"</span> << 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-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#a012238f00ed4e3db77e711848f257f74">q_flowplan</a>-><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->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->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-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#adf7c858a404b725f2f2c67648300f89b">q_qty</a> = ask_qty = - data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#a012238f00ed4e3db77e711848f257f74">q_flowplan</a>-><a class="code" href="a00059.html#a665af7bb916d05a8c9a06f1a8170090f">getQuantity</a>(); <a name="l00125"></a>00125 data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#a658c5379af8ec535090a96dd969f1fc3">q_date</a> = data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#a012238f00ed4e3db77e711848f257f74">q_flowplan</a>-><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-><a class="code" href="a00029.html#a392f247416814b845c086ff1f7196ad9">getLastCommand</a>(); <a name="l00127"></a>00127 curflow-><a class="code" href="a00065.html#a3034ea6d121f86338faeab26ec7464d4">getBuffer</a>()-><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-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#af34ccc319ed0bd6bb387353e0968e622">a_qty</a> > <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-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#af34ccc319ed0bd6bb387353e0968e622">a_qty</a> < ask_qty - <a class="code" href="a00252.html#a42d90a6275119e1b4ce73c50f1867e60">ROUNDING_ERROR</a>) <a name="l00135"></a>00135 { <a name="l00136"></a>00136 flplan-><a class="code" href="a00068.html#a0b5b8438e4f952d0ae4d50a9b5e1d68a">setQuantity</a>(-data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#af34ccc319ed0bd6bb387353e0968e622">a_qty</a>, <span class="keyword">true</span>); <a name="l00137"></a>00137 data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#af34ccc319ed0bd6bb387353e0968e622">a_qty</a> = -flplan-><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-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#af34ccc319ed0bd6bb387353e0968e622">a_qty</a> > <a class="code" href="a00252.html#a42d90a6275119e1b4ce73c50f1867e60">ROUNDING_ERROR</a>) <a name="l00140"></a>00140 { <a name="l00141"></a>00141 data->constrainedPlanning = originalPlanningMode; <a name="l00142"></a>00142 data->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-><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-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#ab56b3877ddc206e8817f04186c0e47a8">a_date</a> < min_next_date) <a name="l00152"></a>00152 min_next_date = data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#ab56b3877ddc206e8817f04186c0e47a8">a_date</a>; <a name="l00153"></a>00153 <span class="keywordflow">if</span> (++i != thealternates.end() && data-><a class="code" href="a00174.html#a1d6f62b1c53725b796ea1c4f8843b85d">getSolver</a>()-><a class="code" href="a00171.html#a7331226cd4ef515184dff2d118c43423">getLogLevel</a>()>1) <a name="l00154"></a>00154 <a class="code" href="a00257.html#a4af9f241e955122820c5e81ceb33edb5">logger</a> << <a class="code" href="a00087.html">indent</a>(curflow-><a class="code" href="a00065.html#af7649182aaa0020e9684ccd337a357ad">getOperation</a>()-><a class="code" href="a00084.html#a44c879fcf3b6ae9193c393630e25fd13">getLevel</a>()) << <span class="stringliteral">" Alternate flow switches from '"</span> <a name="l00155"></a>00155 << curflow-><a class="code" href="a00065.html#a3034ea6d121f86338faeab26ec7464d4">getBuffer</a>()-><a class="code" href="a00182.html#a7416ca220c55147bc1276becc5b9de01">getName</a>() << <span class="stringliteral">"' to '"</span> <a name="l00156"></a>00156 << (*i)->getBuffer()->getName() << <span class="stringliteral">"'"</span> << 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-><a class="code" href="a00068.html#afad8d8ad9e551d7abb012bf1383b18c8">getFlow</a>() != firstAlternate) <a name="l00166"></a>00166 flplan-><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-><a class="code" href="a00174.html#a1d6f62b1c53725b796ea1c4f8843b85d">getSolver</a>()-><a class="code" href="a00171.html#a7331226cd4ef515184dff2d118c43423">getLogLevel</a>()>1) <a name="l00169"></a>00169 <a class="code" href="a00257.html#a4af9f241e955122820c5e81ceb33edb5">logger</a> << <a class="code" href="a00087.html">indent</a>(fl-><a class="code" href="a00065.html#af7649182aaa0020e9684ccd337a357ad">getOperation</a>()-><a class="code" href="a00084.html#a44c879fcf3b6ae9193c393630e25fd13">getLevel</a>()) <a name="l00170"></a>00170 << <span class="stringliteral">" Alternate flow plans unconstrained on alternate '"</span> <a name="l00171"></a>00171 << firstAlternate-><a class="code" href="a00065.html#a3034ea6d121f86338faeab26ec7464d4">getBuffer</a>()-><a class="code" href="a00182.html#a7416ca220c55147bc1276becc5b9de01">getName</a>() << <span class="stringliteral">"'"</span> << endl; <a name="l00172"></a>00172 <span class="comment">// Plan unconstrained</span> <a name="l00173"></a>00173 data->constrainedPlanning = <span class="keyword">false</span>; <a name="l00174"></a>00174 data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><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-><a class="code" href="a00068.html#a0b5b8438e4f952d0ae4d50a9b5e1d68a">setQuantity</a>(firstQuantity, <span class="keyword">true</span>); <a name="l00176"></a>00176 data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#adf7c858a404b725f2f2c67648300f89b">q_qty</a> = ask_qty = - flplan-><a class="code" href="a00059.html#a665af7bb916d05a8c9a06f1a8170090f">getQuantity</a>(); <a name="l00177"></a>00177 data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#a658c5379af8ec535090a96dd969f1fc3">q_date</a> = flplan-><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-><a class="code" href="a00029.html#a392f247416814b845c086ff1f7196ad9">getLastCommand</a>(); <a name="l00179"></a>00179 firstAlternate-><a class="code" href="a00065.html#a3034ea6d121f86338faeab26ec7464d4">getBuffer</a>()-><a class="code" href="a00008.html#a312e9f46eeab928dd58a3418376af2ea">solve</a>(*<span class="keyword">this</span>,data); <a name="l00180"></a>00180 data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#af34ccc319ed0bd6bb387353e0968e622">a_qty</a> = -flplan-><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->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-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#ab56b3877ddc206e8817f04186c0e47a8">a_date</a> = min_next_date; <a name="l00188"></a>00188 data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#af34ccc319ed0bd6bb387353e0968e622">a_qty</a> = 0; <a name="l00189"></a>00189 <span class="keywordflow">if</span> (data-><a class="code" href="a00174.html#a1d6f62b1c53725b796ea1c4f8843b85d">getSolver</a>()-><a class="code" href="a00171.html#a7331226cd4ef515184dff2d118c43423">getLogLevel</a>()>1) <a name="l00190"></a>00190 <a class="code" href="a00257.html#a4af9f241e955122820c5e81ceb33edb5">logger</a> << <a class="code" href="a00087.html">indent</a>(fl-><a class="code" href="a00065.html#af7649182aaa0020e9684ccd337a357ad">getOperation</a>()-><a class="code" href="a00084.html#a44c879fcf3b6ae9193c393630e25fd13">getLevel</a>()) << <a name="l00191"></a>00191 <span class="stringliteral">" Alternate flow doesn't find supply on any alternate : "</span> <a name="l00192"></a>00192 << data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#af34ccc319ed0bd6bb387353e0968e622">a_qty</a> << <span class="stringliteral">" "</span> << data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#ab56b3877ddc206e8817f04186c0e47a8">a_date</a> << 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-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#adf7c858a404b725f2f2c67648300f89b">q_qty</a> = - data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#a012238f00ed4e3db77e711848f257f74">q_flowplan</a>-><a class="code" href="a00059.html#a665af7bb916d05a8c9a06f1a8170090f">getQuantity</a>(); <a name="l00200"></a>00200 data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#a658c5379af8ec535090a96dd969f1fc3">q_date</a> = data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#a012238f00ed4e3db77e711848f257f74">q_flowplan</a>-><a class="code" href="a00058.html#a965645e70dd9f99b0bd4f1325fb382aa">getDate</a>(); <a name="l00201"></a>00201 <span class="keywordflow">if</span> (data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#adf7c858a404b725f2f2c67648300f89b">q_qty</a> != 0.0) <a name="l00202"></a>00202 { <a name="l00203"></a>00203 fl-><a class="code" href="a00065.html#a3034ea6d121f86338faeab26ec7464d4">getBuffer</a>()-><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-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#ab56b3877ddc206e8817f04186c0e47a8">a_date</a> > fl-><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't consume any material any more.</span> <a name="l00208"></a>00208 <span class="keywordflow">if</span> (data-><a class="code" href="a00174.html#a1d6f62b1c53725b796ea1c4f8843b85d">getSolver</a>()-><a class="code" href="a00171.html#a7331226cd4ef515184dff2d118c43423">getLogLevel</a>()>1 <a name="l00209"></a>00209 && data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#af34ccc319ed0bd6bb387353e0968e622">a_qty</a> < <a class="code" href="a00252.html#a42d90a6275119e1b4ce73c50f1867e60">ROUNDING_ERROR</a>) <a name="l00210"></a>00210 <a class="code" href="a00257.html#a4af9f241e955122820c5e81ceb33edb5">logger</a> << <a class="code" href="a00087.html">indent</a>(fl-><a class="code" href="a00065.html#a3034ea6d121f86338faeab26ec7464d4">getBuffer</a>()-><a class="code" href="a00084.html#a44c879fcf3b6ae9193c393630e25fd13">getLevel</a>()) << <span class="stringliteral">" Buffer '"</span> <a name="l00211"></a>00211 << fl-><a class="code" href="a00065.html#a3034ea6d121f86338faeab26ec7464d4">getBuffer</a>()-><a class="code" href="a00182.html#a7416ca220c55147bc1276becc5b9de01">getName</a>() << <span class="stringliteral">"' answer date is adjusted to "</span> <a name="l00212"></a>00212 << fl-><a class="code" href="a00118.html#a3056abd641cadca725336059b9e91b1b">getEffective</a>().<a class="code" href="a00050.html#a165a8f748d8468e5ba8331c0e06bd3a2">getEnd</a>() <a name="l00213"></a>00213 << <span class="stringliteral">" because of a date effective flow"</span> << endl; <a name="l00214"></a>00214 data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#ab56b3877ddc206e8817f04186c0e47a8">a_date</a> = fl-><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'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-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#ab56b3877ddc206e8817f04186c0e47a8">a_date</a> = data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#a658c5379af8ec535090a96dd969f1fc3">q_date</a>; <a name="l00222"></a>00222 data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><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 <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>