<!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: solveroperation.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>solveroperation.cpp</h1><a href="a00244.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/solveroperation.cpp $</span> <a name="l00003"></a>00003 <span class="comment"> version : $LastChangedRevision: 1321 $ $LastChangedBy: jdetaeye $</span> <a name="l00004"></a>00004 <span class="comment"> date : $LastChangedDate: 2010-07-25 09:00:57 +0200 (Sun, 25 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="a00244.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 <span class="keyword">namespace </span>frepple <a name="l00031"></a>00031 { <a name="l00032"></a>00032 <a name="l00033"></a>00033 <a name="l00034"></a>00034 <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> <span class="keywordtype">void</span> <a class="code" href="a00173.html#a030da5fc169a8fe91c80f4d17e854d54">SolverMRP::checkOperationCapacity</a> <a name="l00035"></a><a class="code" href="a00173.html#a030da5fc169a8fe91c80f4d17e854d54">00035</a> (<a class="code" href="a00125.html" title="An operationplan is the key dynamic element of a plan. It represents a certain quantity...">OperationPlan</a>* opplan, <a class="code" href="a00174.html" title="This class is a helper class of the SolverMRP class.">SolverMRP::SolverMRPdata</a>& data) <a name="l00036"></a>00036 { <a name="l00037"></a>00037 <span class="keywordtype">unsigned</span> <span class="keywordtype">short</span> constrainedLoads = 0; <a name="l00038"></a>00038 <span class="keywordflow">for</span> (<a class="code" href="a00106.html" title="An iterator class to go through all loadplans of an operationplan.">OperationPlan::LoadPlanIterator</a> h=opplan-><a class="code" href="a00125.html#af14047934961e9c5f04c0ecc70df649c">beginLoadPlans</a>(); <a name="l00039"></a>00039 h!=opplan-><a class="code" href="a00125.html#af4b4401df92ad9e292edd56d3272b79c">endLoadPlans</a>(); ++h) <a name="l00040"></a>00040 <span class="keywordflow">if</span> (h->getResource()->getType() != *(<a class="code" href="a00158.html#a0664e858a1584b883135fb8e0f095479">ResourceInfinite::metadata</a>) <a name="l00041"></a>00041 && h->isStart() && h->getLoad()->getQuantity() != 0.0) <a name="l00042"></a>00042 { <a name="l00043"></a>00043 <span class="keywordflow">if</span> (++constrainedLoads > 1) <span class="keywordflow">break</span>; <a name="l00044"></a>00044 } <a name="l00045"></a>00045 <a class="code" href="a00050.html" title="This class defines a date-range, i.e. a start-date and end-date pair.">DateRange</a> orig; <a name="l00046"></a>00046 <a name="l00047"></a>00047 <span class="comment">// Loop through all loadplans, and solve for the resource.</span> <a name="l00048"></a>00048 <span class="comment">// This may move an operationplan early or late.</span> <a name="l00049"></a>00049 <a class="code" href="a00134.html" title="A problem represents infeasibilities, alerts and warnings in the plan.">Problem</a>* curConstraint = data.planningDemand-><a class="code" href="a00051.html#acd06be46dd32eb121e408c5b9e035965">getConstraints</a>().<a class="code" href="a00100.html#a0391e63b3596b7820946776182f7bd7f">top</a>(); <a name="l00050"></a>00050 <span class="keywordflow">do</span> <a name="l00051"></a>00051 { <a name="l00052"></a>00052 data.planningDemand-><a class="code" href="a00051.html#acd06be46dd32eb121e408c5b9e035965">getConstraints</a>().<a class="code" href="a00100.html#ad00f9532f9f1aa1f744e7ac6ceccdfac">pop</a>(curConstraint); <a name="l00053"></a>00053 orig = opplan-><a class="code" href="a00125.html#a9f19aec0a96f30616f2ee06e3c8f371a">getDates</a>(); <a name="l00054"></a>00054 <span class="keywordflow">for</span> (<a class="code" href="a00106.html" title="An iterator class to go through all loadplans of an operationplan.">OperationPlan::LoadPlanIterator</a> h=opplan-><a class="code" href="a00125.html#af14047934961e9c5f04c0ecc70df649c">beginLoadPlans</a>(); <a name="l00055"></a>00055 h!=opplan-><a class="code" href="a00125.html#af4b4401df92ad9e292edd56d3272b79c">endLoadPlans</a>() && opplan-><a class="code" href="a00125.html#a9f19aec0a96f30616f2ee06e3c8f371a">getDates</a>()==orig; ++h) <a name="l00056"></a>00056 { <a name="l00057"></a>00057 data.<a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#add71467b24ef4e36294d582d0f1a08f8">q_operationplan</a> = opplan; <a name="l00058"></a>00058 data.<a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#a0184b7e1575ac6c79333fcefa2baee5d">q_loadplan</a> = &*h; <a name="l00059"></a>00059 data.<a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#adf7c858a404b725f2f2c67648300f89b">q_qty</a> = h->getQuantity(); <a name="l00060"></a>00060 data.<a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#a658c5379af8ec535090a96dd969f1fc3">q_date</a> = h->getDate(); <a name="l00061"></a>00061 <span class="comment">// Call the load solver - which will call the resource solver.</span> <a name="l00062"></a>00062 <span class="keywordflow">if</span> (h->getLoad()->getQuantity() != 0.0) <a name="l00063"></a>00063 h->getLoad()->solve(*<span class="keyword">this</span>,&data); <a name="l00064"></a>00064 } <a name="l00065"></a>00065 } <a name="l00066"></a>00066 <span class="comment">// Imagine there are multiple loads. As soon as one of them is moved, we</span> <a name="l00067"></a>00067 <span class="comment">// need to redo the capacity check for the ones we already checked.</span> <a name="l00068"></a>00068 <span class="comment">// Repeat until no load has touched the opplan, or till proven infeasible.</span> <a name="l00069"></a>00069 <span class="comment">// No need to reloop if there is only a single load (= 2 loadplans)</span> <a name="l00070"></a>00070 <span class="keywordflow">while</span> (constrainedLoads>1 && opplan-><a class="code" href="a00125.html#a9f19aec0a96f30616f2ee06e3c8f371a">getDates</a>()!=orig && (data.<a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#af34ccc319ed0bd6bb387353e0968e622">a_qty</a>!=0.0 || data.<a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#a745021223790b651b7d79c41418cb198">forceLate</a>)); <a name="l00071"></a>00071 } <a name="l00072"></a>00072 <a name="l00073"></a>00073 <a name="l00074"></a>00074 <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> <span class="keywordtype">bool</span> <a class="code" href="a00173.html#ab41595b46bdbc8b508b9d7dedad0362f">SolverMRP::checkOperation</a> <a name="l00075"></a><a class="code" href="a00173.html#ab41595b46bdbc8b508b9d7dedad0362f">00075</a> (<a class="code" href="a00125.html" title="An operationplan is the key dynamic element of a plan. It represents a certain quantity...">OperationPlan</a>* opplan, <a class="code" href="a00174.html" title="This class is a helper class of the SolverMRP class.">SolverMRP::SolverMRPdata</a>& data) <a name="l00076"></a>00076 { <a name="l00077"></a>00077 <span class="comment">// The default answer...</span> <a name="l00078"></a>00078 data.<a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#ab56b3877ddc206e8817f04186c0e47a8">a_date</a> = Date::infiniteFuture; <a name="l00079"></a>00079 data.<a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#af34ccc319ed0bd6bb387353e0968e622">a_qty</a> = data.<a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#adf7c858a404b725f2f2c67648300f89b">q_qty</a>; <a name="l00080"></a>00080 <a name="l00081"></a>00081 <span class="comment">// Handle unavailable time.</span> <a name="l00082"></a>00082 <span class="comment">// Note that this unavailable time is checked also in an unconstrained plan.</span> <a name="l00083"></a>00083 <span class="comment">// This means that also an unconstrained plan can plan demand late!</span> <a name="l00084"></a>00084 <span class="keywordflow">if</span> (opplan-><a class="code" href="a00125.html#aa32661a65b2309ba7c35576940274687">getQuantity</a>() == 0.0) <a name="l00085"></a>00085 { <a name="l00086"></a>00086 <span class="comment">// It is possible that the operation could not be created properly.</span> <a name="l00087"></a>00087 <span class="comment">// This happens when the operation is not available for enough time.</span> <a name="l00088"></a>00088 <span class="comment">// Eg. A fixed time operation needs 10 days on jan 20 on an operation</span> <a name="l00089"></a>00089 <span class="comment">// that is only available only 2 days since the start of the horizon.</span> <a name="l00090"></a>00090 <span class="comment">// Resize to the minimum quantity</span> <a name="l00091"></a>00091 opplan-><a class="code" href="a00125.html#aa33a70a23ad111e4b2a35ec96757a1fb">setQuantity</a>(0.0001,<span class="keyword">false</span>); <a name="l00092"></a>00092 <span class="comment">// Move to the earliest start date</span> <a name="l00093"></a>00093 opplan-><a class="code" href="a00125.html#a2265d1554215f7185b8556f53c5805f2">setStart</a>(<a class="code" href="a00132.html#ab297b1f299d472a457784f8022849303">Plan::instance</a>().getCurrent()); <a name="l00094"></a>00094 <span class="comment">// Pick up the earliest date we can reply back</span> <a name="l00095"></a>00095 data.<a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#ab56b3877ddc206e8817f04186c0e47a8">a_date</a> = opplan-><a class="code" href="a00125.html#a9f19aec0a96f30616f2ee06e3c8f371a">getDates</a>().<a class="code" href="a00050.html#a165a8f748d8468e5ba8331c0e06bd3a2">getEnd</a>(); <a name="l00096"></a>00096 data.<a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#af34ccc319ed0bd6bb387353e0968e622">a_qty</a> = 0.0; <a name="l00097"></a>00097 <span class="keywordflow">return</span> <span class="keyword">false</span>; <a name="l00098"></a>00098 } <a name="l00099"></a>00099 <a name="l00100"></a>00100 <span class="comment">// Check the leadtime constraints</span> <a name="l00101"></a>00101 <span class="keywordflow">if</span> (data.constrainedPlanning && !checkOperationLeadtime(opplan,data,<span class="keyword">true</span>)) <a name="l00102"></a>00102 <span class="comment">// This operationplan is a wreck. It is impossible to make it meet the</span> <a name="l00103"></a>00103 <span class="comment">// leadtime constraints</span> <a name="l00104"></a>00104 <span class="keywordflow">return</span> <span class="keyword">false</span>; <a name="l00105"></a>00105 <a name="l00106"></a>00106 <span class="comment">// Store the last command in the list, in order to undo the following</span> <a name="l00107"></a>00107 <span class="comment">// commands if required.</span> <a name="l00108"></a>00108 <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="l00109"></a>00109 <a name="l00110"></a>00110 <span class="comment">// Temporary variables</span> <a name="l00111"></a>00111 <a class="code" href="a00050.html" title="This class defines a date-range, i.e. a start-date and end-date pair.">DateRange</a> orig_dates = opplan-><a class="code" href="a00125.html#a9f19aec0a96f30616f2ee06e3c8f371a">getDates</a>(); <a name="l00112"></a>00112 <span class="keywordtype">bool</span> okay = <span class="keyword">true</span>; <a name="l00113"></a>00113 <a class="code" href="a00049.html" title="This class represents a date and time with an accuracy of one second.">Date</a> a_date; <a name="l00114"></a>00114 <span class="keywordtype">double</span> a_qty; <a name="l00115"></a>00115 <a class="code" href="a00049.html" title="This class represents a date and time with an accuracy of one second.">Date</a> orig_q_date = data.<a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#a658c5379af8ec535090a96dd969f1fc3">q_date</a>; <a name="l00116"></a>00116 <span class="keywordtype">double</span> orig_opplan_qty = data.<a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#adf7c858a404b725f2f2c67648300f89b">q_qty</a>; <a name="l00117"></a>00117 <span class="keywordtype">double</span> q_qty_Flow; <a name="l00118"></a>00118 <a class="code" href="a00049.html" title="This class represents a date and time with an accuracy of one second.">Date</a> q_date_Flow; <a name="l00119"></a>00119 <span class="keywordtype">bool</span> incomplete; <a name="l00120"></a>00120 <span class="keywordtype">bool</span> tmp_forceLate = data.<a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#a745021223790b651b7d79c41418cb198">forceLate</a>; <a name="l00121"></a>00121 <span class="keywordtype">bool</span> isPlannedEarly; <a name="l00122"></a>00122 <a class="code" href="a00050.html" title="This class defines a date-range, i.e. a start-date and end-date pair.">DateRange</a> matnext; <a name="l00123"></a>00123 <a name="l00124"></a>00124 <span class="comment">// Loop till everything is okay. During this loop the quanity and date of the</span> <a name="l00125"></a>00125 <span class="comment">// operationplan can be updated, but it cannot be split or deleted.</span> <a name="l00126"></a>00126 data.<a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#a745021223790b651b7d79c41418cb198">forceLate</a> = <span class="keyword">false</span>; <a name="l00127"></a>00127 <span class="keywordflow">do</span> <a name="l00128"></a>00128 { <a name="l00129"></a>00129 <span class="keywordflow">if</span> (isCapacityConstrained()) <a name="l00130"></a>00130 { <a name="l00131"></a>00131 <span class="comment">// Verify the capacity. This can move the operationplan early or late.</span> <a name="l00132"></a>00132 checkOperationCapacity(opplan,data); <a name="l00133"></a>00133 <span class="comment">// Return false if no capacity is available</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>==0.0) <span class="keywordflow">return</span> <span class="keyword">false</span>; <a name="l00135"></a>00135 } <a name="l00136"></a>00136 <a name="l00137"></a>00137 <span class="comment">// Check material</span> <a name="l00138"></a>00138 data.<a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#adf7c858a404b725f2f2c67648300f89b">q_qty</a> = opplan-><a class="code" href="a00125.html#aa32661a65b2309ba7c35576940274687">getQuantity</a>(); <a name="l00139"></a>00139 data.<a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#a658c5379af8ec535090a96dd969f1fc3">q_date</a> = opplan-><a class="code" href="a00125.html#a9f19aec0a96f30616f2ee06e3c8f371a">getDates</a>().<a class="code" href="a00050.html#a165a8f748d8468e5ba8331c0e06bd3a2">getEnd</a>(); <a name="l00140"></a>00140 a_qty = opplan-><a class="code" href="a00125.html#aa32661a65b2309ba7c35576940274687">getQuantity</a>(); <a name="l00141"></a>00141 a_date = data.<a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#a658c5379af8ec535090a96dd969f1fc3">q_date</a>; <a name="l00142"></a>00142 incomplete = <span class="keyword">false</span>; <a name="l00143"></a>00143 matnext.<a class="code" href="a00050.html#a301068faa83a2a88fdb46ffb26f56502">setStart</a>(Date::infinitePast); <a name="l00144"></a>00144 matnext.<a class="code" href="a00050.html#a953ee79781eee836ae07bd389aca5515">setEnd</a>(Date::infiniteFuture); <a name="l00145"></a>00145 <a name="l00146"></a>00146 <span class="comment">// Loop through all flowplans // xxx @todo need some kind of coordination run here!!! see test alternate_flow_1</span> <a name="l00147"></a>00147 <span class="keywordflow">for</span> (<a class="code" href="a00069.html" title="An iterator class to go through all flowplans of an operationplan.">OperationPlan::FlowPlanIterator</a> g=opplan-><a class="code" href="a00125.html#a4fb68598ded2db1ae3a9f5f975dd09c6">beginFlowPlans</a>(); <a name="l00148"></a>00148 g!=opplan-><a class="code" href="a00125.html#a1b421f000d0a136fa3f9dc3abd5b76cc">endFlowPlans</a>(); ++g) <a name="l00149"></a>00149 <span class="keywordflow">if</span> (g->getFlow()->isConsumer()) <a name="l00150"></a>00150 { <a name="l00151"></a>00151 <span class="comment">// Switch back to the main alternate if this flowplan was already // @todo is this really required? If yes, in this place?</span> <a name="l00152"></a>00152 <span class="comment">// planned on an alternate</span> <a name="l00153"></a>00153 <span class="keywordflow">if</span> (g->getFlow()->getAlternate()) <a name="l00154"></a>00154 g->setFlow(g->getFlow()->getAlternate()); <a name="l00155"></a>00155 <a name="l00156"></a>00156 <span class="comment">// Trigger the flow solver, which will call the buffer solver</span> <a name="l00157"></a>00157 data.<a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#a012238f00ed4e3db77e711848f257f74">q_flowplan</a> = &*g; <a name="l00158"></a>00158 q_qty_Flow = - 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>(); <span class="comment">// @todo flow quantity can change when using alternate flows -> move to flow solver!</span> <a name="l00159"></a>00159 q_date_Flow = 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="l00160"></a>00160 g->getFlow()->solve(*<span class="keyword">this</span>,&data); <a name="l00161"></a>00161 <a name="l00162"></a>00162 <span class="comment">// Validate the answered quantity</span> <a name="l00163"></a>00163 <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> < q_qty_Flow) <a name="l00164"></a>00164 { <a name="l00165"></a>00165 <span class="comment">// Update the opplan, which is required to (1) update the flowplans</span> <a name="l00166"></a>00166 <span class="comment">// and to (2) take care of lot sizing constraints of this operation.</span> <a name="l00167"></a>00167 g->setQuantity(-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="l00168"></a>00168 a_qty = opplan-><a class="code" href="a00125.html#aa32661a65b2309ba7c35576940274687">getQuantity</a>(); <a name="l00169"></a>00169 incomplete = <span class="keyword">true</span>; <a name="l00170"></a>00170 <a name="l00171"></a>00171 <span class="comment">// Validate the answered date of the most limiting flowplan.</span> <a name="l00172"></a>00172 <span class="comment">// Note that the delay variable only reflects the delay due to</span> <a name="l00173"></a>00173 <span class="comment">// material constraints. If the operationplan is moved early or late</span> <a name="l00174"></a>00174 <span class="comment">// for capacity constraints, this is not included.</span> <a name="l00175"></a>00175 <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> < Date::infiniteFuture) <a name="l00176"></a>00176 { <a name="l00177"></a>00177 <a class="code" href="a00127.html" title="A simple class to easily remember the date and quantity of an operationplan.">OperationPlanState</a> at = opplan-><a class="code" href="a00125.html#a2f5ae1046cd50f98e59520ed8910c458">getOperation</a>()-><a class="code" href="a00121.html#a744480cdd80e70a2b0a7606114e1ab73">setOperationPlanParameters</a>( <a name="l00178"></a>00178 opplan, 0.01, data.<a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#ab56b3877ddc206e8817f04186c0e47a8">a_date</a>, Date::infinitePast, <span class="keyword">false</span>, <span class="keyword">false</span> <a name="l00179"></a>00179 ); <a name="l00180"></a>00180 <span class="keywordflow">if</span> (at.<a class="code" href="a00127.html#ab641b640c894007052c4207d353a1f5b">end</a> < matnext.<a class="code" href="a00050.html#a165a8f748d8468e5ba8331c0e06bd3a2">getEnd</a>()) matnext = <a class="code" href="a00050.html" title="This class defines a date-range, i.e. a start-date and end-date pair.">DateRange</a>(at.<a class="code" href="a00127.html#adc56f9e1f5ddccca5f50c50229e18c27">start</a>, at.<a class="code" href="a00127.html#ab641b640c894007052c4207d353a1f5b">end</a>); <a name="l00181"></a>00181 <span class="comment">//xxxif (matnext.getEnd() <= orig_q_date) logger << "STRANGE" << matnext << " " << orig_q_date << " " << at.second << " " << opplan->getQuantity() << endl;</span> <a name="l00182"></a>00182 } <a name="l00183"></a>00183 <a name="l00184"></a>00184 <span class="comment">// Jump out of the loop if the answered quantity is 0.</span> <a name="l00185"></a>00185 <span class="keywordflow">if</span> (a_qty <= <a class="code" href="a00252.html#a42d90a6275119e1b4ce73c50f1867e60">ROUNDING_ERROR</a>) <a name="l00186"></a>00186 { <a name="l00187"></a>00187 <span class="comment">// @TODO disabled To speed up the planning the constraining flow is moved up a</span> <a name="l00188"></a>00188 <span class="comment">// position in the list of flows. It'll thus be checked earlier</span> <a name="l00189"></a>00189 <span class="comment">// when this operation is asked again</span> <a name="l00190"></a>00190 <span class="comment">//const_cast<Operation::flowlist&>(g->getFlow()->getOperation()->getFlows()).promote(g->getFlow());</span> <a name="l00191"></a>00191 <span class="comment">// There is absolutely no need to check other flowplans if the</span> <a name="l00192"></a>00192 <span class="comment">// operationplan quantity is already at 0.</span> <a name="l00193"></a>00193 <span class="keywordflow">break</span>; <a name="l00194"></a>00194 } <a name="l00195"></a>00195 } <a name="l00196"></a>00196 <span class="keywordflow">else</span> <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> >+ q_qty_Flow + <a class="code" href="a00252.html#a42d90a6275119e1b4ce73c50f1867e60">ROUNDING_ERROR</a>) <a name="l00197"></a>00197 <span class="comment">// Never answer more than asked.</span> <a name="l00198"></a>00198 <span class="comment">// The actual operationplan could be bigger because of lot sizing.</span> <a name="l00199"></a>00199 a_qty = - q_qty_Flow / g->getFlow()->getQuantity(); <a name="l00200"></a>00200 } <a name="l00201"></a>00201 <a name="l00202"></a>00202 isPlannedEarly = opplan-><a class="code" href="a00125.html#a9f19aec0a96f30616f2ee06e3c8f371a">getDates</a>().<a class="code" href="a00050.html#a165a8f748d8468e5ba8331c0e06bd3a2">getEnd</a>() < orig_dates.<a class="code" href="a00050.html#a165a8f748d8468e5ba8331c0e06bd3a2">getEnd</a>(); <a name="l00203"></a>00203 <a name="l00204"></a>00204 <span class="keywordflow">if</span> (matnext.<a class="code" href="a00050.html#a165a8f748d8468e5ba8331c0e06bd3a2">getEnd</a>() != Date::infiniteFuture && a_qty <= <a class="code" href="a00252.html#a42d90a6275119e1b4ce73c50f1867e60">ROUNDING_ERROR</a> <a name="l00205"></a>00205 && matnext.<a class="code" href="a00050.html#a165a8f748d8468e5ba8331c0e06bd3a2">getEnd</a>() <= data.<a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#a2627254734463aaa8f0f177bf153e39f">q_date_max</a> && matnext.<a class="code" href="a00050.html#a165a8f748d8468e5ba8331c0e06bd3a2">getEnd</a>() > orig_q_date) <a name="l00206"></a>00206 { <a name="l00207"></a>00207 <span class="comment">// The reply is 0, but the next-date is still less than the maximum</span> <a name="l00208"></a>00208 <span class="comment">// ask date. In this case we will violate the post-operation -soft-</span> <a name="l00209"></a>00209 <span class="comment">// constraint.</span> <a name="l00210"></a>00210 data.<a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#a658c5379af8ec535090a96dd969f1fc3">q_date</a> = matnext.<a class="code" href="a00050.html#a165a8f748d8468e5ba8331c0e06bd3a2">getEnd</a>(); <a name="l00211"></a>00211 orig_q_date = data.<a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#a658c5379af8ec535090a96dd969f1fc3">q_date</a>; <a name="l00212"></a>00212 data.<a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#adf7c858a404b725f2f2c67648300f89b">q_qty</a> = orig_opplan_qty; <a name="l00213"></a>00213 data.<a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#ab56b3877ddc206e8817f04186c0e47a8">a_date</a> = Date::infiniteFuture; <a name="l00214"></a>00214 data.<a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#af34ccc319ed0bd6bb387353e0968e622">a_qty</a> = data.<a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#adf7c858a404b725f2f2c67648300f89b">q_qty</a>; <a name="l00215"></a>00215 opplan-><a class="code" href="a00125.html#a2f5ae1046cd50f98e59520ed8910c458">getOperation</a>()-><a class="code" href="a00121.html#a744480cdd80e70a2b0a7606114e1ab73">setOperationPlanParameters</a>( <a name="l00216"></a>00216 opplan, orig_opplan_qty, Date::infinitePast, matnext.<a class="code" href="a00050.html#a165a8f748d8468e5ba8331c0e06bd3a2">getEnd</a>() <a name="l00217"></a>00217 ); <a name="l00218"></a>00218 okay = <span class="keyword">false</span>; <a name="l00219"></a>00219 <span class="comment">// Pop actions from the command "stack" in the command list</span> <a name="l00220"></a>00220 data.<a class="code" href="a00029.html#a6f38f9a190b88a29f63b58a478cbe982">undo</a>(topcommand); <a name="l00221"></a>00221 <span class="comment">// Echo a message</span> <a name="l00222"></a>00222 <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="l00223"></a>00223 <a class="code" href="a00257.html#a4af9f241e955122820c5e81ceb33edb5">logger</a> << <a class="code" href="a00087.html">indent</a>(opplan-><a class="code" href="a00125.html#a2f5ae1046cd50f98e59520ed8910c458">getOperation</a>()-><a class="code" href="a00084.html#a44c879fcf3b6ae9193c393630e25fd13">getLevel</a>()) <a name="l00224"></a>00224 << <span class="stringliteral">" Retrying new date."</span> << endl; <a name="l00225"></a>00225 } <a name="l00226"></a>00226 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (matnext.<a class="code" href="a00050.html#a165a8f748d8468e5ba8331c0e06bd3a2">getEnd</a>() != Date::infiniteFuture && a_qty <= <a class="code" href="a00252.html#a42d90a6275119e1b4ce73c50f1867e60">ROUNDING_ERROR</a> <a name="l00227"></a>00227 && matnext.<a class="code" href="a00050.html#a73e574de7fbf5df8ebc4c5190e7d49c3">getStart</a>() < a_date) <a name="l00228"></a>00228 { <a name="l00229"></a>00229 <span class="comment">// The reply is 0, but the next-date is not too far out.</span> <a name="l00230"></a>00230 <span class="comment">// If the operationplan would fit in a smaller timeframe we can potentially</span> <a name="l00231"></a>00231 <span class="comment">// create a non-zero reply...</span> <a name="l00232"></a>00232 <span class="comment">// Resize the operationplan</span> <a name="l00233"></a>00233 opplan-><a class="code" href="a00125.html#a2f5ae1046cd50f98e59520ed8910c458">getOperation</a>()-><a class="code" href="a00121.html#a744480cdd80e70a2b0a7606114e1ab73">setOperationPlanParameters</a>( <a name="l00234"></a>00234 opplan, orig_opplan_qty, matnext.<a class="code" href="a00050.html#a73e574de7fbf5df8ebc4c5190e7d49c3">getStart</a>(), <a name="l00235"></a>00235 a_date <a name="l00236"></a>00236 ); <a name="l00237"></a>00237 <span class="keywordflow">if</span> (opplan-><a class="code" href="a00125.html#a9f19aec0a96f30616f2ee06e3c8f371a">getDates</a>().<a class="code" href="a00050.html#a73e574de7fbf5df8ebc4c5190e7d49c3">getStart</a>() >= matnext.<a class="code" href="a00050.html#a73e574de7fbf5df8ebc4c5190e7d49c3">getStart</a>() <a name="l00238"></a>00238 && opplan-><a class="code" href="a00125.html#a9f19aec0a96f30616f2ee06e3c8f371a">getDates</a>().<a class="code" href="a00050.html#a165a8f748d8468e5ba8331c0e06bd3a2">getEnd</a>() <= a_date <a name="l00239"></a>00239 && opplan-><a class="code" href="a00125.html#aa32661a65b2309ba7c35576940274687">getQuantity</a>() > <a class="code" href="a00252.html#a42d90a6275119e1b4ce73c50f1867e60">ROUNDING_ERROR</a>) <a name="l00240"></a>00240 { <a name="l00241"></a>00241 <span class="comment">// It worked</span> <a name="l00242"></a>00242 orig_dates = opplan-><a class="code" href="a00125.html#a9f19aec0a96f30616f2ee06e3c8f371a">getDates</a>(); <a name="l00243"></a>00243 data.<a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#a658c5379af8ec535090a96dd969f1fc3">q_date</a> = orig_dates.<a class="code" href="a00050.html#a165a8f748d8468e5ba8331c0e06bd3a2">getEnd</a>(); <a name="l00244"></a>00244 data.<a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#adf7c858a404b725f2f2c67648300f89b">q_qty</a> = opplan-><a class="code" href="a00125.html#aa32661a65b2309ba7c35576940274687">getQuantity</a>(); <a name="l00245"></a>00245 data.<a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#ab56b3877ddc206e8817f04186c0e47a8">a_date</a> = Date::infiniteFuture; <a name="l00246"></a>00246 data.<a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#af34ccc319ed0bd6bb387353e0968e622">a_qty</a> = data.<a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#adf7c858a404b725f2f2c67648300f89b">q_qty</a>; <a name="l00247"></a>00247 okay = <span class="keyword">false</span>; <a name="l00248"></a>00248 <span class="comment">// Pop actions from the command stack in the command list</span> <a name="l00249"></a>00249 data.<a class="code" href="a00029.html#a6f38f9a190b88a29f63b58a478cbe982">undo</a>(topcommand); <a name="l00250"></a>00250 <span class="comment">// Echo a message</span> <a name="l00251"></a>00251 <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="l00252"></a>00252 <a class="code" href="a00257.html#a4af9f241e955122820c5e81ceb33edb5">logger</a> << <a class="code" href="a00087.html">indent</a>(opplan-><a class="code" href="a00125.html#a2f5ae1046cd50f98e59520ed8910c458">getOperation</a>()-><a class="code" href="a00084.html#a44c879fcf3b6ae9193c393630e25fd13">getLevel</a>()) <a name="l00253"></a>00253 << <span class="stringliteral">" Retrying with a smaller quantity: "</span> <a name="l00254"></a>00254 << opplan-><a class="code" href="a00125.html#aa32661a65b2309ba7c35576940274687">getQuantity</a>() << endl; <a name="l00255"></a>00255 } <a name="l00256"></a>00256 <span class="keywordflow">else</span> <a name="l00257"></a>00257 { <a name="l00258"></a>00258 <span class="comment">// It didn't work</span> <a name="l00259"></a>00259 opplan-><a class="code" href="a00125.html#aa33a70a23ad111e4b2a35ec96757a1fb">setQuantity</a>(0); <a name="l00260"></a>00260 okay = <span class="keyword">true</span>; <a name="l00261"></a>00261 } <a name="l00262"></a>00262 } <a name="l00263"></a>00263 <span class="keywordflow">else</span> <a name="l00264"></a>00264 okay = <span class="keyword">true</span>; <a name="l00265"></a>00265 } <a name="l00266"></a>00266 <span class="keywordflow">while</span> (!okay); <span class="comment">// Repeat the loop if the operation was moved and the</span> <a name="l00267"></a>00267 <span class="comment">// feasibility needs to be rechecked.</span> <a name="l00268"></a>00268 <a name="l00269"></a>00269 <span class="keywordflow">if</span> (a_qty <= ROUNDING_ERROR && !data.state->forceLate <a name="l00270"></a>00270 && isPlannedEarly <a name="l00271"></a>00271 && matnext.<a class="code" href="a00050.html#a73e574de7fbf5df8ebc4c5190e7d49c3">getStart</a>() != Date::infiniteFuture <a name="l00272"></a>00272 && matnext.<a class="code" href="a00050.html#a73e574de7fbf5df8ebc4c5190e7d49c3">getStart</a>() != Date::infinitePast <a name="l00273"></a>00273 && (data.constrainedPlanning && isCapacityConstrained())) <a name="l00274"></a>00274 { <a name="l00275"></a>00275 <span class="comment">// The operationplan was moved early (because of a resource constraint)</span> <a name="l00276"></a>00276 <span class="comment">// and we can't properly trust the reply date in such cases...</span> <a name="l00277"></a>00277 <span class="comment">// We want to enforce rechecking the next date.</span> <a name="l00278"></a>00278 <a name="l00279"></a>00279 <span class="comment">// Move the operationplan to the next date where the material is feasible</span> <a name="l00280"></a>00280 opplan-><a class="code" href="a00125.html#a2f5ae1046cd50f98e59520ed8910c458">getOperation</a>()-><a class="code" href="a00121.html#a744480cdd80e70a2b0a7606114e1ab73">setOperationPlanParameters</a> <a name="l00281"></a>00281 (opplan, orig_opplan_qty, matnext.<a class="code" href="a00050.html#a73e574de7fbf5df8ebc4c5190e7d49c3">getStart</a>(), Date::infinitePast); <a name="l00282"></a>00282 <a name="l00283"></a>00283 <span class="comment">// Move the operationplan to a later date where it is feasible.</span> <a name="l00284"></a>00284 data.<a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#a745021223790b651b7d79c41418cb198">forceLate</a> = <span class="keyword">true</span>; <a name="l00285"></a>00285 checkOperationCapacity(opplan,data); <a name="l00286"></a>00286 <a name="l00287"></a>00287 <span class="comment">// Reply of this function</span> <a name="l00288"></a>00288 a_qty = 0.0; <a name="l00289"></a>00289 matnext.<a class="code" href="a00050.html#a953ee79781eee836ae07bd389aca5515">setEnd</a>(opplan-><a class="code" href="a00125.html#a9f19aec0a96f30616f2ee06e3c8f371a">getDates</a>().<a class="code" href="a00050.html#a165a8f748d8468e5ba8331c0e06bd3a2">getEnd</a>()); <a name="l00290"></a>00290 } <a name="l00291"></a>00291 <a name="l00292"></a>00292 <span class="comment">// Compute the final reply</span> <a name="l00293"></a>00293 data.<a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#ab56b3877ddc206e8817f04186c0e47a8">a_date</a> = incomplete ? matnext.<a class="code" href="a00050.html#a165a8f748d8468e5ba8331c0e06bd3a2">getEnd</a>() : Date::infiniteFuture; <a name="l00294"></a>00294 data.<a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#af34ccc319ed0bd6bb387353e0968e622">a_qty</a> = a_qty; <a name="l00295"></a>00295 data.<a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#a745021223790b651b7d79c41418cb198">forceLate</a> = tmp_forceLate; <a name="l00296"></a>00296 <span class="keywordflow">if</span> (a_qty > <a class="code" href="a00252.html#a42d90a6275119e1b4ce73c50f1867e60">ROUNDING_ERROR</a>) <a name="l00297"></a>00297 <span class="keywordflow">return</span> <span class="keyword">true</span>; <a name="l00298"></a>00298 <span class="keywordflow">else</span> <a name="l00299"></a>00299 { <a name="l00300"></a>00300 <span class="comment">// Undo the plan</span> <a name="l00301"></a>00301 data.<a class="code" href="a00029.html#a6f38f9a190b88a29f63b58a478cbe982">undo</a>(topcommand); <a name="l00302"></a>00302 <span class="keywordflow">return</span> <span class="keyword">false</span>; <a name="l00303"></a>00303 } <a name="l00304"></a>00304 } <a name="l00305"></a>00305 <a name="l00306"></a>00306 <a name="l00307"></a>00307 <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> <span class="keywordtype">bool</span> <a class="code" href="a00173.html#a1be57e20c66257efcc51c61669bdec1c">SolverMRP::checkOperationLeadtime</a> <a name="l00308"></a><a class="code" href="a00173.html#a1be57e20c66257efcc51c61669bdec1c">00308</a> (<a class="code" href="a00125.html" title="An operationplan is the key dynamic element of a plan. It represents a certain quantity...">OperationPlan</a>* opplan, <a class="code" href="a00174.html" title="This class is a helper class of the SolverMRP class.">SolverMRP::SolverMRPdata</a>& data, <span class="keywordtype">bool</span> extra) <a name="l00309"></a>00309 { <a name="l00310"></a>00310 <span class="comment">// No lead time constraints</span> <a name="l00311"></a>00311 <span class="keywordflow">if</span> (!data.constrainedPlanning || (!isFenceConstrained() && !isLeadtimeConstrained())) <a name="l00312"></a>00312 <span class="keywordflow">return</span> <span class="keyword">true</span>; <a name="l00313"></a>00313 <a name="l00314"></a>00314 <span class="comment">// Compute offset from the current date: A fence problem uses the release</span> <a name="l00315"></a>00315 <span class="comment">// fence window, while a leadtimeconstrained constraint has an offset of 0.</span> <a name="l00316"></a>00316 <span class="comment">// If both constraints apply, we need the bigger of the two (since it is the</span> <a name="l00317"></a>00317 <span class="comment">// most constraining date.</span> <a name="l00318"></a>00318 <a class="code" href="a00049.html" title="This class represents a date and time with an accuracy of one second.">Date</a> threshold = <a class="code" href="a00132.html#ab297b1f299d472a457784f8022849303">Plan::instance</a>().<a class="code" href="a00132.html#a6a07002deb9c4f380a54a3e3465e487b">getCurrent</a>(); <a name="l00319"></a>00319 <span class="keywordflow">if</span> (isFenceConstrained() <a name="l00320"></a>00320 && !(isLeadtimeConstrained() && opplan-><a class="code" href="a00125.html#a2f5ae1046cd50f98e59520ed8910c458">getOperation</a>()-><a class="code" href="a00121.html#a0ad8ad3a837a2d93c2811cf568bf2cf0">getFence</a>()<0L)) <a name="l00321"></a>00321 threshold += opplan-><a class="code" href="a00125.html#a2f5ae1046cd50f98e59520ed8910c458">getOperation</a>()-><a class="code" href="a00121.html#a0ad8ad3a837a2d93c2811cf568bf2cf0">getFence</a>(); <a name="l00322"></a>00322 <a name="l00323"></a>00323 <span class="comment">// Check the setup operationplan</span> <a name="l00324"></a>00324 <a class="code" href="a00127.html" title="A simple class to easily remember the date and quantity of an operationplan.">OperationPlanState</a> original(opplan); <a name="l00325"></a>00325 <span class="keywordtype">bool</span> ok = <span class="keyword">true</span>; <a name="l00326"></a>00326 <span class="keywordtype">bool</span> checkSetup = <span class="keyword">true</span>; <a name="l00327"></a>00327 <a name="l00328"></a>00328 <span class="comment">// If there are alternate loads we take the best case and assume that</span> <a name="l00329"></a>00329 <span class="comment">// at least one of those can give us a zero-time setup.</span> <a name="l00330"></a>00330 <span class="comment">// When evaluating the leadtime when solving for capacity we don't use</span> <a name="l00331"></a>00331 <span class="comment">// this assumption. The resource solver takes care of the constraints.</span> <a name="l00332"></a>00332 <span class="keywordflow">if</span> (extra && isCapacityConstrained()) <a name="l00333"></a>00333 <span class="keywordflow">for</span> (Operation::loadlist::const_iterator j = opplan-><a class="code" href="a00125.html#a2f5ae1046cd50f98e59520ed8910c458">getOperation</a>()-><a class="code" href="a00121.html#a7b95131f687f60ec30165e14876dac7c">getLoads</a>().begin(); <a name="l00334"></a>00334 j != opplan-><a class="code" href="a00125.html#a2f5ae1046cd50f98e59520ed8910c458">getOperation</a>()-><a class="code" href="a00121.html#a7b95131f687f60ec30165e14876dac7c">getLoads</a>().end(); ++j) <a name="l00335"></a>00335 <span class="keywordflow">if</span> (j->hasAlternates()) <a name="l00336"></a>00336 { <a name="l00337"></a>00337 checkSetup = <span class="keyword">false</span>; <a name="l00338"></a>00338 <span class="keywordflow">break</span>; <a name="l00339"></a>00339 } <a name="l00340"></a>00340 <span class="keywordflow">if</span> (checkSetup) <a name="l00341"></a>00341 { <a name="l00342"></a>00342 <a class="code" href="a00093.html" title="This class models an STL-like iterator that allows us to iterate over the operationplans...">OperationPlan::iterator</a> i(opplan); <a name="l00343"></a>00343 <span class="keywordflow">if</span> (i != opplan-><a class="code" href="a00125.html#a0f9f6ba7d4fe7e20e9b88c765fe24f25">end</a>() <a name="l00344"></a>00344 && i->getOperation() == <a class="code" href="a00129.html#add35ebccc253401c86cc40dc2fed3f04">OperationSetup::setupoperation</a> <a name="l00345"></a>00345 && i->getDates().getStart() < threshold) <a name="l00346"></a>00346 { <a name="l00347"></a>00347 <span class="comment">// The setup operationplan is violating the lead time and/or fence </span> <a name="l00348"></a>00348 <span class="comment">// constraint. We move it to start on the earliest allowed date,</span> <a name="l00349"></a>00349 <span class="comment">// which automatically also moves the owner operationplan.</span> <a name="l00350"></a>00350 i->setStart(threshold); <a name="l00351"></a>00351 threshold = i->getDates().getEnd(); <a name="l00352"></a>00352 ok = <span class="keyword">false</span>; <a name="l00353"></a>00353 } <a name="l00354"></a>00354 } <a name="l00355"></a>00355 <a name="l00356"></a>00356 <span class="comment">// Compare the operation plan start with the threshold date</span> <a name="l00357"></a>00357 <span class="keywordflow">if</span> (ok && opplan-><a class="code" href="a00125.html#a9f19aec0a96f30616f2ee06e3c8f371a">getDates</a>().<a class="code" href="a00050.html#a73e574de7fbf5df8ebc4c5190e7d49c3">getStart</a>() >= threshold) <a name="l00358"></a>00358 <span class="comment">// There is no problem</span> <a name="l00359"></a>00359 <span class="keywordflow">return</span> <span class="keyword">true</span>; <a name="l00360"></a>00360 <a name="l00361"></a>00361 <span class="comment">// Compute how much we can supply in the current timeframe.</span> <a name="l00362"></a>00362 <span class="comment">// In other words, we try to resize the operation quantity to fit the</span> <a name="l00363"></a>00363 <span class="comment">// available timeframe: used for e.g. time-per operations</span> <a name="l00364"></a>00364 <span class="comment">// Note that we allow the complete post-operation time to be eaten</span> <a name="l00365"></a>00365 <span class="keywordflow">if</span> (extra) <a name="l00366"></a>00366 <span class="comment">// Leadtime check during operation resolver</span> <a name="l00367"></a>00367 opplan-><a class="code" href="a00125.html#a2f5ae1046cd50f98e59520ed8910c458">getOperation</a>()-><a class="code" href="a00121.html#a744480cdd80e70a2b0a7606114e1ab73">setOperationPlanParameters</a>( <a name="l00368"></a>00368 opplan, opplan-><a class="code" href="a00125.html#aa32661a65b2309ba7c35576940274687">getQuantity</a>(), <a name="l00369"></a>00369 threshold, <a name="l00370"></a>00370 original.<a class="code" href="a00127.html#ab641b640c894007052c4207d353a1f5b">end</a> + opplan-><a class="code" href="a00125.html#a2f5ae1046cd50f98e59520ed8910c458">getOperation</a>()-><a class="code" href="a00121.html#a1154c9b0b9d3f732f27f6dcd538174bb">getPostTime</a>(), <a name="l00371"></a>00371 false <a name="l00372"></a>00372 ); <a name="l00373"></a>00373 <span class="keywordflow">else</span> <a name="l00374"></a>00374 <span class="comment">// Leadtime check during capacity resolver</span> <a name="l00375"></a>00375 opplan-><a class="code" href="a00125.html#a2f5ae1046cd50f98e59520ed8910c458">getOperation</a>()-><a class="code" href="a00121.html#a744480cdd80e70a2b0a7606114e1ab73">setOperationPlanParameters</a>( <a name="l00376"></a>00376 opplan, opplan-><a class="code" href="a00125.html#aa32661a65b2309ba7c35576940274687">getQuantity</a>(), <a name="l00377"></a>00377 threshold, <a name="l00378"></a>00378 original.<a class="code" href="a00127.html#ab641b640c894007052c4207d353a1f5b">end</a>, <a name="l00379"></a>00379 true <a name="l00380"></a>00380 ); <a name="l00381"></a>00381 <a name="l00382"></a>00382 <span class="comment">// Check the result of the resize</span> <a name="l00383"></a>00383 <span class="keywordflow">if</span> (opplan-><a class="code" href="a00125.html#a9f19aec0a96f30616f2ee06e3c8f371a">getDates</a>().<a class="code" href="a00050.html#a73e574de7fbf5df8ebc4c5190e7d49c3">getStart</a>() >= threshold <a name="l00384"></a>00384 && (!extra || opplan-><a class="code" href="a00125.html#a9f19aec0a96f30616f2ee06e3c8f371a">getDates</a>().<a class="code" href="a00050.html#a165a8f748d8468e5ba8331c0e06bd3a2">getEnd</a>() <= data.<a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#a2627254734463aaa8f0f177bf153e39f">q_date_max</a>) <a name="l00385"></a>00385 && opplan-><a class="code" href="a00125.html#aa32661a65b2309ba7c35576940274687">getQuantity</a>() > <a class="code" href="a00252.html#a42d90a6275119e1b4ce73c50f1867e60">ROUNDING_ERROR</a>) <a name="l00386"></a>00386 { <a name="l00387"></a>00387 <span class="comment">// Resizing did work! The operation now fits within constrained limits</span> <a name="l00388"></a>00388 data.<a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#af34ccc319ed0bd6bb387353e0968e622">a_qty</a> = opplan-><a class="code" href="a00125.html#aa32661a65b2309ba7c35576940274687">getQuantity</a>(); <a name="l00389"></a>00389 data.<a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#ab56b3877ddc206e8817f04186c0e47a8">a_date</a> = opplan-><a class="code" href="a00125.html#a9f19aec0a96f30616f2ee06e3c8f371a">getDates</a>().<a class="code" href="a00050.html#a165a8f748d8468e5ba8331c0e06bd3a2">getEnd</a>(); <a name="l00390"></a>00390 <span class="comment">// Acknowledge creation of operationplan</span> <a name="l00391"></a>00391 <span class="keywordflow">return</span> <span class="keyword">true</span>; <a name="l00392"></a>00392 } <a name="l00393"></a>00393 <span class="keywordflow">else</span> <a name="l00394"></a>00394 { <a name="l00395"></a>00395 <span class="comment">// This operation doesn't fit at all within the constrained window.</span> <a name="l00396"></a>00396 data.<a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#af34ccc319ed0bd6bb387353e0968e622">a_qty</a> = 0.0; <a name="l00397"></a>00397 <span class="comment">// Resize to the minimum quantity</span> <a name="l00398"></a>00398 <span class="keywordflow">if</span> (opplan-><a class="code" href="a00125.html#aa32661a65b2309ba7c35576940274687">getQuantity</a>() + <a class="code" href="a00252.html#a42d90a6275119e1b4ce73c50f1867e60">ROUNDING_ERROR</a> < opplan-><a class="code" href="a00125.html#a2f5ae1046cd50f98e59520ed8910c458">getOperation</a>()-><a class="code" href="a00121.html#ae1ef1417d3f6b89561e6c0909f772782">getSizeMinimum</a>()) <a name="l00399"></a>00399 opplan-><a class="code" href="a00125.html#aa33a70a23ad111e4b2a35ec96757a1fb">setQuantity</a>(0.0001,<span class="keyword">false</span>); <a name="l00400"></a>00400 <span class="comment">// Move to the earliest start date</span> <a name="l00401"></a>00401 opplan-><a class="code" href="a00125.html#a2265d1554215f7185b8556f53c5805f2">setStart</a>(threshold); <a name="l00402"></a>00402 <span class="comment">// Pick up the earliest date we can reply back</span> <a name="l00403"></a>00403 data.<a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#ab56b3877ddc206e8817f04186c0e47a8">a_date</a> = opplan-><a class="code" href="a00125.html#a9f19aec0a96f30616f2ee06e3c8f371a">getDates</a>().<a class="code" href="a00050.html#a165a8f748d8468e5ba8331c0e06bd3a2">getEnd</a>(); <a name="l00404"></a>00404 <span class="comment">// Set the quantity to 0 (to make sure the buffer doesn't see the supply).</span> <a name="l00405"></a>00405 opplan-><a class="code" href="a00125.html#aa33a70a23ad111e4b2a35ec96757a1fb">setQuantity</a>(0.0); <a name="l00406"></a>00406 <a name="l00407"></a>00407 <span class="comment">// Log the constraint</span> <a name="l00408"></a>00408 <span class="keywordflow">if</span> (data.logConstraints) <a name="l00409"></a>00409 data.planningDemand-><a class="code" href="a00051.html#acd06be46dd32eb121e408c5b9e035965">getConstraints</a>().<a class="code" href="a00100.html#add9d396135451bf2efef6527cea7839a">push</a>( <a name="l00410"></a>00410 (threshold == <a class="code" href="a00132.html#ab297b1f299d472a457784f8022849303">Plan::instance</a>().getCurrent()) ? <a name="l00411"></a>00411 <a class="code" href="a00135.html#aa55a9bf686195db07c0fa8723c2479f2">ProblemBeforeCurrent::metadata</a> : <a name="l00412"></a>00412 <a class="code" href="a00136.html#abd86b7cbefa986340a2b6d80c9aeab17">ProblemBeforeFence::metadata</a>, <a name="l00413"></a>00413 opplan-><a class="code" href="a00125.html#a2f5ae1046cd50f98e59520ed8910c458">getOperation</a>(), original.<a class="code" href="a00127.html#adc56f9e1f5ddccca5f50c50229e18c27">start</a>, original.<a class="code" href="a00127.html#ab641b640c894007052c4207d353a1f5b">end</a>, <a name="l00414"></a>00414 original.<a class="code" href="a00127.html#aae1454106ec8147edd0eb7f6e5f647d7">quantity</a> <a name="l00415"></a>00415 ); <a name="l00416"></a>00416 <a name="l00417"></a>00417 <span class="comment">// Deny creation of the operationplan</span> <a name="l00418"></a>00418 <span class="keywordflow">return</span> <span class="keyword">false</span>; <a name="l00419"></a>00419 } <a name="l00420"></a>00420 } <a name="l00421"></a>00421 <a name="l00422"></a>00422 <a name="l00423"></a><a class="code" href="a00173.html#aed1d08dd6ece530ed9229d463e31cca3">00423</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="a00121.html" title="An operation represents an activity: these consume and produce material, take time...">Operation</a>* oper, <span class="keywordtype">void</span>* v) <a name="l00424"></a>00424 { <a name="l00425"></a>00425 <span class="comment">// Make sure we have a valid operation</span> <a name="l00426"></a>00426 assert(oper); <a name="l00427"></a>00427 <a name="l00428"></a>00428 <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="l00429"></a>00429 <a class="code" href="a00125.html" title="An operationplan is the key dynamic element of a plan. It represents a certain quantity...">OperationPlan</a> *z; <a name="l00430"></a>00430 <a name="l00431"></a>00431 <span class="comment">// Call the user exit</span> <a name="l00432"></a>00432 <span class="keywordflow">if</span> (userexit_operation) userexit_operation.<a class="code" href="a00152.html#a7f199c39019f133986783dfc6017b640">call</a>(oper, <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="l00433"></a>00433 <a name="l00434"></a>00434 <span class="comment">// Find the flow for the quantity-per. This can throw an exception if no</span> <a name="l00435"></a>00435 <span class="comment">// valid flow can be found.</span> <a name="l00436"></a>00436 <span class="keywordtype">double</span> flow_qty_per = 1.0; <a name="l00437"></a>00437 <span class="keywordflow">if</span> (data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#a2f03f32d577521909343d06b884d7081">curBuffer</a>) <a name="l00438"></a>00438 { <a name="l00439"></a>00439 <a class="code" href="a00065.html" title="This class defines a material flow to/from a buffer, linked with an operation. This...">Flow</a>* f = oper-><a class="code" href="a00121.html#aa636fe4ef5ba4352126e6f22f485cd2e">findFlow</a>(data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#a2f03f32d577521909343d06b884d7081">curBuffer</a>, data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#a658c5379af8ec535090a96dd969f1fc3">q_date</a>); <a name="l00440"></a>00440 <span class="keywordflow">if</span> (f && f-><a class="code" href="a00065.html#a29332e8619e350ec887efbdead1c1b11">getQuantity</a>()>0.0) <a name="l00441"></a>00441 flow_qty_per = f-><a class="code" href="a00065.html#a29332e8619e350ec887efbdead1c1b11">getQuantity</a>(); <a name="l00442"></a>00442 <span class="keywordflow">else</span> <a name="l00443"></a>00443 <span class="comment">// The producing operation doesn't have a valid flow into the current</span> <a name="l00444"></a>00444 <span class="comment">// buffer. Either it is missing or it is producing a negative quantity.</span> <a name="l00445"></a>00445 <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">"Invalid producing operation '"</span> + oper-><a class="code" href="a00182.html#a7416ca220c55147bc1276becc5b9de01">getName</a>() <a name="l00446"></a>00446 + <span class="stringliteral">"' for buffer '"</span> + data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#a2f03f32d577521909343d06b884d7081">curBuffer</a>-><a class="code" href="a00182.html#a7416ca220c55147bc1276becc5b9de01">getName</a>() + <span class="stringliteral">"'"</span>); <a name="l00447"></a>00447 } <a name="l00448"></a>00448 <a name="l00449"></a>00449 <span class="comment">// Message</span> <a name="l00450"></a>00450 <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="l00451"></a>00451 <a class="code" href="a00257.html#a4af9f241e955122820c5e81ceb33edb5">logger</a> << <a class="code" href="a00087.html">indent</a>(oper-><a class="code" href="a00084.html#a44c879fcf3b6ae9193c393630e25fd13">getLevel</a>()) << <span class="stringliteral">" Operation '"</span> << oper-><a class="code" href="a00182.html#a7416ca220c55147bc1276becc5b9de01">getName</a>() <a name="l00452"></a>00452 << <span class="stringliteral">"' is asked: "</span> << data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#adf7c858a404b725f2f2c67648300f89b">q_qty</a> << <span class="stringliteral">" "</span> << data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#a658c5379af8ec535090a96dd969f1fc3">q_date</a> << endl; <a name="l00453"></a>00453 <a name="l00454"></a>00454 <span class="comment">// Find the current list of constraints</span> <a name="l00455"></a>00455 <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="l00456"></a>00456 <span class="keywordtype">double</span> originalqty = data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#adf7c858a404b725f2f2c67648300f89b">q_qty</a>; <a name="l00457"></a>00457 <a name="l00458"></a>00458 <span class="comment">// Subtract the post-operation time</span> <a name="l00459"></a>00459 <a class="code" href="a00049.html" title="This class represents a date and time with an accuracy of one second.">Date</a> prev_q_date_max = data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#a2627254734463aaa8f0f177bf153e39f">q_date_max</a>; <a name="l00460"></a>00460 data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#a2627254734463aaa8f0f177bf153e39f">q_date_max</a> = data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#a658c5379af8ec535090a96dd969f1fc3">q_date</a>; <a name="l00461"></a>00461 data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#a658c5379af8ec535090a96dd969f1fc3">q_date</a> -= oper-><a class="code" href="a00121.html#a1154c9b0b9d3f732f27f6dcd538174bb">getPostTime</a>(); <a name="l00462"></a>00462 <a name="l00463"></a>00463 <span class="comment">// Create the operation plan.</span> <a name="l00464"></a>00464 <span class="keywordflow">if</span> (data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#abfd84159a05362d21fe7321c4caef08f">curOwnerOpplan</a>) <a name="l00465"></a>00465 { <a name="l00466"></a>00466 <span class="comment">// There is already an owner and thus also an owner command</span> <a name="l00467"></a>00467 assert(!data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#a4feb35f2632149a1fa7828750a2f61b5">curDemand</a>); <a name="l00468"></a>00468 z = oper-><a class="code" href="a00121.html#ad183a2e72b75cdd83f9e71f6bc235424">createOperationPlan</a>( <a name="l00469"></a>00469 data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#adf7c858a404b725f2f2c67648300f89b">q_qty</a> / flow_qty_per, <a name="l00470"></a>00470 Date::infinitePast, 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#a4feb35f2632149a1fa7828750a2f61b5">curDemand</a>, <a name="l00471"></a>00471 data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#abfd84159a05362d21fe7321c4caef08f">curOwnerOpplan</a>, 0 <a name="l00472"></a>00472 ); <a name="l00473"></a>00473 } <a name="l00474"></a>00474 <span class="keywordflow">else</span> <a name="l00475"></a>00475 { <a name="l00476"></a>00476 <span class="comment">// There is no owner operationplan yet. We need a new command.</span> <a name="l00477"></a>00477 <a class="code" href="a00026.html" title="This command is used to create an operationplan.">CommandCreateOperationPlan</a> *a = <a name="l00478"></a>00478 <span class="keyword">new</span> <a class="code" href="a00026.html" title="This command is used to create an operationplan.">CommandCreateOperationPlan</a>( <a name="l00479"></a>00479 oper, data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#adf7c858a404b725f2f2c67648300f89b">q_qty</a> / flow_qty_per, <a name="l00480"></a>00480 Date::infinitePast, 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#a4feb35f2632149a1fa7828750a2f61b5">curDemand</a>, <a name="l00481"></a>00481 data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#abfd84159a05362d21fe7321c4caef08f">curOwnerOpplan</a> <a name="l00482"></a>00482 ); <a name="l00483"></a>00483 data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#a4feb35f2632149a1fa7828750a2f61b5">curDemand</a> = NULL; <a name="l00484"></a>00484 z = a-><a class="code" href="a00026.html#ab1a9489e2182059cebf9d0fc1606d83d">getOperationPlan</a>(); <a name="l00485"></a>00485 data-><a class="code" href="a00029.html#a0b761c0e2f51f84569de4f242e2cb7b4">add</a>(a); <a name="l00486"></a>00486 } <a name="l00487"></a>00487 assert(z); <a name="l00488"></a>00488 <a name="l00489"></a>00489 <span class="comment">// Check the constraints</span> <a name="l00490"></a>00490 data-><a class="code" href="a00174.html#a1d6f62b1c53725b796ea1c4f8843b85d">getSolver</a>()-><a class="code" href="a00173.html#ab41595b46bdbc8b508b9d7dedad0362f">checkOperation</a>(z,*data); <a name="l00491"></a>00491 data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#a2627254734463aaa8f0f177bf153e39f">q_date_max</a> = prev_q_date_max; <a name="l00492"></a>00492 <a name="l00493"></a>00493 <span class="comment">// Multiply the operation reqply with the flow quantity to get a final reply</span> <a name="l00494"></a>00494 <span class="keywordflow">if</span> (data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#a2f03f32d577521909343d06b884d7081">curBuffer</a>) data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#af34ccc319ed0bd6bb387353e0968e622">a_qty</a> *= flow_qty_per; <a name="l00495"></a>00495 <a name="l00496"></a>00496 <span class="comment">// Ignore any constraints if we get a complete reply.</span> <a name="l00497"></a>00497 <span class="comment">// Sometimes constraints are flagged due to a pre- or post-operation time.</span> <a name="l00498"></a>00498 <span class="comment">// Such constraints ultimately don't result in lateness and can be ignored.</span> <a name="l00499"></a>00499 <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> >= originalqty - <a class="code" href="a00252.html#a42d90a6275119e1b4ce73c50f1867e60">ROUNDING_ERROR</a>) <a name="l00500"></a>00500 data->planningDemand-><a class="code" href="a00051.html#acd06be46dd32eb121e408c5b9e035965">getConstraints</a>().<a class="code" href="a00100.html#ad00f9532f9f1aa1f744e7ac6ceccdfac">pop</a>(topConstraint); <a name="l00501"></a>00501 <a name="l00502"></a>00502 <span class="comment">// Check positive reply quantity</span> <a name="l00503"></a>00503 assert(data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#af34ccc319ed0bd6bb387353e0968e622">a_qty</a> >= 0); <a name="l00504"></a>00504 <a name="l00505"></a>00505 <span class="comment">// Increment the cost</span> <a name="l00506"></a>00506 <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> > 0.0) <a name="l00507"></a>00507 data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#aa2e444a8091c86f71bbcd6d076c6c574">a_cost</a> += z-><a class="code" href="a00125.html#aa32661a65b2309ba7c35576940274687">getQuantity</a>() * oper-><a class="code" href="a00121.html#ab69b08d57703a9d7809530270a6b86bf">getCost</a>(); <a name="l00508"></a>00508 <a name="l00509"></a>00509 <span class="comment">// Message</span> <a name="l00510"></a>00510 <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="l00511"></a>00511 <a class="code" href="a00257.html#a4af9f241e955122820c5e81ceb33edb5">logger</a> << <a class="code" href="a00087.html">indent</a>(oper-><a class="code" href="a00084.html#a44c879fcf3b6ae9193c393630e25fd13">getLevel</a>()) << <span class="stringliteral">" Operation '"</span> << oper-><a class="code" href="a00182.html#a7416ca220c55147bc1276becc5b9de01">getName</a>() <a name="l00512"></a>00512 << <span class="stringliteral">"' answers: "</span> << 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> <a name="l00513"></a>00513 << <span class="stringliteral">" "</span> << 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="l00514"></a>00514 } <a name="l00515"></a>00515 <a name="l00516"></a>00516 <a name="l00517"></a>00517 <span class="comment">// No need to take post- and pre-operation times into account</span> <a name="l00518"></a><a class="code" href="a00173.html#af2c3898fc34e77c303b54f2bf1d41ac6">00518</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="a00128.html" title="Represents a routing operation, i.e. an operation consisting of multiple, sequential...">OperationRouting</a>* oper, <span class="keywordtype">void</span>* v) <a name="l00519"></a>00519 { <a name="l00520"></a>00520 <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="l00521"></a>00521 <a name="l00522"></a>00522 <span class="comment">// Call the user exit</span> <a name="l00523"></a>00523 <span class="keywordflow">if</span> (userexit_operation) userexit_operation.<a class="code" href="a00152.html#a7f199c39019f133986783dfc6017b640">call</a>(oper, <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="l00524"></a>00524 <a name="l00525"></a>00525 <span class="comment">// Message</span> <a name="l00526"></a>00526 <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="l00527"></a>00527 <a class="code" href="a00257.html#a4af9f241e955122820c5e81ceb33edb5">logger</a> << <a class="code" href="a00087.html">indent</a>(oper-><a class="code" href="a00084.html#a44c879fcf3b6ae9193c393630e25fd13">getLevel</a>()) << <span class="stringliteral">" Routing operation '"</span> << oper-><a class="code" href="a00182.html#a7416ca220c55147bc1276becc5b9de01">getName</a>() <a name="l00528"></a>00528 << <span class="stringliteral">"' is asked: "</span> << data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#adf7c858a404b725f2f2c67648300f89b">q_qty</a> << <span class="stringliteral">" "</span> << data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#a658c5379af8ec535090a96dd969f1fc3">q_date</a> << endl; <a name="l00529"></a>00529 <a name="l00530"></a>00530 <span class="comment">// Find the total quantity to flow into the buffer.</span> <a name="l00531"></a>00531 <span class="comment">// Multiple suboperations can all produce into the buffer.</span> <a name="l00532"></a>00532 <span class="keywordtype">double</span> flow_qty = 1.0; <a name="l00533"></a>00533 <span class="keywordflow">if</span> (data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#a2f03f32d577521909343d06b884d7081">curBuffer</a>) <a name="l00534"></a>00534 { <a name="l00535"></a>00535 flow_qty = 0.0; <a name="l00536"></a>00536 <a class="code" href="a00065.html" title="This class defines a material flow to/from a buffer, linked with an operation. This...">Flow</a> *f = oper-><a class="code" href="a00121.html#aa636fe4ef5ba4352126e6f22f485cd2e">findFlow</a>(data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#a2f03f32d577521909343d06b884d7081">curBuffer</a>, data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#a658c5379af8ec535090a96dd969f1fc3">q_date</a>); <a name="l00537"></a>00537 <span class="keywordflow">if</span> (f) flow_qty += f-><a class="code" href="a00065.html#a29332e8619e350ec887efbdead1c1b11">getQuantity</a>(); <a name="l00538"></a>00538 <span class="keywordflow">for</span> (Operation::Operationlist::const_iterator <a name="l00539"></a>00539 e = oper-><a class="code" href="a00128.html#a2630402ce9db63798fd471795b65c155">getSubOperations</a>().begin(); <a name="l00540"></a>00540 e != oper-><a class="code" href="a00128.html#a2630402ce9db63798fd471795b65c155">getSubOperations</a>().end(); <a name="l00541"></a>00541 ++e) <a name="l00542"></a>00542 { <a name="l00543"></a>00543 f = (*e)->findFlow(data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#a2f03f32d577521909343d06b884d7081">curBuffer</a>, data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#a658c5379af8ec535090a96dd969f1fc3">q_date</a>); <a name="l00544"></a>00544 <span class="keywordflow">if</span> (f) flow_qty += f-><a class="code" href="a00065.html#a29332e8619e350ec887efbdead1c1b11">getQuantity</a>(); <a name="l00545"></a>00545 } <a name="l00546"></a>00546 <span class="keywordflow">if</span> (flow_qty <= 0.0) <a name="l00547"></a>00547 <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">"Invalid producing operation '"</span> + oper-><a class="code" href="a00182.html#a7416ca220c55147bc1276becc5b9de01">getName</a>() <a name="l00548"></a>00548 + <span class="stringliteral">"' for buffer '"</span> + data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#a2f03f32d577521909343d06b884d7081">curBuffer</a>-><a class="code" href="a00182.html#a7416ca220c55147bc1276becc5b9de01">getName</a>() + <span class="stringliteral">"'"</span>); <a name="l00549"></a>00549 } <a name="l00550"></a>00550 <span class="comment">// Because we already took care of it... @todo not correct if the suboperation is again a owning operation</span> <a name="l00551"></a>00551 data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#a2f03f32d577521909343d06b884d7081">curBuffer</a> = NULL; <a name="l00552"></a>00552 <span class="keywordtype">double</span> a_qty(data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#adf7c858a404b725f2f2c67648300f89b">q_qty</a> / flow_qty); <a name="l00553"></a>00553 <a name="l00554"></a>00554 <span class="comment">// Create the top operationplan</span> <a name="l00555"></a>00555 <a class="code" href="a00026.html" title="This command is used to create an operationplan.">CommandCreateOperationPlan</a> *a = <span class="keyword">new</span> <a class="code" href="a00026.html" title="This command is used to create an operationplan.">CommandCreateOperationPlan</a>( <a name="l00556"></a>00556 oper, a_qty, Date::infinitePast, <a name="l00557"></a>00557 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#a4feb35f2632149a1fa7828750a2f61b5">curDemand</a>, data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#abfd84159a05362d21fe7321c4caef08f">curOwnerOpplan</a>, <span class="keyword">false</span> <a name="l00558"></a>00558 ); <a name="l00559"></a>00559 data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#a4feb35f2632149a1fa7828750a2f61b5">curDemand</a> = NULL; <a name="l00560"></a>00560 <a name="l00561"></a>00561 <span class="comment">// Make sure the subopplans know their owner & store the previous value</span> <a name="l00562"></a>00562 <a class="code" href="a00125.html" title="An operationplan is the key dynamic element of a plan. It represents a certain quantity...">OperationPlan</a> *prev_owner_opplan = data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#abfd84159a05362d21fe7321c4caef08f">curOwnerOpplan</a>; <a name="l00563"></a>00563 data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#abfd84159a05362d21fe7321c4caef08f">curOwnerOpplan</a> = a-><a class="code" href="a00026.html#ab1a9489e2182059cebf9d0fc1606d83d">getOperationPlan</a>(); <a name="l00564"></a>00564 <a name="l00565"></a>00565 <span class="comment">// Loop through the steps</span> <a name="l00566"></a>00566 <a class="code" href="a00049.html" title="This class represents a date and time with an accuracy of one second.">Date</a> max_Date; <a name="l00567"></a>00567 <span class="keywordflow">for</span> (Operation::Operationlist::const_reverse_iterator <a name="l00568"></a>00568 e = oper-><a class="code" href="a00128.html#a2630402ce9db63798fd471795b65c155">getSubOperations</a>().rbegin(); <a name="l00569"></a>00569 e != oper-><a class="code" href="a00128.html#a2630402ce9db63798fd471795b65c155">getSubOperations</a>().rend() && a_qty > 0.0; <a name="l00570"></a>00570 ++e) <a name="l00571"></a>00571 { <a name="l00572"></a>00572 <span class="comment">// Plan the next step</span> <a name="l00573"></a>00573 data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#adf7c858a404b725f2f2c67648300f89b">q_qty</a> = a_qty; <a name="l00574"></a>00574 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#abfd84159a05362d21fe7321c4caef08f">curOwnerOpplan</a>-><a class="code" href="a00125.html#a9f19aec0a96f30616f2ee06e3c8f371a">getDates</a>().<a class="code" href="a00050.html#a73e574de7fbf5df8ebc4c5190e7d49c3">getStart</a>(); <a name="l00575"></a>00575 (*e)->solve(*<span class="keyword">this</span>,v); <span class="comment">// @todo if the step itself has child operations, the curOwnerOpplan field is changed here!!!</span> <a name="l00576"></a>00576 a_qty = data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#af34ccc319ed0bd6bb387353e0968e622">a_qty</a>; <a name="l00577"></a>00577 <a name="l00578"></a>00578 <span class="comment">// Update the top operationplan</span> <a name="l00579"></a>00579 data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#abfd84159a05362d21fe7321c4caef08f">curOwnerOpplan</a>-><a class="code" href="a00125.html#aa33a70a23ad111e4b2a35ec96757a1fb">setQuantity</a>(a_qty,<span class="keyword">true</span>); <a name="l00580"></a>00580 <a name="l00581"></a>00581 <span class="comment">// Maximum for the next date</span> <a name="l00582"></a>00582 <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> != Date::infiniteFuture) <a name="l00583"></a>00583 { <a name="l00584"></a>00584 <a class="code" href="a00127.html" title="A simple class to easily remember the date and quantity of an operationplan.">OperationPlanState</a> at = data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#abfd84159a05362d21fe7321c4caef08f">curOwnerOpplan</a>-><a class="code" href="a00125.html#a2f5ae1046cd50f98e59520ed8910c458">getOperation</a>()-><a class="code" href="a00121.html#a744480cdd80e70a2b0a7606114e1ab73">setOperationPlanParameters</a>( <a name="l00585"></a>00585 data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#abfd84159a05362d21fe7321c4caef08f">curOwnerOpplan</a>, 0.01, <span class="comment">//data->state->curOwnerOpplan->getQuantity(),</span> <a name="l00586"></a>00586 data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#ab56b3877ddc206e8817f04186c0e47a8">a_date</a>, Date::infinitePast, <span class="keyword">false</span>, <span class="keyword">false</span> <a name="l00587"></a>00587 ); <a name="l00588"></a>00588 <span class="keywordflow">if</span> (at.<a class="code" href="a00127.html#ab641b640c894007052c4207d353a1f5b">end</a> > max_Date) max_Date = at.<a class="code" href="a00127.html#ab641b640c894007052c4207d353a1f5b">end</a>; <a name="l00589"></a>00589 } <a name="l00590"></a>00590 } <a name="l00591"></a>00591 <a name="l00592"></a>00592 <span class="comment">// Check the flows and loads on the top operationplan.</span> <a name="l00593"></a>00593 <span class="comment">// This can happen only after the suboperations have been dealt with</span> <a name="l00594"></a>00594 <span class="comment">// because only now we know how long the operation lasts in total.</span> <a name="l00595"></a>00595 <span class="comment">// Solving for the top operationplan can resize and move the steps that are</span> <a name="l00596"></a>00596 <span class="comment">// in the routing!</span><span class="comment"></span> <a name="l00597"></a>00597 <span class="comment"> /** @todo moving routing opplan doesn't recheck for feasibility of steps... */</span> <a name="l00598"></a>00598 data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#abfd84159a05362d21fe7321c4caef08f">curOwnerOpplan</a>-><a class="code" href="a00125.html#a1c0ab58f6d41e2fd26e50f09158042ee">createFlowLoads</a>(); <a name="l00599"></a>00599 <span class="keywordflow">if</span> (data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#abfd84159a05362d21fe7321c4caef08f">curOwnerOpplan</a>-><a class="code" href="a00125.html#aa32661a65b2309ba7c35576940274687">getQuantity</a>() > 0.0) <a name="l00600"></a>00600 { <a name="l00601"></a>00601 data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#adf7c858a404b725f2f2c67648300f89b">q_qty</a> = a_qty; <a name="l00602"></a>00602 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#abfd84159a05362d21fe7321c4caef08f">curOwnerOpplan</a>-><a class="code" href="a00125.html#a9f19aec0a96f30616f2ee06e3c8f371a">getDates</a>().<a class="code" href="a00050.html#a165a8f748d8468e5ba8331c0e06bd3a2">getEnd</a>(); <a name="l00603"></a>00603 data-><a class="code" href="a00174.html#a1d6f62b1c53725b796ea1c4f8843b85d">getSolver</a>()-><a class="code" href="a00173.html#ab41595b46bdbc8b508b9d7dedad0362f">checkOperation</a>(data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#abfd84159a05362d21fe7321c4caef08f">curOwnerOpplan</a>,*data); <a name="l00604"></a>00604 a_qty = data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#af34ccc319ed0bd6bb387353e0968e622">a_qty</a>; <a name="l00605"></a>00605 <span class="comment">// The reply date is the combination of the reply date of all steps and the</span> <a name="l00606"></a>00606 <span class="comment">// reply date of the top operationplan.</span> <a name="l00607"></a>00607 <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> > max_Date && data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#ab56b3877ddc206e8817f04186c0e47a8">a_date</a> != Date::infiniteFuture) <a name="l00608"></a>00608 max_Date = data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#ab56b3877ddc206e8817f04186c0e47a8">a_date</a>; <a name="l00609"></a>00609 } <a name="l00610"></a>00610 data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#ab56b3877ddc206e8817f04186c0e47a8">a_date</a> = (max_Date ? max_Date : Date::infiniteFuture); <a name="l00611"></a>00611 <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> < data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#a658c5379af8ec535090a96dd969f1fc3">q_date</a>) <a name="l00612"></a>00612 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="l00613"></a>00613 <a name="l00614"></a>00614 <span class="comment">// Multiply the operationplan quantity with the flow quantity to get the</span> <a name="l00615"></a>00615 <span class="comment">// final reply quantity</span> <a name="l00616"></a>00616 data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#af34ccc319ed0bd6bb387353e0968e622">a_qty</a> = a_qty * flow_qty; <a name="l00617"></a>00617 <a name="l00618"></a>00618 <span class="comment">// Add to the list (even if zero-quantity!)</span> <a name="l00619"></a>00619 <span class="keywordflow">if</span> (!prev_owner_opplan) data-><a class="code" href="a00029.html#a0b761c0e2f51f84569de4f242e2cb7b4">add</a>(a); <a name="l00620"></a>00620 <a name="l00621"></a>00621 <span class="comment">// Increment the cost</span> <a name="l00622"></a>00622 <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> > 0.0) <a name="l00623"></a>00623 data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#aa2e444a8091c86f71bbcd6d076c6c574">a_cost</a> += data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#abfd84159a05362d21fe7321c4caef08f">curOwnerOpplan</a>-><a class="code" href="a00125.html#aa32661a65b2309ba7c35576940274687">getQuantity</a>() * oper-><a class="code" href="a00121.html#ab69b08d57703a9d7809530270a6b86bf">getCost</a>(); <a name="l00624"></a>00624 <a name="l00625"></a>00625 <span class="comment">// Make other operationplans don't take this one as owner any more.</span> <a name="l00626"></a>00626 <span class="comment">// We restore the previous owner, which could be NULL.</span> <a name="l00627"></a>00627 data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#abfd84159a05362d21fe7321c4caef08f">curOwnerOpplan</a> = prev_owner_opplan; <a name="l00628"></a>00628 <a name="l00629"></a>00629 <span class="comment">// Check positive reply quantity</span> <a name="l00630"></a>00630 assert(data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#af34ccc319ed0bd6bb387353e0968e622">a_qty</a> >= 0); <a name="l00631"></a>00631 <a name="l00632"></a>00632 <span class="comment">// Check reply date is later than requested date</span> <a name="l00633"></a>00633 assert(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="l00634"></a>00634 <a name="l00635"></a>00635 <span class="comment">// Message</span> <a name="l00636"></a>00636 <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="l00637"></a>00637 <a class="code" href="a00257.html#a4af9f241e955122820c5e81ceb33edb5">logger</a> << <a class="code" href="a00087.html">indent</a>(oper-><a class="code" href="a00084.html#a44c879fcf3b6ae9193c393630e25fd13">getLevel</a>()) << <span class="stringliteral">" Routing operation '"</span> << oper-><a class="code" href="a00182.html#a7416ca220c55147bc1276becc5b9de01">getName</a>() <a name="l00638"></a>00638 << <span class="stringliteral">"' answers: "</span> << 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="l00639"></a>00639 << 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="l00640"></a>00640 } <a name="l00641"></a>00641 <a name="l00642"></a>00642 <a name="l00643"></a>00643 <span class="comment">// No need to take post- and pre-operation times into account</span> <a name="l00644"></a>00644 <span class="comment">// @todo This method should only be allowed to create 1 operationplan</span> <a name="l00645"></a><a class="code" href="a00173.html#a580fb211c927dc18df88fae9e7ce1c8d">00645</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="a00122.html" title="This class represents a choice between multiple operations. The alternates are sorted...">OperationAlternate</a>* oper, <span class="keywordtype">void</span>* v) <a name="l00646"></a>00646 { <a name="l00647"></a>00647 <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="l00648"></a>00648 <a class="code" href="a00049.html" title="This class represents a date and time with an accuracy of one second.">Date</a> origQDate = data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#a658c5379af8ec535090a96dd969f1fc3">q_date</a>; <a name="l00649"></a>00649 <span class="keywordtype">double</span> origQqty = data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#adf7c858a404b725f2f2c67648300f89b">q_qty</a>; <a name="l00650"></a>00650 <a class="code" href="a00008.html" title="A buffer represents a combination of a item and location. It is the entity for keeping...">Buffer</a> *buf = data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#a2f03f32d577521909343d06b884d7081">curBuffer</a>; <a name="l00651"></a>00651 <a class="code" href="a00051.html" title="Represents the (independent) demand in the system. It can represent a customer order...">Demand</a> *d = data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#a4feb35f2632149a1fa7828750a2f61b5">curDemand</a>; <a name="l00652"></a>00652 <a name="l00653"></a>00653 <span class="comment">// Call the user exit</span> <a name="l00654"></a>00654 <span class="keywordflow">if</span> (userexit_operation) userexit_operation.<a class="code" href="a00152.html#a7f199c39019f133986783dfc6017b640">call</a>(oper, <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="l00655"></a>00655 <a name="l00656"></a>00656 <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="l00657"></a>00657 <a class="code" href="a00256.html#aa439ebf4ddfb4983ac3d44abacb9b749">SearchMode</a> search = oper-><a class="code" href="a00122.html#a9eee64d0bb881e81d0fe9ba7dbe05c66">getSearch</a>(); <a name="l00658"></a>00658 <a name="l00659"></a>00659 <span class="comment">// Message</span> <a name="l00660"></a>00660 <span class="keywordflow">if</span> (loglevel>1) <a name="l00661"></a>00661 <a class="code" href="a00257.html#a4af9f241e955122820c5e81ceb33edb5">logger</a> << <a class="code" href="a00087.html">indent</a>(oper-><a class="code" href="a00084.html#a44c879fcf3b6ae9193c393630e25fd13">getLevel</a>()) << <span class="stringliteral">" Alternate operation '"</span> << oper-><a class="code" href="a00182.html#a7416ca220c55147bc1276becc5b9de01">getName</a>() <a name="l00662"></a>00662 << <span class="stringliteral">"' is asked: "</span> << data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#adf7c858a404b725f2f2c67648300f89b">q_qty</a> << <span class="stringliteral">" "</span> << data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#a658c5379af8ec535090a96dd969f1fc3">q_date</a> << endl; <a name="l00663"></a>00663 <a name="l00664"></a>00664 <span class="comment">// Make sure sub-operationplans know their owner & store the previous value</span> <a name="l00665"></a>00665 <a class="code" href="a00125.html" title="An operationplan is the key dynamic element of a plan. It represents a certain quantity...">OperationPlan</a> *prev_owner_opplan = data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#abfd84159a05362d21fe7321c4caef08f">curOwnerOpplan</a>; <a name="l00666"></a>00666 <a name="l00667"></a>00667 <span class="comment">// Find the flow into the requesting buffer for the quantity-per</span> <a name="l00668"></a>00668 <span class="keywordtype">double</span> top_flow_qty_per = 0.0; <a name="l00669"></a>00669 <span class="keywordtype">bool</span> top_flow_exists = <span class="keyword">false</span>; <a name="l00670"></a>00670 <span class="keywordflow">if</span> (buf) <a name="l00671"></a>00671 { <a name="l00672"></a>00672 <a class="code" href="a00065.html" title="This class defines a material flow to/from a buffer, linked with an operation. This...">Flow</a>* f = oper-><a class="code" href="a00121.html#aa636fe4ef5ba4352126e6f22f485cd2e">findFlow</a>(buf, data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#a658c5379af8ec535090a96dd969f1fc3">q_date</a>); <a name="l00673"></a>00673 <span class="keywordflow">if</span> (f && f-><a class="code" href="a00065.html#a29332e8619e350ec887efbdead1c1b11">getQuantity</a>() > 0.0) <a name="l00674"></a>00674 { <a name="l00675"></a>00675 top_flow_qty_per = f-><a class="code" href="a00065.html#a29332e8619e350ec887efbdead1c1b11">getQuantity</a>(); <a name="l00676"></a>00676 top_flow_exists = <span class="keyword">true</span>; <a name="l00677"></a>00677 } <a name="l00678"></a>00678 } <a name="l00679"></a>00679 <a name="l00680"></a>00680 <span class="comment">// Control the planning mode</span> <a name="l00681"></a>00681 <span class="keywordtype">bool</span> originalPlanningMode = data->constrainedPlanning; <a name="l00682"></a>00682 data->constrainedPlanning = <span class="keyword">true</span>; <a name="l00683"></a>00683 <a name="l00684"></a>00684 <span class="comment">// Remember the top constraint</span> <a name="l00685"></a>00685 <span class="keywordtype">bool</span> originalLogConstraints = data->logConstraints; <a name="l00686"></a>00686 <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="l00687"></a>00687 <a name="l00688"></a>00688 <span class="comment">// Try all alternates:</span> <a name="l00689"></a>00689 <span class="comment">// - First, all alternates that are fully effective in the order of priority.</span> <a name="l00690"></a>00690 <span class="comment">// - Next, the alternates beyond their effectivity date.</span> <a name="l00691"></a>00691 <span class="comment">// We loop through these since they can help in meeting a demand on time,</span> <a name="l00692"></a>00692 <span class="comment">// but using them will also create extra inventory or delays.</span> <a name="l00693"></a>00693 <span class="keywordtype">double</span> a_qty = data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#adf7c858a404b725f2f2c67648300f89b">q_qty</a>; <a name="l00694"></a>00694 <span class="keywordtype">bool</span> effectiveOnly = <span class="keyword">true</span>; <a name="l00695"></a>00695 <a class="code" href="a00049.html" title="This class represents a date and time with an accuracy of one second.">Date</a> a_date = Date::infiniteFuture; <a name="l00696"></a>00696 <a class="code" href="a00049.html" title="This class represents a date and time with an accuracy of one second.">Date</a> ask_date; <a name="l00697"></a>00697 <a class="code" href="a00121.html" title="An operation represents an activity: these consume and produce material, take time...">Operation</a> *firstAlternate = NULL; <a name="l00698"></a>00698 <span class="keywordtype">double</span> firstFlowPer; <a name="l00699"></a>00699 <span class="keywordflow">while</span> (a_qty > 0) <a name="l00700"></a>00700 { <a name="l00701"></a>00701 <span class="comment">// Evaluate all alternates</span> <a name="l00702"></a>00702 <span class="keywordtype">bool</span> plannedAlternate = <span class="keyword">false</span>; <a name="l00703"></a>00703 <span class="keywordtype">double</span> bestAlternateValue = DBL_MAX; <a name="l00704"></a>00704 <span class="keywordtype">double</span> bestAlternateQuantity = 0; <a name="l00705"></a>00705 <a class="code" href="a00121.html" title="An operation represents an activity: these consume and produce material, take time...">Operation</a>* bestAlternateSelection = NULL; <a name="l00706"></a>00706 <span class="keywordtype">double</span> bestFlowPer; <a name="l00707"></a>00707 <a class="code" href="a00049.html" title="This class represents a date and time with an accuracy of one second.">Date</a> bestQDate; <a name="l00708"></a>00708 <span class="keywordflow">for</span> (Operation::Operationlist::const_iterator altIter <a name="l00709"></a>00709 = oper-><a class="code" href="a00122.html#a15e4ba08a35bb3a364e2f6ce2512f3c6">getSubOperations</a>().begin(); <a name="l00710"></a>00710 altIter != oper-><a class="code" href="a00122.html#a15e4ba08a35bb3a364e2f6ce2512f3c6">getSubOperations</a>().end(); ) <a name="l00711"></a>00711 { <a name="l00712"></a>00712 <span class="comment">// Store the last command in the list, in order to undo the following</span> <a name="l00713"></a>00713 <span class="comment">// commands if required.</span> <a name="l00714"></a>00714 <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="l00715"></a>00715 <span class="keywordtype">bool</span> nextalternate = <span class="keyword">true</span>; <a name="l00716"></a>00716 <a name="l00717"></a>00717 <span class="comment">// Operations with 0 priority are considered unavailable</span> <a name="l00718"></a>00718 <span class="keyword">const</span> <a class="code" href="a00122.html#a21276a85b32a20ee590af9e02445d5f8">OperationAlternate::alternateProperty</a>& props <a name="l00719"></a>00719 = oper-><a class="code" href="a00122.html#afa54c209215c9841187cecfb0c9e2808">getProperties</a>(*altIter); <a name="l00720"></a>00720 <a name="l00721"></a>00721 <span class="comment">// Filter out alternates that are not suitable</span> <a name="l00722"></a>00722 <span class="keywordflow">if</span> (props.first == 0.0 <a name="l00723"></a>00723 || (effectiveOnly && !props.second.within(data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#a658c5379af8ec535090a96dd969f1fc3">q_date</a>)) <a name="l00724"></a>00724 || (!effectiveOnly && props.second.getEnd() > data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#a658c5379af8ec535090a96dd969f1fc3">q_date</a>) <a name="l00725"></a>00725 ) <a name="l00726"></a>00726 { <a name="l00727"></a>00727 ++altIter; <a name="l00728"></a>00728 <span class="keywordflow">if</span> (altIter == oper-><a class="code" href="a00122.html#a15e4ba08a35bb3a364e2f6ce2512f3c6">getSubOperations</a>().end() && effectiveOnly) <a name="l00729"></a>00729 { <a name="l00730"></a>00730 <span class="comment">// Prepare for a second iteration over all alternates</span> <a name="l00731"></a>00731 effectiveOnly = <span class="keyword">false</span>; <a name="l00732"></a>00732 altIter = oper-><a class="code" href="a00122.html#a15e4ba08a35bb3a364e2f6ce2512f3c6">getSubOperations</a>().begin(); <a name="l00733"></a>00733 } <a name="l00734"></a>00734 <span class="keywordflow">continue</span>; <a name="l00735"></a>00735 } <a name="l00736"></a>00736 <a name="l00737"></a>00737 <span class="comment">// Establish the ask date</span> <a name="l00738"></a>00738 ask_date = effectiveOnly ? origQDate : props.second.getEnd(); <a name="l00739"></a>00739 <a name="l00740"></a>00740 <span class="comment">// Find the flow into the requesting buffer. It may or may not exist, since</span> <a name="l00741"></a>00741 <span class="comment">// the flow could already exist on the top operationplan</span> <a name="l00742"></a>00742 <span class="keywordtype">double</span> sub_flow_qty_per = 0.0; <a name="l00743"></a>00743 <span class="keywordflow">if</span> (buf) <a name="l00744"></a>00744 { <a name="l00745"></a>00745 <a class="code" href="a00065.html" title="This class defines a material flow to/from a buffer, linked with an operation. This...">Flow</a>* f = (*altIter)->findFlow(buf, ask_date); <a name="l00746"></a>00746 <span class="keywordflow">if</span> (f && f-><a class="code" href="a00065.html#a29332e8619e350ec887efbdead1c1b11">getQuantity</a>() > 0.0) <a name="l00747"></a>00747 sub_flow_qty_per = f-><a class="code" href="a00065.html#a29332e8619e350ec887efbdead1c1b11">getQuantity</a>(); <a name="l00748"></a>00748 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (!top_flow_exists) <a name="l00749"></a>00749 { <a name="l00750"></a>00750 <span class="comment">// Neither the top nor the sub operation have a flow in the buffer,</span> <a name="l00751"></a>00751 <span class="comment">// we're in trouble...</span> <a name="l00752"></a>00752 <span class="comment">// Restore the planning mode</span> <a name="l00753"></a>00753 data->constrainedPlanning = originalPlanningMode; <a name="l00754"></a>00754 <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">"Invalid producing operation '"</span> + oper-><a class="code" href="a00182.html#a7416ca220c55147bc1276becc5b9de01">getName</a>() <a name="l00755"></a>00755 + <span class="stringliteral">"' for buffer '"</span> + buf-><a class="code" href="a00182.html#a7416ca220c55147bc1276becc5b9de01">getName</a>() + <span class="stringliteral">"'"</span>); <a name="l00756"></a>00756 } <a name="l00757"></a>00757 } <a name="l00758"></a>00758 <span class="keywordflow">else</span> <a name="l00759"></a>00759 <span class="comment">// Default value is 1.0, if no matching flow is required</span> <a name="l00760"></a>00760 sub_flow_qty_per = 1.0; <a name="l00761"></a>00761 <a name="l00762"></a>00762 <span class="comment">// Remember the first alternate</span> <a name="l00763"></a>00763 <span class="keywordflow">if</span> (!firstAlternate) <a name="l00764"></a>00764 { <a name="l00765"></a>00765 firstAlternate = *altIter; <a name="l00766"></a>00766 firstFlowPer = sub_flow_qty_per + top_flow_qty_per; <a name="l00767"></a>00767 } <a name="l00768"></a>00768 <a name="l00769"></a>00769 <span class="comment">// Constraint tracking</span> <a name="l00770"></a>00770 <span class="keywordflow">if</span> (*altIter != firstAlternate) <a name="l00771"></a>00771 <span class="comment">// Only enabled on first alternate</span> <a name="l00772"></a>00772 data->logConstraints = <span class="keyword">false</span>; <a name="l00773"></a>00773 <span class="keywordflow">else</span> <a name="l00774"></a>00774 { <a name="l00775"></a>00775 <span class="comment">// Forget previous constraints if we are replanning the first alternate </span> <a name="l00776"></a>00776 <span class="comment">// multiple times</span> <a name="l00777"></a>00777 data->planningDemand-><a class="code" href="a00051.html#acd06be46dd32eb121e408c5b9e035965">getConstraints</a>().<a class="code" href="a00100.html#ad00f9532f9f1aa1f744e7ac6ceccdfac">pop</a>(topConstraint); <a name="l00778"></a>00778 <span class="comment">// Potentially keep track of constraints</span> <a name="l00779"></a>00779 data->logConstraints = originalLogConstraints; <a name="l00780"></a>00780 } <a name="l00781"></a>00781 <a name="l00782"></a>00782 <span class="comment">// Create the top operationplan.</span> <a name="l00783"></a>00783 <span class="comment">// Note that both the top- and the sub-operation can have a flow in the</span> <a name="l00784"></a>00784 <span class="comment">// requested buffer</span> <a name="l00785"></a>00785 <a class="code" href="a00026.html" title="This command is used to create an operationplan.">CommandCreateOperationPlan</a> *a = <span class="keyword">new</span> <a class="code" href="a00026.html" title="This command is used to create an operationplan.">CommandCreateOperationPlan</a>( <a name="l00786"></a>00786 oper, a_qty, Date::infinitePast, ask_date, <a name="l00787"></a>00787 d, prev_owner_opplan, <span class="keyword">false</span> <a name="l00788"></a>00788 ); <a name="l00789"></a>00789 <span class="keywordflow">if</span> (!prev_owner_opplan) data-><a class="code" href="a00029.html#a0b761c0e2f51f84569de4f242e2cb7b4">add</a>(a); <a name="l00790"></a>00790 <a name="l00791"></a>00791 <span class="comment">// Create a sub operationplan</span> <a name="l00792"></a>00792 data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#a658c5379af8ec535090a96dd969f1fc3">q_date</a> = ask_date; <a name="l00793"></a>00793 data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#a4feb35f2632149a1fa7828750a2f61b5">curDemand</a> = NULL; <a name="l00794"></a>00794 data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#abfd84159a05362d21fe7321c4caef08f">curOwnerOpplan</a> = a-><a class="code" href="a00026.html#ab1a9489e2182059cebf9d0fc1606d83d">getOperationPlan</a>(); <a name="l00795"></a>00795 data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#a2f03f32d577521909343d06b884d7081">curBuffer</a> = NULL; <span class="comment">// Because we already took care of it... @todo not correct if the suboperation is again a owning operation</span> <a name="l00796"></a>00796 data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#adf7c858a404b725f2f2c67648300f89b">q_qty</a> = a_qty / (sub_flow_qty_per + top_flow_qty_per); <a name="l00797"></a>00797 <a name="l00798"></a>00798 <span class="comment">// Solve constraints on the sub operationplan</span> <a name="l00799"></a>00799 <span class="keywordtype">double</span> beforeCost = data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#aa2e444a8091c86f71bbcd6d076c6c574">a_cost</a>; <a name="l00800"></a>00800 <span class="keywordtype">double</span> beforePenalty = data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#ae007a7c0a1074c1fc1dfe9c5eeedcc0e">a_penalty</a>; <a name="l00801"></a>00801 <span class="keywordflow">if</span> (search == <a class="code" href="a00256.html#aa439ebf4ddfb4983ac3d44abacb9b749a20f9fef00fcbc3cd9fbd27a8a41c1d83">PRIORITY</a>) <a name="l00802"></a>00802 { <a name="l00803"></a>00803 <span class="comment">// Message</span> <a name="l00804"></a>00804 <span class="keywordflow">if</span> (loglevel) <a name="l00805"></a>00805 <a class="code" href="a00257.html#a4af9f241e955122820c5e81ceb33edb5">logger</a> << <a class="code" href="a00087.html">indent</a>(oper-><a class="code" href="a00084.html#a44c879fcf3b6ae9193c393630e25fd13">getLevel</a>()) << <span class="stringliteral">" Alternate operation '"</span> << oper-><a class="code" href="a00182.html#a7416ca220c55147bc1276becc5b9de01">getName</a>() <a name="l00806"></a>00806 << <span class="stringliteral">"' tries alternate '"</span> << *altIter << <span class="stringliteral">"' "</span> << endl; <a name="l00807"></a>00807 (*altIter)->solve(*<span class="keyword">this</span>,v); <a name="l00808"></a>00808 } <a name="l00809"></a>00809 <span class="keywordflow">else</span> <a name="l00810"></a>00810 { <a name="l00811"></a>00811 data-><a class="code" href="a00174.html#a1d6f62b1c53725b796ea1c4f8843b85d">getSolver</a>()-><a class="code" href="a00171.html#a373dc4d480568344c336cb193ce3edc2">setLogLevel</a>(0); <a name="l00812"></a>00812 <span class="keywordflow">try</span> {(*altIter)->solve(*<span class="keyword">this</span>,v);} <a name="l00813"></a>00813 <span class="keywordflow">catch</span> (...) <a name="l00814"></a>00814 { <a name="l00815"></a>00815 data-><a class="code" href="a00174.html#a1d6f62b1c53725b796ea1c4f8843b85d">getSolver</a>()-><a class="code" href="a00171.html#a373dc4d480568344c336cb193ce3edc2">setLogLevel</a>(loglevel); <a name="l00816"></a>00816 <span class="comment">// Restore the planning mode</span> <a name="l00817"></a>00817 data->constrainedPlanning = originalPlanningMode; <a name="l00818"></a>00818 data->logConstraints = originalLogConstraints; <a name="l00819"></a>00819 <span class="keywordflow">throw</span>; <a name="l00820"></a>00820 } <a name="l00821"></a>00821 data-><a class="code" href="a00174.html#a1d6f62b1c53725b796ea1c4f8843b85d">getSolver</a>()-><a class="code" href="a00171.html#a373dc4d480568344c336cb193ce3edc2">setLogLevel</a>(loglevel); <a name="l00822"></a>00822 } <a name="l00823"></a>00823 <span class="keywordtype">double</span> deltaCost = data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#aa2e444a8091c86f71bbcd6d076c6c574">a_cost</a> - beforeCost; <a name="l00824"></a>00824 <span class="keywordtype">double</span> deltaPenalty = data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#ae007a7c0a1074c1fc1dfe9c5eeedcc0e">a_penalty</a> - beforePenalty; <a name="l00825"></a>00825 data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#aa2e444a8091c86f71bbcd6d076c6c574">a_cost</a> = beforeCost; <a name="l00826"></a>00826 data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#ae007a7c0a1074c1fc1dfe9c5eeedcc0e">a_penalty</a> = beforePenalty; <a name="l00827"></a>00827 <a name="l00828"></a>00828 <span class="comment">// Keep the lowest of all next-date answers on the effective alternates</span> <a name="l00829"></a>00829 <span class="keywordflow">if</span> (effectiveOnly && data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#ab56b3877ddc206e8817f04186c0e47a8">a_date</a> < a_date && data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#ab56b3877ddc206e8817f04186c0e47a8">a_date</a> > ask_date) <a name="l00830"></a>00830 a_date = data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#ab56b3877ddc206e8817f04186c0e47a8">a_date</a>; <a name="l00831"></a>00831 <a name="l00832"></a>00832 <span class="comment">// Now solve for loads and flows of the top operationplan.</span> <a name="l00833"></a>00833 <span class="comment">// Only now we know how long that top-operation lasts in total.</span> <a name="l00834"></a>00834 <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="l00835"></a>00835 { <a name="l00836"></a>00836 <span class="comment">// Multiply the operation reply with the flow quantity to obtain the</span> <a name="l00837"></a>00837 <span class="comment">// reply to return</span> <a name="l00838"></a>00838 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#af34ccc319ed0bd6bb387353e0968e622">a_qty</a>; <a name="l00839"></a>00839 data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#a658c5379af8ec535090a96dd969f1fc3">q_date</a> = origQDate; <a name="l00840"></a>00840 data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#abfd84159a05362d21fe7321c4caef08f">curOwnerOpplan</a>-><a class="code" href="a00125.html#a1c0ab58f6d41e2fd26e50f09158042ee">createFlowLoads</a>(); <a name="l00841"></a>00841 data-><a class="code" href="a00174.html#a1d6f62b1c53725b796ea1c4f8843b85d">getSolver</a>()-><a class="code" href="a00173.html#ab41595b46bdbc8b508b9d7dedad0362f">checkOperation</a>(data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#abfd84159a05362d21fe7321c4caef08f">curOwnerOpplan</a>,*data); <a name="l00842"></a>00842 data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#af34ccc319ed0bd6bb387353e0968e622">a_qty</a> *= (sub_flow_qty_per + top_flow_qty_per); <a name="l00843"></a>00843 <a name="l00844"></a>00844 <span class="comment">// Combine the reply date of the top-opplan with the alternate check: we</span> <a name="l00845"></a>00845 <span class="comment">// need to return the minimum next-date.</span> <a name="l00846"></a>00846 <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> < a_date && data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#ab56b3877ddc206e8817f04186c0e47a8">a_date</a> > ask_date) <a name="l00847"></a>00847 a_date = data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#ab56b3877ddc206e8817f04186c0e47a8">a_date</a>; <a name="l00848"></a>00848 } <a name="l00849"></a>00849 <a name="l00850"></a>00850 <span class="comment">// Message</span> <a name="l00851"></a>00851 <span class="keywordflow">if</span> (loglevel && search != <a class="code" href="a00256.html#aa439ebf4ddfb4983ac3d44abacb9b749a20f9fef00fcbc3cd9fbd27a8a41c1d83">PRIORITY</a>) <a name="l00852"></a>00852 <a class="code" href="a00257.html#a4af9f241e955122820c5e81ceb33edb5">logger</a> << <a class="code" href="a00087.html">indent</a>(oper-><a class="code" href="a00084.html#a44c879fcf3b6ae9193c393630e25fd13">getLevel</a>()) << <span class="stringliteral">" Alternate operation '"</span> << oper-><a class="code" href="a00182.html#a7416ca220c55147bc1276becc5b9de01">getName</a>() <a name="l00853"></a>00853 << <span class="stringliteral">"' evaluates alternate '"</span> << *altIter << <span class="stringliteral">"': quantity "</span> << data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#af34ccc319ed0bd6bb387353e0968e622">a_qty</a> <a name="l00854"></a>00854 << <span class="stringliteral">", cost "</span> << deltaCost << <span class="stringliteral">", penalty "</span> << deltaPenalty << endl; <a name="l00855"></a>00855 <a name="l00856"></a>00856 <span class="comment">// Process the result</span> <a name="l00857"></a>00857 <span class="keywordflow">if</span> (search == <a class="code" href="a00256.html#aa439ebf4ddfb4983ac3d44abacb9b749a20f9fef00fcbc3cd9fbd27a8a41c1d83">PRIORITY</a>) <a name="l00858"></a>00858 { <a name="l00859"></a>00859 <span class="comment">// Undo the operationplans of this alternate</span> <a name="l00860"></a>00860 <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>) data-><a class="code" href="a00029.html#a6f38f9a190b88a29f63b58a478cbe982">undo</a>(topcommand); <a name="l00861"></a>00861 <a name="l00862"></a>00862 <span class="comment">// Prepare for the next loop</span> <a name="l00863"></a>00863 a_qty -= data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#af34ccc319ed0bd6bb387353e0968e622">a_qty</a>; <a name="l00864"></a>00864 plannedAlternate = <span class="keyword">true</span>; <a name="l00865"></a>00865 <a name="l00866"></a>00866 <span class="comment">// As long as we get a positive reply we replan on this alternate</span> <a name="l00867"></a>00867 <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> > 0) nextalternate = <span class="keyword">false</span>; <a name="l00868"></a>00868 <a name="l00869"></a>00869 <span class="comment">// Are we at the end already?</span> <a name="l00870"></a>00870 <span class="keywordflow">if</span> (a_qty < <a class="code" href="a00252.html#a42d90a6275119e1b4ce73c50f1867e60">ROUNDING_ERROR</a>) <a name="l00871"></a>00871 { <a name="l00872"></a>00872 a_qty = 0.0; <a name="l00873"></a>00873 <span class="keywordflow">break</span>; <a name="l00874"></a>00874 } <a name="l00875"></a>00875 } <a name="l00876"></a>00876 <span class="keywordflow">else</span> <a name="l00877"></a>00877 { <a name="l00878"></a>00878 <span class="keywordtype">double</span> val; <a name="l00879"></a>00879 <span class="keywordflow">switch</span> (search) <a name="l00880"></a>00880 { <a name="l00881"></a>00881 <span class="keywordflow">case</span> <a class="code" href="a00256.html#aa439ebf4ddfb4983ac3d44abacb9b749ad9914aabe4dd320523d45a0a647dec6e">MINCOST</a>: <a name="l00882"></a>00882 val = deltaCost / data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#af34ccc319ed0bd6bb387353e0968e622">a_qty</a>; <a name="l00883"></a>00883 <span class="keywordflow">break</span>; <a name="l00884"></a>00884 <span class="keywordflow">case</span> <a class="code" href="a00256.html#aa439ebf4ddfb4983ac3d44abacb9b749aa0b35fa57d0c5ce3728116ed47f06ca9">MINPENALTY</a>: <a name="l00885"></a>00885 val = deltaPenalty / data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#af34ccc319ed0bd6bb387353e0968e622">a_qty</a>; <a name="l00886"></a>00886 <span class="keywordflow">break</span>; <a name="l00887"></a>00887 <span class="keywordflow">case</span> <a class="code" href="a00256.html#aa439ebf4ddfb4983ac3d44abacb9b749acffaea7c05036f503a543806f02f51d1">MINCOSTPENALTY</a>: <a name="l00888"></a>00888 val = (deltaCost + deltaPenalty) / data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#af34ccc319ed0bd6bb387353e0968e622">a_qty</a>; <a name="l00889"></a>00889 <span class="keywordflow">break</span>; <a name="l00890"></a>00890 <span class="keywordflow">default</span>: <a name="l00891"></a>00891 <a class="code" href="a00111.html" title="An exception of this type is thrown when the library gets in an inconsistent state...">LogicException</a>(<span class="stringliteral">"Unsupported search mode for alternate operation '"</span> <a name="l00892"></a>00892 + oper-><a class="code" href="a00182.html#a7416ca220c55147bc1276becc5b9de01">getName</a>() + <span class="stringliteral">"'"</span>); <a name="l00893"></a>00893 } <a name="l00894"></a>00894 <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="l00895"></a>00895 val + <a class="code" href="a00252.html#a42d90a6275119e1b4ce73c50f1867e60">ROUNDING_ERROR</a> < bestAlternateValue <a name="l00896"></a>00896 || (fabs(val - bestAlternateValue) < <a class="code" href="a00252.html#a42d90a6275119e1b4ce73c50f1867e60">ROUNDING_ERROR</a> <a name="l00897"></a>00897 && data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#af34ccc319ed0bd6bb387353e0968e622">a_qty</a> > bestAlternateQuantity) <a name="l00898"></a>00898 )) <a name="l00899"></a>00899 { <a name="l00900"></a>00900 <span class="comment">// Found a better alternate</span> <a name="l00901"></a>00901 bestAlternateValue = val; <a name="l00902"></a>00902 bestAlternateSelection = *altIter; <a name="l00903"></a>00903 bestAlternateQuantity = data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#af34ccc319ed0bd6bb387353e0968e622">a_qty</a>; <a name="l00904"></a>00904 bestFlowPer = sub_flow_qty_per + top_flow_qty_per; <a name="l00905"></a>00905 bestQDate = ask_date; <a name="l00906"></a>00906 } <a name="l00907"></a>00907 <span class="comment">// This was only an evaluation</span> <a name="l00908"></a>00908 data-><a class="code" href="a00029.html#a6f38f9a190b88a29f63b58a478cbe982">undo</a>(topcommand); <a name="l00909"></a>00909 } <a name="l00910"></a>00910 <a name="l00911"></a>00911 <span class="comment">// Select the next alternate</span> <a name="l00912"></a>00912 <span class="keywordflow">if</span> (nextalternate) <a name="l00913"></a>00913 { <a name="l00914"></a>00914 ++altIter; <a name="l00915"></a>00915 <span class="keywordflow">if</span> (altIter == oper-><a class="code" href="a00122.html#a15e4ba08a35bb3a364e2f6ce2512f3c6">getSubOperations</a>().end() && effectiveOnly) <a name="l00916"></a>00916 { <a name="l00917"></a>00917 <span class="comment">// Prepare for a second iteration over all alternates</span> <a name="l00918"></a>00918 effectiveOnly = <span class="keyword">false</span>; <a name="l00919"></a>00919 altIter = oper-><a class="code" href="a00122.html#a15e4ba08a35bb3a364e2f6ce2512f3c6">getSubOperations</a>().begin(); <a name="l00920"></a>00920 } <a name="l00921"></a>00921 } <a name="l00922"></a>00922 } <span class="comment">// End loop over all alternates</span> <a name="l00923"></a>00923 <a name="l00924"></a>00924 <span class="comment">// Replan on the best alternate</span> <a name="l00925"></a>00925 <span class="keywordflow">if</span> (bestAlternateQuantity > <a class="code" href="a00252.html#a42d90a6275119e1b4ce73c50f1867e60">ROUNDING_ERROR</a> && search != <a class="code" href="a00256.html#aa439ebf4ddfb4983ac3d44abacb9b749a20f9fef00fcbc3cd9fbd27a8a41c1d83">PRIORITY</a>) <a name="l00926"></a>00926 { <a name="l00927"></a>00927 <span class="comment">// Message</span> <a name="l00928"></a>00928 <span class="keywordflow">if</span> (loglevel) <a name="l00929"></a>00929 <a class="code" href="a00257.html#a4af9f241e955122820c5e81ceb33edb5">logger</a> << <a class="code" href="a00087.html">indent</a>(oper-><a class="code" href="a00084.html#a44c879fcf3b6ae9193c393630e25fd13">getLevel</a>()) << <span class="stringliteral">" Alternate operation '"</span> << oper-><a class="code" href="a00182.html#a7416ca220c55147bc1276becc5b9de01">getName</a>() <a name="l00930"></a>00930 << <span class="stringliteral">"' chooses alternate '"</span> << bestAlternateSelection << <span class="stringliteral">"' "</span> << search << endl; <a name="l00931"></a>00931 <a name="l00932"></a>00932 <span class="comment">// Create the top operationplan.</span> <a name="l00933"></a>00933 <span class="comment">// Note that both the top- and the sub-operation can have a flow in the</span> <a name="l00934"></a>00934 <span class="comment">// requested buffer</span> <a name="l00935"></a>00935 <a class="code" href="a00026.html" title="This command is used to create an operationplan.">CommandCreateOperationPlan</a> *a = <span class="keyword">new</span> <a class="code" href="a00026.html" title="This command is used to create an operationplan.">CommandCreateOperationPlan</a>( <a name="l00936"></a>00936 oper, a_qty, Date::infinitePast, bestQDate, <a name="l00937"></a>00937 d, prev_owner_opplan, <span class="keyword">false</span> <a name="l00938"></a>00938 ); <a name="l00939"></a>00939 <span class="keywordflow">if</span> (!prev_owner_opplan) data-><a class="code" href="a00029.html#a0b761c0e2f51f84569de4f242e2cb7b4">add</a>(a); <a name="l00940"></a>00940 <a name="l00941"></a>00941 <span class="comment">// Recreate the ask</span> <a name="l00942"></a>00942 data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#adf7c858a404b725f2f2c67648300f89b">q_qty</a> = a_qty / bestFlowPer; <a name="l00943"></a>00943 data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#a658c5379af8ec535090a96dd969f1fc3">q_date</a> = bestQDate; <a name="l00944"></a>00944 data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#a4feb35f2632149a1fa7828750a2f61b5">curDemand</a> = NULL; <a name="l00945"></a>00945 data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#abfd84159a05362d21fe7321c4caef08f">curOwnerOpplan</a> = a-><a class="code" href="a00026.html#ab1a9489e2182059cebf9d0fc1606d83d">getOperationPlan</a>(); <a name="l00946"></a>00946 data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#a2f03f32d577521909343d06b884d7081">curBuffer</a> = NULL; <span class="comment">// Because we already took care of it... @todo not correct if the suboperation is again a owning operation</span> <a name="l00947"></a>00947 <a name="l00948"></a>00948 <span class="comment">// Create a sub operationplan and solve constraints</span> <a name="l00949"></a>00949 bestAlternateSelection-><a class="code" href="a00121.html#a15b6686fb03126fea6d5151a79aa5a91">solve</a>(*<span class="keyword">this</span>,v); <a name="l00950"></a>00950 <a name="l00951"></a>00951 <span class="comment">// Now solve for loads and flows of the top operationplan.</span> <a name="l00952"></a>00952 <span class="comment">// Only now we know how long that top-operation lasts in total.</span> <a name="l00953"></a>00953 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#af34ccc319ed0bd6bb387353e0968e622">a_qty</a>; <a name="l00954"></a>00954 data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#a658c5379af8ec535090a96dd969f1fc3">q_date</a> = origQDate; <a name="l00955"></a>00955 data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#abfd84159a05362d21fe7321c4caef08f">curOwnerOpplan</a>-><a class="code" href="a00125.html#a1c0ab58f6d41e2fd26e50f09158042ee">createFlowLoads</a>(); <a name="l00956"></a>00956 data-><a class="code" href="a00174.html#a1d6f62b1c53725b796ea1c4f8843b85d">getSolver</a>()-><a class="code" href="a00173.html#ab41595b46bdbc8b508b9d7dedad0362f">checkOperation</a>(data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#abfd84159a05362d21fe7321c4caef08f">curOwnerOpplan</a>,*data); <a name="l00957"></a>00957 <a name="l00958"></a>00958 <span class="comment">// Multiply the operation reply with the flow quantity to obtain the</span> <a name="l00959"></a>00959 <span class="comment">// reply to return</span> <a name="l00960"></a>00960 data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#af34ccc319ed0bd6bb387353e0968e622">a_qty</a> *= bestFlowPer; <a name="l00961"></a>00961 <a name="l00962"></a>00962 <span class="comment">// Combine the reply date of the top-opplan with the alternate check: we</span> <a name="l00963"></a>00963 <span class="comment">// need to return the minimum next-date.</span> <a name="l00964"></a>00964 <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> < a_date && data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#ab56b3877ddc206e8817f04186c0e47a8">a_date</a> > ask_date) <a name="l00965"></a>00965 a_date = data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#ab56b3877ddc206e8817f04186c0e47a8">a_date</a>; <a name="l00966"></a>00966 <a name="l00967"></a>00967 <span class="comment">// Prepare for the next loop</span> <a name="l00968"></a>00968 a_qty -= data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#af34ccc319ed0bd6bb387353e0968e622">a_qty</a>; <a name="l00969"></a>00969 <a name="l00970"></a>00970 <span class="comment">// Are we at the end already?</span> <a name="l00971"></a>00971 <span class="keywordflow">if</span> (a_qty < <a class="code" href="a00252.html#a42d90a6275119e1b4ce73c50f1867e60">ROUNDING_ERROR</a>) <a name="l00972"></a>00972 { <a name="l00973"></a>00973 a_qty = 0.0; <a name="l00974"></a>00974 <span class="keywordflow">break</span>; <a name="l00975"></a>00975 } <a name="l00976"></a>00976 } <a name="l00977"></a>00977 <span class="keywordflow">else</span> <a name="l00978"></a>00978 <span class="comment">// No alternate can plan anything any more</span> <a name="l00979"></a>00979 <span class="keywordflow">break</span>; <a name="l00980"></a>00980 <a name="l00981"></a>00981 } <span class="comment">// End while loop until the a_qty > 0</span> <a name="l00982"></a>00982 <a name="l00983"></a>00983 <span class="comment">// Forget any constraints if we are not short or are planning unconstrained</span> <a name="l00984"></a>00984 <span class="keywordflow">if</span> (a_qty < <a class="code" href="a00252.html#a42d90a6275119e1b4ce73c50f1867e60">ROUNDING_ERROR</a> || !originalLogConstraints) <a name="l00985"></a>00985 data->planningDemand-><a class="code" href="a00051.html#acd06be46dd32eb121e408c5b9e035965">getConstraints</a>().<a class="code" href="a00100.html#ad00f9532f9f1aa1f744e7ac6ceccdfac">pop</a>(topConstraint); <a name="l00986"></a>00986 <a name="l00987"></a>00987 <span class="comment">// Unconstrained plan: If some unplanned quantity remains, switch to </span> <a name="l00988"></a>00988 <span class="comment">// unconstrained planning on the first alternate.</span> <a name="l00989"></a>00989 <span class="comment">// If something could be planned, we expect the caller to re-ask this </span> <a name="l00990"></a>00990 <span class="comment">// operation.</span> <a name="l00991"></a>00991 <span class="keywordflow">if</span> (!originalPlanningMode && fabs(origQqty - a_qty) < <a class="code" href="a00252.html#a42d90a6275119e1b4ce73c50f1867e60">ROUNDING_ERROR</a> && firstAlternate) <a name="l00992"></a>00992 { <a name="l00993"></a>00993 <span class="comment">// Switch to unconstrained planning </span> <a name="l00994"></a>00994 data->constrainedPlanning = <span class="keyword">false</span>; <a name="l00995"></a>00995 data->logConstraints = <span class="keyword">false</span>; <a name="l00996"></a>00996 <a name="l00997"></a>00997 <span class="comment">// Message</span> <a name="l00998"></a>00998 <span class="keywordflow">if</span> (loglevel) <a name="l00999"></a>00999 <a class="code" href="a00257.html#a4af9f241e955122820c5e81ceb33edb5">logger</a> << <a class="code" href="a00087.html">indent</a>(oper-><a class="code" href="a00084.html#a44c879fcf3b6ae9193c393630e25fd13">getLevel</a>()) << <span class="stringliteral">" Alternate operation '"</span> << oper-><a class="code" href="a00182.html#a7416ca220c55147bc1276becc5b9de01">getName</a>() <a name="l01000"></a>01000 << <span class="stringliteral">"' plans unconstrained on alternate '"</span> << firstAlternate << <span class="stringliteral">"' "</span> << search << endl; <a name="l01001"></a>01001 <a name="l01002"></a>01002 <span class="comment">// Create the top operationplan.</span> <a name="l01003"></a>01003 <span class="comment">// Note that both the top- and the sub-operation can have a flow in the</span> <a name="l01004"></a>01004 <span class="comment">// requested buffer</span> <a name="l01005"></a>01005 <a class="code" href="a00026.html" title="This command is used to create an operationplan.">CommandCreateOperationPlan</a> *a = <span class="keyword">new</span> <a class="code" href="a00026.html" title="This command is used to create an operationplan.">CommandCreateOperationPlan</a>( <a name="l01006"></a>01006 oper, a_qty, Date::infinitePast, origQDate, <a name="l01007"></a>01007 d, prev_owner_opplan, <span class="keyword">false</span> <a name="l01008"></a>01008 ); <a name="l01009"></a>01009 <span class="keywordflow">if</span> (!prev_owner_opplan) data-><a class="code" href="a00029.html#a0b761c0e2f51f84569de4f242e2cb7b4">add</a>(a); <a name="l01010"></a>01010 <a name="l01011"></a>01011 <span class="comment">// Recreate the ask</span> <a name="l01012"></a>01012 data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#adf7c858a404b725f2f2c67648300f89b">q_qty</a> = a_qty / firstFlowPer; <a name="l01013"></a>01013 data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#a658c5379af8ec535090a96dd969f1fc3">q_date</a> = origQDate; <a name="l01014"></a>01014 data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#a4feb35f2632149a1fa7828750a2f61b5">curDemand</a> = NULL; <a name="l01015"></a>01015 data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#abfd84159a05362d21fe7321c4caef08f">curOwnerOpplan</a> = a-><a class="code" href="a00026.html#ab1a9489e2182059cebf9d0fc1606d83d">getOperationPlan</a>(); <a name="l01016"></a>01016 data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#a2f03f32d577521909343d06b884d7081">curBuffer</a> = NULL; <span class="comment">// Because we already took care of it... @todo not correct if the suboperation is again a owning operation</span> <a name="l01017"></a>01017 <a name="l01018"></a>01018 <span class="comment">// Create a sub operationplan and solve constraints</span> <a name="l01019"></a>01019 firstAlternate-><a class="code" href="a00121.html#a15b6686fb03126fea6d5151a79aa5a91">solve</a>(*<span class="keyword">this</span>,v); <a name="l01020"></a>01020 <a name="l01021"></a>01021 <span class="comment">// Expand flows of the top operationplan.</span> <a name="l01022"></a>01022 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#af34ccc319ed0bd6bb387353e0968e622">a_qty</a>; <a name="l01023"></a>01023 data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#a658c5379af8ec535090a96dd969f1fc3">q_date</a> = origQDate; <a name="l01024"></a>01024 data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#abfd84159a05362d21fe7321c4caef08f">curOwnerOpplan</a>-><a class="code" href="a00125.html#a1c0ab58f6d41e2fd26e50f09158042ee">createFlowLoads</a>(); <a name="l01025"></a>01025 data-><a class="code" href="a00174.html#a1d6f62b1c53725b796ea1c4f8843b85d">getSolver</a>()-><a class="code" href="a00173.html#ab41595b46bdbc8b508b9d7dedad0362f">checkOperation</a>(data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#abfd84159a05362d21fe7321c4caef08f">curOwnerOpplan</a>,*data); <a name="l01026"></a>01026 <a name="l01027"></a>01027 <span class="comment">// Fully planned</span> <a name="l01028"></a>01028 a_qty = 0.0; <a name="l01029"></a>01029 data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#ab56b3877ddc206e8817f04186c0e47a8">a_date</a> = origQDate; <a name="l01030"></a>01030 } <a name="l01031"></a>01031 <a name="l01032"></a>01032 <span class="comment">// Set up the reply</span> <a name="l01033"></a>01033 data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#af34ccc319ed0bd6bb387353e0968e622">a_qty</a> = origQqty - a_qty; <span class="comment">// a_qty is the unplanned quantity</span> <a name="l01034"></a>01034 data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#ab56b3877ddc206e8817f04186c0e47a8">a_date</a> = a_date; <a name="l01035"></a>01035 assert(data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#af34ccc319ed0bd6bb387353e0968e622">a_qty</a> >= 0); <a name="l01036"></a>01036 assert(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="l01037"></a>01037 <a name="l01038"></a>01038 <span class="comment">// Restore the planning mode</span> <a name="l01039"></a>01039 data->constrainedPlanning = originalPlanningMode; <a name="l01040"></a>01040 data->logConstraints = originalLogConstraints; <a name="l01041"></a>01041 <a name="l01042"></a>01042 <span class="comment">// Increment the cost</span> <a name="l01043"></a>01043 <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> > 0.0) <a name="l01044"></a>01044 data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#aa2e444a8091c86f71bbcd6d076c6c574">a_cost</a> += data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#abfd84159a05362d21fe7321c4caef08f">curOwnerOpplan</a>-><a class="code" href="a00125.html#aa32661a65b2309ba7c35576940274687">getQuantity</a>() * oper-><a class="code" href="a00121.html#ab69b08d57703a9d7809530270a6b86bf">getCost</a>(); <a name="l01045"></a>01045 <a name="l01046"></a>01046 <span class="comment">// Make other opplans don't take this one as owner any more.</span> <a name="l01047"></a>01047 <span class="comment">// We restore the previous owner, which could be NULL.</span> <a name="l01048"></a>01048 data-><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#abfd84159a05362d21fe7321c4caef08f">curOwnerOpplan</a> = prev_owner_opplan; <a name="l01049"></a>01049 <a name="l01050"></a>01050 <span class="comment">// Message</span> <a name="l01051"></a>01051 <span class="keywordflow">if</span> (loglevel>1) <a name="l01052"></a>01052 <a class="code" href="a00257.html#a4af9f241e955122820c5e81ceb33edb5">logger</a> << <a class="code" href="a00087.html">indent</a>(oper-><a class="code" href="a00084.html#a44c879fcf3b6ae9193c393630e25fd13">getLevel</a>()) << <span class="stringliteral">" Alternate operation '"</span> << oper-><a class="code" href="a00182.html#a7416ca220c55147bc1276becc5b9de01">getName</a>() <a name="l01053"></a>01053 << <span class="stringliteral">"' answers: "</span> << 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> <a name="l01054"></a>01054 << <span class="stringliteral">" "</span> << 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="l01055"></a>01055 } <a name="l01056"></a>01056 <a name="l01057"></a>01057 <a name="l01058"></a>01058 } </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>