Mercurial > hg > octave-lyh
annotate scripts/optimization/glpk.m @ 10635:d1978e7364ad
Print name of function in error() string messages.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Sun, 16 May 2010 22:26:54 -0700 |
parents | 95c3e38098bf |
children | be55736a0783 |
rev | line source |
---|---|
9245 | 1 ## Copyright (C) 2005, 2006, 2007, 2008, 2009 Nicolo' Giorgetti |
5233 | 2 ## |
3 ## This file is part of Octave. | |
4 ## | |
5 ## Octave is free software; you can redistribute it and/or modify it | |
6 ## under the terms of the GNU General Public License as published by | |
7016 | 7 ## the Free Software Foundation; either version 3 of the License, or (at |
8 ## your option) any later version. | |
5233 | 9 ## |
10 ## Octave is distributed in the hope that it will be useful, but | |
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 ## General Public License for more details. | |
14 ## | |
15 ## You should have received a copy of the GNU General Public License | |
7016 | 16 ## along with Octave; see the file COPYING. If not, see |
17 ## <http://www.gnu.org/licenses/>. | |
5233 | 18 |
5244 | 19 ## -*- texinfo -*- |
20 ## @deftypefn {Function File} {[@var{xopt}, @var{fmin}, @var{status}, @var{extra}] =} glpk (@var{c}, @var{a}, @var{b}, @var{lb}, @var{ub}, @var{ctype}, @var{vartype}, @var{sense}, @var{param}) | |
21 ## Solve a linear program using the GNU GLPK library. Given three | |
22 ## arguments, @code{glpk} solves the following standard LP: | |
23 ## | |
6741 | 24 ## @tex |
25 ## $$ | |
26 ## \min_x C^T x | |
27 ## $$ | |
28 ## @end tex | |
29 ## @ifnottex | |
5244 | 30 ## @example |
31 ## min C'*x | |
32 ## @end example | |
6741 | 33 ## @end ifnottex |
5244 | 34 ## |
5237 | 35 ## subject to |
5244 | 36 ## |
6741 | 37 ## @tex |
38 ## $$ | |
39 ## Ax = b \qquad x \geq 0 | |
40 ## $$ | |
41 ## @end tex | |
42 ## @ifnottex | |
5244 | 43 ## @example |
44 ## @group | |
45 ## A*x = b | |
46 ## x >= 0 | |
47 ## @end group | |
48 ## @end example | |
6741 | 49 ## @end ifnottex |
5244 | 50 ## |
5237 | 51 ## but may also solve problems of the form |
5244 | 52 ## |
6741 | 53 ## @tex |
54 ## $$ | |
55 ## [ \min_x | \max_x ] C^T x | |
56 ## $$ | |
57 ## @end tex | |
58 ## @ifnottex | |
5244 | 59 ## @example |
60 ## [ min | max ] C'*x | |
61 ## @end example | |
6741 | 62 ## @end ifnottex |
5244 | 63 ## |
5237 | 64 ## subject to |
5244 | 65 ## |
6741 | 66 ## @tex |
67 ## $$ | |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
68 ## Ax [ = | \leq | \geq ] b \qquad LB \leq x \leq UB |
6741 | 69 ## $$ |
70 ## @end tex | |
71 ## @ifnottex | |
5244 | 72 ## @example |
73 ## @group | |
74 ## A*x [ "=" | "<=" | ">=" ] b | |
75 ## x >= LB | |
76 ## x <= UB | |
77 ## @end group | |
78 ## @end example | |
6741 | 79 ## @end ifnottex |
5244 | 80 ## |
81 ## Input arguments: | |
82 ## | |
83 ## @table @var | |
84 ## @item c | |
85 ## A column array containing the objective function coefficients. | |
86 ## | |
87 ## @item a | |
88 ## A matrix containing the constraints coefficients. | |
89 ## | |
90 ## @item b | |
91 ## A column array containing the right-hand side value for each constraint | |
92 ## in the constraint matrix. | |
93 ## | |
94 ## @item lb | |
95 ## An array containing the lower bound on each of the variables. If | |
96 ## @var{lb} is not supplied, the default lower bound for the variables is | |
97 ## zero. | |
98 ## | |
99 ## @item ub | |
100 ## An array containing the upper bound on each of the variables. If | |
101 ## @var{ub} is not supplied, the default upper bound is assumed to be | |
102 ## infinite. | |
103 ## | |
104 ## @item ctype | |
105 ## An array of characters containing the sense of each constraint in the | |
106 ## constraint matrix. Each element of the array may be one of the | |
107 ## following values | |
108 ## @table @code | |
109 ## @item "F" | |
7096 | 110 ## A free (unbounded) constraint (the constraint is ignored). |
5244 | 111 ## @item "U" |
7096 | 112 ## An inequality constraint with an upper bound (@code{A(i,:)*x <= b(i)}). |
5244 | 113 ## @item "S" |
7096 | 114 ## An equality constraint (@code{A(i,:)*x = b(i)}). |
5244 | 115 ## @item "L" |
7096 | 116 ## An inequality with a lower bound (@code{A(i,:)*x >= b(i)}). |
5244 | 117 ## @item "D" |
7096 | 118 ## An inequality constraint with both upper and lower bounds |
119 ## (@code{A(i,:)*x >= -b(i)} @emph{and} (@code{A(i,:)*x <= b(i)}). | |
5244 | 120 ## @end table |
121 ## | |
122 ## @item vartype | |
123 ## A column array containing the types of the variables. | |
124 ## @table @code | |
7096 | 125 ## @item "C" |
126 ## A continuous variable. | |
127 ## @item "I" | |
128 ## An integer variable. | |
5244 | 129 ## @end table |
130 ## | |
131 ## @item sense | |
132 ## If @var{sense} is 1, the problem is a minimization. If @var{sense} is | |
133 ## -1, the problem is a maximization. The default value is 1. | |
134 ## | |
135 ## @item param | |
136 ## A structure containing the following parameters used to define the | |
137 ## behavior of solver. Missing elements in the structure take on default | |
138 ## values, so you only need to set the elements that you wish to change | |
139 ## from the default. | |
140 ## | |
141 ## Integer parameters: | |
142 ## | |
143 ## @table @code | |
9758
09da0bd91412
Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents:
9245
diff
changeset
|
144 ## @item msglev (@w{@code{LPX_K_MSGLEV}}, default: 1) |
5244 | 145 ## Level of messages output by solver routines: |
146 ## @table @asis | |
147 ## @item 0 | |
148 ## No output. | |
149 ## @item 1 | |
150 ## Error messages only. | |
151 ## @item 2 | |
152 ## Normal output . | |
153 ## @item 3 | |
154 ## Full output (includes informational messages). | |
155 ## @end table | |
156 ## | |
9758
09da0bd91412
Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents:
9245
diff
changeset
|
157 ## @item scale (@w{@code{LPX_K_SCALE}}, default: 1) |
5244 | 158 ## Scaling option: |
159 ## @table @asis | |
160 ## @item 0 | |
7001 | 161 ## No scaling. |
5244 | 162 ## @item 1 |
7001 | 163 ## Equilibration scaling. |
5244 | 164 ## @item 2 |
165 ## Geometric mean scaling, then equilibration scaling. | |
166 ## @end table | |
167 ## | |
10549 | 168 ## @item dual (@w{@code{LPX_K_DUAL}}, default: 0) |
5244 | 169 ## Dual simplex option: |
170 ## @table @asis | |
171 ## @item 0 | |
172 ## Do not use the dual simplex. | |
173 ## @item 1 | |
174 ## If initial basic solution is dual feasible, use the dual simplex. | |
175 ## @end table | |
176 ## | |
10549 | 177 ## @item price (@w{@code{LPX_K_PRICE}}, default: 1) |
5244 | 178 ## Pricing option (for both primal and dual simplex): |
179 ## @table @asis | |
180 ## @item 0 | |
181 ## Textbook pricing. | |
182 ## @item 1 | |
183 ## Steepest edge pricing. | |
184 ## @end table | |
185 ## | |
10549 | 186 ## @item round (@w{@code{LPX_K_ROUND}}, default: 0) |
5244 | 187 ## Solution rounding option: |
188 ## @table @asis | |
189 ## @item 0 | |
190 ## Report all primal and dual values "as is". | |
191 ## @item 1 | |
192 ## Replace tiny primal and dual values by exact zero. | |
193 ## @end table | |
194 ## | |
10549 | 195 ## @item itlim (@w{@code{LPX_K_ITLIM}}, default: -1) |
5244 | 196 ## Simplex iterations limit. If this value is positive, it is decreased by |
197 ## one each time when one simplex iteration has been performed, and | |
198 ## reaching zero value signals the solver to stop the search. Negative | |
199 ## value means no iterations limit. | |
200 ## | |
9758
09da0bd91412
Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents:
9245
diff
changeset
|
201 ## @item itcnt (@w{@code{LPX_K_OUTFRQ}}, default: 200) |
5244 | 202 ## Output frequency, in iterations. This parameter specifies how |
203 ## frequently the solver sends information about the solution to the | |
204 ## standard output. | |
205 ## | |
9758
09da0bd91412
Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents:
9245
diff
changeset
|
206 ## @item branch (@w{@code{LPX_K_BRANCH}}, default: 2) |
5244 | 207 ## Branching heuristic option (for MIP only): |
208 ## @table @asis | |
209 ## @item 0 | |
210 ## Branch on the first variable. | |
211 ## @item 1 | |
212 ## Branch on the last variable. | |
213 ## @item 2 | |
214 ## Branch using a heuristic by Driebeck and Tomlin. | |
215 ## @end table | |
216 ## | |
9758
09da0bd91412
Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents:
9245
diff
changeset
|
217 ## @item btrack (@w{@code{LPX_K_BTRACK}}, default: 2) |
5244 | 218 ## Backtracking heuristic option (for MIP only): |
219 ## @table @asis | |
220 ## @item 0 | |
221 ## Depth first search. | |
222 ## @item 1 | |
223 ## Breadth first search. | |
224 ## @item 2 | |
225 ## Backtrack using the best projection heuristic. | |
226 ## @end table | |
227 ## | |
9758
09da0bd91412
Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents:
9245
diff
changeset
|
228 ## @item presol (@w{@code{LPX_K_PRESOL}}, default: 1) |
5244 | 229 ## If this flag is set, the routine lpx_simplex solves the problem using |
230 ## the built-in LP presolver. Otherwise the LP presolver is not used. | |
231 ## | |
232 ## @item lpsolver (default: 1) | |
233 ## Select which solver to use. If the problem is a MIP problem this flag | |
234 ## will be ignored. | |
235 ## @table @asis | |
236 ## @item 1 | |
237 ## Revised simplex method. | |
238 ## @item 2 | |
239 ## Interior point method. | |
240 ## @end table | |
241 ## @item save (default: 0) | |
7001 | 242 ## If this parameter is nonzero, save a copy of the problem in |
5244 | 243 ## CPLEX LP format to the file @file{"outpb.lp"}. There is currently no |
244 ## way to change the name of the output file. | |
245 ## @end table | |
246 ## | |
247 ## Real parameters: | |
248 ## | |
249 ## @table @code | |
9758
09da0bd91412
Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents:
9245
diff
changeset
|
250 ## @item relax (@w{@code{LPX_K_RELAX}}, default: 0.07) |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
251 ## Relaxation parameter used in the ratio test. If it is zero, the textbook |
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
252 ## ratio test is used. If it is non-zero (should be positive), Harris' |
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
253 ## two-pass ratio test is used. In the latter case on the first pass of the |
5244 | 254 ## ratio test basic variables (in the case of primal simplex) or reduced |
255 ## costs of non-basic variables (in the case of dual simplex) are allowed | |
256 ## to slightly violate their bounds, but not more than | |
257 ## @code{relax*tolbnd} or @code{relax*toldj (thus, @code{relax} is a | |
6248 | 258 ## percentage of @code{tolbnd} or @code{toldj}}. |
5244 | 259 ## |
9758
09da0bd91412
Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents:
9245
diff
changeset
|
260 ## @item tolbnd (@w{@code{LPX_K_TOLBND}}, default: 10e-7) |
5289 | 261 ## Relative tolerance used to check if the current basic solution is primal |
5244 | 262 ## feasible. It is not recommended that you change this parameter unless you |
263 ## have a detailed understanding of its purpose. | |
264 ## | |
9758
09da0bd91412
Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents:
9245
diff
changeset
|
265 ## @item toldj (@w{@code{LPX_K_TOLDJ}}, default: 10e-7) |
5244 | 266 ## Absolute tolerance used to check if the current basic solution is dual |
267 ## feasible. It is not recommended that you change this parameter unless you | |
268 ## have a detailed understanding of its purpose. | |
269 ## | |
9758
09da0bd91412
Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents:
9245
diff
changeset
|
270 ## @item tolpiv (@w{@code{LPX_K_TOLPIV}}, default: 10e-9) |
5244 | 271 ## Relative tolerance used to choose eligible pivotal elements of the |
272 ## simplex table. It is not recommended that you change this parameter unless you | |
273 ## have a detailed understanding of its purpose. | |
274 ## | |
9758
09da0bd91412
Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents:
9245
diff
changeset
|
275 ## @item objll (@w{@code{LPX_K_OBJLL}}, default: -DBL_MAX) |
5244 | 276 ## Lower limit of the objective function. If on the phase II the objective |
277 ## function reaches this limit and continues decreasing, the solver stops | |
278 ## the search. This parameter is used in the dual simplex method only. | |
279 ## | |
9758
09da0bd91412
Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents:
9245
diff
changeset
|
280 ## @item objul (@w{@code{LPX_K_OBJUL}}, default: +DBL_MAX) |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
281 ## Upper limit of the objective function. If on the phase II the objective |
5244 | 282 ## function reaches this limit and continues increasing, the solver stops |
283 ## the search. This parameter is used in the dual simplex only. | |
284 ## | |
9758
09da0bd91412
Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents:
9245
diff
changeset
|
285 ## @item tmlim (@w{@code{LPX_K_TMLIM}}, default: -1.0) |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
286 ## Searching time limit, in seconds. If this value is positive, it is |
5244 | 287 ## decreased each time when one simplex iteration has been performed by the |
288 ## amount of time spent for the iteration, and reaching zero value signals | |
289 ## the solver to stop the search. Negative value means no time limit. | |
290 ## | |
9758
09da0bd91412
Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents:
9245
diff
changeset
|
291 ## @item outdly (@w{@code{LPX_K_OUTDLY}}, default: 0.0) |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
292 ## Output delay, in seconds. This parameter specifies how long the solver |
5244 | 293 ## should delay sending information about the solution to the standard |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
294 ## output. Non-positive value means no delay. |
5244 | 295 ## |
9758
09da0bd91412
Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents:
9245
diff
changeset
|
296 ## @item tolint (@w{@code{LPX_K_TOLINT}}, default: 10e-5) |
5289 | 297 ## Relative tolerance used to check if the current basic solution is integer |
5244 | 298 ## feasible. It is not recommended that you change this parameter unless |
299 ## you have a detailed understanding of its purpose. | |
300 ## | |
9758
09da0bd91412
Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents:
9245
diff
changeset
|
301 ## @item tolobj (@w{@code{LPX_K_TOLOBJ}}, default: 10e-7) |
5244 | 302 ## Relative tolerance used to check if the value of the objective function |
303 ## is not better than in the best known integer feasible solution. It is | |
304 ## not recommended that you change this parameter unless you have a | |
305 ## detailed understanding of its purpose. | |
306 ## @end table | |
307 ## @end table | |
308 ## | |
309 ## Output values: | |
310 ## | |
311 ## @table @var | |
312 ## @item xopt | |
313 ## The optimizer (the value of the decision variables at the optimum). | |
314 ## @item fopt | |
315 ## The optimum value of the objective function. | |
316 ## @item status | |
317 ## Status of the optimization. | |
318 ## | |
319 ## Simplex Method: | |
320 ## @table @asis | |
9758
09da0bd91412
Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents:
9245
diff
changeset
|
321 ## @item 180 (@w{@code{LPX_OPT}}) |
5244 | 322 ## Solution is optimal. |
9758
09da0bd91412
Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents:
9245
diff
changeset
|
323 ## @item 181 (@w{@code{LPX_FEAS}}) |
5244 | 324 ## Solution is feasible. |
9758
09da0bd91412
Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents:
9245
diff
changeset
|
325 ## @item 182 (@w{@code{LPX_INFEAS}}) |
5244 | 326 ## Solution is infeasible. |
9758
09da0bd91412
Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents:
9245
diff
changeset
|
327 ## @item 183 (@w{@code{LPX_NOFEAS}}) |
5244 | 328 ## Problem has no feasible solution. |
9758
09da0bd91412
Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents:
9245
diff
changeset
|
329 ## @item 184 (@w{@code{LPX_UNBND}}) |
5244 | 330 ## Problem has no unbounded solution. |
9758
09da0bd91412
Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents:
9245
diff
changeset
|
331 ## @item 185 (@w{@code{LPX_UNDEF}}) |
5244 | 332 ## Solution status is undefined. |
333 ## @end table | |
334 ## Interior Point Method: | |
335 ## @table @asis | |
9758
09da0bd91412
Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents:
9245
diff
changeset
|
336 ## @item 150 (@w{@code{LPX_T_UNDEF}}) |
5244 | 337 ## The interior point method is undefined. |
9758
09da0bd91412
Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents:
9245
diff
changeset
|
338 ## @item 151 (@w{@code{LPX_T_OPT}}) |
5244 | 339 ## The interior point method is optimal. |
340 ## @end table | |
341 ## Mixed Integer Method: | |
342 ## @table @asis | |
9758
09da0bd91412
Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents:
9245
diff
changeset
|
343 ## @item 170 (@w{@code{LPX_I_UNDEF}}) |
5244 | 344 ## The status is undefined. |
9758
09da0bd91412
Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents:
9245
diff
changeset
|
345 ## @item 171 (@w{@code{LPX_I_OPT}}) |
5244 | 346 ## The solution is integer optimal. |
9758
09da0bd91412
Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents:
9245
diff
changeset
|
347 ## @item 172 (@w{@code{LPX_I_FEAS}}) |
5244 | 348 ## Solution integer feasible but its optimality has not been proven |
9758
09da0bd91412
Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents:
9245
diff
changeset
|
349 ## @item 173 (@w{@code{LPX_I_NOFEAS}}) |
5244 | 350 ## No integer feasible solution. |
351 ## @end table | |
352 ## @noindent | |
353 ## If an error occurs, @var{status} will contain one of the following | |
354 ## codes: | |
5232 | 355 ## |
5244 | 356 ## @table @asis |
9758
09da0bd91412
Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents:
9245
diff
changeset
|
357 ## @item 204 (@w{@code{LPX_E_FAULT}}) |
5244 | 358 ## Unable to start the search. |
9758
09da0bd91412
Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents:
9245
diff
changeset
|
359 ## @item 205 (@w{@code{LPX_E_OBJLL}}) |
5244 | 360 ## Objective function lower limit reached. |
9758
09da0bd91412
Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents:
9245
diff
changeset
|
361 ## @item 206 (@w{@code{LPX_E_OBJUL}}) |
5244 | 362 ## Objective function upper limit reached. |
9758
09da0bd91412
Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents:
9245
diff
changeset
|
363 ## @item 207 (@w{@code{LPX_E_ITLIM}}) |
5244 | 364 ## Iterations limit exhausted. |
9758
09da0bd91412
Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents:
9245
diff
changeset
|
365 ## @item 208 (@w{@code{LPX_E_TMLIM}}) |
5244 | 366 ## Time limit exhausted. |
9758
09da0bd91412
Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents:
9245
diff
changeset
|
367 ## @item 209 (@w{@code{LPX_E_NOFEAS}}) |
5244 | 368 ## No feasible solution. |
9758
09da0bd91412
Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents:
9245
diff
changeset
|
369 ## @item 210 (@w{@code{LPX_E_INSTAB}}) |
5244 | 370 ## Numerical instability. |
9758
09da0bd91412
Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents:
9245
diff
changeset
|
371 ## @item 211 (@w{@code{LPX_E_SING}}) |
5244 | 372 ## Problems with basis matrix. |
9758
09da0bd91412
Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents:
9245
diff
changeset
|
373 ## @item 212 (@w{@code{LPX_E_NOCONV}}) |
5244 | 374 ## No convergence (interior). |
9758
09da0bd91412
Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents:
9245
diff
changeset
|
375 ## @item 213 (@w{@code{LPX_E_NOPFS}}) |
5244 | 376 ## No primal feasible solution (LP presolver). |
9758
09da0bd91412
Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents:
9245
diff
changeset
|
377 ## @item 214 (@w{@code{LPX_E_NODFS}}) |
5244 | 378 ## No dual feasible solution (LP presolver). |
379 ## @end table | |
380 ## @item extra | |
381 ## A data structure containing the following fields: | |
382 ## @table @code | |
383 ## @item lambda | |
384 ## Dual variables. | |
385 ## @item redcosts | |
386 ## Reduced Costs. | |
387 ## @item time | |
388 ## Time (in seconds) used for solving LP/MIP problem. | |
389 ## @item mem | |
6333 | 390 ## Memory (in bytes) used for solving LP/MIP problem (this is not |
391 ## available if the version of GLPK is 4.15 or later). | |
5244 | 392 ## @end table |
393 ## @end table | |
394 ## | |
395 ## Example: | |
396 ## | |
397 ## @example | |
398 ## @group | |
399 ## c = [10, 6, 4]'; | |
400 ## a = [ 1, 1, 1; | |
401 ## 10, 4, 5; | |
402 ## 2, 2, 6]; | |
403 ## b = [100, 600, 300]'; | |
404 ## lb = [0, 0, 0]'; | |
405 ## ub = []; | |
406 ## ctype = "UUU"; | |
407 ## vartype = "CCC"; | |
408 ## s = -1; | |
409 ## | |
410 ## param.msglev = 1; | |
411 ## param.itlim = 100; | |
412 ## | |
9758
09da0bd91412
Periodic grammar check of Octave documentation files to ensure common format
Rik <rdrider0-list@yahoo.com>
parents:
9245
diff
changeset
|
413 ## [xmin, fmin, status, extra] = ... |
5244 | 414 ## glpk (c, a, b, lb, ub, ctype, vartype, s, param); |
415 ## @end group | |
416 ## @end example | |
417 ## @end deftypefn | |
5232 | 418 |
5233 | 419 ## Author: Nicolo' Giorgetti <giorgetti@dii.unisi.it> |
420 ## Adapted-by: jwe | |
5232 | 421 |
5237 | 422 function [xopt, fmin, status, extra] = glpk (c, a, b, lb, ub, ctype, vartype, sense, param) |
5232 | 423 |
5233 | 424 ## If there is no input output the version and syntax |
5237 | 425 if (nargin < 3 || nargin > 9) |
6046 | 426 print_usage (); |
5233 | 427 return; |
428 endif | |
5232 | 429 |
5233 | 430 if (all (size (c) > 1) || iscomplex (c) || ischar (c)) |
10635
d1978e7364ad
Print name of function in error() string messages.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
431 error ("glpk:C must be a real vector"); |
5233 | 432 return; |
433 endif | |
434 nx = length (c); | |
435 ## Force column vector. | |
436 c = c(:); | |
5232 | 437 |
5237 | 438 ## 2) Matrix constraint |
5232 | 439 |
5233 | 440 if (isempty (a)) |
10635
d1978e7364ad
Print name of function in error() string messages.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
441 error ("glpk: A cannot be an empty matrix"); |
5233 | 442 return; |
443 endif | |
444 [nc, nxa] = size(a); | |
445 if (! isreal (a) || nxa != nx) | |
10635
d1978e7364ad
Print name of function in error() string messages.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
446 error ("glpk: A must be a real valued %d by %d matrix", nc, nx); |
5233 | 447 return; |
448 endif | |
449 | |
5237 | 450 ## 3) RHS |
5232 | 451 |
5233 | 452 if (isempty (b)) |
10635
d1978e7364ad
Print name of function in error() string messages.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
453 error ("glpk: B cannot be an empty vector"); |
5233 | 454 return; |
455 endif | |
456 if (! isreal (b) || length (b) != nc) | |
10635
d1978e7364ad
Print name of function in error() string messages.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
457 error ("glpk: B must be a real valued %d by 1 vector", nc); |
5233 | 458 return; |
459 endif | |
460 | |
5237 | 461 ## 4) Vector with the lower bound of each variable |
5232 | 462 |
5237 | 463 if (nargin > 3) |
5233 | 464 if (isempty (lb)) |
8036
854683691d7a
fix invalid memory read in glpk
Jaroslav Hajek <highegg@gmail.com>
parents:
7151
diff
changeset
|
465 lb = zeros (nx, 1); |
5233 | 466 elseif (! isreal (lb) || all (size (lb) > 1) || length (lb) != nx) |
10635
d1978e7364ad
Print name of function in error() string messages.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
467 error ("glpk: LB must be a real valued %d by 1 column vector", nx); |
5233 | 468 return; |
469 endif | |
470 else | |
5237 | 471 lb = zeros (nx, 1); |
7151 | 472 endif |
5233 | 473 |
5237 | 474 ## 5) Vector with the upper bound of each variable |
5232 | 475 |
5237 | 476 if (nargin > 4) |
5233 | 477 if (isempty (ub)) |
10541
e9d1a974a517
Eliminate repmat (Inf, x , y) and simply use Inf (x,y)
Rik <code@nomad.inbox5.com>
parents:
9758
diff
changeset
|
478 ub = Inf (nx, 1); |
5233 | 479 elseif (! isreal (ub) || all (size (ub) > 1) || length (ub) != nx) |
10635
d1978e7364ad
Print name of function in error() string messages.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
480 error ("glpk: UB must be a real valued %d by 1 column vector", nx); |
5233 | 481 return; |
482 endif | |
483 else | |
10541
e9d1a974a517
Eliminate repmat (Inf, x , y) and simply use Inf (x,y)
Rik <code@nomad.inbox5.com>
parents:
9758
diff
changeset
|
484 ub = Inf (nx, 1); |
7151 | 485 endif |
5232 | 486 |
5237 | 487 ## 6) Sense of each constraint |
5232 | 488 |
5237 | 489 if (nargin > 5) |
490 if (isempty (ctype)) | |
491 ctype = repmat ("S", nc, 1); | |
492 elseif (! ischar (ctype) || all (size (ctype) > 1) || length (ctype) != nc) | |
10635
d1978e7364ad
Print name of function in error() string messages.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
493 error ("glpk: CTYPE must be a char valued vector of length %d", nc); |
5237 | 494 return; |
495 elseif (! all (ctype == "F" | ctype == "U" | ctype == "S" | |
10549 | 496 | ctype == "L" | ctype == "D")) |
10635
d1978e7364ad
Print name of function in error() string messages.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
497 error ("glpk: CTYPE must contain only F, U, S, L, or D"); |
5237 | 498 return; |
499 endif | |
500 else | |
501 ctype = repmat ("S", nc, 1); | |
7151 | 502 endif |
5237 | 503 |
504 ## 7) Vector with the type of variables | |
505 | |
506 if (nargin > 6) | |
5289 | 507 if (isempty (vartype)) |
5233 | 508 vartype = repmat ("C", nx, 1); |
509 elseif (! ischar (vartype) || all (size (vartype) > 1) | |
10549 | 510 || length (vartype) != nx) |
10635
d1978e7364ad
Print name of function in error() string messages.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
511 error ("glpk: VARTYPE must be a char valued vector of length %d", nx); |
5233 | 512 return; |
513 elseif (! all (vartype == "C" | vartype == "I")) | |
10635
d1978e7364ad
Print name of function in error() string messages.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
514 error ("glpk: VARTYPE must contain only C or I"); |
5233 | 515 return; |
516 endif | |
517 else | |
518 ## As default we consider continuous vars | |
519 vartype = repmat ("C", nx, 1); | |
520 endif | |
5232 | 521 |
5289 | 522 ## 8) Sense of optimization |
523 | |
524 if (nargin > 7) | |
525 if (isempty (sense)) | |
526 sense = 1; | |
527 elseif (ischar (sense) || all (size (sense) > 1) || ! isreal (sense)) | |
10635
d1978e7364ad
Print name of function in error() string messages.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
528 error ("glpk: SENSE must be an integer value"); |
5289 | 529 elseif (sense >= 0) |
530 sense = 1; | |
531 else | |
532 sense = -1; | |
533 endif | |
534 else | |
535 sense = 1; | |
536 endif | |
537 | |
538 ## 9) Parameters vector | |
5233 | 539 |
540 if (nargin > 8) | |
541 if (! isstruct (param)) | |
10635
d1978e7364ad
Print name of function in error() string messages.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
542 error ("glpk: PARAM must be a structure"); |
5233 | 543 return; |
544 endif | |
545 else | |
546 param = struct (); | |
547 endif | |
5232 | 548 |
5233 | 549 [xopt, fmin, status, extra] = ... |
5237 | 550 __glpk__ (c, a, b, lb, ub, ctype, vartype, sense, param); |
5232 | 551 |
552 endfunction |