Sophie

Sophie

distrib > Fedora > 15 > i386 > by-pkgid > 54cac1c2268db633d66eeff1b4faa585 > files > 515

frepple-doc-0.8.1-3.fc15.noarch.rpm

<!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: lpsolver.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&nbsp;Page</span></a></li>
      <li><a href="pages.html"><span>Related&nbsp;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&nbsp;List</span></a></li>
      <li><a href="globals.html"><span>File&nbsp;Members</span></a></li>
    </ul>
  </div>
  <div class="navpath"><a class="el" href="dir_cfc6129efafb4deb1379318d01a4b532.html">modules</a>&nbsp;&raquo&nbsp;<a class="el" href="dir_12a803726e29de82a20f2c57bbc957ca.html">lp_solver</a>
  </div>
</div>
<div class="contents">
<h1>lpsolver.cpp</h1><a href="a00215.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/modules/lp_solver/lpsolver.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>00028 <span class="preprocessor">#include &quot;<a class="code" href="a00216.html" title="Header file for the module lp_solver.">lpsolver.h</a>&quot;</span>
<a name="l00029"></a>00029 
<a name="l00030"></a><a class="code" href="a00259.html">00030</a> <span class="keyword">namespace </span>module_lp_solver
<a name="l00031"></a>00031 {
<a name="l00032"></a>00032 
<a name="l00033"></a>00033 <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="a00112.html#a06fe14f0a32d32564b39e14933b8dcc1">LPSolver::metadata</a>;
<a name="l00034"></a>00034 
<a name="l00035"></a>00035 <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="a00259.html#a3c066bd64a01663ae7923ce7157c9427">tag_datafile</a>(<span class="stringliteral">&quot;datafile&quot;</span>);
<a name="l00036"></a>00036 <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="a00259.html#a09bd3213510d9b988b069fefbb8eee4d">tag_modelfile</a>(<span class="stringliteral">&quot;modelfile&quot;</span>);
<a name="l00037"></a>00037 <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="a00259.html#ad0f3afe8289adaa0e70aeffbc129e847">tag_solutionfile</a>(<span class="stringliteral">&quot;solutionfile&quot;</span>);
<a name="l00038"></a>00038 <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="a00259.html#a3e3099eabbd5a19d886103977972d149">tag_objective</a>(<span class="stringliteral">&quot;objective&quot;</span>);
<a name="l00039"></a>00039 
<a name="l00040"></a>00040 
<a name="l00041"></a>00041 <a class="code" href="a00252.html#a49d85811d1043ff1f3d7df4be3d90138">MODULE_EXPORT</a> <span class="keyword">const</span> <span class="keywordtype">char</span>* <a class="code" href="a00259.html#a23b340fb5d3b4805500e466be4745537">initialize</a>(<span class="keyword">const</span> <a class="code" href="a00030.html#abed9d8d8563f8322df35b7b9723d6f4f">CommandLoadLibrary::ParameterList</a>&amp; z)
<a name="l00042"></a>00042 {
<a name="l00043"></a>00043   <span class="comment">// Initialize only once</span>
<a name="l00044"></a>00044   <span class="keyword">static</span> <span class="keywordtype">bool</span> init = <span class="keyword">false</span>;
<a name="l00045"></a>00045   <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">char</span>* name = <span class="stringliteral">&quot;lpsolver&quot;</span>;
<a name="l00046"></a>00046   <span class="keywordflow">if</span> (init)
<a name="l00047"></a>00047   {
<a name="l00048"></a>00048     <a class="code" href="a00257.html#a4af9f241e955122820c5e81ceb33edb5">logger</a> &lt;&lt; <span class="stringliteral">&quot;Warning: Initializing module lpsolver more than once.&quot;</span> &lt;&lt; endl;
<a name="l00049"></a>00049     <span class="keywordflow">return</span> name;
<a name="l00050"></a>00050   }
<a name="l00051"></a>00051   init = <span class="keyword">true</span>;
<a name="l00052"></a>00052 
<a name="l00053"></a>00053   <span class="keywordflow">try</span>
<a name="l00054"></a>00054   {
<a name="l00055"></a>00055     <span class="comment">// Register the Python extension</span>
<a name="l00056"></a>00056     PyThreadState *myThreadState = PyGILState_GetThisThreadState();
<a name="l00057"></a>00057     <span class="keywordflow">if</span> (!Py_IsInitialized() || !myThreadState)
<a name="l00058"></a>00058       <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">&quot;Python isn&apos;t initialized correctly&quot;</span>);
<a name="l00059"></a>00059     <span class="keywordflow">try</span>
<a name="l00060"></a>00060     {
<a name="l00061"></a>00061       <span class="comment">// Get the global lock.</span>
<a name="l00062"></a>00062       PyEval_RestoreThread(myThreadState);
<a name="l00063"></a>00063       <span class="comment">// Register new Python data types</span>
<a name="l00064"></a>00064       <span class="keywordflow">if</span> (<a class="code" href="a00112.html#a5b351b4d36fa31bd2ef24c6691b16e13">LPSolver::initialize</a>())
<a name="l00065"></a>00065         <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">&quot;Error registering Python solver_lp extension&quot;</span>);
<a name="l00066"></a>00066     }
<a name="l00067"></a>00067     <span class="comment">// Release the global lock when leaving the function</span>
<a name="l00068"></a>00068     <span class="keywordflow">catch</span> (...)
<a name="l00069"></a>00069     {
<a name="l00070"></a>00070       PyEval_ReleaseLock();
<a name="l00071"></a>00071       <span class="keywordflow">throw</span>;  <span class="comment">// Rethrow the exception</span>
<a name="l00072"></a>00072     }
<a name="l00073"></a>00073     PyEval_ReleaseLock();
<a name="l00074"></a>00074   }
<a name="l00075"></a>00075   <span class="keywordflow">catch</span> (exception &amp;e)
<a name="l00076"></a>00076   {
<a name="l00077"></a>00077     <span class="comment">// Avoid throwing errors during the initialization!</span>
<a name="l00078"></a>00078     <a class="code" href="a00257.html#a4af9f241e955122820c5e81ceb33edb5">logger</a> &lt;&lt; <span class="stringliteral">&quot;Error: &quot;</span> &lt;&lt; e.what() &lt;&lt; endl;
<a name="l00079"></a>00079   }
<a name="l00080"></a>00080   <span class="keywordflow">catch</span> (...)
<a name="l00081"></a>00081   {
<a name="l00082"></a>00082     <a class="code" href="a00257.html#a4af9f241e955122820c5e81ceb33edb5">logger</a> &lt;&lt; <span class="stringliteral">&quot;Error: unknown exception&quot;</span> &lt;&lt; endl;
<a name="l00083"></a>00083   }
<a name="l00084"></a>00084 
<a name="l00085"></a>00085   <span class="comment">// Return the name of the module</span>
<a name="l00086"></a>00086   <span class="keywordflow">return</span> name;
<a name="l00087"></a>00087 }
<a name="l00088"></a>00088 
<a name="l00089"></a>00089 
<a name="l00090"></a><a class="code" href="a00112.html#a5b351b4d36fa31bd2ef24c6691b16e13">00090</a> <span class="keywordtype">int</span> <a class="code" href="a00112.html#a5b351b4d36fa31bd2ef24c6691b16e13">LPSolver::initialize</a>()
<a name="l00091"></a>00091 {
<a name="l00092"></a>00092   <span class="comment">// Initialize the metadata.</span>
<a name="l00093"></a>00093   <a class="code" href="a00112.html#a06fe14f0a32d32564b39e14933b8dcc1">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>(<span class="stringliteral">&quot;solver&quot;</span>, <span class="stringliteral">&quot;solver_lp&quot;</span>,
<a name="l00094"></a>00094     Object::createString&lt;LPSolver&gt;);
<a name="l00095"></a>00095 
<a name="l00096"></a>00096   <span class="comment">// Initialize the Python class</span>
<a name="l00097"></a>00097   <span class="keywordflow">return</span> <a class="code" href="a00112.html#a5b351b4d36fa31bd2ef24c6691b16e13">FreppleClass&lt;LPSolver,Solver&gt;::initialize</a>();
<a name="l00098"></a>00098 }
<a name="l00099"></a>00099 
<a name="l00100"></a>00100 
<a name="l00101"></a>00101 <span class="keywordtype">void</span> LPSolver::solveObjective(<span class="keyword">const</span> <span class="keywordtype">string</span>&amp; colname)
<a name="l00102"></a>00102 {
<a name="l00103"></a>00103   <span class="comment">// Set the objective coefficient</span>
<a name="l00104"></a>00104   <span class="keywordflow">if</span> (colname.empty()) <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">&quot;Empty objective name&quot;</span>);
<a name="l00105"></a>00105   <span class="keywordtype">int</span> col = glp_find_col(lp, colname.c_str());
<a name="l00106"></a>00106   <span class="keywordflow">if</span> (!col)
<a name="l00107"></a>00107     <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">&quot;Unknown objective name &apos;&quot;</span> + <span class="keywordtype">string</span>(colname) + <span class="stringliteral">&quot;&apos;&quot;</span>);
<a name="l00108"></a>00108   lpx_set_obj_coef(lp, col, 1.0);
<a name="l00109"></a>00109 
<a name="l00110"></a>00110   <span class="comment">// Message</span>
<a name="l00111"></a>00111   <span class="keywordflow">if</span> (<a class="code" href="a00171.html#a7331226cd4ef515184dff2d118c43423">getLogLevel</a>()&gt;0)
<a name="l00112"></a>00112     <a class="code" href="a00257.html#a4af9f241e955122820c5e81ceb33edb5">logger</a> &lt;&lt; <span class="stringliteral">&quot;Solving for &quot;</span> &lt;&lt; colname &lt;&lt; <span class="stringliteral">&quot;...&quot;</span> &lt;&lt; endl;
<a name="l00113"></a>00113 
<a name="l00114"></a>00114   <span class="comment">// Solve</span>
<a name="l00115"></a>00115   <span class="keywordtype">int</span> result = glp_simplex(lp, &amp;parameters);
<a name="l00116"></a>00116 
<a name="l00117"></a>00117   <span class="comment">// Echo the result</span>
<a name="l00118"></a>00118   <span class="keywordtype">double</span> val = lpx_get_obj_val(lp);
<a name="l00119"></a>00119   <span class="keywordflow">if</span> (<a class="code" href="a00171.html#a7331226cd4ef515184dff2d118c43423">getLogLevel</a>()&gt;0)
<a name="l00120"></a>00120   {
<a name="l00121"></a>00121     <span class="keywordflow">if</span> (result)
<a name="l00122"></a>00122       <a class="code" href="a00257.html#a4af9f241e955122820c5e81ceb33edb5">logger</a> &lt;&lt; <span class="stringliteral">&quot;  Error &quot;</span> &lt;&lt; result &lt;&lt; endl;
<a name="l00123"></a>00123     <span class="keywordflow">else</span>
<a name="l00124"></a>00124       <a class="code" href="a00257.html#a4af9f241e955122820c5e81ceb33edb5">logger</a> &lt;&lt; <span class="stringliteral">&quot;  Optimum &quot;</span> &lt;&lt; val &lt;&lt;  <span class="stringliteral">&quot; found at &quot;</span> &lt;&lt; Date::now() &lt;&lt; endl;
<a name="l00125"></a>00125   }
<a name="l00126"></a>00126 
<a name="l00127"></a>00127   <span class="comment">// Freeze the column bounds</span>
<a name="l00128"></a>00128   lpx_set_col_bnds(lp, col, LPX_DB,
<a name="l00129"></a>00129     val&gt;=<a class="code" href="a00252.html#a42d90a6275119e1b4ce73c50f1867e60">ROUNDING_ERROR</a> ? val-<a class="code" href="a00252.html#a42d90a6275119e1b4ce73c50f1867e60">ROUNDING_ERROR</a> : 0.0,
<a name="l00130"></a>00130     val&gt;=-<a class="code" href="a00252.html#a42d90a6275119e1b4ce73c50f1867e60">ROUNDING_ERROR</a> ? val+<a class="code" href="a00252.html#a42d90a6275119e1b4ce73c50f1867e60">ROUNDING_ERROR</a> : 0.0);
<a name="l00131"></a>00131 
<a name="l00132"></a>00132   <span class="comment">// Remove from the objective</span>
<a name="l00133"></a>00133   lpx_set_obj_coef(lp, col, 0.0);
<a name="l00134"></a>00134 
<a name="l00135"></a>00135   <span class="comment">// No more presolving required after 1 objective</span>
<a name="l00136"></a>00136   <span class="keywordflow">if</span> (parameters.presolve) parameters.presolve = 0;
<a name="l00137"></a>00137 }
<a name="l00138"></a>00138 
<a name="l00139"></a>00139 
<a name="l00140"></a><a class="code" href="a00112.html#ae17238aac24456062ecf2939201e5b74">00140</a> <span class="keywordtype">void</span> <a class="code" href="a00112.html#ae17238aac24456062ecf2939201e5b74">LPSolver::solve</a>(<span class="keywordtype">void</span> *v)
<a name="l00141"></a>00141 {
<a name="l00142"></a>00142   <span class="keywordflow">if</span> (<a class="code" href="a00171.html#a7331226cd4ef515184dff2d118c43423">getLogLevel</a>()&gt;0)
<a name="l00143"></a>00143     <a class="code" href="a00257.html#a4af9f241e955122820c5e81ceb33edb5">logger</a> &lt;&lt; <span class="stringliteral">&quot;Start running the solver at &quot;</span> &lt;&lt; Date::now() &lt;&lt; endl;
<a name="l00144"></a>00144 
<a name="l00145"></a>00145   <span class="comment">// Capture all terminal output of the solver</span>
<a name="l00146"></a>00146   glp_term_hook(solveroutputredirect,NULL);
<a name="l00147"></a>00147 
<a name="l00148"></a>00148   <span class="comment">// Configure verbosity of the output</span>
<a name="l00149"></a>00149   glp_init_smcp(&amp;parameters);
<a name="l00150"></a>00150   <span class="keywordflow">if</span> (<a class="code" href="a00171.html#a7331226cd4ef515184dff2d118c43423">getLogLevel</a>() == 0)
<a name="l00151"></a>00151     parameters.msg_lev = GLP_MSG_OFF;
<a name="l00152"></a>00152   <span class="keywordflow">else</span> <span class="keywordflow">if</span> (<a class="code" href="a00171.html#a7331226cd4ef515184dff2d118c43423">getLogLevel</a>() == 1)
<a name="l00153"></a>00153     parameters.msg_lev = GLP_MSG_ERR;
<a name="l00154"></a>00154   <span class="keywordflow">else</span> <span class="keywordflow">if</span> (<a class="code" href="a00171.html#a7331226cd4ef515184dff2d118c43423">getLogLevel</a>() == 2)
<a name="l00155"></a>00155     parameters.msg_lev = GLP_MSG_ON;
<a name="l00156"></a>00156   <span class="keywordflow">else</span>
<a name="l00157"></a>00157     parameters.msg_lev = GLP_MSG_ALL;
<a name="l00158"></a>00158 
<a name="l00159"></a>00159   <span class="comment">// Read the problem from a file in the GNU MathProg language.</span>
<a name="l00160"></a>00160   <span class="keywordflow">if</span> (modelfilename.empty())
<a name="l00161"></a>00161     <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">&quot;No model file specified&quot;</span>);
<a name="l00162"></a>00162   <span class="keywordflow">if</span> (datafilename.empty())
<a name="l00163"></a>00163     lp = lpx_read_model(modelfilename.c_str(), NULL, NULL);
<a name="l00164"></a>00164   <span class="keywordflow">else</span>
<a name="l00165"></a>00165     lp = lpx_read_model(modelfilename.c_str(), datafilename.c_str(), NULL);
<a name="l00166"></a>00166   <span class="keywordflow">if</span> (lp == NULL)
<a name="l00167"></a>00167     <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">&quot;Cannot read model file &apos;&quot;</span> + modelfilename + <span class="stringliteral">&quot;&apos;&quot;</span>);
<a name="l00168"></a>00168 
<a name="l00169"></a>00169   <span class="comment">// Optinally, write the model in MPS format. This format can be read</span>
<a name="l00170"></a>00170   <span class="comment">// directly by other Linear Programming packages.</span>
<a name="l00171"></a>00171   <span class="keywordflow">if</span> (<a class="code" href="a00171.html#a7331226cd4ef515184dff2d118c43423">getLogLevel</a>()&gt;2)
<a name="l00172"></a>00172   {
<a name="l00173"></a>00173     <span class="keywordtype">string</span> c = modelfilename + <span class="stringliteral">&quot;.mps&quot;</span>;
<a name="l00174"></a>00174     lpx_write_mps(lp,c.c_str());
<a name="l00175"></a>00175   }
<a name="l00176"></a>00176 
<a name="l00177"></a>00177   <span class="comment">// Scale the problem data</span>
<a name="l00178"></a>00178   lpx_scale_prob(lp);
<a name="l00179"></a>00179 
<a name="l00180"></a>00180   <span class="comment">// Enable pre-solving</span>
<a name="l00181"></a>00181   <span class="comment">// After the first objective, the presolving is switched off.</span>
<a name="l00182"></a>00182   parameters.presolve = 1;
<a name="l00183"></a>00183 
<a name="l00184"></a>00184   <span class="comment">// Minimize the goal</span>
<a name="l00185"></a>00185   glp_set_obj_dir(lp, minimum ? GLP_MIN : GLP_MAX);
<a name="l00186"></a>00186 
<a name="l00187"></a>00187   <span class="comment">// Create an index for quick searching on names</span>
<a name="l00188"></a>00188   glp_create_index(lp);
<a name="l00189"></a>00189 
<a name="l00190"></a>00190   <span class="keywordflow">if</span> (<a class="code" href="a00171.html#a7331226cd4ef515184dff2d118c43423">getLogLevel</a>()&gt;0)
<a name="l00191"></a>00191     <a class="code" href="a00257.html#a4af9f241e955122820c5e81ceb33edb5">logger</a> &lt;&lt; <span class="stringliteral">&quot;Finished solver initialisation at &quot;</span> &lt;&lt; Date::now() &lt;&lt; endl;
<a name="l00192"></a>00192 
<a name="l00193"></a>00193   <span class="comment">// Solving...</span>
<a name="l00194"></a>00194   <span class="keywordflow">if</span> (objectives.empty())
<a name="l00195"></a>00195     <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">&quot;No solver objectives are specified&quot;</span>);
<a name="l00196"></a>00196   <span class="keywordflow">for</span> (list&lt;string&gt;::const_iterator i = objectives.begin();
<a name="l00197"></a>00197     i != objectives.end(); ++i)
<a name="l00198"></a>00198       solveObjective(*i);
<a name="l00199"></a>00199 
<a name="l00200"></a>00200   <span class="comment">// Write solution</span>
<a name="l00201"></a>00201   <span class="keywordflow">if</span> (!solutionfilename.empty())
<a name="l00202"></a>00202     lpx_print_sol(lp,solutionfilename.c_str());
<a name="l00203"></a>00203 
<a name="l00204"></a>00204   <span class="comment">// Cleanup</span>
<a name="l00205"></a>00205   lpx_delete_prob(lp);
<a name="l00206"></a>00206   glp_term_hook(NULL,NULL);
<a name="l00207"></a>00207 
<a name="l00208"></a>00208   <span class="keywordflow">if</span> (<a class="code" href="a00171.html#a7331226cd4ef515184dff2d118c43423">getLogLevel</a>()&gt;0)
<a name="l00209"></a>00209     <a class="code" href="a00257.html#a4af9f241e955122820c5e81ceb33edb5">logger</a> &lt;&lt; <span class="stringliteral">&quot;Finished running the solver at &quot;</span> &lt;&lt; Date::now() &lt;&lt; endl;
<a name="l00210"></a>00210 }
<a name="l00211"></a>00211 
<a name="l00212"></a>00212 
<a name="l00213"></a>00213 <span class="keywordtype">string</span> LPSolver::replaceSpaces(<span class="keyword">const</span> <span class="keywordtype">string</span>&amp; input)
<a name="l00214"></a>00214 {
<a name="l00215"></a>00215   <span class="keywordtype">string</span> x = input;
<a name="l00216"></a>00216   <span class="keywordflow">for</span> (string::iterator i = x.begin(); i != x.end(); ++i)
<a name="l00217"></a>00217     <span class="keywordflow">if</span> (*i == <span class="charliteral">&apos; &apos;</span>) *i = <span class="charliteral">&apos;_&apos;</span>;
<a name="l00218"></a>00218   <span class="keywordflow">return</span> x;
<a name="l00219"></a>00219 }
<a name="l00220"></a>00220 
<a name="l00221"></a>00221 
<a name="l00222"></a><a class="code" href="a00112.html#a85c8ba00f73569c997bb002970764aab">00222</a> <span class="keywordtype">void</span> <a class="code" href="a00112.html#a85c8ba00f73569c997bb002970764aab">LPSolver::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>&amp; 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-&gt;<a class="code" href="a00189.html#a711922eea4cfe3c33b97e4188dacc7d2">writeElement</a>(tag, <a class="code" href="a00177.html#aeb3841a93774dfc303e3df16304b5af2">Tags::tag_name</a>, <a class="code" href="a00182.html#a7416ca220c55147bc1276becc5b9de01">getName</a>());
<a name="l00228"></a>00228     <span class="keywordflow">return</span>;
<a name="l00229"></a>00229   }
<a name="l00230"></a>00230 
<a name="l00231"></a>00231   <span class="comment">// Write the complete object</span>
<a name="l00232"></a>00232   <span class="keywordflow">if</span> (m != <a class="code" href="a00257.html#a20c2c7e4c6b668e71c154ae3eb18f398a2ad5e75fe119e297630882d182832243">NOHEADER</a>) o-&gt;<a class="code" href="a00189.html#a5c1811dae2e3eae344ad366f6441a8a5">BeginObject</a>
<a name="l00233"></a>00233     (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="a00112.html#a59e80bd6c085f2b987c9382d7e78354d">getType</a>().<a class="code" href="a00171.html" title="This class is an implementation of the &amp;quot;visitor&amp;quot; design pattern. It is...">type</a>);
<a name="l00234"></a>00234 
<a name="l00235"></a>00235   <span class="comment">// Fields</span>
<a name="l00236"></a>00236   <span class="keywordflow">if</span> (<a class="code" href="a00112.html#a644e361a095800c4db61a532cfb13ff9">getMinimum</a>())
<a name="l00237"></a>00237     o-&gt;<a class="code" href="a00189.html#a711922eea4cfe3c33b97e4188dacc7d2">writeElement</a>(<a class="code" href="a00177.html#ac361ec1b9a7c26e74fbc4c21acb99049">Tags::tag_minimum</a>, <span class="keyword">true</span>);
<a name="l00238"></a>00238   <span class="keywordflow">else</span>
<a name="l00239"></a>00239     o-&gt;<a class="code" href="a00189.html#a711922eea4cfe3c33b97e4188dacc7d2">writeElement</a>(<a class="code" href="a00177.html#a608a97000f23fdec1baec4504d095b24">Tags::tag_maximum</a>, <span class="keyword">true</span>);
<a name="l00240"></a>00240   o-&gt;<a class="code" href="a00189.html#a711922eea4cfe3c33b97e4188dacc7d2">writeElement</a>(tag_modelfile, <a class="code" href="a00112.html#a05fb54b8f285cd3f6843c9febde8864d">getModelFile</a>());
<a name="l00241"></a>00241   o-&gt;<a class="code" href="a00189.html#a711922eea4cfe3c33b97e4188dacc7d2">writeElement</a>(tag_datafile, <a class="code" href="a00112.html#aa06224f89b9a520d833f04e329d69b0f">getDataFile</a>());
<a name="l00242"></a>00242   o-&gt;<a class="code" href="a00189.html#a711922eea4cfe3c33b97e4188dacc7d2">writeElement</a>(tag_solutionfile, <a class="code" href="a00112.html#a8adb53e496e6355e86909fef0df5729b">getSolutionFile</a>());
<a name="l00243"></a>00243   <span class="keywordflow">for</span> (list&lt;string&gt;::const_iterator i = objectives.begin();
<a name="l00244"></a>00244     i != objectives.end(); ++i)
<a name="l00245"></a>00245       o-&gt;<a class="code" href="a00189.html#a711922eea4cfe3c33b97e4188dacc7d2">writeElement</a>(tag_objective, *i);
<a name="l00246"></a>00246   <a class="code" href="a00112.html#a85c8ba00f73569c997bb002970764aab">Solver::writeElement</a>(o, tag, <a class="code" href="a00257.html#a20c2c7e4c6b668e71c154ae3eb18f398a2ad5e75fe119e297630882d182832243">NOHEADER</a>);
<a name="l00247"></a>00247 }
<a name="l00248"></a>00248 
<a name="l00249"></a>00249 
<a name="l00250"></a><a class="code" href="a00112.html#a1efedc96cb52751b3b3efca56401fd30">00250</a> <span class="keywordtype">void</span> <a class="code" href="a00112.html#a1efedc96cb52751b3b3efca56401fd30">LPSolver::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>&amp; pIn, <span class="keyword">const</span> <a class="code" href="a00002.html" title="A class to model keyword instances.">Attribute</a>&amp; 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>&amp; pElement)
<a name="l00251"></a>00251 {
<a name="l00252"></a>00252   <span class="keywordflow">if</span> (pAttr.<a class="code" href="a00002.html#aebffce6c4fcf1696ca34f63f2b6ee091">isA</a>(<a class="code" href="a00177.html#ac361ec1b9a7c26e74fbc4c21acb99049">Tags::tag_minimum</a>))
<a name="l00253"></a>00253     <a class="code" href="a00112.html#a6401173b7600ee08b35322dd8078bc53">setMinimum</a>(pElement.<a class="code" href="a00047.html#a542b814710b3242bd4c81aad2fc269d8">getBool</a>());
<a name="l00254"></a>00254   <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#a608a97000f23fdec1baec4504d095b24">Tags::tag_maximum</a>))
<a name="l00255"></a>00255     <a class="code" href="a00112.html#a6401173b7600ee08b35322dd8078bc53">setMinimum</a>(!pElement.<a class="code" href="a00047.html#a542b814710b3242bd4c81aad2fc269d8">getBool</a>());
<a name="l00256"></a>00256   <span class="keywordflow">else</span> <span class="keywordflow">if</span> (pAttr.<a class="code" href="a00002.html#aebffce6c4fcf1696ca34f63f2b6ee091">isA</a>(tag_datafile))
<a name="l00257"></a>00257     <a class="code" href="a00112.html#af708b6aa075482fc0a15156101cf764a">setDataFile</a>(pElement.<a class="code" href="a00047.html#a053aa4cde35b21a399f26bca0132ab3f">getString</a>());
<a name="l00258"></a>00258   <span class="keywordflow">else</span> <span class="keywordflow">if</span> (pAttr.<a class="code" href="a00002.html#aebffce6c4fcf1696ca34f63f2b6ee091">isA</a>(tag_modelfile))
<a name="l00259"></a>00259     <a class="code" href="a00112.html#ac225e17c08274edccba96f31b18f22c3">setModelFile</a>(pElement.<a class="code" href="a00047.html#a053aa4cde35b21a399f26bca0132ab3f">getString</a>());
<a name="l00260"></a>00260   <span class="keywordflow">else</span> <span class="keywordflow">if</span> (pAttr.<a class="code" href="a00002.html#aebffce6c4fcf1696ca34f63f2b6ee091">isA</a>(tag_solutionfile))
<a name="l00261"></a>00261     <a class="code" href="a00112.html#a14bae3e7e9bf5a5dc57e3f7e75bdb868">setSolutionFile</a>(pElement.<a class="code" href="a00047.html#a053aa4cde35b21a399f26bca0132ab3f">getString</a>());
<a name="l00262"></a>00262   <span class="keywordflow">else</span> <span class="keywordflow">if</span> (pAttr.<a class="code" href="a00002.html#aebffce6c4fcf1696ca34f63f2b6ee091">isA</a>(tag_objective))
<a name="l00263"></a>00263     <a class="code" href="a00112.html#a48fc88567e5e4ce858dd72ddfb0f9aed">addObjective</a>(pElement.<a class="code" href="a00047.html#a053aa4cde35b21a399f26bca0132ab3f">getString</a>());
<a name="l00264"></a>00264   <span class="keywordflow">else</span>
<a name="l00265"></a>00265     <span class="comment">// The standard fields of a solver...</span>
<a name="l00266"></a>00266     <a class="code" href="a00112.html#a1efedc96cb52751b3b3efca56401fd30">Solver::endElement</a>(pIn, pAttr, pElement);
<a name="l00267"></a>00267 }
<a name="l00268"></a>00268 
<a name="l00269"></a>00269 
<a name="l00270"></a><a class="code" href="a00112.html#a05c791c87438080ee3dccf793d1d7e51">00270</a> PyObject* <a class="code" href="a00112.html#a05c791c87438080ee3dccf793d1d7e51">LPSolver::getattro</a>(<span class="keyword">const</span> <a class="code" href="a00002.html" title="A class to model keyword instances.">Attribute</a>&amp; attr)
<a name="l00271"></a>00271 {
<a name="l00272"></a>00272   <span class="keywordflow">if</span> (attr.<a class="code" href="a00002.html#aebffce6c4fcf1696ca34f63f2b6ee091">isA</a>(<a class="code" href="a00177.html#ac361ec1b9a7c26e74fbc4c21acb99049">Tags::tag_minimum</a>))
<a name="l00273"></a>00273     <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="a00112.html#a644e361a095800c4db61a532cfb13ff9">getMinimum</a>());
<a name="l00274"></a>00274   <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#a608a97000f23fdec1baec4504d095b24">Tags::tag_maximum</a>))
<a name="l00275"></a>00275     <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="a00112.html#a644e361a095800c4db61a532cfb13ff9">getMinimum</a>()));
<a name="l00276"></a>00276   <span class="keywordflow">else</span> <span class="keywordflow">if</span> (attr.<a class="code" href="a00002.html#aebffce6c4fcf1696ca34f63f2b6ee091">isA</a>(tag_datafile))
<a name="l00277"></a>00277     <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="a00112.html#aa06224f89b9a520d833f04e329d69b0f">getDataFile</a>());
<a name="l00278"></a>00278   <span class="keywordflow">else</span> <span class="keywordflow">if</span> (attr.<a class="code" href="a00002.html#aebffce6c4fcf1696ca34f63f2b6ee091">isA</a>(tag_modelfile))
<a name="l00279"></a>00279     <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="a00112.html#a05fb54b8f285cd3f6843c9febde8864d">getModelFile</a>());
<a name="l00280"></a>00280   <span class="keywordflow">else</span> <span class="keywordflow">if</span> (attr.<a class="code" href="a00002.html#aebffce6c4fcf1696ca34f63f2b6ee091">isA</a>(tag_solutionfile))
<a name="l00281"></a>00281     <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="a00112.html#a8adb53e496e6355e86909fef0df5729b">getSolutionFile</a>());
<a name="l00282"></a>00282   <span class="keywordflow">else</span> <span class="keywordflow">if</span> (attr.<a class="code" href="a00002.html#aebffce6c4fcf1696ca34f63f2b6ee091">isA</a>(tag_objective))
<a name="l00283"></a>00283   {
<a name="l00284"></a>00284     <span class="comment">// The list of objectives is returned as a list of strings</span>
<a name="l00285"></a>00285     PyObject* result = PyList_New(<a class="code" href="a00112.html#ae57e697cc8bcc4dcacfbf2c64e203f5e">getObjectives</a>().<a class="code" href="a00085.html#a942c27efb3a90dba22215a6e4287d8e4">size</a>());
<a name="l00286"></a>00286     <span class="keywordtype">int</span> count = 0;
<a name="l00287"></a>00287     <span class="keywordflow">for</span> (list&lt;string&gt;::const_iterator i = <a class="code" href="a00112.html#ae57e697cc8bcc4dcacfbf2c64e203f5e">getObjectives</a>().<a class="code" href="a00085.html#a1926a798edd9c04bc37e596936003cd6">begin</a>();
<a name="l00288"></a>00288         i != <a class="code" href="a00112.html#ae57e697cc8bcc4dcacfbf2c64e203f5e">getObjectives</a>().end(); ++i)
<a name="l00289"></a>00289       PyList_SetItem(result, count++, <a class="code" href="a00154.html" title="This class handles two-way translation between the data types in C++ and Python.">PythonObject</a>(*i));
<a name="l00290"></a>00290     <span class="keywordflow">return</span> result;
<a name="l00291"></a>00291   }
<a name="l00292"></a>00292   <span class="keywordflow">return</span> <a class="code" href="a00112.html#a05c791c87438080ee3dccf793d1d7e51">Solver::getattro</a>(attr);
<a name="l00293"></a>00293 }
<a name="l00294"></a>00294 
<a name="l00295"></a>00295 
<a name="l00296"></a><a class="code" href="a00112.html#a4717526cb4db2ca217646e8af799de8b">00296</a> <span class="keywordtype">int</span> <a class="code" href="a00112.html#a4717526cb4db2ca217646e8af799de8b">LPSolver::setattro</a>(<span class="keyword">const</span> <a class="code" href="a00002.html" title="A class to model keyword instances.">Attribute</a>&amp; 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>&amp; field)
<a name="l00297"></a>00297 {
<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#ac361ec1b9a7c26e74fbc4c21acb99049">Tags::tag_minimum</a>))
<a name="l00299"></a>00299     <a class="code" href="a00112.html#a6401173b7600ee08b35322dd8078bc53">setMinimum</a>(field.<a class="code" href="a00154.html#a804b478fb76759d334882ee468fc84f9">getBool</a>());
<a name="l00300"></a>00300   <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#a608a97000f23fdec1baec4504d095b24">Tags::tag_maximum</a>))
<a name="l00301"></a>00301     <a class="code" href="a00112.html#a6401173b7600ee08b35322dd8078bc53">setMinimum</a>(!field.<a class="code" href="a00154.html#a804b478fb76759d334882ee468fc84f9">getBool</a>());
<a name="l00302"></a>00302   <span class="keywordflow">else</span> <span class="keywordflow">if</span> (attr.<a class="code" href="a00002.html#aebffce6c4fcf1696ca34f63f2b6ee091">isA</a>(tag_datafile))
<a name="l00303"></a>00303     <a class="code" href="a00112.html#af708b6aa075482fc0a15156101cf764a">setDataFile</a>(field.<a class="code" href="a00154.html#a471bd4797fe735e12a1f485e05fc5940">getString</a>());
<a name="l00304"></a>00304   <span class="keywordflow">else</span> <span class="keywordflow">if</span> (attr.<a class="code" href="a00002.html#aebffce6c4fcf1696ca34f63f2b6ee091">isA</a>(tag_modelfile))
<a name="l00305"></a>00305     <a class="code" href="a00112.html#ac225e17c08274edccba96f31b18f22c3">setModelFile</a>(field.<a class="code" href="a00154.html#a471bd4797fe735e12a1f485e05fc5940">getString</a>());
<a name="l00306"></a>00306   <span class="keywordflow">else</span> <span class="keywordflow">if</span> (attr.<a class="code" href="a00002.html#aebffce6c4fcf1696ca34f63f2b6ee091">isA</a>(tag_solutionfile))
<a name="l00307"></a>00307     <a class="code" href="a00112.html#a14bae3e7e9bf5a5dc57e3f7e75bdb868">setSolutionFile</a>(field.<a class="code" href="a00154.html#a471bd4797fe735e12a1f485e05fc5940">getString</a>());
<a name="l00308"></a>00308   <span class="keywordflow">else</span> <span class="keywordflow">if</span> (attr.<a class="code" href="a00002.html#aebffce6c4fcf1696ca34f63f2b6ee091">isA</a>(tag_objective))
<a name="l00309"></a>00309   {
<a name="l00310"></a>00310     <span class="comment">// The objective argument is a list of strings</span>
<a name="l00311"></a>00311     PyObject* seq = PySequence_Fast(static_cast&lt;PyObject*&gt;(field), <span class="stringliteral">&quot;expected a list&quot;</span>);
<a name="l00312"></a>00312     <span class="keywordflow">if</span> (!PyList_Check(seq))
<a name="l00313"></a>00313     {
<a name="l00314"></a>00314       PyErr_SetString(<a class="code" href="a00257.html#a75c689d2dca4282e2ca0dad79dab1063" title="Python exception class matching with frepple::DataException.">PythonDataException</a>, <span class="stringliteral">&quot;expected a list&quot;</span>);
<a name="l00315"></a>00315       <span class="keywordflow">return</span> -1; <span class="comment">// Error</span>
<a name="l00316"></a>00316     }
<a name="l00317"></a>00317     <span class="keywordtype">int</span> len = PySequence_Size(static_cast&lt;PyObject*&gt;(field));
<a name="l00318"></a>00318     <a class="code" href="a00154.html" title="This class handles two-way translation between the data types in C++ and Python.">PythonObject</a> item;
<a name="l00319"></a>00319     <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i &lt; len; i++)
<a name="l00320"></a>00320     {
<a name="l00321"></a>00321       item = PyList_GET_ITEM(seq, i);
<a name="l00322"></a>00322       <a class="code" href="a00112.html#a48fc88567e5e4ce858dd72ddfb0f9aed">addObjective</a>(item.<a class="code" href="a00154.html#a471bd4797fe735e12a1f485e05fc5940">getString</a>());
<a name="l00323"></a>00323     }
<a name="l00324"></a>00324   }
<a name="l00325"></a>00325   <span class="keywordflow">else</span>
<a name="l00326"></a>00326     <span class="keywordflow">return</span> <a class="code" href="a00112.html#a4717526cb4db2ca217646e8af799de8b">Solver::setattro</a>(attr, field);
<a name="l00327"></a>00327   <span class="keywordflow">return</span> 0; <span class="comment">// OK</span>
<a name="l00328"></a>00328 }
<a name="l00329"></a>00329 
<a name="l00330"></a>00330 }  <span class="comment">// End namespace</span>
</pre></div></div>
<hr size="1"/><address style="align: right;"><small>Documentation generated for frePPLe by&nbsp;
<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>