1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591
|
<!DOCTYPE html>
<html>
<!-- Created by GNU Texinfo 7.1.1, https://www.gnu.org/software/texinfo/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Linear Programming (GNU Octave (version 10.3.0))</title>
<meta name="description" content="Linear Programming (GNU Octave (version 10.3.0))">
<meta name="keywords" content="Linear Programming (GNU Octave (version 10.3.0))">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<meta name="viewport" content="width=device-width,initial-scale=1">
<link href="index.html" rel="start" title="Top">
<link href="Concept-Index.html" rel="index" title="Concept Index">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="Optimization.html" rel="up" title="Optimization">
<link href="Quadratic-Programming.html" rel="next" title="Quadratic Programming">
<style type="text/css">
<!--
a.copiable-link {visibility: hidden; text-decoration: none; line-height: 0em}
div.example {margin-left: 3.2em}
span:hover a.copiable-link {visibility: visible}
strong.def-name {font-family: monospace; font-weight: bold; font-size: larger}
-->
</style>
<link rel="stylesheet" type="text/css" href="octave.css">
</head>
<body lang="en">
<div class="section-level-extent" id="Linear-Programming">
<div class="nav-panel">
<p>
Next: <a href="Quadratic-Programming.html" accesskey="n" rel="next">Quadratic Programming</a>, Up: <a href="Optimization.html" accesskey="u" rel="up">Optimization</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<h3 class="section" id="Linear-Programming-1"><span>25.1 Linear Programming<a class="copiable-link" href="#Linear-Programming-1"> ¶</a></span></h3>
<p>Octave can solve Linear Programming problems using the <code class="code">glpk</code>
function. That is, Octave can solve
</p>
<div class="example">
<pre class="example-preformatted">min C'*x
</pre></div>
<p>subject to the linear constraints
<em class="math">A*x = b</em> where <em class="math">x ≥ 0</em>.
</p>
<p>The <code class="code">glpk</code> function also supports variations of this problem.
</p>
<a class="anchor" id="XREFglpk"></a><span style="display:block; margin-top:-4.5ex;"> </span>
<dl class="first-deftypefn">
<dt class="deftypefn" id="index-glpk"><span><code class="def-type">[<var class="var">xopt</var>, <var class="var">fmin</var>, <var class="var">errnum</var>, <var class="var">extra</var>] =</code> <strong class="def-name">glpk</strong> <code class="def-code-arguments">(<var class="var">c</var>, <var class="var">A</var>, <var class="var">b</var>, <var class="var">lb</var>, <var class="var">ub</var>, <var class="var">ctype</var>, <var class="var">vartype</var>, <var class="var">sense</var>, <var class="var">param</var>)</code><a class="copiable-link" href="#index-glpk"> ¶</a></span></dt>
<dd><p>Solve a linear program using the GNU <small class="sc">GLPK</small> library.
</p>
<p>Given three arguments, <code class="code">glpk</code> solves the following standard LP:
</p>
<div class="example">
<pre class="example-preformatted">min C'*x
</pre></div>
<p>subject to
</p>
<div class="example">
<div class="group"><pre class="example-preformatted">A*x = b
x >= 0
</pre></div></div>
<p>but may also solve problems of the form
</p>
<div class="example">
<pre class="example-preformatted">[ min | max ] C'*x
</pre></div>
<p>subject to
</p>
<div class="example">
<div class="group"><pre class="example-preformatted">A*x [ "=" | "<=" | ">=" ] b
x >= LB
x <= UB
</pre></div></div>
<p>Input arguments:
</p>
<dl class="table">
<dt><var class="var">c</var></dt>
<dd><p>A column array containing the objective function coefficients.
</p>
</dd>
<dt><var class="var">A</var></dt>
<dd><p>A matrix containing the constraints coefficients.
</p>
</dd>
<dt><var class="var">b</var></dt>
<dd><p>A column array containing the right-hand side value for each constraint in
the constraint matrix.
</p>
</dd>
<dt><var class="var">lb</var></dt>
<dd><p>An array containing the lower bound on each of the variables. If <var class="var">lb</var>
is not supplied, the default lower bound for the variables is zero.
</p>
</dd>
<dt><var class="var">ub</var></dt>
<dd><p>An array containing the upper bound on each of the variables. If <var class="var">ub</var>
is not supplied, the default upper bound is assumed to be infinite.
</p>
</dd>
<dt><var class="var">ctype</var></dt>
<dd><p>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
</p>
<dl class="table">
<dt><code class="code">"F"</code></dt>
<dd><p>A free (unbounded) constraint (the constraint is ignored).
</p>
</dd>
<dt><code class="code">"U"</code></dt>
<dd><p>An inequality constraint with an upper bound (<code class="code">A(i,:)*x <= b(i)</code>).
</p>
</dd>
<dt><code class="code">"S"</code></dt>
<dd><p>An equality constraint (<code class="code">A(i,:)*x = b(i)</code>).
</p>
</dd>
<dt><code class="code">"L"</code></dt>
<dd><p>An inequality with a lower bound (<code class="code">A(i,:)*x >= b(i)</code>).
</p>
</dd>
<dt><code class="code">"D"</code></dt>
<dd><p>An inequality constraint with both upper and lower bounds
(<code class="code">A(i,:)*x >= -b(i)</code>) <em class="emph">and</em> (<code class="code">A(i,:)*x <= b(i)</code>).
</p></dd>
</dl>
</dd>
<dt><var class="var">vartype</var></dt>
<dd><p>A column array containing the types of the variables.
</p>
<dl class="table">
<dt><code class="code">"C"</code></dt>
<dd><p>A continuous variable.
</p>
</dd>
<dt><code class="code">"I"</code></dt>
<dd><p>An integer variable.
</p></dd>
</dl>
</dd>
<dt><var class="var">sense</var></dt>
<dd><p>If <var class="var">sense</var> is 1, the problem is a minimization. If <var class="var">sense</var> is -1,
the problem is a maximization. The default value is 1.
</p>
</dd>
<dt><var class="var">param</var></dt>
<dd><p>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>
<p>Integer parameters:
</p>
<dl class="table">
<dt><code class="code">msglev (default: 1)</code></dt>
<dd><p>Level of messages output by solver routines:
</p>
<dl class="table">
<dt>0 (<code class="code">GLP_MSG_OFF</code><!-- /@w -->)</dt>
<dd><p>No output.
</p>
</dd>
<dt>1 (<code class="code">GLP_MSG_ERR</code><!-- /@w -->)</dt>
<dd><p>Error and warning messages only.
</p>
</dd>
<dt>2 (<code class="code">GLP_MSG_ON</code><!-- /@w -->)</dt>
<dd><p>Normal output.
</p>
</dd>
<dt>3 (<code class="code">GLP_MSG_ALL</code><!-- /@w -->)</dt>
<dd><p>Full output (includes informational messages).
</p></dd>
</dl>
</dd>
<dt><code class="code">scale (default: 16)</code></dt>
<dd><p>Scaling option. The values can be combined with the bitwise OR operator and
may be the following:
</p>
<dl class="table">
<dt>1 (<code class="code">GLP_SF_GM</code><!-- /@w -->)</dt>
<dd><p>Geometric mean scaling.
</p>
</dd>
<dt>16 (<code class="code">GLP_SF_EQ</code><!-- /@w -->)</dt>
<dd><p>Equilibration scaling.
</p>
</dd>
<dt>32 (<code class="code">GLP_SF_2N</code><!-- /@w -->)</dt>
<dd><p>Round scale factors to power of two.
</p>
</dd>
<dt>64 (<code class="code">GLP_SF_SKIP</code><!-- /@w -->)</dt>
<dd><p>Skip if problem is well scaled.
</p></dd>
</dl>
<p>Alternatively, a value of 128 (<code class="env">GLP_SF_AUTO</code><!-- /@w -->) may be also
specified, in which case the routine chooses the scaling options
automatically.
</p>
</dd>
<dt><code class="code">dual (default: 1)</code></dt>
<dd><p>Simplex method option:
</p>
<dl class="table">
<dt>1 (<code class="code">GLP_PRIMAL</code><!-- /@w -->)</dt>
<dd><p>Use two-phase primal simplex.
</p>
</dd>
<dt>2 (<code class="code">GLP_DUALP</code><!-- /@w -->)</dt>
<dd><p>Use two-phase dual simplex, and if it fails, switch to the primal simplex.
</p>
</dd>
<dt>3 (<code class="code">GLP_DUAL</code><!-- /@w -->)</dt>
<dd><p>Use two-phase dual simplex.
</p></dd>
</dl>
</dd>
<dt><code class="code">price (default: 34)</code></dt>
<dd><p>Pricing option (for both primal and dual simplex):
</p>
<dl class="table">
<dt>17 (<code class="code">GLP_PT_STD</code><!-- /@w -->)</dt>
<dd><p>Textbook pricing.
</p>
</dd>
<dt>34 (<code class="code">GLP_PT_PSE</code><!-- /@w -->)</dt>
<dd><p>Steepest edge pricing.
</p></dd>
</dl>
</dd>
<dt><code class="code">itlim (default: intmax)</code></dt>
<dd><p>Simplex iterations limit. 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.
</p>
</dd>
<dt><code class="code">outfrq (default: 200)</code></dt>
<dd><p>Output frequency, in iterations. This parameter specifies how frequently
the solver sends information about the solution to the standard output.
</p>
</dd>
<dt><code class="code">branch (default: 4)</code></dt>
<dd><p>Branching technique option (for MIP only):
</p>
<dl class="table">
<dt>1 (<code class="code">GLP_BR_FFV</code><!-- /@w -->)</dt>
<dd><p>First fractional variable.
</p>
</dd>
<dt>2 (<code class="code">GLP_BR_LFV</code><!-- /@w -->)</dt>
<dd><p>Last fractional variable.
</p>
</dd>
<dt>3 (<code class="code">GLP_BR_MFV</code><!-- /@w -->)</dt>
<dd><p>Most fractional variable.
</p>
</dd>
<dt>4 (<code class="code">GLP_BR_DTH</code><!-- /@w -->)</dt>
<dd><p>Heuristic by Driebeck and Tomlin.
</p>
</dd>
<dt>5 (<code class="code">GLP_BR_PCH</code><!-- /@w -->)</dt>
<dd><p>Hybrid pseudocost heuristic.
</p></dd>
</dl>
</dd>
<dt><code class="code">btrack (default: 4)</code></dt>
<dd><p>Backtracking technique option (for MIP only):
</p>
<dl class="table">
<dt>1 (<code class="code">GLP_BT_DFS</code><!-- /@w -->)</dt>
<dd><p>Depth first search.
</p>
</dd>
<dt>2 (<code class="code">GLP_BT_BFS</code><!-- /@w -->)</dt>
<dd><p>Breadth first search.
</p>
</dd>
<dt>3 (<code class="code">GLP_BT_BLB</code><!-- /@w -->)</dt>
<dd><p>Best local bound.
</p>
</dd>
<dt>4 (<code class="code">GLP_BT_BPH</code><!-- /@w -->)</dt>
<dd><p>Best projection heuristic.
</p></dd>
</dl>
</dd>
<dt><code class="code">presol (default: 1)</code></dt>
<dd><p>If this flag is set, the simplex solver uses the built-in LP presolver.
Otherwise the LP presolver is not used.
</p>
</dd>
<dt><code class="code">lpsolver (default: 1)</code></dt>
<dd><p>Select which solver to use. If the problem is a MIP problem this flag
will be ignored.
</p>
<dl class="table">
<dt>1</dt>
<dd><p>Revised simplex method.
</p>
</dd>
<dt>2</dt>
<dd><p>Interior point method.
</p></dd>
</dl>
</dd>
<dt><code class="code">rtest (default: 34)</code></dt>
<dd><p>Ratio test technique:
</p>
<dl class="table">
<dt>17 (<code class="code">GLP_RT_STD</code><!-- /@w -->)</dt>
<dd><p>Standard ("textbook").
</p>
</dd>
<dt>34 (<code class="code">GLP_RT_HAR</code><!-- /@w -->)</dt>
<dd><p>Harris’ two-pass ratio test.
</p></dd>
</dl>
</dd>
<dt><code class="code">tmlim (default: intmax)</code></dt>
<dd><p>Searching time limit, in milliseconds.
</p>
</dd>
<dt><code class="code">outdly (default: 0)</code></dt>
<dd><p>Output delay, in seconds. This parameter specifies how long the solver
should delay sending information about the solution to the standard output.
</p>
</dd>
<dt><code class="code">save (default: 0)</code></dt>
<dd><p>If this parameter is nonzero, save a copy of the problem in CPLEX
LP format to the file <samp class="file">"outpb.lp"</samp>. There is currently no way to
change the name of the output file.
</p></dd>
</dl>
<p>Real parameters:
</p>
<dl class="table">
<dt><code class="code">tolbnd (default: 1e-7)</code></dt>
<dd><p>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.
</p>
</dd>
<dt><code class="code">toldj (default: 1e-7)</code></dt>
<dd><p>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.
</p>
</dd>
<dt><code class="code">tolpiv (default: 1e-9)</code></dt>
<dd><p>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.
</p>
</dd>
<dt><code class="code">objll (default: -DBL_MAX)</code></dt>
<dd><p>Lower limit of the objective function. If the objective function reaches
this limit and continues decreasing, the solver stops the search. This
parameter is used in the dual simplex method only.
</p>
</dd>
<dt><code class="code">objul (default: +DBL_MAX)</code></dt>
<dd><p>Upper limit of the objective function. If the objective function reaches
this limit and continues increasing, the solver stops the search. This
parameter is used in the dual simplex only.
</p>
</dd>
<dt><code class="code">tolint (default: 1e-5)</code></dt>
<dd><p>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.
</p>
</dd>
<dt><code class="code">tolobj (default: 1e-7)</code></dt>
<dd><p>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.
</p></dd>
</dl>
</dd>
</dl>
<p>Output values:
</p>
<dl class="table">
<dt><var class="var">xopt</var></dt>
<dd><p>The optimizer (the value of the decision variables at the optimum).
</p>
</dd>
<dt><var class="var">fopt</var></dt>
<dd><p>The optimum value of the objective function.
</p>
</dd>
<dt><var class="var">errnum</var></dt>
<dd><p>Error code.
</p>
<dl class="table">
<dt>0</dt>
<dd><p>No error.
</p>
</dd>
<dt>1 (<code class="code">GLP_EBADB</code><!-- /@w -->)</dt>
<dd><p>Invalid basis.
</p>
</dd>
<dt>2 (<code class="code">GLP_ESING</code><!-- /@w -->)</dt>
<dd><p>Singular matrix.
</p>
</dd>
<dt>3 (<code class="code">GLP_ECOND</code><!-- /@w -->)</dt>
<dd><p>Ill-conditioned matrix.
</p>
</dd>
<dt>4 (<code class="code">GLP_EBOUND</code><!-- /@w -->)</dt>
<dd><p>Invalid bounds.
</p>
</dd>
<dt>5 (<code class="code">GLP_EFAIL</code><!-- /@w -->)</dt>
<dd><p>Solver failed.
</p>
</dd>
<dt>6 (<code class="code">GLP_EOBJLL</code><!-- /@w -->)</dt>
<dd><p>Objective function lower limit reached.
</p>
</dd>
<dt>7 (<code class="code">GLP_EOBJUL</code><!-- /@w -->)</dt>
<dd><p>Objective function upper limit reached.
</p>
</dd>
<dt>8 (<code class="code">GLP_EITLIM</code><!-- /@w -->)</dt>
<dd><p>Iterations limit exhausted.
</p>
</dd>
<dt>9 (<code class="code">GLP_ETMLIM</code><!-- /@w -->)</dt>
<dd><p>Time limit exhausted.
</p>
</dd>
<dt>10 (<code class="code">GLP_ENOPFS</code><!-- /@w -->)</dt>
<dd><p>No primal feasible solution.
</p>
</dd>
<dt>11 (<code class="code">GLP_ENODFS</code><!-- /@w -->)</dt>
<dd><p>No dual feasible solution.
</p>
</dd>
<dt>12 (<code class="code">GLP_EROOT</code><!-- /@w -->)</dt>
<dd><p>Root LP optimum not provided.
</p>
</dd>
<dt>13 (<code class="code">GLP_ESTOP</code><!-- /@w -->)</dt>
<dd><p>Search terminated by application.
</p>
</dd>
<dt>14 (<code class="code">GLP_EMIPGAP</code><!-- /@w -->)</dt>
<dd><p>Relative MIP gap tolerance reached.
</p>
</dd>
<dt>15 (<code class="code">GLP_ENOFEAS</code><!-- /@w -->)</dt>
<dd><p>No primal/dual feasible solution.
</p>
</dd>
<dt>16 (<code class="code">GLP_ENOCVG</code><!-- /@w -->)</dt>
<dd><p>No convergence.
</p>
</dd>
<dt>17 (<code class="code">GLP_EINSTAB</code><!-- /@w -->)</dt>
<dd><p>Numerical instability.
</p>
</dd>
<dt>18 (<code class="code">GLP_EDATA</code><!-- /@w -->)</dt>
<dd><p>Invalid data.
</p>
</dd>
<dt>19 (<code class="code">GLP_ERANGE</code><!-- /@w -->)</dt>
<dd><p>Result out of range.
</p></dd>
</dl>
</dd>
<dt><var class="var">extra</var></dt>
<dd><p>A data structure containing the following fields:
</p>
<dl class="table">
<dt><code class="code">lambda</code></dt>
<dd><p>Dual variables.
</p>
</dd>
<dt><code class="code">redcosts</code></dt>
<dd><p>Reduced Costs.
</p>
</dd>
<dt><code class="code">time</code></dt>
<dd><p>Time (in seconds) used for solving LP/MIP problem.
</p>
</dd>
<dt><code class="code">status</code></dt>
<dd><p>Status of the optimization.
</p>
<dl class="table">
<dt>1 (<code class="code">GLP_UNDEF</code><!-- /@w -->)</dt>
<dd><p>Solution status is undefined.
</p>
</dd>
<dt>2 (<code class="code">GLP_FEAS</code><!-- /@w -->)</dt>
<dd><p>Solution is feasible.
</p>
</dd>
<dt>3 (<code class="code">GLP_INFEAS</code><!-- /@w -->)</dt>
<dd><p>Solution is infeasible.
</p>
</dd>
<dt>4 (<code class="code">GLP_NOFEAS</code><!-- /@w -->)</dt>
<dd><p>Problem has no feasible solution.
</p>
</dd>
<dt>5 (<code class="code">GLP_OPT</code><!-- /@w -->)</dt>
<dd><p>Solution is optimal.
</p>
</dd>
<dt>6 (<code class="code">GLP_UNBND</code><!-- /@w -->)</dt>
<dd><p>Problem has no unbounded solution.
</p></dd>
</dl>
</dd>
</dl>
</dd>
</dl>
<p>Example:
</p>
<div class="example">
<div class="group"><pre class="example-preformatted">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></div></div>
</dd></dl>
</div>
<hr>
<div class="nav-panel">
<p>
Next: <a href="Quadratic-Programming.html">Quadratic Programming</a>, Up: <a href="Optimization.html">Optimization</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html" title="Index" rel="index">Index</a>]</p>
</div>
</body>
</html>
|