<!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: solverplan.cpp Source File</title> <link href="doxygen.css" rel="stylesheet" type="text/css"> <link href="tabs.css" rel="stylesheet" type="text/css"> <link href="../styles.css" rel="stylesheet" type="text/css"> </head> <body> <div id="container"> <div id="menubar"> <div id="logo" align="center"> <br/><img src='../frepple.bmp' alt="frepple" /><br/> <a href='http://www.frepple.com/'> <strong>a Free<br/>Production Planning<br/>Library</strong> </a> </div> <div id="menu"> <br/> <h3><a href='../Main/HomePage.html'>Main</a></h3> <h3><a href='../UI/Main.html'>User Manual</a></h3> <h3><a href='../Tutorial/Main.html'>Tutorial</a></h3> <h3><a href='../Frepple/Main.html'>Reference Manual</a></h3> <h3><a href='../Main/FAQ.html'>FAQ</a></h3> <h3><a href='index.html'>C++ API</a></h3> <br/> </div> </div> <div id="content"> <br/> <!-- Generated by Doxygen 1.6.1 --> <div class="navigation" id="top"> <div class="tabs"> <ul> <li><a href="index.html"><span>Main Page</span></a></li> <li><a href="pages.html"><span>Related Pages</span></a></li> <li><a href="namespaces.html"><span>Namespaces</span></a></li> <li><a href="annotated.html"><span>Classes</span></a></li> <li class="current"><a href="files.html"><span>Files</span></a></li> <li><a href="dirs.html"><span>Directories</span></a></li> </ul> </div> <div class="tabs"> <ul> <li><a href="files.html"><span>File List</span></a></li> <li><a href="globals.html"><span>File Members</span></a></li> </ul> </div> <div class="navpath"><a class="el" href="dir_88117dff2735251a69c8eb9084477714.html">src</a> » <a class="el" href="dir_f53ab566a495928d11ba5681eabceaaf.html">solver</a> </div> </div> <div class="contents"> <h1>solverplan.cpp</h1><a href="a00245.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/***************************************************************************</span> <a name="l00002"></a>00002 <span class="comment"> file : $URL: https://frepple.svn.sourceforge.net/svnroot/frepple/trunk/src/solver/solverplan.cpp $</span> <a name="l00003"></a>00003 <span class="comment"> version : $LastChangedRevision: 1315 $ $LastChangedBy: jdetaeye $</span> <a name="l00004"></a>00004 <span class="comment"> date : $LastChangedDate: 2010-07-17 18:08:53 +0200 (Sat, 17 Jul 2010) $</span> <a name="l00005"></a>00005 <span class="comment"> ***************************************************************************/</span> <a name="l00006"></a>00006 <a name="l00007"></a>00007 <span class="comment">/***************************************************************************</span> <a name="l00008"></a>00008 <span class="comment"> * *</span> <a name="l00009"></a>00009 <span class="comment"> * Copyright (C) 2007-2010 by Johan De Taeye *</span> <a name="l00010"></a>00010 <span class="comment"> * *</span> <a name="l00011"></a>00011 <span class="comment"> * This library is free software; you can redistribute it and/or modify it *</span> <a name="l00012"></a>00012 <span class="comment"> * under the terms of the GNU Lesser General Public License as published *</span> <a name="l00013"></a>00013 <span class="comment"> * by the Free Software Foundation; either version 2.1 of the License, or *</span> <a name="l00014"></a>00014 <span class="comment"> * (at your option) any later version. *</span> <a name="l00015"></a>00015 <span class="comment"> * *</span> <a name="l00016"></a>00016 <span class="comment"> * This library is distributed in the hope that it will be useful, *</span> <a name="l00017"></a>00017 <span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of *</span> <a name="l00018"></a>00018 <span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser *</span> <a name="l00019"></a>00019 <span class="comment"> * General Public License for more details. *</span> <a name="l00020"></a>00020 <span class="comment"> * *</span> <a name="l00021"></a>00021 <span class="comment"> * You should have received a copy of the GNU Lesser General Public *</span> <a name="l00022"></a>00022 <span class="comment"> * License along with this library; if not, write to the Free Software *</span> <a name="l00023"></a>00023 <span class="comment"> * Foundation Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 *</span> <a name="l00024"></a>00024 <span class="comment"> * USA *</span> <a name="l00025"></a>00025 <span class="comment"> * *</span> <a name="l00026"></a>00026 <span class="comment"> ***************************************************************************/</span> <a name="l00027"></a>00027 <a name="l00028"></a><a class="code" href="a00245.html#a342983a479ae7a921be5face83fdb029">00028</a> <span class="preprocessor">#define FREPPLE_CORE</span> <a name="l00029"></a>00029 <span class="preprocessor"></span><span class="preprocessor">#include "<a class="code" href="a00239.html">frepple/solver.h</a>"</span> <a name="l00030"></a>00030 <span class="keyword">namespace </span>frepple <a name="l00031"></a>00031 { <a name="l00032"></a>00032 <a name="l00033"></a>00033 <a 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">SolverMRP::metadata</a>; <a name="l00034"></a>00034 <a name="l00035"></a>00035 <a name="l00036"></a><a class="code" href="a00098.html#a8582b00a7f30e8ee46333c8dd5c809a0">00036</a> <span class="keywordtype">void</span> <a class="code" href="a00098.html#a8582b00a7f30e8ee46333c8dd5c809a0">LibrarySolver::initialize</a>() <a name="l00037"></a>00037 { <a name="l00038"></a>00038 <span class="comment">// Initialize only once</span> <a name="l00039"></a>00039 <span class="keyword">static</span> <span class="keywordtype">bool</span> init = <span class="keyword">false</span>; <a name="l00040"></a>00040 <span class="keywordflow">if</span> (init) <a name="l00041"></a>00041 { <a name="l00042"></a>00042 <a class="code" href="a00257.html#a4af9f241e955122820c5e81ceb33edb5">logger</a> << <span class="stringliteral">"Warning: Calling frepple::LibrarySolver::initialize() more "</span> <a name="l00043"></a>00043 << <span class="stringliteral">"than once."</span> << endl; <a name="l00044"></a>00044 <span class="keywordflow">return</span>; <a name="l00045"></a>00045 } <a name="l00046"></a>00046 init = <span class="keyword">true</span>; <a name="l00047"></a>00047 <a name="l00048"></a>00048 <span class="comment">// Register all classes.</span> <a name="l00049"></a>00049 <span class="keywordflow">if</span> (<a class="code" href="a00173.html#a4789a0e47176fdf3dfdd30cc8965b08a">SolverMRP::initialize</a>()) <a name="l00050"></a>00050 <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">"Error registering solver_mrp Python type"</span>); <a name="l00051"></a>00051 } <a name="l00052"></a>00052 <a name="l00053"></a>00053 <a name="l00054"></a><a class="code" href="a00173.html#a4789a0e47176fdf3dfdd30cc8965b08a">00054</a> <span class="keywordtype">int</span> <a class="code" href="a00173.html#a4789a0e47176fdf3dfdd30cc8965b08a">SolverMRP::initialize</a>() <a name="l00055"></a>00055 { <a name="l00056"></a>00056 <span class="comment">// Initialize the metadata</span> <a name="l00057"></a>00057 <a class="code" href="a00173.html#a8b5bca7cd0d37393e1b20a5b08613a56">metadata</a> = <span class="keyword">new</span> <a class="code" href="a00115.html" title="This class stores metadata about the classes in the library. The stored information...">MetaClass</a> <a name="l00058"></a>00058 (<span class="stringliteral">"solver"</span>,<span class="stringliteral">"solver_mrp"</span>,Object::createString<SolverMRP>,<span class="keyword">true</span>); <a name="l00059"></a>00059 <a name="l00060"></a>00060 <span class="comment">// Initialize the Python class</span> <a name="l00061"></a>00061 <a class="code" href="a00173.html#ae304221980e02fc4d5acca0618beddbb">FreppleClass<SolverMRP,Solver>::getType</a>().addMethod(<span class="stringliteral">"solve"</span>, <a class="code" href="a00173.html#aed1d08dd6ece530ed9229d463e31cca3">solve</a>, METH_VARARGS, <span class="stringliteral">"run the solver"</span>); <a name="l00062"></a>00062 <a class="code" href="a00173.html#ae304221980e02fc4d5acca0618beddbb">FreppleClass<SolverMRP,Solver>::getType</a>().addMethod(<span class="stringliteral">"commit"</span>, <a class="code" href="a00173.html#a68d0f5b398ced2a94c2495b09cdd2632">commit</a>, METH_NOARGS, <span class="stringliteral">"commit the plan changes"</span>); <a name="l00063"></a>00063 <a class="code" href="a00173.html#ae304221980e02fc4d5acca0618beddbb">FreppleClass<SolverMRP,Solver>::getType</a>().addMethod(<span class="stringliteral">"undo"</span>, <a class="code" href="a00173.html#aef91f162235173fcbd3a7e99c418a32c">undo</a>, METH_NOARGS, <span class="stringliteral">"undo the plan changes"</span>); <a name="l00064"></a>00064 <span class="keywordflow">return</span> <a class="code" href="a00173.html#a4789a0e47176fdf3dfdd30cc8965b08a">FreppleClass<SolverMRP,Solver>::initialize</a>(); <a name="l00065"></a>00065 } <a name="l00066"></a>00066 <a name="l00067"></a>00067 <a name="l00068"></a><a class="code" href="a00173.html#a3a53347a65ba93402d3d1de0b14ce0e1">00068</a> <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> <span class="keywordtype">bool</span> <a class="code" href="a00173.html#a3a53347a65ba93402d3d1de0b14ce0e1">SolverMRP::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>* l1, <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>* l2) <a name="l00069"></a>00069 { <a name="l00070"></a>00070 <span class="keywordflow">if</span> (l1-><a class="code" href="a00051.html#a312655c39f5d5acc4db3676c9a741a45">getPriority</a>() != l2-><a class="code" href="a00051.html#a312655c39f5d5acc4db3676c9a741a45">getPriority</a>()) <a name="l00071"></a>00071 <span class="keywordflow">return</span> l1-><a class="code" href="a00051.html#a312655c39f5d5acc4db3676c9a741a45">getPriority</a>() < l2-><a class="code" href="a00051.html#a312655c39f5d5acc4db3676c9a741a45">getPriority</a>(); <a name="l00072"></a>00072 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (l1-><a class="code" href="a00051.html#ab21889e9a16e3701a84ba8f3aa68628b">getDue</a>() != l2-><a class="code" href="a00051.html#ab21889e9a16e3701a84ba8f3aa68628b">getDue</a>()) <a name="l00073"></a>00073 <span class="keywordflow">return</span> l1-><a class="code" href="a00051.html#ab21889e9a16e3701a84ba8f3aa68628b">getDue</a>() < l2-><a class="code" href="a00051.html#ab21889e9a16e3701a84ba8f3aa68628b">getDue</a>(); <a name="l00074"></a>00074 <span class="keywordflow">else</span> <a name="l00075"></a>00075 <span class="keywordflow">return</span> l1-><a class="code" href="a00051.html#af5fe6f1b6e8f9b2c24ce3479b6546444">getQuantity</a>() < l2-><a class="code" href="a00051.html#af5fe6f1b6e8f9b2c24ce3479b6546444">getQuantity</a>(); <a name="l00076"></a>00076 } <a name="l00077"></a>00077 <a name="l00078"></a>00078 <a name="l00079"></a><a class="code" href="a00174.html#acc70df491327f7ca8e3f7f2f8fe59305">00079</a> <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> <span class="keywordtype">void</span> <a class="code" href="a00174.html#acc70df491327f7ca8e3f7f2f8fe59305">SolverMRP::SolverMRPdata::execute</a>() <a name="l00080"></a>00080 { <a name="l00081"></a>00081 <span class="comment">// Check</span> <a name="l00082"></a>00082 <span class="keywordflow">if</span> (!demands || !<a class="code" href="a00174.html#a1d6f62b1c53725b796ea1c4f8843b85d">getSolver</a>()) <a name="l00083"></a>00083 <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">"Missing demands or solver."</span>); <a name="l00084"></a>00084 <a name="l00085"></a>00085 <span class="comment">// Message</span> <a name="l00086"></a>00086 <a class="code" href="a00173.html" title="This solver implements a heuristic algorithm for planning demands.">SolverMRP</a>* <a class="code" href="a00171.html" title="This class is an implementation of the &quot;visitor&quot; design pattern. It is...">Solver</a> = <a class="code" href="a00174.html#a1d6f62b1c53725b796ea1c4f8843b85d">getSolver</a>(); <a name="l00087"></a>00087 <span class="keywordflow">if</span> (Solver-><a class="code" href="a00171.html#a7331226cd4ef515184dff2d118c43423">getLogLevel</a>()>0) <a name="l00088"></a>00088 <a class="code" href="a00257.html#a4af9f241e955122820c5e81ceb33edb5">logger</a> << <span class="stringliteral">"Start solving cluster "</span> << cluster << <span class="stringliteral">" at "</span> << Date::now() << endl; <a name="l00089"></a>00089 <a name="l00090"></a>00090 <span class="comment">// Solve the planning problem</span> <a name="l00091"></a>00091 <span class="keywordflow">try</span> <a name="l00092"></a>00092 { <a name="l00093"></a>00093 <span class="comment">// Sort the demands of this problem.</span> <a name="l00094"></a>00094 <span class="comment">// We use a stable sort to get reproducible results between platforms</span> <a name="l00095"></a>00095 <span class="comment">// and STL implementations.</span> <a name="l00096"></a>00096 stable_sort(demands->begin(), demands->end(), <a class="code" href="a00173.html#a3a53347a65ba93402d3d1de0b14ce0e1">demand_comparison</a>); <a name="l00097"></a>00097 <a name="l00098"></a>00098 <span class="comment">// Loop through the list of all demands in this planning problem</span> <a name="l00099"></a>00099 constrainedPlanning = (Solver-><a class="code" href="a00173.html#aa79ce0df49103c6cc5088b161e79bda3">getPlanType</a>() == 1); <a name="l00100"></a>00100 <span class="keywordflow">for</span> (deque<Demand*>::const_iterator i = demands->begin(); <a name="l00101"></a>00101 i != demands->end(); ++i) <a name="l00102"></a>00102 { <a name="l00103"></a>00103 <a class="code" href="a00025.html" title="Abstract base class for all commands.">Command</a>* topcommand = <a class="code" href="a00029.html#a392f247416814b845c086ff1f7196ad9">getLastCommand</a>(); <a name="l00104"></a>00104 <span class="keywordflow">try</span> <a name="l00105"></a>00105 { <a name="l00106"></a>00106 <span class="comment">// Delete previous constraints</span> <a name="l00107"></a>00107 (*i)->getConstraints().clear(); <a name="l00108"></a>00108 <a name="l00109"></a>00109 <span class="comment">// Create a state stack</span> <a name="l00110"></a>00110 <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>* mystate = <a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a>; <a name="l00111"></a>00111 <a class="code" href="a00174.html#a99c25a0cbb86773a59443cc81e9d915e">push</a>(); <a name="l00112"></a>00112 <a name="l00113"></a>00113 <span class="comment">// Plan the demand</span> <a name="l00114"></a>00114 planningDemand = *i; <a name="l00115"></a>00115 logConstraints = (Solver-><a class="code" href="a00173.html#aa79ce0df49103c6cc5088b161e79bda3">getPlanType</a>() == 1); <a name="l00116"></a>00116 <span class="keywordflow">try</span> {(*i)->solve(*Solver,<span class="keyword">this</span>);} <a name="l00117"></a>00117 <span class="keywordflow">catch</span> (...) <a name="l00118"></a>00118 { <a name="l00119"></a>00119 <span class="keywordflow">while</span> (<a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a> > mystate) <a class="code" href="a00174.html#a8f732ee498931ff8220a6392c68839e1">pop</a>(); <a name="l00120"></a>00120 <span class="keywordflow">throw</span>; <a name="l00121"></a>00121 } <a name="l00122"></a>00122 <span class="keywordflow">while</span> (<a class="code" href="a00174.html#a592e60ca8e03a80e5460bfb1bf973b4e">state</a> > mystate) <a class="code" href="a00174.html#a8f732ee498931ff8220a6392c68839e1">pop</a>(); <a name="l00123"></a>00123 } <a name="l00124"></a>00124 <span class="keywordflow">catch</span> (...) <a name="l00125"></a>00125 { <a name="l00126"></a>00126 <span class="comment">// Error message</span> <a name="l00127"></a>00127 <a class="code" href="a00257.html#a4af9f241e955122820c5e81ceb33edb5">logger</a> << <span class="stringliteral">"Error: Caught an exception while solving demand '"</span> <a name="l00128"></a>00128 << (*i)->getName() << <span class="stringliteral">"':"</span> << endl; <a name="l00129"></a>00129 <span class="keywordflow">try</span> {<span class="keywordflow">throw</span>;} <a name="l00130"></a>00130 <span class="keywordflow">catch</span> (bad_exception&) {<a class="code" href="a00257.html#a4af9f241e955122820c5e81ceb33edb5">logger</a> << <span class="stringliteral">" bad exception"</span> << endl;} <a name="l00131"></a>00131 <span class="keywordflow">catch</span> (exception& e) {<a class="code" href="a00257.html#a4af9f241e955122820c5e81ceb33edb5">logger</a> << <span class="stringliteral">" "</span> << e.what() << endl;} <a name="l00132"></a>00132 <span class="keywordflow">catch</span> (...) {<a class="code" href="a00257.html#a4af9f241e955122820c5e81ceb33edb5">logger</a> << <span class="stringliteral">" Unknown type"</span> << endl;} <a name="l00133"></a>00133 <a name="l00134"></a>00134 <span class="comment">// Cleaning up</span> <a name="l00135"></a>00135 <a class="code" href="a00029.html#a6f38f9a190b88a29f63b58a478cbe982">undo</a>(topcommand); <a name="l00136"></a>00136 } <a name="l00137"></a>00137 } <a name="l00138"></a>00138 <a name="l00139"></a>00139 <span class="comment">// Clean the list of demands of this cluster</span> <a name="l00140"></a>00140 demands->clear(); <a name="l00141"></a>00141 } <a name="l00142"></a>00142 <span class="keywordflow">catch</span> (...) <a name="l00143"></a>00143 { <a name="l00144"></a>00144 <span class="comment">// We come in this exception handling code only if there is a problem with</span> <a name="l00145"></a>00145 <span class="comment">// with this cluster that goes beyond problems with single orders.</span> <a name="l00146"></a>00146 <span class="comment">// If the problem is with single orders, the exception handling code above</span> <a name="l00147"></a>00147 <span class="comment">// will do a proper rollback.</span> <a name="l00148"></a>00148 <a name="l00149"></a>00149 <span class="comment">// Error message</span> <a name="l00150"></a>00150 <a class="code" href="a00257.html#a4af9f241e955122820c5e81ceb33edb5">logger</a> << <span class="stringliteral">"Error: Caught an exception while solving cluster "</span> <a name="l00151"></a>00151 << cluster << <span class="stringliteral">":"</span> << endl; <a name="l00152"></a>00152 <span class="keywordflow">try</span> {<span class="keywordflow">throw</span>;} <a name="l00153"></a>00153 <span class="keywordflow">catch</span> (bad_exception&){<a class="code" href="a00257.html#a4af9f241e955122820c5e81ceb33edb5">logger</a> << <span class="stringliteral">" bad exception"</span> << endl;} <a name="l00154"></a>00154 <span class="keywordflow">catch</span> (exception& e) {<a class="code" href="a00257.html#a4af9f241e955122820c5e81ceb33edb5">logger</a> << <span class="stringliteral">" "</span> << e.what() << endl;} <a name="l00155"></a>00155 <span class="keywordflow">catch</span> (...) {<a class="code" href="a00257.html#a4af9f241e955122820c5e81ceb33edb5">logger</a> << <span class="stringliteral">" Unknown type"</span> << endl;} <a name="l00156"></a>00156 <a name="l00157"></a>00157 <span class="comment">// Clean up the operationplans of this cluster</span> <a name="l00158"></a>00158 <span class="keywordflow">for</span> (Operation::iterator f=<a class="code" href="a00085.html#a1926a798edd9c04bc37e596936003cd6">Operation::begin</a>(); f!=<a class="code" href="a00085.html#abb9d04973550ac71037718511358f2ff">Operation::end</a>(); ++f) <a name="l00159"></a>00159 <span class="keywordflow">if</span> (f->getCluster() == cluster) <a name="l00160"></a>00160 f->deleteOperationPlans(); <a name="l00161"></a>00161 <a name="l00162"></a>00162 <span class="comment">// Clean the list of demands of this cluster</span> <a name="l00163"></a>00163 demands->clear(); <a name="l00164"></a>00164 } <a name="l00165"></a>00165 <a name="l00166"></a>00166 <span class="comment">// Message</span> <a name="l00167"></a>00167 <span class="keywordflow">if</span> (Solver-><a class="code" href="a00171.html#a7331226cd4ef515184dff2d118c43423">getLogLevel</a>()>0) <a name="l00168"></a>00168 <a class="code" href="a00257.html#a4af9f241e955122820c5e81ceb33edb5">logger</a> << <span class="stringliteral">"End solving cluster "</span> << cluster << <span class="stringliteral">" at "</span> << Date::now() << endl; <a name="l00169"></a>00169 } <a name="l00170"></a>00170 <a name="l00171"></a>00171 <a name="l00172"></a><a class="code" href="a00173.html#aa2c15022c8853a62bd83e4ab8a0902e5">00172</a> <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> <span class="keywordtype">void</span> <a class="code" href="a00173.html#aed1d08dd6ece530ed9229d463e31cca3">SolverMRP::solve</a>(<span class="keywordtype">void</span> *v) <a name="l00173"></a>00173 { <a name="l00174"></a>00174 <span class="comment">// Categorize all demands in their cluster</span> <a name="l00175"></a>00175 <span class="keywordflow">for</span> (Demand::iterator i = <a class="code" href="a00085.html#a1926a798edd9c04bc37e596936003cd6">Demand::begin</a>(); i != <a class="code" href="a00085.html#abb9d04973550ac71037718511358f2ff">Demand::end</a>(); ++i) <a name="l00176"></a>00176 demands_per_cluster[i->getCluster()].push_back(&*i); <a name="l00177"></a>00177 <a name="l00178"></a>00178 <span class="comment">// Delete of operationplans of the affected clusters</span> <a name="l00179"></a>00179 <span class="comment">// This deletion is not multi-threaded... But on the other hand we need to</span> <a name="l00180"></a>00180 <span class="comment">// loop through the operations only once (rather than as many times as there</span> <a name="l00181"></a>00181 <span class="comment">// are clusters)</span> <a name="l00182"></a>00182 <span class="comment">// A multi-threaded alternative would be to hash the operations here, and</span> <a name="l00183"></a>00183 <span class="comment">// then delete in each thread.</span> <a name="l00184"></a>00184 <span class="keywordflow">if</span> (<a class="code" href="a00171.html#a7331226cd4ef515184dff2d118c43423">getLogLevel</a>()>0) <a class="code" href="a00257.html#a4af9f241e955122820c5e81ceb33edb5">logger</a> << <span class="stringliteral">"Deleting previous plan"</span> << endl; <a name="l00185"></a>00185 <span class="keywordflow">for</span> (Operation::iterator e=<a class="code" href="a00085.html#a1926a798edd9c04bc37e596936003cd6">Operation::begin</a>(); e!=<a class="code" href="a00085.html#abb9d04973550ac71037718511358f2ff">Operation::end</a>(); ++e) <a name="l00186"></a>00186 <span class="comment">// The next if-condition is actually redundant if we plan everything</span> <a name="l00187"></a>00187 <span class="keywordflow">if</span> (demands_per_cluster.find(e->getCluster())!=demands_per_cluster.end()) <a name="l00188"></a>00188 e->deleteOperationPlans(); <a name="l00189"></a>00189 <a name="l00190"></a>00190 <span class="comment">// Count how many clusters we have to plan</span> <a name="l00191"></a>00191 <span class="keywordtype">int</span> cl = demands_per_cluster.size(); <a name="l00192"></a>00192 <span class="keywordflow">if</span> (cl<1) <span class="keywordflow">return</span>; <a name="l00193"></a>00193 <a name="l00194"></a>00194 <span class="comment">// Create the command list to control the execution</span> <a name="l00195"></a>00195 <a class="code" href="a00029.html" title="A container command to group a series of commands together.">CommandList</a> threads; <a name="l00196"></a>00196 <a name="l00197"></a>00197 <span class="comment">// Solve in parallel threads.</span> <a name="l00198"></a>00198 <span class="comment">// When not solving in silent and autocommit mode, we only use a single</span> <a name="l00199"></a>00199 <span class="comment">// solver thread.</span> <a name="l00200"></a>00200 <span class="keywordflow">if</span> (<a class="code" href="a00171.html#a7331226cd4ef515184dff2d118c43423">getLogLevel</a>()>0 || !<a class="code" href="a00173.html#afe90ff4ad851caa35b2e55b4bcd13ac8">getAutocommit</a>()) <a name="l00201"></a>00201 threads.<a class="code" href="a00029.html#a41cde709abae9c54d1c23cc9a770d269">setMaxParallel</a>(1); <a name="l00202"></a>00202 <span class="keywordflow">else</span> <a name="l00203"></a>00203 threads.<a class="code" href="a00029.html#a41cde709abae9c54d1c23cc9a770d269">setMaxParallel</a>( cl > <a class="code" href="a00173.html#a3678855c17eb7320e0b7eb0066e416c4">getMaxParallel</a>() ? <a class="code" href="a00173.html#a3678855c17eb7320e0b7eb0066e416c4">getMaxParallel</a>() : cl); <a name="l00204"></a>00204 <a name="l00205"></a>00205 <span class="comment">// Make sure a problem in a single cluster doesn't spoil it all</span> <a name="l00206"></a>00206 threads.<a class="code" href="a00029.html#a958191669941f0d3ea35f3b6c10fa32a">setAbortOnError</a>(<span class="keyword">false</span>); <a name="l00207"></a>00207 <span class="keywordflow">for</span> (classified_demand::iterator j = demands_per_cluster.begin(); <a name="l00208"></a>00208 j != demands_per_cluster.end(); ++j) <a name="l00209"></a>00209 threads.<a class="code" href="a00029.html#a0b761c0e2f51f84569de4f242e2cb7b4">add</a>(<span class="keyword">new</span> <a class="code" href="a00174.html" title="This class is a helper class of the SolverMRP class.">SolverMRPdata</a>(<span class="keyword">this</span>, j->first, &(j->second))); <a name="l00210"></a>00210 <a name="l00211"></a>00211 <span class="comment">// Run the planning command threads and wait for them to exit</span> <a name="l00212"></a>00212 threads.<a class="code" href="a00029.html#a3ab89f96275985cb36836157a719cf9a">execute</a>(); <a name="l00213"></a>00213 <a name="l00214"></a>00214 <span class="comment">// @todo Check the resource setups that were broken - needs to be removed</span> <a name="l00215"></a>00215 <span class="keywordflow">for</span> (Resource::iterator gres = <a class="code" href="a00085.html#a1926a798edd9c04bc37e596936003cd6">Resource::begin</a>(); gres != <a class="code" href="a00085.html#abb9d04973550ac71037718511358f2ff">Resource::end</a>(); ++gres) <a name="l00216"></a>00216 { <a name="l00217"></a>00217 <span class="keywordflow">if</span> (gres->getSetupMatrix()) gres->updateSetups(); <a name="l00218"></a>00218 } <a name="l00219"></a>00219 } <a name="l00220"></a>00220 <a name="l00221"></a>00221 <a name="l00222"></a><a class="code" href="a00173.html#a8eefc9113d28d22731cbe1d3013f4948">00222</a> <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> <span class="keywordtype">void</span> <a class="code" href="a00173.html#a8eefc9113d28d22731cbe1d3013f4948">SolverMRP::writeElement</a>(<a class="code" href="a00189.html" title="Base class for writing XML formatted data to an output stream.">XMLOutput</a> *o, <span class="keyword">const</span> <a class="code" href="a00096.html" title="This class defines a keyword for the frePPLe data model.">Keyword</a>& tag, <a class="code" href="a00257.html#a20c2c7e4c6b668e71c154ae3eb18f398">mode</a> m)<span class="keyword"> const</span> <a name="l00223"></a>00223 <span class="keyword"></span>{ <a name="l00224"></a>00224 <span class="comment">// Writing a reference</span> <a name="l00225"></a>00225 <span class="keywordflow">if</span> (m == <a class="code" href="a00257.html#a20c2c7e4c6b668e71c154ae3eb18f398a874240ada53cc5b608466064d86d91ae">REFERENCE</a>) <a name="l00226"></a>00226 { <a name="l00227"></a>00227 o-><a class="code" href="a00189.html#a711922eea4cfe3c33b97e4188dacc7d2">writeElement</a> <a name="l00228"></a>00228 (tag, <a class="code" href="a00177.html#aeb3841a93774dfc303e3df16304b5af2">Tags::tag_name</a>, <a class="code" href="a00182.html#a7416ca220c55147bc1276becc5b9de01">getName</a>(), <a class="code" href="a00177.html#a6745112e0237e378e2b0cbe41aa5926a">Tags::tag_type</a>, <a class="code" href="a00173.html#ae304221980e02fc4d5acca0618beddbb">getType</a>().<a class="code" href="a00171.html" title="This class is an implementation of the &quot;visitor&quot; design pattern. It is...">type</a>); <a name="l00229"></a>00229 <span class="keywordflow">return</span>; <a name="l00230"></a>00230 } <a name="l00231"></a>00231 <a name="l00232"></a>00232 <span class="comment">// Write the complete object</span> <a name="l00233"></a>00233 <span class="keywordflow">if</span> (m != <a class="code" href="a00257.html#a20c2c7e4c6b668e71c154ae3eb18f398a2ad5e75fe119e297630882d182832243">NOHEADER</a>) o-><a class="code" href="a00189.html#a5c1811dae2e3eae344ad366f6441a8a5">BeginObject</a> <a name="l00234"></a>00234 (tag, <a class="code" href="a00177.html#aeb3841a93774dfc303e3df16304b5af2">Tags::tag_name</a>, <a class="code" href="a00182.html#a7416ca220c55147bc1276becc5b9de01">getName</a>(), <a class="code" href="a00177.html#a6745112e0237e378e2b0cbe41aa5926a">Tags::tag_type</a>, <a class="code" href="a00173.html#ae304221980e02fc4d5acca0618beddbb">getType</a>().<a class="code" href="a00171.html" title="This class is an implementation of the &quot;visitor&quot; design pattern. It is...">type</a>); <a name="l00235"></a>00235 <a name="l00236"></a>00236 <span class="comment">// Write the fields</span> <a name="l00237"></a>00237 <span class="keywordflow">if</span> (<a class="code" href="a00173.html#aba7f9976dce31fdd088ac17aec600fd9">constrts</a> != 15) o-><a class="code" href="a00189.html#a711922eea4cfe3c33b97e4188dacc7d2">writeElement</a>(<a class="code" href="a00177.html#a9d22c8aaeea7a0d2ca1a19150891e049">Tags::tag_constraints</a>, <a class="code" href="a00173.html#aba7f9976dce31fdd088ac17aec600fd9">constrts</a>); <a name="l00238"></a>00238 <span class="keywordflow">if</span> (plantype != 1) o-><a class="code" href="a00189.html#a711922eea4cfe3c33b97e4188dacc7d2">writeElement</a>(<a class="code" href="a00177.html#a6d3322f7ca9a0e8400135d9293a00978">Tags::tag_plantype</a>, plantype); <a name="l00239"></a>00239 <span class="keywordflow">if</span> (maxparallel) o-><a class="code" href="a00189.html#a711922eea4cfe3c33b97e4188dacc7d2">writeElement</a>(<a class="code" href="a00177.html#add7fef81ffe4d393ee780b33d13679b8">Tags::tag_maxparallel</a>, maxparallel); <a name="l00240"></a>00240 <span class="keywordflow">if</span> (!autocommit) o-><a class="code" href="a00189.html#a711922eea4cfe3c33b97e4188dacc7d2">writeElement</a>(<a class="code" href="a00177.html#af4bee69c6d53d9fd0f26488391453f45">Tags::tag_autocommit</a>, autocommit); <a name="l00241"></a>00241 <span class="keywordflow">if</span> (userexit_flow) <a name="l00242"></a>00242 o-><a class="code" href="a00189.html#a711922eea4cfe3c33b97e4188dacc7d2">writeElement</a>(<a class="code" href="a00177.html#a0f05022812ad8b27f866eb46d34e7c78">Tags::tag_userexit_flow</a>, static_cast<string>(userexit_flow)); <a name="l00243"></a>00243 <span class="keywordflow">if</span> (userexit_demand) <a name="l00244"></a>00244 o-><a class="code" href="a00189.html#a711922eea4cfe3c33b97e4188dacc7d2">writeElement</a>(<a class="code" href="a00177.html#a2398d0a8cfd2853301f9e4ad798ffb65">Tags::tag_userexit_demand</a>, static_cast<string>(userexit_demand)); <a name="l00245"></a>00245 <span class="keywordflow">if</span> (userexit_buffer) <a name="l00246"></a>00246 o-><a class="code" href="a00189.html#a711922eea4cfe3c33b97e4188dacc7d2">writeElement</a>(<a class="code" href="a00177.html#a354fe1a97af966228775b601605376ee">Tags::tag_userexit_buffer</a>, static_cast<string>(userexit_buffer)); <a name="l00247"></a>00247 <span class="keywordflow">if</span> (userexit_resource) <a name="l00248"></a>00248 o-><a class="code" href="a00189.html#a711922eea4cfe3c33b97e4188dacc7d2">writeElement</a>(<a class="code" href="a00177.html#a1320e190d5767aca6235dda9ad954cd2">Tags::tag_userexit_resource</a>, static_cast<string>(userexit_resource)); <a name="l00249"></a>00249 <span class="keywordflow">if</span> (userexit_operation) <a name="l00250"></a>00250 o-><a class="code" href="a00189.html#a711922eea4cfe3c33b97e4188dacc7d2">writeElement</a>(<a class="code" href="a00177.html#a6d4ff1eb85db38b4c1d67f57c7ef07f1">Tags::tag_userexit_operation</a>, static_cast<string>(userexit_operation)); <a name="l00251"></a>00251 <a name="l00252"></a>00252 <span class="comment">// Write the parent class</span> <a name="l00253"></a>00253 <a class="code" href="a00173.html#a8eefc9113d28d22731cbe1d3013f4948">Solver::writeElement</a>(o, tag, <a class="code" href="a00257.html#a20c2c7e4c6b668e71c154ae3eb18f398a2ad5e75fe119e297630882d182832243">NOHEADER</a>); <a name="l00254"></a>00254 } <a name="l00255"></a>00255 <a name="l00256"></a>00256 <a name="l00257"></a><a class="code" href="a00173.html#ace591189b4cce0a842d7ca10a224988c">00257</a> <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> <span class="keywordtype">void</span> <a class="code" href="a00173.html#ace591189b4cce0a842d7ca10a224988c">SolverMRP::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="l00258"></a>00258 { <a name="l00259"></a>00259 <span class="keywordflow">if</span> (pAttr.<a class="code" href="a00002.html#aebffce6c4fcf1696ca34f63f2b6ee091">isA</a>(<a class="code" href="a00177.html#a9d22c8aaeea7a0d2ca1a19150891e049">Tags::tag_constraints</a>)) <a name="l00260"></a>00260 <a class="code" href="a00173.html#a2a08ac5234b79aa2c1b2d846784f976c">setConstraints</a>(pElement.<a class="code" href="a00047.html#a0d8c973cc584400f5ea5d8acfd82ace2">getInt</a>()); <a name="l00261"></a>00261 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (pAttr.<a class="code" href="a00002.html#aebffce6c4fcf1696ca34f63f2b6ee091">isA</a>(<a class="code" href="a00177.html#add7fef81ffe4d393ee780b33d13679b8">Tags::tag_maxparallel</a>)) <a name="l00262"></a>00262 <a class="code" href="a00173.html#ac65f4614ff1262897bebf56144ec4a4f">setMaxParallel</a>(pElement.<a class="code" href="a00047.html#a0d8c973cc584400f5ea5d8acfd82ace2">getInt</a>()); <a name="l00263"></a>00263 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (pAttr.<a class="code" href="a00002.html#aebffce6c4fcf1696ca34f63f2b6ee091">isA</a>(<a class="code" href="a00177.html#af4bee69c6d53d9fd0f26488391453f45">Tags::tag_autocommit</a>)) <a name="l00264"></a>00264 <a class="code" href="a00173.html#ae951a19e8064a82cc153c007232ef699">setAutocommit</a>(pElement.<a class="code" href="a00047.html#a542b814710b3242bd4c81aad2fc269d8">getBool</a>()); <a name="l00265"></a>00265 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (pAttr.<a class="code" href="a00002.html#aebffce6c4fcf1696ca34f63f2b6ee091">isA</a>(<a class="code" href="a00177.html#a0f05022812ad8b27f866eb46d34e7c78">Tags::tag_userexit_flow</a>)) <a name="l00266"></a>00266 <a class="code" href="a00173.html#ad29440d03599171908fe82b63f97aab8">setUserExitFlow</a>(pElement.<a class="code" href="a00047.html#a053aa4cde35b21a399f26bca0132ab3f">getString</a>()); <a name="l00267"></a>00267 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (pAttr.<a class="code" href="a00002.html#aebffce6c4fcf1696ca34f63f2b6ee091">isA</a>(<a class="code" href="a00177.html#a2398d0a8cfd2853301f9e4ad798ffb65">Tags::tag_userexit_demand</a>)) <a name="l00268"></a>00268 <a class="code" href="a00173.html#af09e81e3b2ea8c3f0c7b9022a617d146">setUserExitDemand</a>(pElement.<a class="code" href="a00047.html#a053aa4cde35b21a399f26bca0132ab3f">getString</a>()); <a name="l00269"></a>00269 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (pAttr.<a class="code" href="a00002.html#aebffce6c4fcf1696ca34f63f2b6ee091">isA</a>(<a class="code" href="a00177.html#a354fe1a97af966228775b601605376ee">Tags::tag_userexit_buffer</a>)) <a name="l00270"></a>00270 <a class="code" href="a00173.html#aaff934ce3d755804b9bd48e54e9ebd3f">setUserExitBuffer</a>(pElement.<a class="code" href="a00047.html#a053aa4cde35b21a399f26bca0132ab3f">getString</a>()); <a name="l00271"></a>00271 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (pAttr.<a class="code" href="a00002.html#aebffce6c4fcf1696ca34f63f2b6ee091">isA</a>(<a class="code" href="a00177.html#a1320e190d5767aca6235dda9ad954cd2">Tags::tag_userexit_resource</a>)) <a name="l00272"></a>00272 <a class="code" href="a00173.html#aa0727c098fbe25ba45cb0ba19e2d148e">setUserExitResource</a>(pElement.<a class="code" href="a00047.html#a053aa4cde35b21a399f26bca0132ab3f">getString</a>()); <a name="l00273"></a>00273 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (pAttr.<a class="code" href="a00002.html#aebffce6c4fcf1696ca34f63f2b6ee091">isA</a>(<a class="code" href="a00177.html#a6d4ff1eb85db38b4c1d67f57c7ef07f1">Tags::tag_userexit_operation</a>)) <a name="l00274"></a>00274 <a class="code" href="a00173.html#ab8793421e04af5750b8f21bf4bfd168d">setUserExitOperation</a>(pElement.<a class="code" href="a00047.html#a053aa4cde35b21a399f26bca0132ab3f">getString</a>()); <a name="l00275"></a>00275 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (pAttr.<a class="code" href="a00002.html#aebffce6c4fcf1696ca34f63f2b6ee091">isA</a>(<a class="code" href="a00177.html#a6d3322f7ca9a0e8400135d9293a00978">Tags::tag_plantype</a>)) <a name="l00276"></a>00276 <a class="code" href="a00173.html#ae75727c286b4ab0b5fe71d6fb25fac56">setPlanType</a>(pElement.<a class="code" href="a00047.html#a0d8c973cc584400f5ea5d8acfd82ace2">getInt</a>()); <a name="l00277"></a>00277 <span class="keywordflow">else</span> <a name="l00278"></a>00278 <a class="code" href="a00173.html#ace591189b4cce0a842d7ca10a224988c">Solver::endElement</a>(pIn, pAttr, pElement); <a name="l00279"></a>00279 } <a name="l00280"></a>00280 <a name="l00281"></a>00281 <a name="l00282"></a><a class="code" href="a00173.html#a7cde63ea91a5b9a65e2454093c160b70">00282</a> <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> PyObject* <a class="code" href="a00173.html#a7cde63ea91a5b9a65e2454093c160b70">SolverMRP::getattro</a>(<span class="keyword">const</span> <a class="code" href="a00002.html" title="A class to model keyword instances.">Attribute</a>& attr) <a name="l00283"></a>00283 { <a name="l00284"></a>00284 <span class="keywordflow">if</span> (attr.<a class="code" href="a00002.html#aebffce6c4fcf1696ca34f63f2b6ee091">isA</a>(<a class="code" href="a00177.html#a9d22c8aaeea7a0d2ca1a19150891e049">Tags::tag_constraints</a>)) <a name="l00285"></a>00285 <span class="keywordflow">return</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 class="code" href="a00173.html#a5af37d44aeae58f324d2b2b97eabef0f">getConstraints</a>()); <a name="l00286"></a>00286 <span class="keywordflow">if</span> (attr.<a class="code" href="a00002.html#aebffce6c4fcf1696ca34f63f2b6ee091">isA</a>(<a class="code" href="a00177.html#add7fef81ffe4d393ee780b33d13679b8">Tags::tag_maxparallel</a>)) <a name="l00287"></a>00287 <span class="keywordflow">return</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 class="code" href="a00173.html#a3678855c17eb7320e0b7eb0066e416c4">getMaxParallel</a>()); <a name="l00288"></a>00288 <span class="keywordflow">if</span> (attr.<a class="code" href="a00002.html#aebffce6c4fcf1696ca34f63f2b6ee091">isA</a>(<a class="code" href="a00177.html#af4bee69c6d53d9fd0f26488391453f45">Tags::tag_autocommit</a>)) <a name="l00289"></a>00289 <span class="keywordflow">return</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 class="code" href="a00173.html#afe90ff4ad851caa35b2e55b4bcd13ac8">getAutocommit</a>()); <a name="l00290"></a>00290 <span class="keywordflow">if</span> (attr.<a class="code" href="a00002.html#aebffce6c4fcf1696ca34f63f2b6ee091">isA</a>(<a class="code" href="a00177.html#a0f05022812ad8b27f866eb46d34e7c78">Tags::tag_userexit_flow</a>)) <a name="l00291"></a>00291 <span class="keywordflow">return</span> <a class="code" href="a00173.html#ad622af357dee0cea251769851ce25d15">getUserExitFlow</a>(); <a name="l00292"></a>00292 <span class="keywordflow">if</span> (attr.<a class="code" href="a00002.html#aebffce6c4fcf1696ca34f63f2b6ee091">isA</a>(<a class="code" href="a00177.html#a2398d0a8cfd2853301f9e4ad798ffb65">Tags::tag_userexit_demand</a>)) <a name="l00293"></a>00293 <span class="keywordflow">return</span> <a class="code" href="a00173.html#a14b1cb5f34384352cf0851e7ad5154ae">getUserExitDemand</a>(); <a name="l00294"></a>00294 <span class="keywordflow">if</span> (attr.<a class="code" href="a00002.html#aebffce6c4fcf1696ca34f63f2b6ee091">isA</a>(<a class="code" href="a00177.html#a354fe1a97af966228775b601605376ee">Tags::tag_userexit_buffer</a>)) <a name="l00295"></a>00295 <span class="keywordflow">return</span> <a class="code" href="a00173.html#a1f39dd7ced78fa651731e05baa16fc0b">getUserExitBuffer</a>(); <a name="l00296"></a>00296 <span class="keywordflow">if</span> (attr.<a class="code" href="a00002.html#aebffce6c4fcf1696ca34f63f2b6ee091">isA</a>(<a class="code" href="a00177.html#a1320e190d5767aca6235dda9ad954cd2">Tags::tag_userexit_resource</a>)) <a name="l00297"></a>00297 <span class="keywordflow">return</span> <a class="code" href="a00173.html#af2cab8daee66acd958c672860cf8cfa9">getUserExitResource</a>(); <a name="l00298"></a>00298 <span class="keywordflow">if</span> (attr.<a class="code" href="a00002.html#aebffce6c4fcf1696ca34f63f2b6ee091">isA</a>(<a class="code" href="a00177.html#a6d4ff1eb85db38b4c1d67f57c7ef07f1">Tags::tag_userexit_operation</a>)) <a name="l00299"></a>00299 <span class="keywordflow">return</span> <a class="code" href="a00173.html#a1f5a9da34c0d59bcb2ef6c8fad5d2140">getUserExitOperation</a>(); <a name="l00300"></a>00300 <span class="keywordflow">if</span> (attr.<a class="code" href="a00002.html#aebffce6c4fcf1696ca34f63f2b6ee091">isA</a>(<a class="code" href="a00177.html#a6d3322f7ca9a0e8400135d9293a00978">Tags::tag_plantype</a>)) <a name="l00301"></a>00301 <span class="keywordflow">return</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 class="code" href="a00173.html#aa79ce0df49103c6cc5088b161e79bda3">getPlanType</a>()); <a name="l00302"></a>00302 <span class="keywordflow">return</span> <a class="code" href="a00173.html#a7cde63ea91a5b9a65e2454093c160b70">Solver::getattro</a>(attr); <a name="l00303"></a>00303 } <a name="l00304"></a>00304 <a name="l00305"></a>00305 <a name="l00306"></a><a class="code" href="a00173.html#a0ff1f4d1312dca29b36e01ac052643ae">00306</a> <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> <span class="keywordtype">int</span> <a class="code" href="a00173.html#a0ff1f4d1312dca29b36e01ac052643ae">SolverMRP::setattro</a>(<span class="keyword">const</span> <a class="code" href="a00002.html" title="A class to model keyword instances.">Attribute</a>& attr, <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>& field) <a name="l00307"></a>00307 { <a name="l00308"></a>00308 <span class="keywordflow">if</span> (attr.<a class="code" href="a00002.html#aebffce6c4fcf1696ca34f63f2b6ee091">isA</a>(<a class="code" href="a00177.html#a9d22c8aaeea7a0d2ca1a19150891e049">Tags::tag_constraints</a>)) <a name="l00309"></a>00309 <a class="code" href="a00173.html#a2a08ac5234b79aa2c1b2d846784f976c">setConstraints</a>(field.<a class="code" href="a00154.html#a783ec10f02cad37886df55bc3f08ba5e">getInt</a>()); <a name="l00310"></a>00310 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (attr.<a class="code" href="a00002.html#aebffce6c4fcf1696ca34f63f2b6ee091">isA</a>(<a class="code" href="a00177.html#add7fef81ffe4d393ee780b33d13679b8">Tags::tag_maxparallel</a>)) <a name="l00311"></a>00311 <a class="code" href="a00173.html#ac65f4614ff1262897bebf56144ec4a4f">setMaxParallel</a>(field.<a class="code" href="a00154.html#a783ec10f02cad37886df55bc3f08ba5e">getInt</a>()); <a name="l00312"></a>00312 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (attr.<a class="code" href="a00002.html#aebffce6c4fcf1696ca34f63f2b6ee091">isA</a>(<a class="code" href="a00177.html#af4bee69c6d53d9fd0f26488391453f45">Tags::tag_autocommit</a>)) <a name="l00313"></a>00313 <a class="code" href="a00173.html#ae951a19e8064a82cc153c007232ef699">setAutocommit</a>(field.<a class="code" href="a00154.html#a804b478fb76759d334882ee468fc84f9">getBool</a>()); <a name="l00314"></a>00314 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (attr.<a class="code" href="a00002.html#aebffce6c4fcf1696ca34f63f2b6ee091">isA</a>(<a class="code" href="a00177.html#a0f05022812ad8b27f866eb46d34e7c78">Tags::tag_userexit_flow</a>)) <a name="l00315"></a>00315 <a class="code" href="a00173.html#ad29440d03599171908fe82b63f97aab8">setUserExitFlow</a>(field); <a name="l00316"></a>00316 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (attr.<a class="code" href="a00002.html#aebffce6c4fcf1696ca34f63f2b6ee091">isA</a>(<a class="code" href="a00177.html#a2398d0a8cfd2853301f9e4ad798ffb65">Tags::tag_userexit_demand</a>)) <a name="l00317"></a>00317 <a class="code" href="a00173.html#af09e81e3b2ea8c3f0c7b9022a617d146">setUserExitDemand</a>(field); <a name="l00318"></a>00318 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (attr.<a class="code" href="a00002.html#aebffce6c4fcf1696ca34f63f2b6ee091">isA</a>(<a class="code" href="a00177.html#a354fe1a97af966228775b601605376ee">Tags::tag_userexit_buffer</a>)) <a name="l00319"></a>00319 <a class="code" href="a00173.html#aaff934ce3d755804b9bd48e54e9ebd3f">setUserExitBuffer</a>(field); <a name="l00320"></a>00320 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (attr.<a class="code" href="a00002.html#aebffce6c4fcf1696ca34f63f2b6ee091">isA</a>(<a class="code" href="a00177.html#a1320e190d5767aca6235dda9ad954cd2">Tags::tag_userexit_resource</a>)) <a name="l00321"></a>00321 <a class="code" href="a00173.html#aa0727c098fbe25ba45cb0ba19e2d148e">setUserExitResource</a>(field); <a name="l00322"></a>00322 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (attr.<a class="code" href="a00002.html#aebffce6c4fcf1696ca34f63f2b6ee091">isA</a>(<a class="code" href="a00177.html#a6d4ff1eb85db38b4c1d67f57c7ef07f1">Tags::tag_userexit_operation</a>)) <a name="l00323"></a>00323 <a class="code" href="a00173.html#ab8793421e04af5750b8f21bf4bfd168d">setUserExitOperation</a>(field); <a name="l00324"></a>00324 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (attr.<a class="code" href="a00002.html#aebffce6c4fcf1696ca34f63f2b6ee091">isA</a>(<a class="code" href="a00177.html#a6d3322f7ca9a0e8400135d9293a00978">Tags::tag_plantype</a>)) <a name="l00325"></a>00325 <a class="code" href="a00173.html#ae75727c286b4ab0b5fe71d6fb25fac56">setPlanType</a>(field.<a class="code" href="a00154.html#a783ec10f02cad37886df55bc3f08ba5e">getInt</a>()); <a name="l00326"></a>00326 <span class="keywordflow">else</span> <a name="l00327"></a>00327 <span class="keywordflow">return</span> <a class="code" href="a00173.html#a0ff1f4d1312dca29b36e01ac052643ae">Solver::setattro</a>(attr, field); <a name="l00328"></a>00328 <span class="keywordflow">return</span> 0; <a name="l00329"></a>00329 } <a name="l00330"></a>00330 <a name="l00331"></a>00331 <a name="l00332"></a><a class="code" href="a00173.html#aa1a936a6dab4db293a96509cafe6b3b6">00332</a> <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> PyObject* <a class="code" href="a00173.html#aed1d08dd6ece530ed9229d463e31cca3">SolverMRP::solve</a>(PyObject *<span class="keyword">self</span>, PyObject *args) <a name="l00333"></a>00333 { <a name="l00334"></a>00334 <span class="comment">// Parse the argument</span> <a name="l00335"></a>00335 PyObject *dem = NULL; <a name="l00336"></a>00336 <span class="keywordflow">if</span> (args && !PyArg_ParseTuple(args, <span class="stringliteral">"|O:solve"</span>, &dem)) <span class="keywordflow">return</span> NULL; <a name="l00337"></a>00337 <span class="keywordflow">if</span> (dem && !PyObject_TypeCheck(dem, <a class="code" href="a00051.html#ab47d40bcf25de651514118609b00362b">Demand::metadata</a>->pythonClass)) <a name="l00338"></a>00338 <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">"solver argument must be a demand"</span>); <a name="l00339"></a>00339 <a name="l00340"></a>00340 Py_BEGIN_ALLOW_THREADS <span class="comment">// Free Python interpreter for other threads</span> <a name="l00341"></a>00341 <span class="keywordflow">try</span> <a name="l00342"></a>00342 { <a name="l00343"></a>00343 <a class="code" href="a00173.html" title="This solver implements a heuristic algorithm for planning demands.">SolverMRP</a>* sol = <span class="keyword">static_cast<</span><a class="code" href="a00173.html" title="This solver implements a heuristic algorithm for planning demands.">SolverMRP</a>*<span class="keyword">></span>(<span class="keyword">self</span>); <a name="l00344"></a>00344 <span class="keywordflow">if</span> (!dem) <a name="l00345"></a>00345 { <a name="l00346"></a>00346 <span class="comment">// Complete replan</span> <a name="l00347"></a>00347 sol-><a class="code" href="a00173.html#ae951a19e8064a82cc153c007232ef699">setAutocommit</a>(<span class="keyword">true</span>); <a name="l00348"></a>00348 sol-><a class="code" href="a00173.html#aed1d08dd6ece530ed9229d463e31cca3">solve</a>(); <a name="l00349"></a>00349 } <a name="l00350"></a>00350 <span class="keywordflow">else</span> <a name="l00351"></a>00351 { <a name="l00352"></a>00352 <span class="comment">// Incrementally plan a single demand</span> <a name="l00353"></a>00353 sol-><a class="code" href="a00173.html#ae951a19e8064a82cc153c007232ef699">setAutocommit</a>(<span class="keyword">false</span>); <a name="l00354"></a>00354 sol-><a class="code" href="a00173.html#a2c81fc731c11b888376e05e8e6068ef8">commands</a>.sol = sol; <a name="l00355"></a>00355 <span class="keyword">static_cast<</span><a class="code" href="a00051.html" title="Represents the (independent) demand in the system. It can represent a customer order...">Demand</a>*<span class="keyword">></span>(dem)-><a class="code" href="a00173.html#aed1d08dd6ece530ed9229d463e31cca3">solve</a>(*sol, &(sol-><a class="code" href="a00173.html#a2c81fc731c11b888376e05e8e6068ef8">commands</a>)); <a name="l00356"></a>00356 } <a name="l00357"></a>00357 } <a name="l00358"></a>00358 <span class="keywordflow">catch</span>(...) <a name="l00359"></a>00359 { <a name="l00360"></a>00360 Py_BLOCK_THREADS; <a name="l00361"></a>00361 PythonType::evalException(); <a name="l00362"></a>00362 <span class="keywordflow">return</span> NULL; <a name="l00363"></a>00363 } <a name="l00364"></a>00364 Py_END_ALLOW_THREADS <span class="comment">// Reclaim Python interpreter</span> <a name="l00365"></a>00365 <span class="keywordflow">return</span> Py_BuildValue(<span class="stringliteral">""</span>); <a name="l00366"></a>00366 } <a name="l00367"></a>00367 <a name="l00368"></a>00368 <a name="l00369"></a><a class="code" href="a00173.html#a68d0f5b398ced2a94c2495b09cdd2632">00369</a> <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> PyObject* <a class="code" href="a00173.html#a68d0f5b398ced2a94c2495b09cdd2632">SolverMRP::commit</a>(PyObject *<span class="keyword">self</span>, PyObject *args) <a name="l00370"></a>00370 { <a name="l00371"></a>00371 Py_BEGIN_ALLOW_THREADS <span class="comment">// Free Python interpreter for other threads</span> <a name="l00372"></a>00372 <span class="keywordflow">try</span> <a name="l00373"></a>00373 { <a name="l00374"></a>00374 <a class="code" href="a00173.html" title="This solver implements a heuristic algorithm for planning demands.">SolverMRP</a> * me = <span class="keyword">static_cast<</span><a class="code" href="a00173.html" title="This solver implements a heuristic algorithm for planning demands.">SolverMRP</a>*<span class="keyword">></span>(<span class="keyword">self</span>); <a name="l00375"></a>00375 me-><a class="code" href="a00173.html#a45b15f36c3d23ab1ed15997e072f2153">scanExcess</a>(me-><a class="code" href="a00173.html#a2c81fc731c11b888376e05e8e6068ef8">commands</a>.<a class="code" href="a00029.html#afeac711703a14926b23f431a0e633c81">getFirstCommand</a>()); <a name="l00376"></a>00376 me-><a class="code" href="a00173.html#a2c81fc731c11b888376e05e8e6068ef8">commands</a>.CommandList::execute(); <a name="l00377"></a>00377 } <a name="l00378"></a>00378 <span class="keywordflow">catch</span>(...) <a name="l00379"></a>00379 { <a name="l00380"></a>00380 Py_BLOCK_THREADS; <a name="l00381"></a>00381 PythonType::evalException(); <a name="l00382"></a>00382 <span class="keywordflow">return</span> NULL; <a name="l00383"></a>00383 } <a name="l00384"></a>00384 Py_END_ALLOW_THREADS <span class="comment">// Reclaim Python interpreter</span> <a name="l00385"></a>00385 <span class="keywordflow">return</span> Py_BuildValue(<span class="stringliteral">""</span>); <a name="l00386"></a>00386 } <a name="l00387"></a>00387 <a name="l00388"></a>00388 <a name="l00389"></a><a class="code" href="a00173.html#aef91f162235173fcbd3a7e99c418a32c">00389</a> <a class="code" href="a00252.html#a99b94ab8c2f2a32277559c7b2b0a054c">DECLARE_EXPORT</a> PyObject* <a class="code" href="a00173.html#aef91f162235173fcbd3a7e99c418a32c">SolverMRP::undo</a>(PyObject *<span class="keyword">self</span>, PyObject *args) <a name="l00390"></a>00390 { <a name="l00391"></a>00391 Py_BEGIN_ALLOW_THREADS <span class="comment">// Free Python interpreter for other threads</span> <a name="l00392"></a>00392 <span class="keywordflow">try</span> <a name="l00393"></a>00393 { <a name="l00394"></a>00394 <span class="keyword">static_cast<</span><a class="code" href="a00173.html" title="This solver implements a heuristic algorithm for planning demands.">SolverMRP</a>*<span class="keyword">></span>(<span class="keyword">self</span>)-><a class="code" href="a00173.html#a2c81fc731c11b888376e05e8e6068ef8">commands</a>.<a class="code" href="a00029.html#a6f38f9a190b88a29f63b58a478cbe982">undo</a>(); <a name="l00395"></a>00395 } <a name="l00396"></a>00396 <span class="keywordflow">catch</span>(...) <a name="l00397"></a>00397 { <a name="l00398"></a>00398 Py_BLOCK_THREADS; <a name="l00399"></a>00399 PythonType::evalException(); <a name="l00400"></a>00400 <span class="keywordflow">return</span> NULL; <a name="l00401"></a>00401 } <a name="l00402"></a>00402 Py_END_ALLOW_THREADS <span class="comment">// Reclaim Python interpreter</span> <a name="l00403"></a>00403 <span class="keywordflow">return</span> Py_BuildValue(<span class="stringliteral">""</span>); <a name="l00404"></a>00404 } <a name="l00405"></a>00405 <a name="l00406"></a>00406 } <span class="comment">// end namespace</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>