Sophie

Sophie

distrib > Mandriva > 2010.0 > i586 > media > contrib-release > by-pkgid > 3e60ff9d4d6f58c8fbd17208f14089fa > files > 262

octave-doc-3.2.3-3mdv2010.0.i586.rpm

<html lang="en">
<head>
<title>Linear Programming - Untitled</title>
<meta http-equiv="Content-Type" content="text/html">
<meta name="description" content="Untitled">
<meta name="generator" content="makeinfo 4.13">
<link title="Top" rel="start" href="index.html#Top">
<link rel="up" href="Optimization.html#Optimization" title="Optimization">
<link rel="next" href="Quadratic-Programming.html#Quadratic-Programming" title="Quadratic Programming">
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
<meta http-equiv="Content-Style-Type" content="text/css">
<style type="text/css"><!--
  pre.display { font-family:inherit }
  pre.format  { font-family:inherit }
  pre.smalldisplay { font-family:inherit; font-size:smaller }
  pre.smallformat  { font-family:inherit; font-size:smaller }
  pre.smallexample { font-size:smaller }
  pre.smalllisp    { font-size:smaller }
  span.sc    { font-variant:small-caps }
  span.roman { font-family:serif; font-weight:normal; } 
  span.sansserif { font-family:sans-serif; font-weight:normal; } 
--></style>
</head>
<body>
<div class="node">
<a name="Linear-Programming"></a>
<p>
Next:&nbsp;<a rel="next" accesskey="n" href="Quadratic-Programming.html#Quadratic-Programming">Quadratic Programming</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="Optimization.html#Optimization">Optimization</a>
<hr>
</div>

<h3 class="section">24.1 Linear Programming</h3>

<p>Octave can solve Linear Programming problems using the <code>glpk</code>
function.  That is, Octave can solve

<pre class="example">     min C'*x
</pre>
   <p>subject to the linear constraints
A*x = b where x &gt;= 0.

<p class="noindent">The <code>glpk</code> function also supports variations of this problem.

<!-- ./optimization/glpk.m -->
   <p><a name="doc_002dglpk"></a>

<div class="defun">
&mdash; Function File: [<var>xopt</var>, <var>fmin</var>, <var>status</var>, <var>extra</var>] = <b>glpk</b> (<var>c, a, b, lb, ub, ctype, vartype, sense, param</var>)<var><a name="index-glpk-1801"></a></var><br>
<blockquote><p>Solve a linear program using the GNU GLPK library.  Given three
arguments, <code>glpk</code> solves the following standard LP:

     <pre class="example">          min C'*x
</pre>
        <p>subject to

     <pre class="example">          A*x  = b
            x &gt;= 0
</pre>
        <p>but may also solve problems of the form

     <pre class="example">          [ min | max ] C'*x
</pre>
        <p>subject to

     <pre class="example">          A*x [ "=" | "&lt;=" | "&gt;=" ] b
            x &gt;= LB
            x &lt;= UB
</pre>
        <p>Input arguments:

          <dl>
<dt><var>c</var><dd>A column array containing the objective function coefficients.

          <br><dt><var>a</var><dd>A matrix containing the constraints coefficients.

          <br><dt><var>b</var><dd>A column array containing the right-hand side value for each constraint
in the constraint matrix.

          <br><dt><var>lb</var><dd>An array containing the lower bound on each of the variables.  If
<var>lb</var> is not supplied, the default lower bound for the variables is
zero.

          <br><dt><var>ub</var><dd>An array containing the upper bound on each of the variables.  If
<var>ub</var> is not supplied, the default upper bound is assumed to be
infinite.

          <br><dt><var>ctype</var><dd>An array of characters containing the sense of each constraint in the
constraint matrix.  Each element of the array may be one of the
following values
               <dl>
