<!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: solver.h 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_18992602582d7248789456d5a25e14d1.html">include</a> » <a class="el" href="dir_d7b4472e78ce4d9f89572afca2a9177a.html">frepple</a> </div> </div> <div class="contents"> <h1>solver.h</h1><a href="a00239.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/include/frepple/solver.h $</span> <a name="l00003"></a>00003 <span class="comment"> version : $LastChangedRevision: 1315 $ $LastChangedBy: jdetaeye $</span> <a name="l00004"></a>00004 <span class="comment"> date : $LastChangedDate: 2010-07-17 18:08:53 +0200 (Sat, 17 Jul 2010) $</span> <a name="l00005"></a>00005 <span class="comment"> ***************************************************************************/</span> <a name="l00006"></a>00006 <a name="l00007"></a>00007 <span class="comment">/***************************************************************************</span> <a name="l00008"></a>00008 <span class="comment"> * *</span> <a name="l00009"></a>00009 <span class="comment"> * Copyright (C) 2007-2010 by Johan De Taeye *</span> <a name="l00010"></a>00010 <span class="comment"> * *</span> <a name="l00011"></a>00011 <span class="comment"> * This library is free software; you can redistribute it and/or modify it *</span> <a name="l00012"></a>00012 <span class="comment"> * under the terms of the GNU Lesser General Public License as published *</span> <a name="l00013"></a>00013 <span class="comment"> * by the Free Software Foundation; either version 2.1 of the License, or *</span> <a name="l00014"></a>00014 <span class="comment"> * (at your option) any later version. *</span> <a name="l00015"></a>00015 <span class="comment"> * *</span> <a name="l00016"></a>00016 <span class="comment"> * This library is distributed in the hope that it will be useful, *</span> <a name="l00017"></a>00017 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of *</span> <a name="l00018"></a>00018 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser *</span> <a name="l00019"></a>00019 <span class="comment"> * General Public License for more details. *</span> <a name="l00020"></a>00020 <span class="comment"> * *</span> <a name="l00021"></a>00021 <span class="comment"> * You should have received a copy of the GNU Lesser General Public *</span> <a name="l00022"></a>00022 <span class="comment"> * License along with this library; if not, write to the Free Software *</span> <a name="l00023"></a>00023 <span class="comment"> * Foundation Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 *</span> <a name="l00024"></a>00024 <span class="comment"> * USA *</span> <a name="l00025"></a>00025 <span class="comment"> * *</span> <a name="l00026"></a>00026 <span class="comment"> ***************************************************************************/</span> <a name="l00027"></a>00027 <a name="l00028"></a>00028 <span class="preprocessor">#ifndef SOLVER_H</span> <a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#define SOLVER_H</span> <a name="l00030"></a>00030 <span class="preprocessor"></span> <a name="l00031"></a>00031 <span class="preprocessor">#include "<a class="code" href="a00218.html">frepple/model.h</a>"</span> <a name="l00032"></a>00032 <span class="preprocessor">#ifndef DOXYGEN</span> <a name="l00033"></a>00033 <span class="preprocessor"></span><span class="preprocessor">#include <deque></span> <a name="l00034"></a>00034 <span class="preprocessor">#include <cmath></span> <a name="l00035"></a>00035 <span class="preprocessor">#endif</span> <a name="l00036"></a>00036 <span class="preprocessor"></span> <a name="l00037"></a>00037 <span class="keyword">namespace </span>frepple <a name="l00038"></a>00038 { <a name="l00039"></a>00039 <span class="comment"></span> <a name="l00040"></a>00040 <span class="comment">/** @brief This solver implements a heuristic algorithm for planning demands.</span> <a name="l00041"></a>00041 <span class="comment"> *</span> <a name="l00042"></a>00042 <span class="comment"> * One by one the demands are processed. The demand will consume step by step</span> <a name="l00043"></a>00043 <span class="comment"> * any upstream materials, respecting all constraints on its path.<br></span> <a name="l00044"></a>00044 <span class="comment"> * The solver supports all planning constraints as defined in Solver</span> <a name="l00045"></a>00045 <span class="comment"> * class.<br></span> <a name="l00046"></a>00046 <span class="comment"> * See the documentation of the different solve methods to understand the</span> <a name="l00047"></a>00047 <span class="comment"> * functionality in more detail.</span> <a name="l00048"></a>00048 <span class="comment"> *</span> <a name="l00049"></a>00049 <span class="comment"> * The logging levels have the following meaning:</span> <a name="l00050"></a>00050 <span class="comment"> * - 0: Silent operation. Default logging level.</span> <a name="l00051"></a>00051 <span class="comment"> * - 1: Show solver progress for each demand.</span> <a name="l00052"></a>00052 <span class="comment"> * - 2: Show the complete ask&reply communication of the solver.</span> <a name="l00053"></a>00053 <span class="comment"> * - 3: Trace the status of all entities.</span> <a name="l00054"></a>00054 <span class="comment"> */</span> <a name="l00055"></a><a class="code" href="a00173.html">00055</a> <span class="keyword">class </span><a class="code" href="a00173.html" title="This solver implements a heuristic algorithm for planning demands.">SolverMRP</a> : <span class="keyword">public</span> <a class="code" href="a00171.html" title="This class is an implementation of the &quot;visitor&quot; design pattern. It is...">Solver</a> <a name="l00056"></a>00056 { <a name="l00057"></a>00057 <span class="keyword">protected</span>:<span class="comment"></span> <a name="l00058"></a>00058 <span class="comment"> /** This variable stores the constraint which the solver should respect.</span> <a name="l00059"></a>00059 <span class="comment"> * By default no constraints are enabled. */</span> <a name="l00060"></a><a class="code" href="a00173.html#aba7f9976dce31fdd088ac17aec600fd9">00060</a> <span class="keywordtype">short</span> <a class="code" href="a00173.html#aba7f9976dce31fdd088ac17aec600fd9">constrts</a>; <a name="l00061"></a>00061 <span class="comment"></span> <a name="l00062"></a>00062 <span class="comment"> /** Behavior of this solver method is:</span> <a name="l00063"></a>00063 <span class="comment"> * - It will ask the consuming flows for the required quantity.</span> <a name="l00064"></a>00064 <span class="comment"> * - The quantity asked for takes into account the quantity_per of the</span> <a name="l00065"></a>00065 <span class="comment"> * producing flow.</span> <a name="l00066"></a>00066 <span class="comment"> * - The date asked for takes into account the post-operation time</span> <a name="l00067"></a>00067 <span class="comment"> * of the operation.</span> <a name="l00068"></a>00068 <span class="comment"> */</span> <a name="l00069"></a>00069 <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> <span class="keywordtype">void</span> <a class="code" href="a00173.html#aed1d08dd6ece530ed9229d463e31cca3">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>*, <span class="keywordtype">void</span>* = NULL); <a name="l00070"></a>00070 <span class="comment"></span> <a name="l00071"></a>00071 <span class="comment"> /** Behavior of this solver method is:</span> <a name="l00072"></a>00072 <span class="comment"> * - Asks each of the routing steps for the requested quantity, starting</span> <a name="l00073"></a>00073 <span class="comment"> * with the last routing step.<br></span> <a name="l00074"></a>00074 <span class="comment"> * The time requested for the operation is based on the start date of</span> <a name="l00075"></a>00075 <span class="comment"> * the next routing step.</span> <a name="l00076"></a>00076 <span class="comment"> */</span> <a name="l00077"></a>00077 <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> <span class="keywordtype">void</span> <a class="code" href="a00173.html#aed1d08dd6ece530ed9229d463e31cca3">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>*, <span class="keywordtype">void</span>* = NULL); <a name="l00078"></a>00078 <span class="comment"></span> <a name="l00079"></a>00079 <span class="comment"> /** Behavior of this solver method is:</span> <a name="l00080"></a>00080 <span class="comment"> * - The solver loops through each alternate operation in order of</span> <a name="l00081"></a>00081 <span class="comment"> * priority. On each alternate operation, the solver will try to plan</span> <a name="l00082"></a>00082 <span class="comment"> * the quantity that hasn't been planned on higher priority alternates.</span> <a name="l00083"></a>00083 <span class="comment"> * - As a special case, operations with zero priority are skipped in the</span> <a name="l00084"></a>00084 <span class="comment"> * loop. These operations are considered to be temporarily unavailable.</span> <a name="l00085"></a>00085 <span class="comment"> * - The requested operation can be planned over multiple alternates.</span> <a name="l00086"></a>00086 <span class="comment"> * We don't garantuee that a request is planned using a single alternate</span> <a name="l00087"></a>00087 <span class="comment"> * operation.</span> <a name="l00088"></a>00088 <span class="comment"> * - The solver properly considers the quantity_per of all flows producing</span> <a name="l00089"></a>00089 <span class="comment"> * into the requested buffer, if such a buffer is specified.</span> <a name="l00090"></a>00090 <span class="comment"> */</span> <a name="l00091"></a>00091 <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> <span class="keywordtype">void</span> <a class="code" href="a00173.html#aed1d08dd6ece530ed9229d463e31cca3">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>*,<span class="keywordtype">void</span>* = NULL); <a name="l00092"></a>00092 <span class="comment"></span> <a name="l00093"></a>00093 <span class="comment"> /** Behavior of this solver method:</span> <a name="l00094"></a>00094 <span class="comment"> * - No propagation to upstream buffers at all, even if a producing</span> <a name="l00095"></a>00095 <span class="comment"> * operation has been specified.</span> <a name="l00096"></a>00096 <span class="comment"> * - Always give an answer for the full quantity on the requested date.</span> <a name="l00097"></a>00097 <span class="comment"> */</span> <a name="l00098"></a>00098 <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> <span class="keywordtype">void</span> <a class="code" href="a00173.html#aed1d08dd6ece530ed9229d463e31cca3">solve</a>(<span class="keyword">const</span> <a class="code" href="a00010.html" title="This class represents a material buffer with an infinite supply of extra material...">BufferInfinite</a>*,<span class="keywordtype">void</span>* = NULL); <a name="l00099"></a>00099 <span class="comment"></span> <a name="l00100"></a>00100 <span class="comment"> /** Behavior of this solver method:</span> <a name="l00101"></a>00101 <span class="comment"> * - Consider 0 as the hard minimum limit. It is not possible</span> <a name="l00102"></a>00102 <span class="comment"> * to plan with a 'hard' safety stock reservation.</span> <a name="l00103"></a>00103 <span class="comment"> * - Minimum inventory is treated as a 'wish' inventory. When replenishing</span> <a name="l00104"></a>00104 <span class="comment"> * a buffer we try to satisfy the minimum target. If that turns out</span> <a name="l00105"></a>00105 <span class="comment"> * not to be possible we use whatever available supply for satisfying</span> <a name="l00106"></a>00106 <span class="comment"> * the demand first.</span> <a name="l00107"></a>00107 <span class="comment"> * - Planning for the minimum target is part of planning a demand. There</span> <a name="l00108"></a>00108 <span class="comment"> * is no planning run independent of demand to satisfy the minimum</span> <a name="l00109"></a>00109 <span class="comment"> * target.<br></span> <a name="l00110"></a>00110 <span class="comment"> * E.g. If a buffer has no demand on it, the solver won't try to</span> <a name="l00111"></a>00111 <span class="comment"> * replenish to the minimum target.<br></span> <a name="l00112"></a>00112 <span class="comment"> * E.g. If the minimum target increases after the latest date required</span> <a name="l00113"></a>00113 <span class="comment"> * for satisfying a certain demand that change will not be considered.</span> <a name="l00114"></a>00114 <span class="comment"> * - The solver completely ignores the maximum target.</span> <a name="l00115"></a>00115 <span class="comment"> */</span> <a name="l00116"></a>00116 <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> <span class="keywordtype">void</span> <a class="code" href="a00173.html#aed1d08dd6ece530ed9229d463e31cca3">solve</a>(<span class="keyword">const</span> <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>*, <span class="keywordtype">void</span>* = NULL); <a name="l00117"></a>00117 <span class="comment"></span> <a name="l00118"></a>00118 <span class="comment"> /** Behavior of this solver method:</span> <a name="l00119"></a>00119 <span class="comment"> * - When the inventory drops below the minimum inventory level, a new</span> <a name="l00120"></a>00120 <span class="comment"> * replenishment is triggered.</span> <a name="l00121"></a>00121 <span class="comment"> * The replenishment brings the inventory to the maximum level again.</span> <a name="l00122"></a>00122 <span class="comment"> * - The minimum and maximum inventory are soft-constraints. The actual</span> <a name="l00123"></a>00123 <span class="comment"> * inventory can go lower than the minimum or exceed the maximum.</span> <a name="l00124"></a>00124 <span class="comment"> * - The minimum, maximum and multiple size of the replenishment are</span> <a name="l00125"></a>00125 <span class="comment"> * hard constraints, and will always be respected.</span> <a name="l00126"></a>00126 <span class="comment"> * - A minimum and maximum interval between replenishment is also</span> <a name="l00127"></a>00127 <span class="comment"> * respected as a hard constraint.</span> <a name="l00128"></a>00128 <span class="comment"> * - No propagation to upstream buffers at all, even if a producing</span> <a name="l00129"></a>00129 <span class="comment"> * operation has been specified.</span> <a name="l00130"></a>00130 <span class="comment"> * - The minimum calendar isn't used by the solver.</span> <a name="l00131"></a>00131 <span class="comment"> *</span> <a name="l00132"></a>00132 <span class="comment"> * @todo Optimize the solver method as follows for the common case of infinite</span> <a name="l00133"></a>00133 <span class="comment"> * buying capability (ie no max quantity + min time):</span> <a name="l00134"></a>00134 <span class="comment"> * - beyond lead time: always reply OK, without rearranging the operation plans</span> <a name="l00135"></a>00135 <span class="comment"> * - at the end of the solver loop, we revisit the procurement buffers to establish</span> <a name="l00136"></a>00136 <span class="comment"> * the final purchasing profile</span> <a name="l00137"></a>00137 <span class="comment"> */</span> <a name="l00138"></a>00138 <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> <span class="keywordtype">void</span> <a class="code" href="a00173.html#aed1d08dd6ece530ed9229d463e31cca3">solve</a>(<span class="keyword">const</span> <a class="code" href="a00012.html" title="This class models a buffer that is replenish by an external supplier using a reorder-point...">BufferProcure</a>*, <span class="keywordtype">void</span>* = NULL); <a name="l00139"></a>00139 <span class="comment"></span> <a name="l00140"></a>00140 <span class="comment"> /** Behavior of this solver method:</span> <a name="l00141"></a>00141 <span class="comment"> * - This method simply passes on the request to the referenced buffer.</span> <a name="l00142"></a>00142 <span class="comment"> * It is called from a solve(Operation*) method and passes on the</span> <a name="l00143"></a>00143 <span class="comment"> * control to a solve(Buffer*) method.</span> <a name="l00144"></a>00144 <span class="comment"> * @see checkOperationMaterial</span> <a name="l00145"></a>00145 <span class="comment"> */</span> <a name="l00146"></a>00146 <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> <span class="keywordtype">void</span> <a class="code" href="a00173.html#aed1d08dd6ece530ed9229d463e31cca3">solve</a>(<span class="keyword">const</span> <a class="code" href="a00065.html" title="This class defines a material flow to/from a buffer, linked with an operation. This...">Flow</a>*, <span class="keywordtype">void</span>* = NULL); <a name="l00147"></a>00147 <span class="comment"></span> <a name="l00148"></a>00148 <span class="comment"> /** Behavior of this solver method:</span> <a name="l00149"></a>00149 <span class="comment"> * - The operationplan is checked for a capacity overload. When detected</span> <a name="l00150"></a>00150 <span class="comment"> * it is moved to an earlier date.</span> <a name="l00151"></a>00151 <span class="comment"> * - This move can be repeated until no capacity is found till a suitable</span> <a name="l00152"></a>00152 <span class="comment"> * time slot is found. If the fence and/or leadtime constraints are</span> <a name="l00153"></a>00153 <span class="comment"> * enabled they can restrict the feasible moving time.<br></span> <a name="l00154"></a>00154 <span class="comment"> * If a feasible timeslot is found, the method exits here.</span> <a name="l00155"></a>00155 <span class="comment"> * - If no suitable time slot can be found at all, the operation plan is</span> <a name="l00156"></a>00156 <span class="comment"> * put on its original date and we now try to move it to a feasible</span> <a name="l00157"></a>00157 <span class="comment"> * later date. Again, successive moves are possible till a suitable</span> <a name="l00158"></a>00158 <span class="comment"> * slot is found or till we reach the end of the horizon.</span> <a name="l00159"></a>00159 <span class="comment"> * The result of the search is returned as the answer-date to the</span> <a name="l00160"></a>00160 <span class="comment"> * solver.</span> <a name="l00161"></a>00161 <span class="comment"> */</span> <a name="l00162"></a>00162 <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> <span class="keywordtype">void</span> <a class="code" href="a00173.html#aed1d08dd6ece530ed9229d463e31cca3">solve</a>(<span class="keyword">const</span> <a class="code" href="a00156.html" title="This class represents a workcentre, a physical or logical representation of capacity...">Resource</a>*, <span class="keywordtype">void</span>* = NULL); <a name="l00163"></a>00163 <span class="comment"></span> <a name="l00164"></a>00164 <span class="comment"> /** Behavior of this solver method:</span> <a name="l00165"></a>00165 <span class="comment"> * - Always return OK.</span> <a name="l00166"></a>00166 <span class="comment"> */</span> <a name="l00167"></a>00167 <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> <span class="keywordtype">void</span> <a class="code" href="a00173.html#aed1d08dd6ece530ed9229d463e31cca3">solve</a>(<span class="keyword">const</span> <a class="code" href="a00158.html" title="This class represents a resource that&#39;ll never have any capacity shortage.">ResourceInfinite</a>*,<span class="keywordtype">void</span>* = NULL); <a name="l00168"></a>00168 <span class="comment"></span> <a name="l00169"></a>00169 <span class="comment"> /** Behavior of this solver method:</span> <a name="l00170"></a>00170 <span class="comment"> * - This method simply passes on the request to the referenced resource.</span> <a name="l00171"></a>00171 <span class="comment"> * With the current model structure it could easily be avoided (and</span> <a name="l00172"></a>00172 <span class="comment"> * thus gain a bit in performance), but we wanted to include it anyway</span> <a name="l00173"></a>00173 <span class="comment"> * to make the solver as generic and future-proof as possible.</span> <a name="l00174"></a>00174 <span class="comment"> * @see checkOperationCapacity</span> <a name="l00175"></a>00175 <span class="comment"> */</span> <a name="l00176"></a>00176 <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> <span class="keywordtype">void</span> <a class="code" href="a00173.html#aed1d08dd6ece530ed9229d463e31cca3">solve</a>(<span class="keyword">const</span> <a class="code" href="a00103.html" title="This class links a resource to a certain operation.">Load</a>*, <span class="keywordtype">void</span>* = NULL); <a name="l00177"></a>00177 <span class="comment"></span> <a name="l00178"></a>00178 <span class="comment"> /** Behavior of this solver method:</span> <a name="l00179"></a>00179 <span class="comment"> * - Respects the following demand planning policies:<br></span> <a name="l00180"></a>00180 <span class="comment"> * 1) Maximum allowed lateness</span> <a name="l00181"></a>00181 <span class="comment"> * 2) Minimum shipment quantity</span> <a name="l00182"></a>00182 <span class="comment"> * This method is normally called from within the main solve method, but</span> <a name="l00183"></a>00183 <span class="comment"> * it can also be called independently to plan a certain demand.</span> <a name="l00184"></a>00184 <span class="comment"> * @see solve</span> <a name="l00185"></a>00185 <span class="comment"> */</span> <a name="l00186"></a>00186 <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> <span class="keywordtype">void</span> <a class="code" href="a00173.html#aed1d08dd6ece530ed9229d463e31cca3">solve</a>(<span class="keyword">const</span> <a class="code" href="a00051.html" title="Represents the (independent) demand in the system. It can represent a customer order...">Demand</a>*, <span class="keywordtype">void</span>* = NULL); <a name="l00187"></a>00187 <a name="l00188"></a>00188 <span class="keyword">public</span>:<span class="comment"></span> <a name="l00189"></a>00189 <span class="comment"> /** This is the main solver method that will appropriately call the other</span> <a name="l00190"></a>00190 <span class="comment"> * solve methods.<br></span> <a name="l00191"></a>00191 <span class="comment"> * The demands in the model will all be sorted with the criteria defined in</span> <a name="l00192"></a>00192 <span class="comment"> * the demand_comparison() method. For each of demand the solve(Demand*)</span> <a name="l00193"></a>00193 <span class="comment"> * method is called to plan it.</span> <a name="l00194"></a>00194 <span class="comment"> */</span> <a name="l00195"></a>00195 <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> <span class="keywordtype">void</span> <a class="code" href="a00173.html#aed1d08dd6ece530ed9229d463e31cca3">solve</a>(<span class="keywordtype">void</span> *v = NULL); <a name="l00196"></a>00196 <span class="comment"></span> <a name="l00197"></a>00197 <span class="comment"> /** Constructor. */</span> <a name="l00198"></a><a class="code" href="a00173.html#a70364e4d12007366263a2b9e21cd0f71">00198</a> <a class="code" href="a00173.html#a70364e4d12007366263a2b9e21cd0f71">SolverMRP</a>(<span class="keyword">const</span> <span class="keywordtype">string</span>& n) : <a class="code" href="a00171.html" title="This class is an implementation of the &quot;visitor&quot; design pattern. It is...">Solver</a>(n), <a class="code" href="a00173.html#aba7f9976dce31fdd088ac17aec600fd9">constrts</a>(15), maxparallel(0), <a name="l00199"></a>00199 plantype(1), lazydelay(86400L), autocommit(true) <a name="l00200"></a>00200 {<a class="code" href="a00151.html#ae5f2cd7cfa5367e07b3de396fe98fbfd">initType</a>(<a class="code" href="a00173.html#a8b5bca7cd0d37393e1b20a5b08613a56">metadata</a>);} <a name="l00201"></a>00201 <span class="comment"></span> <a name="l00202"></a>00202 <span class="comment"> /** Destructor. */</span> <a name="l00203"></a><a class="code" href="a00173.html#a3ac05fe2e045f824ad11d3d36f25e4a6">00203</a> <span class="keyword">virtual</span> <a class="code" href="a00173.html#a3ac05fe2e045f824ad11d3d36f25e4a6">~SolverMRP</a>() {} <a name="l00204"></a>00204 <a name="l00205"></a>00205 <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> <span class="keywordtype">void</span> <a class="code" href="a00173.html#a8eefc9113d28d22731cbe1d3013f4948">writeElement</a>(<a class="code" href="a00189.html" title="Base class for writing XML formatted data to an output stream.">XMLOutput</a>*, <span class="keyword">const</span> <a class="code" href="a00096.html" title="This class defines a keyword for the frePPLe data model.">Keyword</a>&, <a class="code" href="a00257.html#a20c2c7e4c6b668e71c154ae3eb18f398">mode</a>=<a class="code" href="a00257.html#a20c2c7e4c6b668e71c154ae3eb18f398a976ad2abb9fd10ca7e48fdff6bef2341">DEFAULT</a>) <span class="keyword">const</span>; <a name="l00206"></a>00206 <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> <span class="keywordtype">void</span> <a class="code" href="a00173.html#ace591189b4cce0a842d7ca10a224988c">endElement</a>(<a class="code" href="a00186.html" title="This class will read in an XML-file and call the appropriate handler functions of...">XMLInput</a>& pIn, <span class="keyword">const</span> <a class="code" href="a00002.html" title="A class to model keyword instances.">Attribute</a>& pAttr, <span class="keyword">const</span> <a class="code" href="a00047.html" title="This abstract class represents a attribute and value pair for updating objects in...">DataElement</a>& pElement); <a name="l00207"></a>00207 <span class="keyword">virtual</span> <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> PyObject* <a class="code" href="a00173.html#a7cde63ea91a5b9a65e2454093c160b70">getattro</a>(<span class="keyword">const</span> <a class="code" href="a00002.html" title="A class to model keyword instances.">Attribute</a>&); <a name="l00208"></a>00208 <span class="keyword">virtual</span> <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> <span class="keywordtype">int</span> <a class="code" href="a00173.html#a0ff1f4d1312dca29b36e01ac052643ae">setattro</a>(<span class="keyword">const</span> <a class="code" href="a00002.html" title="A class to model keyword instances.">Attribute</a>&, <span class="keyword">const</span> <a class="code" href="a00154.html" title="This class handles two-way translation between the data types in C++ and Python.">PythonObject</a>&); <a name="l00209"></a>00209 <span class="keyword">static</span> <span class="keywordtype">int</span> <a class="code" href="a00173.html#a4789a0e47176fdf3dfdd30cc8965b08a">initialize</a>(); <a name="l00210"></a>00210 <a name="l00211"></a><a class="code" href="a00173.html#ae304221980e02fc4d5acca0618beddbb">00211</a> <span class="keyword">virtual</span> <span class="keyword">const</span> <a class="code" href="a00115.html" title="This class stores metadata about the classes in the library. The stored information...">MetaClass</a>& <a class="code" href="a00173.html#ae304221980e02fc4d5acca0618beddbb">getType</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> *<a class="code" href="a00173.html#a8b5bca7cd0d37393e1b20a5b08613a56">metadata</a>;} <a name="l00212"></a><a class="code" href="a00173.html#a8b5bca7cd0d37393e1b20a5b08613a56">00212</a> <span class="keyword">static</span> <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> <span class="keyword">const</span> <a class="code" href="a00115.html" title="This class stores metadata about the classes in the library. The stored information...">MetaClass</a>* <a class="code" href="a00173.html#a8b5bca7cd0d37393e1b20a5b08613a56">metadata</a>; <a name="l00213"></a><a class="code" href="a00173.html#a75ef102b24b5bc2f037c371141101176">00213</a> <span class="keyword">virtual</span> <span class="keywordtype">size_t</span> <a class="code" href="a00173.html#a75ef102b24b5bc2f037c371141101176">getSize</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> <span class="keyword">sizeof</span>(<a class="code" href="a00173.html" title="This solver implements a heuristic algorithm for planning demands.">SolverMRP</a>);} <a name="l00214"></a>00214 <span class="comment"></span> <a name="l00215"></a>00215 <span class="comment"> /** Static constant for the LEADTIME constraint type.<br></span> <a name="l00216"></a>00216 <span class="comment"> * The numeric value is 1.</span> <a name="l00217"></a>00217 <span class="comment"> * @see MATERIAL</span> <a name="l00218"></a>00218 <span class="comment"> * @see CAPACITY</span> <a name="l00219"></a>00219 <span class="comment"> * @see FENCE</span> <a name="l00220"></a>00220 <span class="comment"> */</span> <a name="l00221"></a><a class="code" href="a00173.html#a3367b53a8d0ce95af1e3c8aa284bed66">00221</a> <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">short</span> <a class="code" href="a00173.html#a3367b53a8d0ce95af1e3c8aa284bed66">LEADTIME</a> = 1; <a name="l00222"></a>00222 <span class="comment"></span> <a name="l00223"></a>00223 <span class="comment"> /** Static constant for the MATERIAL constraint type.<br></span> <a name="l00224"></a>00224 <span class="comment"> * The numeric value is 2.</span> <a name="l00225"></a>00225 <span class="comment"> * @see LEADTIME</span> <a name="l00226"></a>00226 <span class="comment"> * @see CAPACITY</span> <a name="l00227"></a>00227 <span class="comment"> * @see FENCE</span> <a name="l00228"></a>00228 <span class="comment"> */</span> <a name="l00229"></a><a class="code" href="a00173.html#a053bfcd159ef9a2311ddb545fa32bd36">00229</a> <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">short</span> <a class="code" href="a00173.html#a053bfcd159ef9a2311ddb545fa32bd36">MATERIAL</a> = 2; <a name="l00230"></a>00230 <span class="comment"></span> <a name="l00231"></a>00231 <span class="comment"> /** Static constant for the CAPACITY constraint type.<br></span> <a name="l00232"></a>00232 <span class="comment"> * The numeric value is 4.</span> <a name="l00233"></a>00233 <span class="comment"> * @see MATERIAL</span> <a name="l00234"></a>00234 <span class="comment"> * @see LEADTIME</span> <a name="l00235"></a>00235 <span class="comment"> * @see FENCE</span> <a name="l00236"></a>00236 <span class="comment"> */</span> <a name="l00237"></a><a class="code" href="a00173.html#a16373c09882eef654b42c433935356d3">00237</a> <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">short</span> <a class="code" href="a00173.html#a16373c09882eef654b42c433935356d3">CAPACITY</a> = 4; <a name="l00238"></a>00238 <span class="comment"></span> <a name="l00239"></a>00239 <span class="comment"> /** Static constant for the FENCE constraint type.<br></span> <a name="l00240"></a>00240 <span class="comment"> * The numeric value is 8.</span> <a name="l00241"></a>00241 <span class="comment"> * @see MATERIAL</span> <a name="l00242"></a>00242 <span class="comment"> * @see CAPACITY</span> <a name="l00243"></a>00243 <span class="comment"> * @see LEADTIME</span> <a name="l00244"></a>00244 <span class="comment"> */</span> <a name="l00245"></a><a class="code" href="a00173.html#a01576b564e09170b5537e1abad2f46f3">00245</a> <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">short</span> <a class="code" href="a00173.html#a01576b564e09170b5537e1abad2f46f3">FENCE</a> = 8; <a name="l00246"></a>00246 <span class="comment"></span> <a name="l00247"></a>00247 <span class="comment"> /** Update the constraints to be considered by this solver. This field may</span> <a name="l00248"></a>00248 <span class="comment"> * not be applicable for all solvers. */</span> <a name="l00249"></a><a class="code" href="a00173.html#a2a08ac5234b79aa2c1b2d846784f976c">00249</a> <span class="keywordtype">void</span> <a class="code" href="a00173.html#a2a08ac5234b79aa2c1b2d846784f976c">setConstraints</a>(<span class="keywordtype">short</span> i) {<a class="code" href="a00173.html#aba7f9976dce31fdd088ac17aec600fd9">constrts</a> = i;} <a name="l00250"></a>00250 <span class="comment"></span> <a name="l00251"></a>00251 <span class="comment"> /** Returns the constraints considered by the solve. */</span> <a name="l00252"></a><a class="code" href="a00173.html#a5af37d44aeae58f324d2b2b97eabef0f">00252</a> <span class="keywordtype">short</span> <a class="code" href="a00173.html#a5af37d44aeae58f324d2b2b97eabef0f">getConstraints</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> <a class="code" href="a00173.html#aba7f9976dce31fdd088ac17aec600fd9">constrts</a>;} <a name="l00253"></a>00253 <span class="comment"></span> <a name="l00254"></a>00254 <span class="comment"> /** Returns true if this solver respects the operation release fences.</span> <a name="l00255"></a>00255 <span class="comment"> * The solver isn't allowed to create any operation plans within the</span> <a name="l00256"></a>00256 <span class="comment"> * release fence.</span> <a name="l00257"></a>00257 <span class="comment"> */</span> <a name="l00258"></a><a class="code" href="a00173.html#a1e53acb4eafd521ea81a99f08e8e95ae">00258</a> <span class="keywordtype">bool</span> <a class="code" href="a00173.html#a1e53acb4eafd521ea81a99f08e8e95ae">isFenceConstrained</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> (<a class="code" href="a00173.html#aba7f9976dce31fdd088ac17aec600fd9">constrts</a> & <a class="code" href="a00173.html#a01576b564e09170b5537e1abad2f46f3">FENCE</a>)>0;} <a name="l00259"></a>00259 <span class="comment"></span> <a name="l00260"></a>00260 <span class="comment"> /** Returns true if the solver respects the current time of the plan.</span> <a name="l00261"></a>00261 <span class="comment"> * The solver isn't allowed to create any operation plans in the past.</span> <a name="l00262"></a>00262 <span class="comment"> */</span> <a name="l00263"></a><a class="code" href="a00173.html#a984cf92a5d2fdfbfe91f3d349fd903b2">00263</a> <span class="keywordtype">bool</span> <a class="code" href="a00173.html#a984cf92a5d2fdfbfe91f3d349fd903b2">isLeadtimeConstrained</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> (<a class="code" href="a00173.html#aba7f9976dce31fdd088ac17aec600fd9">constrts</a> & <a class="code" href="a00173.html#a3367b53a8d0ce95af1e3c8aa284bed66">LEADTIME</a>)>0;} <a name="l00264"></a>00264 <span class="comment"></span> <a name="l00265"></a>00265 <span class="comment"> /** Returns true if the solver respects the material procurement </span> <a name="l00266"></a>00266 <span class="comment"> * constraints on procurement buffers.</span> <a name="l00267"></a>00267 <span class="comment"> */</span> <a name="l00268"></a><a class="code" href="a00173.html#a8abcb4e32ffb3663bb1cf42d94c96ddc">00268</a> <span class="keywordtype">bool</span> <a class="code" href="a00173.html#a8abcb4e32ffb3663bb1cf42d94c96ddc">isMaterialConstrained</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> (<a class="code" href="a00173.html#aba7f9976dce31fdd088ac17aec600fd9">constrts</a> & <a class="code" href="a00173.html#a053bfcd159ef9a2311ddb545fa32bd36">MATERIAL</a>)>0;} <a name="l00269"></a>00269 <span class="comment"></span> <a name="l00270"></a>00270 <span class="comment"> /** Returns true if the solver respects capacity constraints. */</span> <a name="l00271"></a><a class="code" href="a00173.html#a390ddc1912146f9b835d154f77dc2d05">00271</a> <span class="keywordtype">bool</span> <a class="code" href="a00173.html#a390ddc1912146f9b835d154f77dc2d05">isCapacityConstrained</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> (<a class="code" href="a00173.html#aba7f9976dce31fdd088ac17aec600fd9">constrts</a> & <a class="code" href="a00173.html#a16373c09882eef654b42c433935356d3">CAPACITY</a>)>0;} <a name="l00272"></a>00272 <span class="comment"></span> <a name="l00273"></a>00273 <span class="comment"> /** Returns true if any constraint is relevant for the solver. */</span> <a name="l00274"></a><a class="code" href="a00173.html#a4bc4f05f9f0d4e153dde779a8fd4154f">00274</a> <span class="keywordtype">bool</span> <a class="code" href="a00173.html#a4bc4f05f9f0d4e153dde779a8fd4154f">isConstrained</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> <a class="code" href="a00173.html#aba7f9976dce31fdd088ac17aec600fd9">constrts</a>>0;} <a name="l00275"></a>00275 <span class="comment"></span> <a name="l00276"></a>00276 <span class="comment"> /** Returns the plan type:</span> <a name="l00277"></a>00277 <span class="comment"> * - 1: Constrained plan.<br></span> <a name="l00278"></a>00278 <span class="comment"> * This plan doesn't not violate any constraints.<br></span> <a name="l00279"></a>00279 <span class="comment"> * In case of material or capacity shortages the demand is delayed</span> <a name="l00280"></a>00280 <span class="comment"> * or planned short.</span> <a name="l00281"></a>00281 <span class="comment"> * - 2: Unconstrained plan with alternate search.<br></span> <a name="l00282"></a>00282 <span class="comment"> * This unconstrained plan leaves material, capacity and operation</span> <a name="l00283"></a>00283 <span class="comment"> * problems when shortages are found. Availability is searched across</span> <a name="l00284"></a>00284 <span class="comment"> * alternates and the remaining shortage is shown on the primary </span> <a name="l00285"></a>00285 <span class="comment"> * alternate.<br></span> <a name="l00286"></a>00286 <span class="comment"> * The demand is always fully met on time.</span> <a name="l00287"></a>00287 <span class="comment"> * - 3: Unconstrained plan without alternate search.<br></span> <a name="l00288"></a>00288 <span class="comment"> * This unconstrained plan leaves material, capacity and operation</span> <a name="l00289"></a>00289 <span class="comment"> * problems when shortages are found. It doesn't evaluate availability</span> <a name="l00290"></a>00290 <span class="comment"> * on alternates.<br></span> <a name="l00291"></a>00291 <span class="comment"> * The demand is always fully met on time.</span> <a name="l00292"></a>00292 <span class="comment"> */</span> <a name="l00293"></a><a class="code" href="a00173.html#aa79ce0df49103c6cc5088b161e79bda3">00293</a> <span class="keywordtype">short</span> <a class="code" href="a00173.html#aa79ce0df49103c6cc5088b161e79bda3">getPlanType</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> plantype;} <a name="l00294"></a>00294 <a name="l00295"></a><a class="code" href="a00173.html#ae75727c286b4ab0b5fe71d6fb25fac56">00295</a> <span class="keywordtype">void</span> <a class="code" href="a00173.html#ae75727c286b4ab0b5fe71d6fb25fac56">setPlanType</a>(<span class="keywordtype">short</span> b) {plantype = b;} <a name="l00296"></a>00296 <span class="comment"></span> <a name="l00297"></a>00297 <span class="comment"> /** This function defines the order in which the demands are being</span> <a name="l00298"></a>00298 <span class="comment"> * planned.<br></span> <a name="l00299"></a>00299 <span class="comment"> * The following sorting criteria are appplied in order:</span> <a name="l00300"></a>00300 <span class="comment"> * - demand priority: smaller priorities first</span> <a name="l00301"></a>00301 <span class="comment"> * - demand due date: earlier due dates first</span> <a name="l00302"></a>00302 <span class="comment"> * - demand quantity: smaller quantities first</span> <a name="l00303"></a>00303 <span class="comment"> */</span> <a name="l00304"></a>00304 <span class="keyword">static</span> <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> <span class="keywordtype">bool</span> <a class="code" href="a00173.html#a3a53347a65ba93402d3d1de0b14ce0e1">demand_comparison</a>(<span class="keyword">const</span> <a class="code" href="a00051.html" title="Represents the (independent) demand in the system. It can represent a customer order...">Demand</a>*, <span class="keyword">const</span> <a class="code" href="a00051.html" title="Represents the (independent) demand in the system. It can represent a customer order...">Demand</a>*); <a name="l00305"></a>00305 <span class="comment"></span> <a name="l00306"></a>00306 <span class="comment"> /** Update the number of parallel solver threads.<br></span> <a name="l00307"></a>00307 <span class="comment"> * The default value depends on whether the solver is run in verbose mode</span> <a name="l00308"></a>00308 <span class="comment"> * or not:</span> <a name="l00309"></a>00309 <span class="comment"> * - In normal mode the solver uses as many threads as specified by</span> <a name="l00310"></a>00310 <span class="comment"> * the environment variable NUMBER_OF_PROCESSORS.</span> <a name="l00311"></a>00311 <span class="comment"> * - In verbose mode the solver runs in a single thread to avoid</span> <a name="l00312"></a>00312 <span class="comment"> * mangling the debugging output of different threads.</span> <a name="l00313"></a>00313 <span class="comment"> */</span> <a name="l00314"></a><a class="code" href="a00173.html#ac65f4614ff1262897bebf56144ec4a4f">00314</a> <span class="keywordtype">void</span> <a class="code" href="a00173.html#ac65f4614ff1262897bebf56144ec4a4f">setMaxParallel</a>(<span class="keywordtype">int</span> i) <a name="l00315"></a>00315 { <a name="l00316"></a>00316 <span class="keywordflow">if</span> (i >= 1) maxparallel = i; <a name="l00317"></a>00317 <span class="keywordflow">else</span> <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 number of parallel solver threads"</span>); <a name="l00318"></a>00318 } <a name="l00319"></a>00319 <span class="comment"></span> <a name="l00320"></a>00320 <span class="comment"> /** Return the number of threads used for planning. */</span> <a name="l00321"></a><a class="code" href="a00173.html#a3678855c17eb7320e0b7eb0066e416c4">00321</a> <span class="keywordtype">int</span> <a class="code" href="a00173.html#a3678855c17eb7320e0b7eb0066e416c4">getMaxParallel</a>()<span class="keyword"> const</span> <a name="l00322"></a>00322 <span class="keyword"> </span>{ <a name="l00323"></a>00323 <span class="comment">// Or: Explicitly specified number of threads</span> <a name="l00324"></a>00324 <span class="keywordflow">if</span> (maxparallel) <span class="keywordflow">return</span> maxparallel; <a name="l00325"></a>00325 <span class="comment">// Or: Default number of threads</span> <a name="l00326"></a>00326 <span class="keywordflow">else</span> <span class="keywordflow">return</span> <a class="code" href="a00171.html#a7331226cd4ef515184dff2d118c43423">getLogLevel</a>()>0 ? 1 : Environment::getProcessors(); <a name="l00327"></a>00327 } <a name="l00328"></a>00328 <span class="comment"></span> <a name="l00329"></a>00329 <span class="comment"> /** Return the time increment between requests when the answered reply</span> <a name="l00330"></a>00330 <span class="comment"> * date isn't usable. */</span> <a name="l00331"></a><a class="code" href="a00173.html#a6cbfff22e0badfcd1bf5dd59b37ee4e8">00331</a> <a class="code" href="a00179.html" title="This class represents a time duration with an accuracy of one second.">TimePeriod</a> <a class="code" href="a00173.html#a6cbfff22e0badfcd1bf5dd59b37ee4e8">getLazyDelay</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> lazydelay;} <a name="l00332"></a>00332 <span class="comment"></span> <a name="l00333"></a>00333 <span class="comment"> /** Update the time increment between requests when the answered reply</span> <a name="l00334"></a>00334 <span class="comment"> * date isn't usable. */</span> <a name="l00335"></a><a class="code" href="a00173.html#a30901c61445056059017ca8450a91587">00335</a> <span class="keywordtype">void</span> <a class="code" href="a00173.html#a30901c61445056059017ca8450a91587">setLazyDelay</a>(<a class="code" href="a00179.html" title="This class represents a time duration with an accuracy of one second.">TimePeriod</a> l) <a name="l00336"></a>00336 { <a name="l00337"></a>00337 <span class="keywordflow">if</span> (l > 0L) lazydelay = l; <a name="l00338"></a>00338 <span class="keywordflow">else</span> <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 lazy delay"</span>); <a name="l00339"></a>00339 } <a name="l00340"></a>00340 <span class="comment"></span> <a name="l00341"></a>00341 <span class="comment"> /** Return whether or not we automatically commit the changes after</span> <a name="l00342"></a>00342 <span class="comment"> * planning a demand. */</span> <a name="l00343"></a><a class="code" href="a00173.html#afe90ff4ad851caa35b2e55b4bcd13ac8">00343</a> <span class="keywordtype">bool</span> <a class="code" href="a00173.html#afe90ff4ad851caa35b2e55b4bcd13ac8">getAutocommit</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> autocommit;} <a name="l00344"></a>00344 <span class="comment"></span> <a name="l00345"></a>00345 <span class="comment"> /** Update whether or not we automatically commit the changes after</span> <a name="l00346"></a>00346 <span class="comment"> * planning a demand. */</span> <a name="l00347"></a><a class="code" href="a00173.html#ae951a19e8064a82cc153c007232ef699">00347</a> <span class="keywordtype">void</span> <a class="code" href="a00173.html#ae951a19e8064a82cc153c007232ef699">setAutocommit</a>(<span class="keyword">const</span> <span class="keywordtype">bool</span> b) {autocommit = b;} <a name="l00348"></a>00348 <span class="comment"></span> <a name="l00349"></a>00349 <span class="comment"> /** Specify a Python function that is called before solving a flow. */</span> <a name="l00350"></a><a class="code" href="a00173.html#ad29440d03599171908fe82b63f97aab8">00350</a> <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> <span class="keywordtype">void</span> <a class="code" href="a00173.html#ad29440d03599171908fe82b63f97aab8">setUserExitFlow</a>(<span class="keyword">const</span> <span class="keywordtype">string</span>& n) {userexit_flow = n;} <a name="l00351"></a>00351 <span class="comment"></span> <a name="l00352"></a>00352 <span class="comment"> /** Specify a Python function that is called before solving a flow. */</span> <a name="l00353"></a><a class="code" href="a00173.html#a38dc8408b30f216ccdcc5b359209ca27">00353</a> <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> <span class="keywordtype">void</span> <a class="code" href="a00173.html#a38dc8408b30f216ccdcc5b359209ca27">setUserExitFlow</a>(PyObject* p) {userexit_flow = p;} <a name="l00354"></a>00354 <span class="comment"></span> <a name="l00355"></a>00355 <span class="comment"> /** Return the Python function that is called before solving a flow. */</span> <a name="l00356"></a><a class="code" href="a00173.html#ad622af357dee0cea251769851ce25d15">00356</a> <a class="code" href="a00152.html" title="This call is a wrapper around a Python function that can be called from the C++ code...">PythonFunction</a> <a class="code" href="a00173.html#ad622af357dee0cea251769851ce25d15">getUserExitFlow</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> userexit_flow;} <a name="l00357"></a>00357 <span class="comment"></span> <a name="l00358"></a>00358 <span class="comment"> /** Specify a Python function that is called before solving a demand. */</span> <a name="l00359"></a><a class="code" href="a00173.html#af09e81e3b2ea8c3f0c7b9022a617d146">00359</a> <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> <span class="keywordtype">void</span> <a class="code" href="a00173.html#af09e81e3b2ea8c3f0c7b9022a617d146">setUserExitDemand</a>(<span class="keyword">const</span> <span class="keywordtype">string</span>& n) {userexit_demand = n;} <a name="l00360"></a>00360 <span class="comment"></span> <a name="l00361"></a>00361 <span class="comment"> /** Specify a Python function that is called before solving a demand. */</span> <a name="l00362"></a><a class="code" href="a00173.html#a2415120269473d8306fe307bee588fd1">00362</a> <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> <span class="keywordtype">void</span> <a class="code" href="a00173.html#a2415120269473d8306fe307bee588fd1">setUserExitDemand</a>(PyObject* p) {userexit_demand = p;} <a name="l00363"></a>00363 <span class="comment"></span> <a name="l00364"></a>00364 <span class="comment"> /** Return the Python function that is called before solving a demand. */</span> <a name="l00365"></a><a class="code" href="a00173.html#a14b1cb5f34384352cf0851e7ad5154ae">00365</a> <a class="code" href="a00152.html" title="This call is a wrapper around a Python function that can be called from the C++ code...">PythonFunction</a> <a class="code" href="a00173.html#a14b1cb5f34384352cf0851e7ad5154ae">getUserExitDemand</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> userexit_demand;} <a name="l00366"></a>00366 <span class="comment"></span> <a name="l00367"></a>00367 <span class="comment"> /** Specify a Python function that is called before solving a buffer. */</span> <a name="l00368"></a><a class="code" href="a00173.html#aaff934ce3d755804b9bd48e54e9ebd3f">00368</a> <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> <span class="keywordtype">void</span> <a class="code" href="a00173.html#aaff934ce3d755804b9bd48e54e9ebd3f">setUserExitBuffer</a>(<span class="keyword">const</span> <span class="keywordtype">string</span>& n) {userexit_buffer = n;} <a name="l00369"></a>00369 <span class="comment"></span> <a name="l00370"></a>00370 <span class="comment"> /** Specify a Python function that is called before solving a buffer. */</span> <a name="l00371"></a><a class="code" href="a00173.html#aab43f9100d9214b09e084985ad74ed4a">00371</a> <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> <span class="keywordtype">void</span> <a class="code" href="a00173.html#aab43f9100d9214b09e084985ad74ed4a">setUserExitBuffer</a>(PyObject* p) {userexit_buffer = p;} <a name="l00372"></a>00372 <span class="comment"></span> <a name="l00373"></a>00373 <span class="comment"> /** Return the Python function that is called before solving a buffer. */</span> <a name="l00374"></a><a class="code" href="a00173.html#a1f39dd7ced78fa651731e05baa16fc0b">00374</a> <a class="code" href="a00152.html" title="This call is a wrapper around a Python function that can be called from the C++ code...">PythonFunction</a> <a class="code" href="a00173.html#a1f39dd7ced78fa651731e05baa16fc0b">getUserExitBuffer</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> userexit_buffer;} <a name="l00375"></a>00375 <span class="comment"></span> <a name="l00376"></a>00376 <span class="comment"> /** Specify a Python function that is called before solving a resource. */</span> <a name="l00377"></a><a class="code" href="a00173.html#aa0727c098fbe25ba45cb0ba19e2d148e">00377</a> <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> <span class="keywordtype">void</span> <a class="code" href="a00173.html#aa0727c098fbe25ba45cb0ba19e2d148e">setUserExitResource</a>(<span class="keyword">const</span> <span class="keywordtype">string</span>& n) {userexit_resource = n;} <a name="l00378"></a>00378 <span class="comment"></span> <a name="l00379"></a>00379 <span class="comment"> /** Specify a Python function that is called before solving a resource. */</span> <a name="l00380"></a><a class="code" href="a00173.html#a24e5339a80fd51a2e9dac1368cc7833d">00380</a> <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> <span class="keywordtype">void</span> <a class="code" href="a00173.html#a24e5339a80fd51a2e9dac1368cc7833d">setUserExitResource</a>(PyObject* p) {userexit_resource = p;} <a name="l00381"></a>00381 <span class="comment"></span> <a name="l00382"></a>00382 <span class="comment"> /** Return the Python function that is called before solving a resource. */</span> <a name="l00383"></a><a class="code" href="a00173.html#af2cab8daee66acd958c672860cf8cfa9">00383</a> <a class="code" href="a00152.html" title="This call is a wrapper around a Python function that can be called from the C++ code...">PythonFunction</a> <a class="code" href="a00173.html#af2cab8daee66acd958c672860cf8cfa9">getUserExitResource</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> userexit_resource;} <a name="l00384"></a>00384 <span class="comment"></span> <a name="l00385"></a>00385 <span class="comment"> /** Specify a Python function that is called before solving a operation. */</span> <a name="l00386"></a><a class="code" href="a00173.html#ab8793421e04af5750b8f21bf4bfd168d">00386</a> <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> <span class="keywordtype">void</span> <a class="code" href="a00173.html#ab8793421e04af5750b8f21bf4bfd168d">setUserExitOperation</a>(<span class="keyword">const</span> <span class="keywordtype">string</span>& n) {userexit_operation = n;} <a name="l00387"></a>00387 <span class="comment"></span> <a name="l00388"></a>00388 <span class="comment"> /** Specify a Python function that is called before solving a operation. */</span> <a name="l00389"></a><a class="code" href="a00173.html#a43f01241a8b9b53a0a66647f2b0a556a">00389</a> <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> <span class="keywordtype">void</span> <a class="code" href="a00173.html#a43f01241a8b9b53a0a66647f2b0a556a">setUserExitOperation</a>(PyObject* p) {userexit_operation = p;} <a name="l00390"></a>00390 <span class="comment"></span> <a name="l00391"></a>00391 <span class="comment"> /** Return the Python function that is called before solving a operation. */</span> <a name="l00392"></a><a class="code" href="a00173.html#a1f5a9da34c0d59bcb2ef6c8fad5d2140">00392</a> <a class="code" href="a00152.html" title="This call is a wrapper around a Python function that can be called from the C++ code...">PythonFunction</a> <a class="code" href="a00173.html#a1f5a9da34c0d59bcb2ef6c8fad5d2140">getUserExitOperation</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> userexit_operation;} <a name="l00393"></a>00393 <span class="comment"></span> <a name="l00394"></a>00394 <span class="comment"> /** Python method for running the solver. */</span> <a name="l00395"></a>00395 <span class="keyword">static</span> <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> PyObject* <a class="code" href="a00173.html#aed1d08dd6ece530ed9229d463e31cca3">solve</a>(PyObject*, PyObject*); <a name="l00396"></a>00396 <span class="comment"></span> <a name="l00397"></a>00397 <span class="comment"> /** Python method for commiting the plan changes. */</span> <a name="l00398"></a>00398 <span class="keyword">static</span> <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> PyObject* <a class="code" href="a00173.html#a68d0f5b398ced2a94c2495b09cdd2632">commit</a>(PyObject*, PyObject*); <a name="l00399"></a>00399 <span class="comment"></span> <a name="l00400"></a>00400 <span class="comment"> /** Python method for undoing the plan changes. */</span> <a name="l00401"></a>00401 <span class="keyword">static</span> <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> PyObject* <a class="code" href="a00173.html#aef91f162235173fcbd3a7e99c418a32c">undo</a>(PyObject*, PyObject*); <a name="l00402"></a>00402 <a name="l00403"></a>00403 <span class="keyword">private</span>: <a name="l00404"></a>00404 <span class="keyword">typedef</span> map < int, deque<Demand*>, less<int> > classified_demand; <a name="l00405"></a>00405 <span class="keyword">typedef</span> classified_demand::iterator cluster_iterator; <a name="l00406"></a>00406 classified_demand demands_per_cluster; <a name="l00407"></a>00407 <span class="comment"></span> <a name="l00408"></a>00408 <span class="comment"> /** Number of parallel solver threads.<br></span> <a name="l00409"></a>00409 <span class="comment"> * The default value depends on whether the solver is run in verbose mode</span> <a name="l00410"></a>00410 <span class="comment"> * or not:</span> <a name="l00411"></a>00411 <span class="comment"> * - In normal mode the solver uses NUMBER_OF_PROCESSORS threads.</span> <a name="l00412"></a>00412 <span class="comment"> * - In verbose mode the solver runs in a single thread to avoid</span> <a name="l00413"></a>00413 <span class="comment"> * mangling the debugging output of different threads.</span> <a name="l00414"></a>00414 <span class="comment"> */</span> <a name="l00415"></a>00415 <span class="keywordtype">int</span> maxparallel; <a name="l00416"></a>00416 <span class="comment"></span> <a name="l00417"></a>00417 <span class="comment"> /** Type of plan to be created. */</span> <a name="l00418"></a>00418 <span class="keywordtype">short</span> plantype; <a name="l00419"></a>00419 <span class="comment"></span> <a name="l00420"></a>00420 <span class="comment"> /** Time increments for a lazy replan.<br></span> <a name="l00421"></a>00421 <span class="comment"> * The solver is expected to return always a next-feasible date when the</span> <a name="l00422"></a>00422 <span class="comment"> * request can't be met. The solver can then retry the request with an</span> <a name="l00423"></a>00423 <span class="comment"> * updated request date. In some corner cases and in case of a bug it is</span> <a name="l00424"></a>00424 <span class="comment"> * possible that no valid date is returned. The solver will then try the</span> <a name="l00425"></a>00425 <span class="comment"> * request with a request date incremented by this value.<br></span> <a name="l00426"></a>00426 <span class="comment"> * The default value is 1 day.</span> <a name="l00427"></a>00427 <span class="comment"> */</span> <a name="l00428"></a>00428 <a class="code" href="a00179.html" title="This class represents a time duration with an accuracy of one second.">TimePeriod</a> lazydelay; <a name="l00429"></a>00429 <span class="comment"></span> <a name="l00430"></a>00430 <span class="comment"> /** Enable or disable automatically committing the changes in the plan</span> <a name="l00431"></a>00431 <span class="comment"> * after planning each demand.<br></span> <a name="l00432"></a>00432 <span class="comment"> * The flag is only respected when planning incremental changes, and</span> <a name="l00433"></a>00433 <span class="comment"> * is ignored when doing a complete replan.</span> <a name="l00434"></a>00434 <span class="comment"> */</span> <a name="l00435"></a>00435 <span class="keywordtype">bool</span> autocommit; <a name="l00436"></a>00436 <span class="comment"></span> <a name="l00437"></a>00437 <span class="comment"> /** A Python callback function that is called for each alternate</span> <a name="l00438"></a>00438 <span class="comment"> * flow. If the callback function returns false, that alternate</span> <a name="l00439"></a>00439 <span class="comment"> * flow is an invalid choice.</span> <a name="l00440"></a>00440 <span class="comment"> */</span> <a name="l00441"></a>00441 <a class="code" href="a00152.html" title="This call is a wrapper around a Python function that can be called from the C++ code...">PythonFunction</a> userexit_flow; <a name="l00442"></a>00442 <span class="comment"></span> <a name="l00443"></a>00443 <span class="comment"> /** A Python callback function that is called for each demand. The return</span> <a name="l00444"></a>00444 <span class="comment"> * value is not used.</span> <a name="l00445"></a>00445 <span class="comment"> */</span> <a name="l00446"></a>00446 <a class="code" href="a00152.html" title="This call is a wrapper around a Python function that can be called from the C++ code...">PythonFunction</a> userexit_demand; <a name="l00447"></a>00447 <span class="comment"></span> <a name="l00448"></a>00448 <span class="comment"> /** A Python callback function that is called for each buffer. The return</span> <a name="l00449"></a>00449 <span class="comment"> * value is not used.</span> <a name="l00450"></a>00450 <span class="comment"> */</span> <a name="l00451"></a>00451 <a class="code" href="a00152.html" title="This call is a wrapper around a Python function that can be called from the C++ code...">PythonFunction</a> userexit_buffer; <a name="l00452"></a>00452 <span class="comment"></span> <a name="l00453"></a>00453 <span class="comment"> /** A Python callback function that is called for each resource. The return</span> <a name="l00454"></a>00454 <span class="comment"> * value is not used.</span> <a name="l00455"></a>00455 <span class="comment"> */</span> <a name="l00456"></a>00456 <a class="code" href="a00152.html" title="This call is a wrapper around a Python function that can be called from the C++ code...">PythonFunction</a> userexit_resource; <a name="l00457"></a>00457 <span class="comment"></span> <a name="l00458"></a>00458 <span class="comment"> /** A Python callback function that is called for each operation. The return</span> <a name="l00459"></a>00459 <span class="comment"> * value is not used.</span> <a name="l00460"></a>00460 <span class="comment"> */</span> <a name="l00461"></a>00461 <a class="code" href="a00152.html" title="This call is a wrapper around a Python function that can be called from the C++ code...">PythonFunction</a> userexit_operation; <a name="l00462"></a>00462 <a name="l00463"></a>00463 <span class="keyword">protected</span>:<span class="comment"></span> <a name="l00464"></a>00464 <span class="comment"> /** @brief This class is used to store the solver status during the</span> <a name="l00465"></a>00465 <span class="comment"> * ask-reply calls of the solver.</span> <a name="l00466"></a>00466 <span class="comment"> */</span> <a name="l00467"></a><a class="code" href="a00175.html">00467</a> <span class="keyword">struct </span><a class="code" href="a00175.html" title="This class is used to store the solver status during the ask-reply calls of the solver...">State</a> <a name="l00468"></a>00468 {<span class="comment"></span> <a name="l00469"></a>00469 <span class="comment"> /** Points to the demand being planned.<br></span> <a name="l00470"></a>00470 <span class="comment"> * This field is only non-null when planning the delivery operation. </span> <a name="l00471"></a>00471 <span class="comment"> */</span> <a name="l00472"></a><a class="code" href="a00175.html#a4feb35f2632149a1fa7828750a2f61b5">00472</a> <a class="code" href="a00051.html" title="Represents the (independent) demand in the system. It can represent a customer order...">Demand</a>* <a class="code" href="a00175.html#a4feb35f2632149a1fa7828750a2f61b5">curDemand</a>; <a name="l00473"></a>00473 <span class="comment"></span> <a name="l00474"></a>00474 <span class="comment"> /** Points to the current owner operationplan. This is used when</span> <a name="l00475"></a>00475 <span class="comment"> * operations are nested. */</span> <a name="l00476"></a><a class="code" href="a00175.html#abfd84159a05362d21fe7321c4caef08f">00476</a> <a class="code" href="a00125.html" title="An operationplan is the key dynamic element of a plan. It represents a certain quantity...">OperationPlan</a>* <a class="code" href="a00175.html#abfd84159a05362d21fe7321c4caef08f">curOwnerOpplan</a>; <a name="l00477"></a>00477 <span class="comment"></span> <a name="l00478"></a>00478 <span class="comment"> /** Points to the current buffer. */</span> <a name="l00479"></a><a class="code" href="a00175.html#a2f03f32d577521909343d06b884d7081">00479</a> <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>* <a class="code" href="a00175.html#a2f03f32d577521909343d06b884d7081">curBuffer</a>; <a name="l00480"></a>00480 <span class="comment"></span> <a name="l00481"></a>00481 <span class="comment"> /** A flag to force the resource solver to move the operationplan to</span> <a name="l00482"></a>00482 <span class="comment"> * a later date where it is feasible.<br></span> <a name="l00483"></a>00483 <span class="comment"> * Admittedly this is an ugly hack...</span> <a name="l00484"></a>00484 <span class="comment"> */</span> <a name="l00485"></a><a class="code" href="a00175.html#a745021223790b651b7d79c41418cb198">00485</a> <span class="keywordtype">bool</span> <a class="code" href="a00175.html#a745021223790b651b7d79c41418cb198">forceLate</a>; <a name="l00486"></a>00486 <span class="comment"></span> <a name="l00487"></a>00487 <span class="comment"> /** This is the quantity we are asking for. */</span> <a name="l00488"></a><a class="code" href="a00175.html#adf7c858a404b725f2f2c67648300f89b">00488</a> <span class="keywordtype">double</span> <a class="code" href="a00175.html#adf7c858a404b725f2f2c67648300f89b">q_qty</a>; <a name="l00489"></a>00489 <span class="comment"></span> <a name="l00490"></a>00490 <span class="comment"> /** This is the date we are asking for. */</span> <a name="l00491"></a><a class="code" href="a00175.html#a658c5379af8ec535090a96dd969f1fc3">00491</a> <a class="code" href="a00049.html" title="This class represents a date and time with an accuracy of one second.">Date</a> <a class="code" href="a00175.html#a658c5379af8ec535090a96dd969f1fc3">q_date</a>; <a name="l00492"></a>00492 <span class="comment"></span> <a name="l00493"></a>00493 <span class="comment"> /** This is the maximum date we are asking for.<br></span> <a name="l00494"></a>00494 <span class="comment"> * In case of a post-operation time there is a difference between</span> <a name="l00495"></a>00495 <span class="comment"> * q_date and q_date_max.</span> <a name="l00496"></a>00496 <span class="comment"> */</span> <a name="l00497"></a><a class="code" href="a00175.html#a2627254734463aaa8f0f177bf153e39f">00497</a> <a class="code" href="a00049.html" title="This class represents a date and time with an accuracy of one second.">Date</a> <a class="code" href="a00175.html#a2627254734463aaa8f0f177bf153e39f">q_date_max</a>; <a name="l00498"></a>00498 <span class="comment"></span> <a name="l00499"></a>00499 <span class="comment"> /** This is the quantity we can get by the requested Date. */</span> <a name="l00500"></a><a class="code" href="a00175.html#af34ccc319ed0bd6bb387353e0968e622">00500</a> <span class="keywordtype">double</span> <a class="code" href="a00175.html#af34ccc319ed0bd6bb387353e0968e622">a_qty</a>; <a name="l00501"></a>00501 <span class="comment"></span> <a name="l00502"></a>00502 <span class="comment"> /** This is the Date when we can get extra availability. */</span> <a name="l00503"></a><a class="code" href="a00175.html#ab56b3877ddc206e8817f04186c0e47a8">00503</a> <a class="code" href="a00049.html" title="This class represents a date and time with an accuracy of one second.">Date</a> <a class="code" href="a00175.html#ab56b3877ddc206e8817f04186c0e47a8">a_date</a>; <a name="l00504"></a>00504 <span class="comment"></span> <a name="l00505"></a>00505 <span class="comment"> /** This is a pointer to a LoadPlan. It is used for communication</span> <a name="l00506"></a>00506 <span class="comment"> * between the Operation-Solver and the Resource-Solver. */</span> <a name="l00507"></a><a class="code" href="a00175.html#a0184b7e1575ac6c79333fcefa2baee5d">00507</a> <a class="code" href="a00105.html" title="This class represents the resource capacity of an operationplan.">LoadPlan</a>* <a class="code" href="a00175.html#a0184b7e1575ac6c79333fcefa2baee5d">q_loadplan</a>; <a name="l00508"></a>00508 <span class="comment"></span> <a name="l00509"></a>00509 <span class="comment"> /** This is a pointer to a FlowPlan. It is used for communication</span> <a name="l00510"></a>00510 <span class="comment"> * between the Operation-Solver and the Buffer-Solver. */</span> <a name="l00511"></a><a class="code" href="a00175.html#a012238f00ed4e3db77e711848f257f74">00511</a> <a class="code" href="a00068.html" title="A flowplan represents a planned material flow in or out of a buffer.">FlowPlan</a>* <a class="code" href="a00175.html#a012238f00ed4e3db77e711848f257f74">q_flowplan</a>; <a name="l00512"></a>00512 <span class="comment"></span> <a name="l00513"></a>00513 <span class="comment"> /** A pointer to an operationplan currently being solved. */</span> <a name="l00514"></a><a class="code" href="a00175.html#add71467b24ef4e36294d582d0f1a08f8">00514</a> <a class="code" href="a00125.html" title="An operationplan is the key dynamic element of a plan. It represents a certain quantity...">OperationPlan</a>* <a class="code" href="a00175.html#add71467b24ef4e36294d582d0f1a08f8">q_operationplan</a>; <a name="l00515"></a>00515 <span class="comment"></span> <a name="l00516"></a>00516 <span class="comment"> /** Cost of the reply.<br></span> <a name="l00517"></a>00517 <span class="comment"> * Only the direct cost should be returned in this field.</span> <a name="l00518"></a>00518 <span class="comment"> */</span> <a name="l00519"></a><a class="code" href="a00175.html#aa2e444a8091c86f71bbcd6d076c6c574">00519</a> <span class="keywordtype">double</span> <a class="code" href="a00175.html#aa2e444a8091c86f71bbcd6d076c6c574">a_cost</a>; <a name="l00520"></a>00520 <span class="comment"></span> <a name="l00521"></a>00521 <span class="comment"> /** Penalty associated with the reply.<br></span> <a name="l00522"></a>00522 <span class="comment"> * This field contains indirect costs and other penalties that are</span> <a name="l00523"></a>00523 <span class="comment"> * not strictly related to the request. Examples are setup costs,</span> <a name="l00524"></a>00524 <span class="comment"> * inventory carrying costs, ...</span> <a name="l00525"></a>00525 <span class="comment"> */</span> <a name="l00526"></a><a class="code" href="a00175.html#ae007a7c0a1074c1fc1dfe9c5eeedcc0e">00526</a> <span class="keywordtype">double</span> <a class="code" href="a00175.html#ae007a7c0a1074c1fc1dfe9c5eeedcc0e">a_penalty</a>; <a name="l00527"></a>00527 }; <a name="l00528"></a>00528 <span class="comment"></span> <a name="l00529"></a>00529 <span class="comment"> /** @brief This class is a helper class of the SolverMRP class.</span> <a name="l00530"></a>00530 <span class="comment"> *</span> <a name="l00531"></a>00531 <span class="comment"> * It stores the solver state maintained by each solver thread.</span> <a name="l00532"></a>00532 <span class="comment"> * @see SolverMRP</span> <a name="l00533"></a>00533 <span class="comment"> */</span> <a name="l00534"></a><a class="code" href="a00174.html">00534</a> <span class="keyword">class </span><a class="code" href="a00174.html" title="This class is a helper class of the SolverMRP class.">SolverMRPdata</a> : <span class="keyword">public</span> <a class="code" href="a00029.html" title="A container command to group a series of commands together.">CommandList</a> <a name="l00535"></a>00535 { <a name="l00536"></a><a class="code" href="a00174.html#a422d4ff7cfe9cadaaf996aa8ae53ec52">00536</a> <span class="keyword">friend</span> <span class="keyword">class </span><a class="code" href="a00173.html" title="This solver implements a heuristic algorithm for planning demands.">SolverMRP</a>; <a name="l00537"></a>00537 <span class="keyword">public</span>:<span class="comment"></span> <a name="l00538"></a>00538 <span class="comment"> /** Return the solver. */</span> <a name="l00539"></a><a class="code" href="a00174.html#a1d6f62b1c53725b796ea1c4f8843b85d">00539</a> <a class="code" href="a00173.html" title="This solver implements a heuristic algorithm for planning demands.">SolverMRP</a>* <a class="code" href="a00174.html#a1d6f62b1c53725b796ea1c4f8843b85d">getSolver</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> sol;} <a name="l00540"></a>00540 <span class="comment"></span> <a name="l00541"></a>00541 <span class="comment"> /** Constructor. */</span> <a name="l00542"></a><a class="code" href="a00174.html#a664bd9c338026b290eb6ae0d5bede25d">00542</a> <a class="code" href="a00174.html#a664bd9c338026b290eb6ae0d5bede25d">SolverMRPdata</a>(<a class="code" href="a00173.html" title="This solver implements a heuristic algorithm for planning demands.">SolverMRP</a>* s = NULL, <span class="keywordtype">int</span> c = 0, deque<Demand*>* d = NULL) <a name="l00543"></a>00543 : sol(s), cluster(c), demands(d), constrainedPlanning(true), <a name="l00544"></a>00544 <a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>(statestack), <a class="code" href="a00174.html#ae5186f8cb969f0a29000927df25ce66d">prevstate</a>(statestack-1) {} <a name="l00545"></a>00545 <span class="comment"></span> <a name="l00546"></a>00546 <span class="comment"> /** Verbose mode is inherited from the solver. */</span> <a name="l00547"></a><a class="code" href="a00174.html#a57e1ece095107af5bc03387ba117b867">00547</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">short</span> <a class="code" href="a00174.html#a57e1ece095107af5bc03387ba117b867">getLogLevel</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> sol ? sol-><a class="code" href="a00171.html#a7331226cd4ef515184dff2d118c43423">getLogLevel</a>() : 0;} <a name="l00548"></a>00548 <span class="comment"></span> <a name="l00549"></a>00549 <span class="comment"> /** This function runs a single planning thread. Such a thread will loop</span> <a name="l00550"></a>00550 <span class="comment"> * through the following steps:</span> <a name="l00551"></a>00551 <span class="comment"> * - Use the method next_cluster() to find another unplanned cluster.</span> <a name="l00552"></a>00552 <span class="comment"> * - Exit the thread if no more cluster is found.</span> <a name="l00553"></a>00553 <span class="comment"> * - Sort all demands in the cluster, using the demand_comparison()</span> <a name="l00554"></a>00554 <span class="comment"> * method.</span> <a name="l00555"></a>00555 <span class="comment"> * - Loop through the sorted list of demands and plan each of them.</span> <a name="l00556"></a>00556 <span class="comment"> * During planning the demands exceptions are caught, and the</span> <a name="l00557"></a>00557 <span class="comment"> * planning loop will simply move on to the next demand.</span> <a name="l00558"></a>00558 <span class="comment"> * In this way, an error in a part of the model doesn't ruin the</span> <a name="l00559"></a>00559 <span class="comment"> * complete plan.</span> <a name="l00560"></a>00560 <span class="comment"> * @see demand_comparison</span> <a name="l00561"></a>00561 <span class="comment"> * @see next_cluster</span> <a name="l00562"></a>00562 <span class="comment"> */</span> <a name="l00563"></a>00563 <span class="keyword">virtual</span> <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> <span class="keywordtype">void</span> <a class="code" href="a00174.html#acc70df491327f7ca8e3f7f2f8fe59305">execute</a>(); <a name="l00564"></a>00564 <a name="l00565"></a><a class="code" href="a00174.html#a62e3658a9cd13d7d059b10016e1aea04">00565</a> <span class="keyword">virtual</span> <span class="keyword">const</span> <a class="code" href="a00115.html" title="This class stores metadata about the classes in the library. The stored information...">MetaClass</a>& <a class="code" href="a00174.html#a62e3658a9cd13d7d059b10016e1aea04">getType</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> *<a class="code" href="a00173.html#a8b5bca7cd0d37393e1b20a5b08613a56">SolverMRP::metadata</a>;} <a name="l00566"></a><a class="code" href="a00174.html#a32aafa0108de9b858757a841264de27c">00566</a> <span class="keyword">virtual</span> <span class="keywordtype">size_t</span> <a class="code" href="a00174.html#a32aafa0108de9b858757a841264de27c">getSize</a>()<span class="keyword"> const </span>{<span class="keywordflow">return</span> <span class="keyword">sizeof</span>(<a class="code" href="a00174.html" title="This class is a helper class of the SolverMRP class.">SolverMRPdata</a>);} <a name="l00567"></a>00567 <a name="l00568"></a><a class="code" href="a00174.html#ae4ba2e9c29cecac8c2575e3325aef863">00568</a> <span class="keywordtype">bool</span> <a class="code" href="a00174.html#ae4ba2e9c29cecac8c2575e3325aef863">getVerbose</a>()<span class="keyword"> const</span> <a name="l00569"></a>00569 <span class="keyword"> </span>{ <a name="l00570"></a>00570 <span class="keywordflow">throw</span> <a class="code" href="a00111.html" title="An exception of this type is thrown when the library gets in an inconsistent state...">LogicException</a>(<span class="stringliteral">"Use the method SolverMRPdata::getLogLevel() instead of SolverMRPdata::getVerbose()"</span>); <a name="l00571"></a>00571 } <a name="l00572"></a>00572 <span class="comment"></span> <a name="l00573"></a>00573 <span class="comment"> /** Add a new state to the status stack. */</span> <a name="l00574"></a><a class="code" href="a00174.html#a99c25a0cbb86773a59443cc81e9d915e">00574</a> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="a00174.html#a99c25a0cbb86773a59443cc81e9d915e">push</a>(<span class="keywordtype">double</span> q = 0.0, <a class="code" href="a00049.html" title="This class represents a date and time with an accuracy of one second.">Date</a> d = Date::infiniteFuture) <a name="l00575"></a>00575 { <a name="l00576"></a>00576 <span class="keywordflow">if</span> (<a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a> >= statestack + MAXSTATES) <a name="l00577"></a>00577 <span class="keywordflow">throw</span> <a class="code" href="a00162.html" title="An exception of this type is thrown when the library runs into problems that are...">RuntimeException</a>(<span class="stringliteral">"Maximum recursion depth exceeded"</span>); <a name="l00578"></a>00578 ++<a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>; <a name="l00579"></a>00579 ++<a class="code" href="a00174.html#ae5186f8cb969f0a29000927df25ce66d">prevstate</a>; <a name="l00580"></a>00580 <a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#adf7c858a404b725f2f2c67648300f89b">q_qty</a> = q; <a name="l00581"></a>00581 <a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#a658c5379af8ec535090a96dd969f1fc3">q_date</a> = d; <a name="l00582"></a>00582 <a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#abfd84159a05362d21fe7321c4caef08f">curOwnerOpplan</a> = NULL; <a name="l00583"></a>00583 <a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#a0184b7e1575ac6c79333fcefa2baee5d">q_loadplan</a> = NULL; <a name="l00584"></a>00584 <a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#a012238f00ed4e3db77e711848f257f74">q_flowplan</a> = NULL; <a name="l00585"></a>00585 <a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#add71467b24ef4e36294d582d0f1a08f8">q_operationplan</a> = NULL; <a name="l00586"></a>00586 <a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#a4feb35f2632149a1fa7828750a2f61b5">curDemand</a> = NULL; <a name="l00587"></a>00587 <a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#aa2e444a8091c86f71bbcd6d076c6c574">a_cost</a> = 0.0; <a name="l00588"></a>00588 <a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>-><a class="code" href="a00175.html#ae007a7c0a1074c1fc1dfe9c5eeedcc0e">a_penalty</a> = 0.0; <a name="l00589"></a>00589 } <a name="l00590"></a>00590 <span class="comment"></span> <a name="l00591"></a>00591 <span class="comment"> /** Removes a state from the status stack. */</span> <a name="l00592"></a><a class="code" href="a00174.html#a8f732ee498931ff8220a6392c68839e1">00592</a> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="a00174.html#a8f732ee498931ff8220a6392c68839e1">pop</a>() <a name="l00593"></a>00593 { <a name="l00594"></a>00594 <span class="keywordflow">if</span> (--<a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a> < statestack) <a name="l00595"></a>00595 <span class="keywordflow">throw</span> <a class="code" href="a00111.html" title="An exception of this type is thrown when the library gets in an inconsistent state...">LogicException</a>(<span class="stringliteral">"State stack empty"</span>); <a name="l00596"></a>00596 --<a class="code" href="a00174.html#ae5186f8cb969f0a29000927df25ce66d">prevstate</a>; <a name="l00597"></a>00597 } <a name="l00598"></a>00598 <a name="l00599"></a>00599 <span class="keyword">private</span>: <a name="l00600"></a>00600 <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">int</span> MAXSTATES = 256; <a name="l00601"></a>00601 <span class="comment"></span> <a name="l00602"></a>00602 <span class="comment"> /** Points to the solver. */</span> <a name="l00603"></a>00603 <a class="code" href="a00173.html" title="This solver implements a heuristic algorithm for planning demands.">SolverMRP</a>* sol; <a name="l00604"></a>00604 <span class="comment"></span> <a name="l00605"></a>00605 <span class="comment"> /** An identifier of the cluster being replanned. Note that it isn't</span> <a name="l00606"></a>00606 <span class="comment"> * always the complete cluster that is being planned.</span> <a name="l00607"></a>00607 <span class="comment"> */</span> <a name="l00608"></a>00608 <span class="keywordtype">int</span> cluster; <a name="l00609"></a>00609 <span class="comment"></span> <a name="l00610"></a>00610 <span class="comment"> /** A deque containing all demands to be (re-)planned. */</span> <a name="l00611"></a>00611 deque<Demand*>* demands; <a name="l00612"></a>00612 <span class="comment"></span> <a name="l00613"></a>00613 <span class="comment"> /** Stack of solver status information. */</span> <a name="l00614"></a>00614 <a class="code" href="a00175.html" title="This class is used to store the solver status during the ask-reply calls of the solver...">State</a> statestack[MAXSTATES]; <a name="l00615"></a>00615 <span class="comment"></span> <a name="l00616"></a>00616 <span class="comment"> /** True when planning in constrained mode. */</span> <a name="l00617"></a>00617 <span class="keywordtype">bool</span> constrainedPlanning; <a name="l00618"></a>00618 <span class="comment"></span> <a name="l00619"></a>00619 <span class="comment"> /** Flags whether or not constraints are being tracked. */</span> <a name="l00620"></a>00620 <span class="keywordtype">bool</span> logConstraints; <a name="l00621"></a>00621 <span class="comment"></span> <a name="l00622"></a>00622 <span class="comment"> /** Points to the demand being planned. */</span> <a name="l00623"></a>00623 <a class="code" href="a00051.html" title="Represents the (independent) demand in the system. It can represent a customer order...">Demand</a>* planningDemand; <a name="l00624"></a>00624 <a name="l00625"></a>00625 <span class="keyword">public</span>:<span class="comment"></span> <a name="l00626"></a>00626 <span class="comment"> /** Pointer to the current solver status. */</span> <a name="l00627"></a><a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">00627</a> <a class="code" href="a00175.html" title="This class is used to store the solver status during the ask-reply calls of the solver...">State</a>* <a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>; <a name="l00628"></a>00628 <span class="comment"></span> <a name="l00629"></a>00629 <span class="comment"> /** Pointer to the solver status one level higher on the stack. */</span> <a name="l00630"></a><a class="code" href="a00174.html#ae5186f8cb969f0a29000927df25ce66d">00630</a> <a class="code" href="a00175.html" title="This class is used to store the solver status during the ask-reply calls of the solver...">State</a>* <a class="code" href="a00174.html#ae5186f8cb969f0a29000927df25ce66d">prevstate</a>; <a name="l00631"></a>00631 }; <a name="l00632"></a>00632 <span class="comment"></span> <a name="l00633"></a>00633 <span class="comment"> /** When autocommit is switched off, this command structure will contain</span> <a name="l00634"></a>00634 <span class="comment"> * all plan changes.</span> <a name="l00635"></a>00635 <span class="comment"> */</span> <a name="l00636"></a><a class="code" href="a00173.html#a2c81fc731c11b888376e05e8e6068ef8">00636</a> <a class="code" href="a00174.html" title="This class is a helper class of the SolverMRP class.">SolverMRPdata</a> <a class="code" href="a00173.html#a2c81fc731c11b888376e05e8e6068ef8">commands</a>; <a name="l00637"></a>00637 <span class="comment"></span> <a name="l00638"></a>00638 <span class="comment"> /** This function will check all constraints for an operationplan</span> <a name="l00639"></a>00639 <span class="comment"> * and propagate it upstream. The check does NOT check eventual</span> <a name="l00640"></a>00640 <span class="comment"> * sub operationplans.<br></span> <a name="l00641"></a>00641 <span class="comment"> * The return value is a flag whether the operationplan is</span> <a name="l00642"></a>00642 <span class="comment"> * acceptable (sometimes in reduced quantity) or not.</span> <a name="l00643"></a>00643 <span class="comment"> */</span> <a name="l00644"></a>00644 <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> <span class="keywordtype">bool</span> <a class="code" href="a00173.html#ab41595b46bdbc8b508b9d7dedad0362f">checkOperation</a>(<a class="code" href="a00125.html" title="An operationplan is the key dynamic element of a plan. It represents a certain quantity...">OperationPlan</a>*, <a class="code" href="a00174.html" title="This class is a helper class of the SolverMRP class.">SolverMRPdata</a>& data); <a name="l00645"></a>00645 <span class="comment"></span> <a name="l00646"></a>00646 <span class="comment"> /** Verifies whether this operationplan violates the leadtime</span> <a name="l00647"></a>00647 <span class="comment"> * constraints. */</span> <a name="l00648"></a>00648 <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> <span class="keywordtype">bool</span> <a class="code" href="a00173.html#a1be57e20c66257efcc51c61669bdec1c">checkOperationLeadtime</a>(<a class="code" href="a00125.html" title="An operationplan is the key dynamic element of a plan. It represents a certain quantity...">OperationPlan</a>*, <a class="code" href="a00174.html" title="This class is a helper class of the SolverMRP class.">SolverMRPdata</a>&, <span class="keywordtype">bool</span>); <a name="l00649"></a>00649 <span class="comment"></span> <a name="l00650"></a>00650 <span class="comment"> /** Verifies whether this operationplan violates the capacity constraint.<br></span> <a name="l00651"></a>00651 <span class="comment"> * In case it does the operationplan is moved to an earlier or later</span> <a name="l00652"></a>00652 <span class="comment"> * feasible date.</span> <a name="l00653"></a>00653 <span class="comment"> */</span> <a name="l00654"></a>00654 <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> <span class="keywordtype">void</span> <a class="code" href="a00173.html#a030da5fc169a8fe91c80f4d17e854d54">checkOperationCapacity</a>(<a class="code" href="a00125.html" title="An operationplan is the key dynamic element of a plan. It represents a certain quantity...">OperationPlan</a>*, <a class="code" href="a00174.html" title="This class is a helper class of the SolverMRP class.">SolverMRPdata</a>&); <a name="l00655"></a>00655 <span class="comment"></span> <a name="l00656"></a>00656 <span class="comment"> /** Scan the operationplans that are about to be committed to verify that</span> <a name="l00657"></a>00657 <span class="comment"> * they are not creating any excess. </span> <a name="l00658"></a>00658 <span class="comment"> */</span> <a name="l00659"></a>00659 <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> <span class="keywordtype">void</span> <a class="code" href="a00173.html#a45b15f36c3d23ab1ed15997e072f2153">scanExcess</a>(<a class="code" href="a00025.html" title="Abstract base class for all commands.">Command</a>*); <a name="l00660"></a>00660 }; <a name="l00661"></a>00661 <a name="l00662"></a>00662 <span class="comment"></span> <a name="l00663"></a>00663 <span class="comment">/** @brief This class holds functions that used for maintenance of the solver</span> <a name="l00664"></a>00664 <span class="comment"> * code.</span> <a name="l00665"></a>00665 <span class="comment"> */</span> <a name="l00666"></a><a class="code" href="a00098.html">00666</a> <span class="keyword">class </span><a class="code" href="a00098.html" title="This class holds functions that used for maintenance of the solver code.">LibrarySolver</a> <a name="l00667"></a>00667 { <a name="l00668"></a>00668 <span class="keyword">public</span>: <a name="l00669"></a>00669 <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="a00098.html#a8582b00a7f30e8ee46333c8dd5c809a0">initialize</a>(); <a name="l00670"></a>00670 }; <a name="l00671"></a>00671 <a name="l00672"></a>00672 <a name="l00673"></a>00673 } <span class="comment">// end namespace</span> <a name="l00674"></a>00674 <a name="l00675"></a>00675 <a name="l00676"></a>00676 <span class="preprocessor">#endif</span> </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>