<!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: solverdemand.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>solverdemand.cpp</h1><a href="a00241.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/solverdemand.cpp $</span> <a name="l00003"></a>00003 <span class="comment"> version : $LastChangedRevision: 1317 $ $LastChangedBy: jdetaeye $</span> <a name="l00004"></a>00004 <span class="comment"> date : $LastChangedDate: 2010-07-20 22:03:36 +0200 (Tue, 20 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="a00241.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 <a name="l00032"></a>00032 <span class="keyword">namespace </span>frepple <a name="l00033"></a>00033 { <a name="l00034"></a>00034 <a name="l00035"></a>00035 <a name="l00036"></a><a class="code" href="a00173.html#a8552e53484b925c03fcb1d65efefc658">00036</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="a00051.html" title="Represents the (independent) demand in the system. It can represent a customer order...">Demand</a>* l, <span class="keywordtype">void</span>* v) <a name="l00037"></a>00037 { <a name="l00038"></a>00038 <span class="comment">// Call the user exit</span> <a name="l00039"></a>00039 <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="l00040"></a>00040 <span class="keywordflow">if</span> (userexit_demand) userexit_demand.<a class="code" href="a00152.html#a7f199c39019f133986783dfc6017b640">call</a>(l, <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="l00041"></a>00041 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> loglevel = data-><a class="code" href="a00174.html#a1d6f62b1c53725b796ea1c4f8843b85d">getSolver</a>()-><a class="code" href="a00171.html#a7331226cd4ef515184dff2d118c43423">getLogLevel</a>(); <a name="l00042"></a>00042 <a name="l00043"></a>00043 <span class="comment">// Note: This solver method does not push/pop states on the stack.</span> <a name="l00044"></a>00044 <span class="comment">// We continue to work on the top element of the stack.</span> <a name="l00045"></a>00045 <a name="l00046"></a>00046 <span class="comment">// Message</span> <a name="l00047"></a>00047 <span class="keywordflow">if</span> (data-><a class="code" href="a00174.html#a1d6f62b1c53725b796ea1c4f8843b85d">getSolver</a>()-><a class="code" href="a00171.html#a7331226cd4ef515184dff2d118c43423">getLogLevel</a>()>0) <a name="l00048"></a>00048 { <a name="l00049"></a>00049 <a class="code" href="a00257.html#a4af9f241e955122820c5e81ceb33edb5">logger</a> << <span class="stringliteral">"Planning demand '"</span> << l-><a class="code" href="a00182.html#a7416ca220c55147bc1276becc5b9de01">getName</a>() << <span class="stringliteral">"' ("</span> << l-><a class="code" href="a00051.html#a312655c39f5d5acc4db3676c9a741a45">getPriority</a>() <a name="l00050"></a>00050 << <span class="stringliteral">", "</span> << l-><a class="code" href="a00051.html#ab21889e9a16e3701a84ba8f3aa68628b">getDue</a>() << <span class="stringliteral">", "</span> << l-><a class="code" href="a00051.html#af5fe6f1b6e8f9b2c24ce3479b6546444">getQuantity</a>() << <span class="stringliteral">")"</span>; <a name="l00051"></a>00051 <span class="keywordflow">if</span> (!data->constrainedPlanning || !data-><a class="code" href="a00174.html#a1d6f62b1c53725b796ea1c4f8843b85d">getSolver</a>()-><a class="code" href="a00173.html#a4bc4f05f9f0d4e153dde779a8fd4154f">isConstrained</a>()) <a name="l00052"></a>00052 <a class="code" href="a00257.html#a4af9f241e955122820c5e81ceb33edb5">logger</a> << <span class="stringliteral">" in unconstrained mode"</span>; <a name="l00053"></a>00053 <a class="code" href="a00257.html#a4af9f241e955122820c5e81ceb33edb5">logger</a> << endl; <a name="l00054"></a>00054 } <a name="l00055"></a>00055 <a name="l00056"></a>00056 <span class="comment">// Unattach previous delivery operationplans.</span> <a name="l00057"></a>00057 <span class="comment">// Locked operationplans will NOT be deleted, and a part of the demand can</span> <a name="l00058"></a>00058 <span class="comment">// still remain planned.</span> <a name="l00059"></a>00059 <span class="keyword">const_cast<</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">></span>(l)->deleteOperationPlans(<span class="keyword">false</span>, data); <a name="l00060"></a>00060 <a name="l00061"></a>00061 <span class="comment">// Determine the quantity to be planned and the date for the planning loop</span> <a name="l00062"></a>00062 <span class="keywordtype">double</span> plan_qty = l-><a class="code" href="a00051.html#af5fe6f1b6e8f9b2c24ce3479b6546444">getQuantity</a>() - l-><a class="code" href="a00051.html#aa20cd6f8d1aef67b9822d2f847911168">getPlannedQuantity</a>(); <a name="l00063"></a>00063 <a class="code" href="a00049.html" title="This class represents a date and time with an accuracy of one second.">Date</a> plan_date = l-><a class="code" href="a00051.html#ab21889e9a16e3701a84ba8f3aa68628b">getDue</a>(); <a name="l00064"></a>00064 <a name="l00065"></a>00065 <span class="comment">// Nothing to be planned any more (e.g. all deliveries are locked...)</span> <a name="l00066"></a>00066 <span class="keywordflow">if</span> (plan_qty < <a class="code" href="a00252.html#a42d90a6275119e1b4ce73c50f1867e60">ROUNDING_ERROR</a>) <a name="l00067"></a>00067 { <a name="l00068"></a>00068 <span class="keywordflow">if</span> (loglevel>0) <a class="code" href="a00257.html#a4af9f241e955122820c5e81ceb33edb5">logger</a> << <span class="stringliteral">" Nothing to be planned."</span> << endl; <a name="l00069"></a>00069 <span class="keywordflow">return</span>; <a name="l00070"></a>00070 } <a name="l00071"></a>00071 <a name="l00072"></a>00072 <span class="comment">// Temporary values to store the 'best-reply' so far</span> <a name="l00073"></a>00073 <span class="keywordtype">double</span> best_q_qty = 0.0, best_a_qty = 0.0; <a name="l00074"></a>00074 <a class="code" href="a00049.html" title="This class represents a date and time with an accuracy of one second.">Date</a> best_q_date; <a name="l00075"></a>00075 <a name="l00076"></a>00076 <span class="comment">// Which operation to use?</span> <a name="l00077"></a>00077 <a class="code" href="a00121.html" title="An operation represents an activity: these consume and produce material, take time...">Operation</a>* deliveryoper = l-><a class="code" href="a00051.html#aa8a606ec515a77824b54bce3053bf182">getDeliveryOperation</a>(); <a name="l00078"></a>00078 <span class="keywordtype">string</span> problemtext = string(<span class="stringliteral">"Demand '"</span>) + l-><a class="code" href="a00182.html#a7416ca220c55147bc1276becc5b9de01">getName</a>() + <span class="stringliteral">"' has no delivery operation"</span>; <a name="l00079"></a>00079 <span class="keywordflow">if</span> (!deliveryoper) <a name="l00080"></a>00080 { <a name="l00081"></a>00081 <span class="comment">// Create a problem</span> <a name="l00082"></a>00082 <span class="keyword">new</span> <a class="code" href="a00142.html" title="A Problem of this class is created in the model when a data exception prevents planning...">ProblemInvalidData</a>(const_cast<Demand*>(l), problemtext, <span class="stringliteral">"demand"</span>, <a name="l00083"></a>00083 l-><a class="code" href="a00051.html#ab21889e9a16e3701a84ba8f3aa68628b">getDue</a>(), l-><a class="code" href="a00051.html#ab21889e9a16e3701a84ba8f3aa68628b">getDue</a>(), l-><a class="code" href="a00051.html#af5fe6f1b6e8f9b2c24ce3479b6546444">getQuantity</a>()); <a name="l00084"></a>00084 <span class="comment">// Abort planning of this demand</span> <a name="l00085"></a>00085 <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">"Demand '"</span> + l-><a class="code" href="a00182.html#a7416ca220c55147bc1276becc5b9de01">getName</a>() + <span class="stringliteral">"' can't be planned"</span>); <a name="l00086"></a>00086 } <a name="l00087"></a>00087 <span class="keywordflow">else</span> <a name="l00088"></a>00088 { <a name="l00089"></a>00089 <span class="comment">// Remove problem that may already exist</span> <a name="l00090"></a>00090 <span class="keywordflow">for</span> (<a class="code" href="a00039.html" title="This class models an STL-like iterator that allows us to iterate over the named entities...">Problem::const_iterator</a> j = <a class="code" href="a00134.html#a1532b2bb7078ebcd527a8bf332ffb861">Problem::begin</a>(const_cast<Demand*>(l), <span class="keyword">false</span>); <a name="l00091"></a>00091 j!=<a class="code" href="a00085.html#abb9d04973550ac71037718511358f2ff">Problem::end</a>(); ++j) <a name="l00092"></a>00092 <span class="keywordflow">if</span> (&(j->getType()) == <a class="code" href="a00142.html#a5d8c463f13053c0527013927e8b737ee">ProblemInvalidData::metadata</a> <a name="l00093"></a>00093 && j->getDescription() == problemtext) <a name="l00094"></a>00094 { <a name="l00095"></a>00095 <span class="keyword">delete</span> &*j; <a name="l00096"></a>00096 <span class="keywordflow">break</span>; <a name="l00097"></a>00097 } <a name="l00098"></a>00098 } <a name="l00099"></a>00099 <a name="l00100"></a>00100 <span class="comment">// Planning loop</span> <a name="l00101"></a>00101 <span class="keywordflow">do</span> <a name="l00102"></a>00102 { <a name="l00103"></a>00103 <span class="comment">// Message</span> <a name="l00104"></a>00104 <span class="keywordflow">if</span> (loglevel>0) <a name="l00105"></a>00105 <a class="code" href="a00257.html#a4af9f241e955122820c5e81ceb33edb5">logger</a> << <span class="stringliteral">"Demand '"</span> << l << <span class="stringliteral">"' asks: "</span> <a name="l00106"></a>00106 << plan_qty << <span class="stringliteral">" "</span> << plan_date << endl; <a name="l00107"></a>00107 <a name="l00108"></a>00108 <span class="comment">// Store the last command in the list, in order to undo the following</span> <a name="l00109"></a>00109 <span class="comment">// commands if required.</span> <a name="l00110"></a>00110 <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="l00111"></a>00111 <a name="l00112"></a>00112 <span class="comment">// Plan the demand by asking the delivery operation to plan</span> <a name="l00113"></a>00113 data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#a2f03f32d577521909343d06b884d7081">curBuffer</a> = NULL; <a name="l00114"></a>00114 data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#adf7c858a404b725f2f2c67648300f89b">q_qty</a> = plan_qty; <a name="l00115"></a>00115 data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#a658c5379af8ec535090a96dd969f1fc3">q_date</a> = plan_date; <a name="l00116"></a>00116 data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#a4feb35f2632149a1fa7828750a2f61b5">curDemand</a> = <span class="keyword">const_cast<</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">></span>(l); <a name="l00117"></a>00117 deliveryoper-><a class="code" href="a00121.html#a15b6686fb03126fea6d5151a79aa5a91">solve</a>(*<span class="keyword">this</span>,v); <a name="l00118"></a>00118 <a name="l00119"></a>00119 <span class="comment">// Message</span> <a name="l00120"></a>00120 <span class="keywordflow">if</span> (loglevel>0) <a name="l00121"></a>00121 <a class="code" href="a00257.html#a4af9f241e955122820c5e81ceb33edb5">logger</a> << <span class="stringliteral">"Demand '"</span> << l << <span class="stringliteral">"' gets answer: "</span> <a name="l00122"></a>00122 << 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> << <span class="stringliteral">" "</span> <a name="l00123"></a>00123 << data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#aa2e444a8091c86f71bbcd6d076c6c574">a_cost</a> << <span class="stringliteral">" "</span> << data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#ae007a7c0a1074c1fc1dfe9c5eeedcc0e">a_penalty</a> << endl; <a name="l00124"></a>00124 <a name="l00125"></a>00125 <span class="comment">// Update the date to plan in the next loop</span> <a name="l00126"></a>00126 <a class="code" href="a00049.html" title="This class represents a date and time with an accuracy of one second.">Date</a> copy_plan_date = plan_date; <a name="l00127"></a>00127 <a name="l00128"></a>00128 <span class="comment">// Compare the planned quantity with the minimum allowed shipment quantity</span> <a name="l00129"></a>00129 <span class="comment">// We don't accept the answer in case:</span> <a name="l00130"></a>00130 <span class="comment">// 1) Nothing is planned</span> <a name="l00131"></a>00131 <span class="comment">// 2) The planned quantity is less than the minimum shipment quantity</span> <a name="l00132"></a>00132 <span class="comment">// 3) The remaining quantity after accepting this answer is less than</span> <a name="l00133"></a>00133 <span class="comment">// the minimum quantity.</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> < <a class="code" href="a00252.html#a42d90a6275119e1b4ce73c50f1867e60">ROUNDING_ERROR</a> <a name="l00135"></a>00135 || data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#af34ccc319ed0bd6bb387353e0968e622">a_qty</a> + ROUNDING_ERROR < l->getMinShipment() <a name="l00136"></a>00136 || (plan_qty - data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#af34ccc319ed0bd6bb387353e0968e622">a_qty</a> < l-><a class="code" href="a00051.html#a26550f7a85971d7a1280dc3691d96782">getMinShipment</a>() <a name="l00137"></a>00137 && plan_qty - 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="l00138"></a>00138 { <a name="l00139"></a>00139 <span class="keywordflow">if</span> (plan_qty - data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#af34ccc319ed0bd6bb387353e0968e622">a_qty</a> < l-><a class="code" href="a00051.html#a26550f7a85971d7a1280dc3691d96782">getMinShipment</a>() <a name="l00140"></a>00140 && 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> >= l-><a class="code" href="a00051.html#a26550f7a85971d7a1280dc3691d96782">getMinShipment</a>() <a name="l00141"></a>00141 && data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#af34ccc319ed0bd6bb387353e0968e622">a_qty</a> > best_a_qty ) <a name="l00142"></a>00142 { <a name="l00143"></a>00143 <span class="comment">// The remaining quantity after accepting this answer is less than</span> <a name="l00144"></a>00144 <span class="comment">// the minimum quantity. Therefore, we delay accepting it now, but</span> <a name="l00145"></a>00145 <span class="comment">// still keep track of this best offer.</span> <a name="l00146"></a>00146 best_a_qty = data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#af34ccc319ed0bd6bb387353e0968e622">a_qty</a>; <a name="l00147"></a>00147 best_q_qty = plan_qty; <a name="l00148"></a>00148 best_q_date = plan_date; <a name="l00149"></a>00149 } <a name="l00150"></a>00150 <a name="l00151"></a>00151 <span class="comment">// Delete operationplans - Undo all changes</span> <a name="l00152"></a>00152 data-><a class="code" href="a00029.html#a6f38f9a190b88a29f63b58a478cbe982">undo</a>(topcommand); <a name="l00153"></a>00153 <a name="l00154"></a>00154 <span class="comment">// Set the ask date for the next pass through the loop</span> <a name="l00155"></a>00155 <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> <= copy_plan_date) <a name="l00156"></a>00156 { <a name="l00157"></a>00157 <span class="comment">// Oops, we didn't get a proper answer we can use for the next loop.</span> <a name="l00158"></a>00158 <span class="comment">// Print a warning and simply try one day later.</span> <a name="l00159"></a>00159 <span class="keywordflow">if</span> (loglevel>0) <a name="l00160"></a>00160 <a class="code" href="a00257.html#a4af9f241e955122820c5e81ceb33edb5">logger</a> << <span class="stringliteral">"Warning: Demand '"</span> << l << <span class="stringliteral">"': Lazy retry"</span> << endl; <a name="l00161"></a>00161 plan_date = copy_plan_date + data->sol-><a class="code" href="a00173.html#a6cbfff22e0badfcd1bf5dd59b37ee4e8">getLazyDelay</a>(); <a name="l00162"></a>00162 } <a name="l00163"></a>00163 <span class="keywordflow">else</span> <a name="l00164"></a>00164 <span class="comment">// Use the next-date answer from the solver</span> <a name="l00165"></a>00165 plan_date = data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#ab56b3877ddc206e8817f04186c0e47a8">a_date</a>; <a name="l00166"></a>00166 } <a name="l00167"></a>00167 <span class="keywordflow">else</span> <a name="l00168"></a>00168 { <a name="l00169"></a>00169 <span class="comment">// Accepting this answer</span> <a name="l00170"></a>00170 <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> < plan_qty) <a name="l00171"></a>00171 { <a name="l00172"></a>00172 <span class="comment">// The demand was only partially planned. We need to do a new</span> <a name="l00173"></a>00173 <span class="comment">// 'coordinated' planning run.</span> <a name="l00174"></a>00174 <a name="l00175"></a>00175 <span class="comment">// Delete operationplans created in the 'testing round'</span> <a name="l00176"></a>00176 data-><a class="code" href="a00029.html#a6f38f9a190b88a29f63b58a478cbe982">undo</a>(topcommand); <a name="l00177"></a>00177 <a name="l00178"></a>00178 <span class="comment">// Create the correct operationplans</span> <a name="l00179"></a>00179 <span class="keywordflow">if</span> (loglevel>=2) <a name="l00180"></a>00180 <a class="code" href="a00257.html#a4af9f241e955122820c5e81ceb33edb5">logger</a> << <span class="stringliteral">"Demand '"</span> << l << <span class="stringliteral">"' plans coordination."</span> << endl; <a name="l00181"></a>00181 data-><a class="code" href="a00174.html#a1d6f62b1c53725b796ea1c4f8843b85d">getSolver</a>()-><a class="code" href="a00171.html#a373dc4d480568344c336cb193ce3edc2">setLogLevel</a>(0); <a name="l00182"></a>00182 <span class="keywordtype">double</span> tmpresult = data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#af34ccc319ed0bd6bb387353e0968e622">a_qty</a>; <a name="l00183"></a>00183 <span class="keywordflow">try</span> <a name="l00184"></a>00184 { <a name="l00185"></a>00185 <span class="keywordflow">for</span>(<span class="keywordtype">double</span> remainder = data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#af34ccc319ed0bd6bb387353e0968e622">a_qty</a>; <a name="l00186"></a>00186 remainder > <a class="code" href="a00252.html#a42d90a6275119e1b4ce73c50f1867e60">ROUNDING_ERROR</a>; remainder -= data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#af34ccc319ed0bd6bb387353e0968e622">a_qty</a>) <a name="l00187"></a>00187 { <a name="l00188"></a>00188 data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#adf7c858a404b725f2f2c67648300f89b">q_qty</a> = remainder; <a name="l00189"></a>00189 data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#a658c5379af8ec535090a96dd969f1fc3">q_date</a> = copy_plan_date; <a name="l00190"></a>00190 data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#a4feb35f2632149a1fa7828750a2f61b5">curDemand</a> = <span class="keyword">const_cast<</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">></span>(l); <a name="l00191"></a>00191 data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#a2f03f32d577521909343d06b884d7081">curBuffer</a> = NULL; <a name="l00192"></a>00192 deliveryoper-><a class="code" href="a00121.html#a15b6686fb03126fea6d5151a79aa5a91">solve</a>(*<span class="keyword">this</span>,v); <a name="l00193"></a>00193 <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="l00194"></a>00194 { <a name="l00195"></a>00195 <a class="code" href="a00257.html#a4af9f241e955122820c5e81ceb33edb5">logger</a> << <span class="stringliteral">"Warning: Demand '"</span> << l << <span class="stringliteral">"': Failing coordination"</span> << endl; <a name="l00196"></a>00196 <span class="keywordflow">break</span>; <a name="l00197"></a>00197 } <a name="l00198"></a>00198 } <a name="l00199"></a>00199 } <a name="l00200"></a>00200 <span class="keywordflow">catch</span> (...) <a name="l00201"></a>00201 { <a name="l00202"></a>00202 data-><a class="code" href="a00174.html#a1d6f62b1c53725b796ea1c4f8843b85d">getSolver</a>()-><a class="code" href="a00171.html#a373dc4d480568344c336cb193ce3edc2">setLogLevel</a>(loglevel); <a name="l00203"></a>00203 <span class="keywordflow">throw</span>; <a name="l00204"></a>00204 } <a name="l00205"></a>00205 data-><a class="code" href="a00174.html#a1d6f62b1c53725b796ea1c4f8843b85d">getSolver</a>()-><a class="code" href="a00171.html#a373dc4d480568344c336cb193ce3edc2">setLogLevel</a>(loglevel); <a name="l00206"></a>00206 data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#af34ccc319ed0bd6bb387353e0968e622">a_qty</a> = tmpresult; <a name="l00207"></a>00207 } <a name="l00208"></a>00208 <a name="l00209"></a>00209 <span class="comment">// Register the new operationplans. We need to make sure that the</span> <a name="l00210"></a>00210 <span class="comment">// correct execute method is called!</span> <a name="l00211"></a>00211 <span class="keywordflow">if</span> (data-><a class="code" href="a00174.html#a1d6f62b1c53725b796ea1c4f8843b85d">getSolver</a>()-><a class="code" href="a00173.html#afe90ff4ad851caa35b2e55b4bcd13ac8">getAutocommit</a>()) <a name="l00212"></a>00212 { <a name="l00213"></a>00213 data-><a class="code" href="a00174.html#a1d6f62b1c53725b796ea1c4f8843b85d">getSolver</a>()-><a class="code" href="a00173.html#a45b15f36c3d23ab1ed15997e072f2153">scanExcess</a>(data-><a class="code" href="a00029.html#afeac711703a14926b23f431a0e633c81">getFirstCommand</a>()); <a name="l00214"></a>00214 data->CommandList::execute(); <a name="l00215"></a>00215 } <a name="l00216"></a>00216 <a name="l00217"></a>00217 <a name="l00218"></a>00218 <span class="comment">// Update the quantity to plan in the next loop</span> <a name="l00219"></a>00219 plan_qty -= data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#af34ccc319ed0bd6bb387353e0968e622">a_qty</a>; <a name="l00220"></a>00220 best_a_qty = 0.0; <span class="comment">// Reset 'best-answer' remember</span> <a name="l00221"></a>00221 } <a name="l00222"></a>00222 <a name="l00223"></a>00223 } <a name="l00224"></a>00224 <span class="comment">// Repeat while there is still a quantity left to plan and we aren't</span> <a name="l00225"></a>00225 <span class="comment">// exceeding the maximum delivery delay.</span> <a name="l00226"></a>00226 <span class="keywordflow">while</span> (plan_qty > <a class="code" href="a00252.html#a42d90a6275119e1b4ce73c50f1867e60">ROUNDING_ERROR</a> <a name="l00227"></a>00227 && ((data-><a class="code" href="a00174.html#a1d6f62b1c53725b796ea1c4f8843b85d">getSolver</a>()-><a class="code" href="a00173.html#aa79ce0df49103c6cc5088b161e79bda3">getPlanType</a>() != 2 && plan_date < l-><a class="code" href="a00051.html#ab21889e9a16e3701a84ba8f3aa68628b">getDue</a>() + l-><a class="code" href="a00051.html#a654d21757dbce28956747a52952d8c08">getMaxLateness</a>()) <a name="l00228"></a>00228 || (data-><a class="code" href="a00174.html#a1d6f62b1c53725b796ea1c4f8843b85d">getSolver</a>()-><a class="code" href="a00173.html#aa79ce0df49103c6cc5088b161e79bda3">getPlanType</a>() == 2 && !data->constrainedPlanning && plan_date < l-><a class="code" href="a00051.html#ab21889e9a16e3701a84ba8f3aa68628b">getDue</a>() + l-><a class="code" href="a00051.html#a654d21757dbce28956747a52952d8c08">getMaxLateness</a>()) <a name="l00229"></a>00229 || (data-><a class="code" href="a00174.html#a1d6f62b1c53725b796ea1c4f8843b85d">getSolver</a>()-><a class="code" href="a00173.html#aa79ce0df49103c6cc5088b161e79bda3">getPlanType</a>() == 2 && data->constrainedPlanning && plan_date == l-><a class="code" href="a00051.html#ab21889e9a16e3701a84ba8f3aa68628b">getDue</a>()) <a name="l00230"></a>00230 )); <a name="l00231"></a>00231 <a name="l00232"></a>00232 <span class="comment">// Accept the best possible answer.</span> <a name="l00233"></a>00233 <span class="comment">// We may have skipped it in the previous loop, awaiting a still better answer</span> <a name="l00234"></a>00234 <span class="keywordflow">if</span> (best_a_qty > 0.0 && data->constrainedPlanning) <a name="l00235"></a>00235 { <a name="l00236"></a>00236 <span class="keywordflow">if</span> (loglevel>=2) <a class="code" href="a00257.html#a4af9f241e955122820c5e81ceb33edb5">logger</a> << <span class="stringliteral">"Demand '"</span> << l << <span class="stringliteral">"' accepts a best answer."</span> << endl; <a name="l00237"></a>00237 data-><a class="code" href="a00174.html#a1d6f62b1c53725b796ea1c4f8843b85d">getSolver</a>()-><a class="code" href="a00171.html#a373dc4d480568344c336cb193ce3edc2">setLogLevel</a>(0); <a name="l00238"></a>00238 <span class="keywordflow">try</span> <a name="l00239"></a>00239 { <a name="l00240"></a>00240 <span class="keywordflow">for</span>(<span class="keywordtype">double</span> remainder = best_q_qty; <a name="l00241"></a>00241 remainder > <a class="code" href="a00252.html#a42d90a6275119e1b4ce73c50f1867e60">ROUNDING_ERROR</a>; remainder -= data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#af34ccc319ed0bd6bb387353e0968e622">a_qty</a>) <a name="l00242"></a>00242 { <a name="l00243"></a>00243 data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#adf7c858a404b725f2f2c67648300f89b">q_qty</a> = remainder; <a name="l00244"></a>00244 data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#a658c5379af8ec535090a96dd969f1fc3">q_date</a> = best_q_date; <a name="l00245"></a>00245 data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#a4feb35f2632149a1fa7828750a2f61b5">curDemand</a> = <span class="keyword">const_cast<</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">></span>(l); <a name="l00246"></a>00246 data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#a2f03f32d577521909343d06b884d7081">curBuffer</a> = NULL; <a name="l00247"></a>00247 deliveryoper-><a class="code" href="a00121.html#a15b6686fb03126fea6d5151a79aa5a91">solve</a>(*<span class="keyword">this</span>,v); <a name="l00248"></a>00248 <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> < ROUNDING_ERROR) <a name="l00249"></a>00249 { <a name="l00250"></a>00250 <a class="code" href="a00257.html#a4af9f241e955122820c5e81ceb33edb5">logger</a> << <span class="stringliteral">"Warning: Demand '"</span> << l << <span class="stringliteral">"': Failing accepting best answer"</span> << endl; <a name="l00251"></a>00251 <span class="keywordflow">break</span>; <a name="l00252"></a>00252 } <a name="l00253"></a>00253 } <a name="l00254"></a>00254 <span class="keywordflow">if</span> (data-><a class="code" href="a00174.html#a1d6f62b1c53725b796ea1c4f8843b85d">getSolver</a>()-><a class="code" href="a00173.html#afe90ff4ad851caa35b2e55b4bcd13ac8">getAutocommit</a>()) <a name="l00255"></a>00255 { <a name="l00256"></a>00256 data-><a class="code" href="a00174.html#a1d6f62b1c53725b796ea1c4f8843b85d">getSolver</a>()-><a class="code" href="a00173.html#a45b15f36c3d23ab1ed15997e072f2153">scanExcess</a>(data-><a class="code" href="a00029.html#afeac711703a14926b23f431a0e633c81">getFirstCommand</a>()); <a name="l00257"></a>00257 data->CommandList::execute(); <a name="l00258"></a>00258 } <a name="l00259"></a>00259 } <a name="l00260"></a>00260 <span class="keywordflow">catch</span> (...) <a name="l00261"></a>00261 { <a name="l00262"></a>00262 data-><a class="code" href="a00174.html#a1d6f62b1c53725b796ea1c4f8843b85d">getSolver</a>()-><a class="code" href="a00171.html#a373dc4d480568344c336cb193ce3edc2">setLogLevel</a>(loglevel); <a name="l00263"></a>00263 <span class="keywordflow">throw</span>; <a name="l00264"></a>00264 } <a name="l00265"></a>00265 data-><a class="code" href="a00174.html#a1d6f62b1c53725b796ea1c4f8843b85d">getSolver</a>()-><a class="code" href="a00171.html#a373dc4d480568344c336cb193ce3edc2">setLogLevel</a>(loglevel); <a name="l00266"></a>00266 } <a name="l00267"></a>00267 } <a name="l00268"></a>00268 <a name="l00269"></a>00269 <a name="l00270"></a><a class="code" href="a00173.html#a45b15f36c3d23ab1ed15997e072f2153">00270</a> <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> <span class="keywordtype">void</span> <a class="code" href="a00173.html#a45b15f36c3d23ab1ed15997e072f2153">SolverMRP::scanExcess</a>(<a class="code" href="a00025.html" title="Abstract base class for all commands.">Command</a>* cmd) <a name="l00271"></a>00271 { <a name="l00272"></a>00272 <span class="comment">// Loop over all newly created operationplans found in the command stack</span> <a name="l00273"></a>00273 <span class="keywordflow">for</span>(; cmd; cmd = cmd-><a class="code" href="a00025.html#a0c492a39639bc1912b6d7a36e1c408e2">getNext</a>()) <a name="l00274"></a>00274 { <a name="l00275"></a>00275 <a class="code" href="a00026.html" title="This command is used to create an operationplan.">CommandCreateOperationPlan</a>* createcmd = <span class="keyword">dynamic_cast<</span><a class="code" href="a00026.html" title="This command is used to create an operationplan.">CommandCreateOperationPlan</a>*<span class="keyword">></span>(cmd); <a name="l00276"></a>00276 <span class="keywordflow">if</span> (!createcmd) <a name="l00277"></a>00277 { <a name="l00278"></a>00278 <span class="comment">// If the command is a list: recursively call this function</span> <a name="l00279"></a>00279 <span class="keywordflow">if</span> (dynamic_cast<CommandList*>(cmd)) <a name="l00280"></a>00280 <a class="code" href="a00173.html#a45b15f36c3d23ab1ed15997e072f2153">scanExcess</a>(dynamic_cast<CommandList*>(cmd)->getFirstCommand()); <a name="l00281"></a>00281 <span class="comment">//else: Not a command creating an operationplan: move on</span> <a name="l00282"></a>00282 } <a name="l00283"></a>00283 <span class="keywordflow">else</span> <a name="l00284"></a>00284 { <a name="l00285"></a>00285 <span class="comment">// Detect excess operationplans and undo them</span> <a name="l00286"></a>00286 <span class="keywordflow">if</span> (createcmd-><a class="code" href="a00026.html#ab1a9489e2182059cebf9d0fc1606d83d">getOperationPlan</a>() && createcmd-><a class="code" href="a00026.html#ab1a9489e2182059cebf9d0fc1606d83d">getOperationPlan</a>()-><a class="code" href="a00125.html#ae129bfa670287a41f69687fc23e6203f">isExcess</a>()) <a name="l00287"></a>00287 { <a name="l00288"></a>00288 <span class="keywordflow">if</span> (<a class="code" href="a00171.html#a7331226cd4ef515184dff2d118c43423">getLogLevel</a>()) <a name="l00289"></a>00289 <a class="code" href="a00257.html#a4af9f241e955122820c5e81ceb33edb5">logger</a> << <span class="stringliteral">"Denying creation of redundant operationplan "</span> <a name="l00290"></a>00290 << createcmd-><a class="code" href="a00026.html#ab1a9489e2182059cebf9d0fc1606d83d">getOperationPlan</a>()-><a class="code" href="a00125.html#a2f5ae1046cd50f98e59520ed8910c458">getOperation</a>() << <span class="stringliteral">" "</span> <a name="l00291"></a>00291 << createcmd-><a class="code" href="a00026.html#ab1a9489e2182059cebf9d0fc1606d83d">getOperationPlan</a>()-><a class="code" href="a00125.html#a9f19aec0a96f30616f2ee06e3c8f371a">getDates</a>() << <span class="stringliteral">" "</span> <a name="l00292"></a>00292 << createcmd-><a class="code" href="a00026.html#ab1a9489e2182059cebf9d0fc1606d83d">getOperationPlan</a>()-><a class="code" href="a00125.html#aa32661a65b2309ba7c35576940274687">getQuantity</a>() << endl; <a name="l00293"></a>00293 createcmd-><a class="code" href="a00026.html#a306ddae494588b4a394ff3b84fa7e236">undo</a>(); <a name="l00294"></a>00294 } <a name="l00295"></a>00295 } <a name="l00296"></a>00296 } <a name="l00297"></a>00297 } <a name="l00298"></a>00298 <a name="l00299"></a>00299 } </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>