<dt><code>"F"</code><dd>A free (unbounded) constraint (the constraint is ignored). 
<br><dt><code>"U"</code><dd>An inequality constraint with an upper bound (<code>A(i,:)*x &lt;= b(i)</code>). 
<br><dt><code>"S"</code><dd>An equality constraint (<code>A(i,:)*x = b(i)</code>). 
<br><dt><code>"L"</code><dd>An inequality with a lower bound (<code>A(i,:)*x &gt;= b(i)</code>). 
<br><dt><code>"D"</code><dd>An inequality constraint with both upper and lower bounds
(<code>A(i,:)*x &gt;= -b(i)</code> <em>and</em> (<code>A(i,:)*x &lt;= b(i)</code>). 
</dl>

          <br><dt><var>vartype</var><dd>A column array containing the types of the variables.
               <dl>
<dt><code>"C"</code><dd>A continuous variable. 
<br><dt><code>"I"</code><dd>An integer variable. 
</dl>

          <br><dt><var>sense</var><dd>If <var>sense</var> is 1, the problem is a minimization.  If <var>sense</var> is
-1, the problem is a maximization.  The default value is 1.

          <br><dt><var>param</var><dd>A structure containing the following parameters used to define the
behavior of solver.  Missing elements in the structure take on default
values, so you only need to set the elements that you wish to change
from the default.

          <p>Integer parameters:

               <dl>
<dt><code>msglev (LPX_K_MSGLEV, default: 1)</code><dd>Level of messages output by solver routines:
                    <dl>
<dt>0<dd>No output. 
<br><dt>1<dd>Error messages only. 
<br><dt>2<dd>Normal output . 
<br><dt>3<dd>Full output (includes informational messages). 
</dl>

               <br><dt><code>scale (LPX_K_SCALE, default: 1)</code><dd>Scaling option:
                    <dl>
<dt>0<dd>No scaling. 
<br><dt>1<dd>Equilibration scaling. 
<br><dt>2<dd>Geometric mean scaling, then equilibration scaling. 
</dl>

               <br><dt><code>dual	 (LPX_K_DUAL, default: 0)</code><dd>Dual simplex option:
                    <dl>
<dt>0<dd>Do not use the dual simplex. 
<br><dt>1<dd>If initial basic solution is dual feasible, use the dual simplex. 
</dl>

               <br><dt><code>price	 (LPX_K_PRICE, default: 1)</code><dd>Pricing option (for both primal and dual simplex):
                    <dl>
<dt>0<dd>Textbook pricing. 
<br><dt>1<dd>Steepest edge pricing. 
</dl>

               <br><dt><code>round	 (LPX_K_ROUND, default: 0)</code><dd>Solution rounding option:
                    <dl>
<dt>0<dd>Report all primal and dual values "as is". 
<br><dt>1<dd>Replace tiny primal and dual values by exact zero. 
</dl>

               <br><dt><code>itlim	 (LPX_K_ITLIM, default: -1)</code><dd>Simplex iterations limit.  If this value is positive, it is decreased by
one each time when one simplex iteration has been performed, and
reaching zero value signals the solver to stop the search.  Negative
value means no iterations limit.

               <br><dt><code>itcnt (LPX_K_OUTFRQ, default: 200)</code><dd>Output frequency, in iterations.  This parameter specifies how
frequently the solver sends information about the solution to the
standard output.

               <br><dt><code>branch (LPX_K_BRANCH, default: 2)</code><dd>Branching heuristic option (for MIP only):
                    <dl>
<dt>0<dd>Branch on the first variable. 
<br><dt>1<dd>Branch on the last variable. 
<br><dt>2<dd>Branch using a heuristic by Driebeck and Tomlin. 
</dl>

               <br><dt><code>btrack (LPX_K_BTRACK, default: 2)</code><dd>Backtracking heuristic option (for MIP only):
                    <dl>
<dt>0<dd>Depth first search. 
<br><dt>1<dd>Breadth first search. 
<br><dt>2<dd>Backtrack using the best projection heuristic. 
</dl>

               <br><dt><code>presol (LPX_K_PRESOL, default: 1)</code><dd>If this flag is set, the routine lpx_simplex solves the problem using
the built-in LP presolver.  Otherwise the LP presolver is not used.

               <br><dt><code>lpsolver (default: 1)</code><dd>Select which solver to use.  If the problem is a MIP problem this flag
will be ignored.
                    <dl>
<dt>1<dd>Revised simplex method. 
<br><dt>2<dd>Interior point method. 
</dl>
               <br><dt><code>save (default: 0)</code><dd>If this parameter is nonzero, save a copy of the problem in
CPLEX LP format to the file <samp><span class="file">"outpb.lp"</span></samp>.  There is currently no
way to change the name of the output file. 
</dl>

          <p>Real parameters:

               <dl>
<dt><code>relax (LPX_K_RELAX, default: 0.07)</code><dd>Relaxation parameter used in the ratio test.  If it is zero, the textbook
ratio test is used.  If it is non-zero (should be positive), Harris'
two-pass ratio test is used.  In the latter case on the first pass of the
ratio test basic variables (in the case of primal simplex) or reduced
costs of non-basic variables (in the case of dual simplex) are allowed
to slightly violate their bounds, but not more than
<code>relax*tolbnd</code> or <code>relax*toldj (thus, relax is a
percentage of tolbnd or toldj</code>.

               <br><dt><code>tolbnd (LPX_K_TOLBND, default: 10e-7)</code><dd>Relative tolerance used to check if the current basic solution is primal
feasible.  It is not recommended that you change this parameter unless you
have a detailed understanding of its purpose.

               <br><dt><code>toldj (LPX_K_TOLDJ, default: 10e-7)</code><dd>Absolute tolerance used to check if the current basic solution is dual
feasible.  It is not recommended that you change this parameter unless you
have a detailed understanding of its purpose.

               <br><dt><code>tolpiv (LPX_K_TOLPIV, default: 10e-9)</code><dd>Relative tolerance used to choose eligible pivotal elements of the
simplex table.  It is not recommended that you change this parameter unless you
have a detailed understanding of its purpose.

               <br><dt><code>objll (LPX_K_OBJLL, default: -DBL_MAX)</code><dd>Lower limit of the objective function.  If on the phase II the objective
function reaches this limit and continues decreasing, the solver stops
the search.  This parameter is used in the dual simplex method only.

               <br><dt><code>objul (LPX_K_OBJUL, default: +DBL_MAX)</code><dd>Upper limit of the objective function.  If on the phase II the objective
function reaches this limit and continues increasing, the solver stops
the search.  This parameter is used in the dual simplex only.

               <br><dt><code>tmlim (LPX_K_TMLIM, default: -1.0)</code><dd>Searching time limit, in seconds.  If this value is positive, it is
decreased each time when one simplex iteration has been performed by the
amount of time spent for the iteration, and reaching zero value signals
the solver to stop the search.  Negative value means no time limit.

               <br><dt><code>outdly (LPX_K_OUTDLY, default: 0.0)</code><dd>Output delay, in seconds.  This parameter specifies how long the solver
should delay sending information about the solution to the standard
output.  Non-positive value means no delay.

               <br><dt><code>tolint (LPX_K_TOLINT, default: 10e-5)</code><dd>Relative tolerance used to check if the current basic solution is integer
feasible.  It is not recommended that you change this parameter unless
you have a detailed understanding of its purpose.

               <br><dt><code>tolobj (LPX_K_TOLOBJ, default: 10e-7)</code><dd>Relative tolerance used to check if the value of the objective function
is not better than in the best known integer feasible solution.  It is
not recommended that you change this parameter unless you have a
detailed understanding of its purpose. 
</dl>
          </dl>

        <p>Output values:

          <dl>
<dt><var>xopt</var><dd>The optimizer (the value of the decision variables at the optimum). 
<br><dt><var>fopt</var><dd>The optimum value of the objective function. 
<br><dt><var>status</var><dd>Status of the optimization.

          <p>Simplex Method:
               <dl>
<dt>180 (<code>LPX_OPT</code>)<dd>Solution is optimal. 
<br><dt>181 (<code>LPX_FEAS</code>)<dd>Solution is feasible. 
<br><dt>182 (<code>LPX_INFEAS</code>)<dd>Solution is infeasible. 
<br><dt>183 (<code>LPX_NOFEAS</code>)<dd>Problem has no feasible solution. 
<br><dt>184 (<code>LPX_UNBND</code>)<dd>Problem has no unbounded solution. 
<br><dt>185 (<code>LPX_UNDEF</code>)<dd>Solution status is undefined. 
</dl>
          Interior Point Method:
               <dl>
<dt>150 (<code>LPX_T_UNDEF</code>)<dd>The interior point method is undefined. 
<br><dt>151 (<code>LPX_T_OPT</code>)<dd>The interior point method is optimal. 
</dl>
          Mixed Integer Method:
               <dl>
<dt>170 (<code>LPX_I_UNDEF</code>)<dd>The status is undefined. 
<br><dt>171 (<code>LPX_I_OPT</code>)<dd>The solution is integer optimal. 
<br><dt>172 (<code>LPX_I_FEAS</code>)<dd>Solution integer feasible but its optimality has not been proven
<br><dt>173 (<code>LPX_I_NOFEAS</code>)<dd>No integer feasible solution. 
</dl>
          If an error occurs, <var>status</var> will contain one of the following
codes:

               <dl>
<dt>204 (<code>LPX_E_FAULT</code>)<dd>Unable to start the search. 
<br><dt>205 (<code>LPX_E_OBJLL</code>)<dd>Objective function lower limit reached. 
<br><dt>206 (<code>LPX_E_OBJUL</code>)<dd>Objective function upper limit reached. 
<br><dt>207 (<code>LPX_E_ITLIM</code>)<dd>Iterations limit exhausted. 
<br><dt>208 (<code>LPX_E_TMLIM</code>)<dd>Time limit exhausted. 
<br><dt>209 (<code>LPX_E_NOFEAS</code>)<dd>No feasible solution. 
<br><dt>210 (<code>LPX_E_INSTAB</code>)<dd>Numerical instability. 
<br><dt>211 (<code>LPX_E_SING</code>)<dd>Problems with basis matrix. 
<br><dt>212 (<code>LPX_E_NOCONV</code>)<dd>No convergence (interior). 
<br><dt>213 (<code>LPX_E_NOPFS</code>)<dd>No primal feasible solution (LP presolver). 
<br><dt>214 (<code>LPX_E_NODFS</code>)<dd>No dual feasible solution (LP presolver). 
</dl>
          <br><dt><var>extra</var><dd>A data structure containing the following fields:
               <dl>
<dt><code>lambda</code><dd>Dual variables. 
<br><dt><code>redcosts</code><dd>Reduced Costs. 
<br><dt><code>time</code><dd>Time (in seconds) used for solving LP/MIP problem. 
<br><dt><code>mem</code><dd>Memory (in bytes) used for solving LP/MIP problem (this is not
available if the version of GLPK is 4.15 or later). 
</dl>
          </dl>

        <p>Example:

     <pre class="example">          c = [10, 6, 4]';
          a = [ 1, 1, 1;
               10, 4, 5;
                2, 2, 6];
          b = [100, 600, 300]';
          lb = [0, 0, 0]';
          ub = [];
          ctype = "UUU";
          vartype = "CCC";
          s = -1;
          
          param.msglev = 1;
          param.itlim = 100;
          
          [xmin, fmin, status, extra] = ...
             glpk (c, a, b, lb, ub, ctype, vartype, s, param);
</pre>
        </blockquote></div>

   </body></html>