Mercurial > octave
annotate libinterp/dldfcn/__glpk__.cc @ 23577:80c42f4cca13
maint: Deprecate is_empty and replace with isempty.
* ov.h (is_empty): Use OCTAVE_DEPRECATED macro around function.
* ov.h (isempty): New function.
* Array.h (is_empty): Use OCTAVE_DEPRECATED macro around function.
* Array.h (isempty): New function.
* Range.h (is_empty): Use OCTAVE_DEPRECATED macro around function.
* Range.h (isempty): New function.
* Sparse.h (is_empty): Use OCTAVE_DEPRECATED macro around function.
* Sparse.h (isempty): New function.
* Backend.cc, BaseControl.cc, Canvas.cc, Figure.cc, gl-select.cc,
__magick_read__.cc, __qp__.cc, cellfun.cc, daspk.cc, dasrt.cc, dassl.cc,
data.cc, debug.cc, det.cc, eig.cc, error.cc, fft.cc, filter.cc, find.cc,
ft-text-renderer.cc, gl-render.cc, gl2ps-print.cc, graphics.cc, graphics.in.h,
hess.cc, inv.cc, lsode.cc, lu.cc, max.cc, mex.cc, mxarray.in.h, oct-handle.h,
oct-lvalue.cc, oct-map.cc, oct-map.h, oct-stream.cc, pinv.cc, pr-output.cc,
quadcc.cc, qz.cc, strfind.cc, strfns.cc, sylvester.cc, time.cc, toplev.cc,
tril.cc, urlwrite.cc, utils.cc, utils.h, xnorm.cc, __delaunayn__.cc,
__glpk__.cc, __init_fltk__.cc, __init_gnuplot__.cc, __ode15__.cc,
__voronoi__.cc, chol.cc, convhulln.cc, ov-base-diag.cc, ov-base-mat.cc,
ov-base-sparse.cc, ov-base.cc, ov-base.h, ov-bool-mat.cc, ov-bool-sparse.cc,
ov-cell.cc, ov-class.cc, ov-classdef.cc, ov-cx-sparse.cc, ov-fcn-inline.cc,
ov-flt-re-mat.cc, ov-intx.h, ov-java.cc, ov-perm.cc, ov-range.cc, ov-re-mat.cc,
ov-re-sparse.cc, ov-str-mat.cc, ov-struct.cc, ov-usr-fcn.cc, ov.cc, ov.h,
bp-table.cc, oct-parse.in.yy, pt-eval.cc, pt-tm-const.cc, pt-tm-const.h,
Array.cc, Range.cc, Range.h, Sparse.cc, Sparse.h, chNDArray.cc, dNDArray.cc,
fNDArray.cc, DASPK.cc, DASRT.cc, DASSL.cc, LSODE.cc, bsxfun-defs.cc,
eigs-base.cc, oct-convn.cc, qr.cc:
Replace instances of is_empty with isempty.
author | Rik <rik@octave.org> |
---|---|
date | Sun, 11 Jun 2017 22:14:09 -0700 |
parents | 73ff72d3d603 |
children | b7747a2c88b2 |
rev | line source |
---|---|
5234 | 1 /* |
2 | |
23219
3ac9f9ecfae5
maint: Update copyright dates.
John W. Eaton <jwe@octave.org>
parents:
23083
diff
changeset
|
3 Copyright (C) 2005-2017 Nicolo' Giorgetti |
22323
bac0d6f07a3e
maint: Update copyright notices for 2016.
John W. Eaton <jwe@octave.org>
parents:
22197
diff
changeset
|
4 Copyright (C) 2013-2016 Sébastien Villemot <sebastien@debian.org> |
5234 | 5 |
6 This file is part of Octave. | |
7 | |
8 Octave is free software; you can redistribute it and/or modify it | |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
9 under the terms of the GNU General Public License as published by |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
10 the Free Software Foundation; either version 3 of the License, or |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
11 (at your option) any later version. |
5234 | 12 |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
13 Octave is distributed in the hope that it will be useful, but |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
14 WITHOUT ANY WARRANTY; without even the implied warranty of |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
16 GNU General Public License for more details. |
5234 | 17 |
18 You should have received a copy of the GNU General Public License | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
5234 | 21 |
22 */ | |
23 | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21723
diff
changeset
|
24 #if defined (HAVE_CONFIG_H) |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21200
diff
changeset
|
25 # include "config.h" |
5234 | 26 #endif |
5232 | 27 |
28 #include <ctime> | |
29 | |
23024
a6a7b054e4ba
Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
30 #include <limits> |
a6a7b054e4ba
Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
31 |
a6a7b054e4ba
Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
32 #include "Array.h" |
a6a7b054e4ba
Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
33 #include "chMatrix.h" |
a6a7b054e4ba
Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
34 #include "dColVector.h" |
a6a7b054e4ba
Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
35 #include "dMatrix.h" |
a6a7b054e4ba
Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
36 #include "dSparse.h" |
9003
0631d397fbe0
replace lo_ieee_isnan by xisnan, add missing includes
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
37 #include "lo-ieee.h" |
0631d397fbe0
replace lo_ieee_isnan by xisnan, add missing includes
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
38 |
5234 | 39 #include "defun-dld.h" |
40 #include "error.h" | |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21091
diff
changeset
|
41 #include "errwarn.h" |
5235 | 42 #include "oct-map.h" |
23024
a6a7b054e4ba
Rationalize #includes in libinterp/dldfcn directory.
Rik <rik@octave.org>
parents:
22755
diff
changeset
|
43 #include "ov.h" |
20940
48b2ad5ee801
maint: Rename oct-obj.[cc|h] to ovl.[cc|h] for clarity.
Rik <rik@octave.org>
parents:
20939
diff
changeset
|
44 #include "ovl.h" |
5235 | 45 |
46 #if defined (HAVE_GLPK) | |
5232 | 47 |
6333 | 48 extern "C" |
49 { | |
6804 | 50 #if defined (HAVE_GLPK_GLPK_H) |
21200
fcac5dbbf9ed
maint: Indent #ifdef blocks in libinterp.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
51 # include <glpk/glpk.h> |
6804 | 52 #else |
21200
fcac5dbbf9ed
maint: Indent #ifdef blocks in libinterp.
Rik <rik@octave.org>
parents:
21100
diff
changeset
|
53 # include <glpk.h> |
6804 | 54 #endif |
6472 | 55 } |
6333 | 56 |
17181
4e9ff411d0fa
Remove minor stylistic C'ism
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
17180
diff
changeset
|
57 struct control_params |
17180
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
58 { |
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
59 int msglev; |
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
60 int dual; |
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
61 int price; |
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
62 int itlim; |
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
63 int outfrq; |
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
64 int branch; |
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
65 int btrack; |
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
66 int presol; |
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
67 int rtest; |
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
68 int tmlim; |
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
69 int outdly; |
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
70 double tolbnd; |
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
71 double toldj; |
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
72 double tolpiv; |
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
73 double objll; |
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
74 double objul; |
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
75 double tolint; |
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
76 double tolobj; |
17181
4e9ff411d0fa
Remove minor stylistic C'ism
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents:
17180
diff
changeset
|
77 }; |
5232 | 78 |
5234 | 79 int |
80 glpk (int sense, int n, int m, double *c, int nz, int *rn, int *cn, | |
81 double *a, double *b, char *ctype, int *freeLB, double *lb, | |
82 int *freeUB, double *ub, int *vartype, int isMIP, int lpsolver, | |
17180
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
83 int save_pb, int scale, const control_params *par, |
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
84 double *xmin, double *fmin, int *status, |
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
85 double *lambda, double *redcosts, double *time) |
5232 | 86 { |
5234 | 87 int typx = 0; |
17180
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
88 int errnum = 0; |
5234 | 89 |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14501
diff
changeset
|
90 clock_t t_start = clock (); |
5234 | 91 |
17180
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
92 glp_prob *lp = glp_create_prob (); |
5232 | 93 |
20946 | 94 // Set the sense of optimization |
5234 | 95 if (sense == 1) |
17180
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
96 glp_set_obj_dir (lp, GLP_MIN); |
5234 | 97 else |
17180
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
98 glp_set_obj_dir (lp, GLP_MAX); |
5234 | 99 |
17180
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
100 glp_add_cols (lp, n); |
5234 | 101 for (int i = 0; i < n; i++) |
102 { | |
20946 | 103 // Define type of the structural variables |
5234 | 104 if (! freeLB[i] && ! freeUB[i]) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9003
diff
changeset
|
105 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9003
diff
changeset
|
106 if (lb[i] != ub[i]) |
17180
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
107 glp_set_col_bnds (lp, i+1, GLP_DB, lb[i], ub[i]); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9003
diff
changeset
|
108 else |
17180
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
109 glp_set_col_bnds (lp, i+1, GLP_FX, lb[i], ub[i]); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9003
diff
changeset
|
110 } |
5234 | 111 else |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9003
diff
changeset
|
112 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9003
diff
changeset
|
113 if (! freeLB[i] && freeUB[i]) |
17180
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
114 glp_set_col_bnds (lp, i+1, GLP_LO, lb[i], ub[i]); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9003
diff
changeset
|
115 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9003
diff
changeset
|
116 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9003
diff
changeset
|
117 if (freeLB[i] && ! freeUB[i]) |
17180
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
118 glp_set_col_bnds (lp, i+1, GLP_UP, lb[i], ub[i]); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9003
diff
changeset
|
119 else |
17180
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
120 glp_set_col_bnds (lp, i+1, GLP_FR, lb[i], ub[i]); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9003
diff
changeset
|
121 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9003
diff
changeset
|
122 } |
5234 | 123 |
124 // -- Set the objective coefficient of the corresponding | |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21724
diff
changeset
|
125 // -- structural variable. No constant term is assumed. |
17180
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
126 glp_set_obj_coef(lp,i+1,c[i]); |
5232 | 127 |
5234 | 128 if (isMIP) |
17180
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
129 glp_set_col_kind (lp, i+1, vartype[i]); |
5234 | 130 } |
131 | |
17180
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
132 glp_add_rows (lp, m); |
5234 | 133 |
134 for (int i = 0; i < m; i++) | |
135 { | |
20946 | 136 // If the i-th row has no lower bound (types F,U), the |
137 // corrispondent parameter will be ignored. If the i-th row has | |
138 // no upper bound (types F,L), the corrispondent parameter will be | |
139 // ignored. If the i-th row is of S type, the i-th LB is used, | |
140 // but the i-th UB is ignored. | |
5234 | 141 |
142 switch (ctype[i]) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9003
diff
changeset
|
143 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9003
diff
changeset
|
144 case 'F': |
17180
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
145 typx = GLP_FR; |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9003
diff
changeset
|
146 break; |
5234 | 147 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9003
diff
changeset
|
148 case 'U': |
17180
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
149 typx = GLP_UP; |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9003
diff
changeset
|
150 break; |
5234 | 151 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9003
diff
changeset
|
152 case 'L': |
17180
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
153 typx = GLP_LO; |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9003
diff
changeset
|
154 break; |
5232 | 155 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9003
diff
changeset
|
156 case 'S': |
17180
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
157 typx = GLP_FX; |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9003
diff
changeset
|
158 break; |
5232 | 159 |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9003
diff
changeset
|
160 case 'D': |
17180
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
161 typx = GLP_DB; |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9003
diff
changeset
|
162 break; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9003
diff
changeset
|
163 } |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11574
diff
changeset
|
164 |
17180
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
165 glp_set_row_bnds (lp, i+1, typx, b[i], b[i]); |
5234 | 166 |
167 } | |
168 | |
17180
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
169 glp_load_matrix (lp, nz, rn, cn, a); |
5232 | 170 |
5234 | 171 if (save_pb) |
172 { | |
6484 | 173 static char tmp[] = "outpb.lp"; |
21090
93d294511277
don't use setjmp/longjmp to handle error in glpk
John W. Eaton <jwe@octave.org>
parents:
21082
diff
changeset
|
174 if (glp_write_lp (lp, 0, tmp) != 0) |
93d294511277
don't use setjmp/longjmp to handle error in glpk
John W. Eaton <jwe@octave.org>
parents:
21082
diff
changeset
|
175 error ("__glpk__: unable to write problem"); |
5234 | 176 } |
177 | |
20946 | 178 // scale the problem data |
20955
77f5591878bf
maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents:
20946
diff
changeset
|
179 if (! par->presol || lpsolver != 1) |
17180
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
180 glp_scale_prob (lp, scale); |
5234 | 181 |
20946 | 182 // build advanced initial basis (if required) |
20955
77f5591878bf
maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents:
20946
diff
changeset
|
183 if (lpsolver == 1 && ! par->presol) |
17180
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
184 glp_adv_basis (lp, 0); |
5232 | 185 |
20946 | 186 // For MIP problems without a presolver, a first pass with glp_simplex |
187 // is required | |
20955
77f5591878bf
maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents:
20946
diff
changeset
|
188 if ((! isMIP && lpsolver == 1) |
77f5591878bf
maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents:
20946
diff
changeset
|
189 || (isMIP && ! par->presol)) |
5234 | 190 { |
17180
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
191 glp_smcp smcp; |
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
192 glp_init_smcp (&smcp); |
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
193 smcp.msg_lev = par->msglev; |
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
194 smcp.meth = par->dual; |
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
195 smcp.pricing = par->price; |
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
196 smcp.r_test = par->rtest; |
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
197 smcp.tol_bnd = par->tolbnd; |
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
198 smcp.tol_dj = par->toldj; |
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
199 smcp.tol_piv = par->tolpiv; |
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
200 smcp.obj_ll = par->objll; |
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
201 smcp.obj_ul = par->objul; |
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
202 smcp.it_lim = par->itlim; |
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
203 smcp.tm_lim = par->tmlim; |
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
204 smcp.out_frq = par->outfrq; |
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
205 smcp.out_dly = par->outdly; |
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
206 smcp.presolve = par->presol; |
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
207 errnum = glp_simplex (lp, &smcp); |
5234 | 208 } |
209 | |
17180
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
210 if (isMIP) |
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
211 { |
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
212 glp_iocp iocp; |
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
213 glp_init_iocp (&iocp); |
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
214 iocp.msg_lev = par->msglev; |
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
215 iocp.br_tech = par->branch; |
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
216 iocp.bt_tech = par->btrack; |
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
217 iocp.tol_int = par->tolint; |
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
218 iocp.tol_obj = par->tolobj; |
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
219 iocp.tm_lim = par->tmlim; |
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
220 iocp.out_frq = par->outfrq; |
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
221 iocp.out_dly = par->outdly; |
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
222 iocp.presolve = par->presol; |
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
223 errnum = glp_intopt (lp, &iocp); |
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
224 } |
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
225 |
20955
77f5591878bf
maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents:
20946
diff
changeset
|
226 if (! isMIP && lpsolver == 2) |
17180
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
227 { |
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
228 glp_iptcp iptcp; |
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
229 glp_init_iptcp (&iptcp); |
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
230 iptcp.msg_lev = par->msglev; |
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
231 errnum = glp_interior (lp, &iptcp); |
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
232 } |
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
233 |
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
234 if (errnum == 0) |
5234 | 235 { |
236 if (isMIP) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9003
diff
changeset
|
237 { |
17180
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
238 *status = glp_mip_status (lp); |
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
239 *fmin = glp_mip_obj_val (lp); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9003
diff
changeset
|
240 } |
5234 | 241 else |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9003
diff
changeset
|
242 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9003
diff
changeset
|
243 if (lpsolver == 1) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9003
diff
changeset
|
244 { |
17180
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
245 *status = glp_get_status (lp); |
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
246 *fmin = glp_get_obj_val (lp); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9003
diff
changeset
|
247 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9003
diff
changeset
|
248 else |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9003
diff
changeset
|
249 { |
17180
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
250 *status = glp_ipt_status (lp); |
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
251 *fmin = glp_ipt_obj_val (lp); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9003
diff
changeset
|
252 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9003
diff
changeset
|
253 } |
5232 | 254 |
5234 | 255 if (isMIP) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9003
diff
changeset
|
256 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9003
diff
changeset
|
257 for (int i = 0; i < n; i++) |
17180
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
258 xmin[i] = glp_mip_col_val (lp, i+1); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9003
diff
changeset
|
259 } |
5234 | 260 else |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9003
diff
changeset
|
261 { |
20946 | 262 // Primal values |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9003
diff
changeset
|
263 for (int i = 0; i < n; i++) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9003
diff
changeset
|
264 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9003
diff
changeset
|
265 if (lpsolver == 1) |
17180
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
266 xmin[i] = glp_get_col_prim (lp, i+1); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9003
diff
changeset
|
267 else |
17180
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
268 xmin[i] = glp_ipt_col_prim (lp, i+1); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9003
diff
changeset
|
269 } |
5232 | 270 |
20946 | 271 // Dual values |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9003
diff
changeset
|
272 for (int i = 0; i < m; i++) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9003
diff
changeset
|
273 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9003
diff
changeset
|
274 if (lpsolver == 1) |
17180
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
275 lambda[i] = glp_get_row_dual (lp, i+1); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9003
diff
changeset
|
276 else |
17180
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
277 lambda[i] = glp_ipt_row_dual (lp, i+1); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9003
diff
changeset
|
278 } |
5234 | 279 |
20946 | 280 // Reduced costs |
17180
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
281 for (int i = 0; i < glp_get_num_cols (lp); i++) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9003
diff
changeset
|
282 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9003
diff
changeset
|
283 if (lpsolver == 1) |
17180
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
284 redcosts[i] = glp_get_col_dual (lp, i+1); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9003
diff
changeset
|
285 else |
17180
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
286 redcosts[i] = glp_ipt_col_dual (lp, i+1); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9003
diff
changeset
|
287 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9003
diff
changeset
|
288 } |
5234 | 289 |
5241 | 290 *time = (clock () - t_start) / CLOCKS_PER_SEC; |
5234 | 291 } |
292 | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
293 glp_delete_prob (lp); |
21445
de155ca994d4
Ask glpk to free all resources used after solving problem.
Rik <rik@octave.org>
parents:
21301
diff
changeset
|
294 // Request that GLPK free all memory resources. |
de155ca994d4
Ask glpk to free all resources used after solving problem.
Rik <rik@octave.org>
parents:
21301
diff
changeset
|
295 // This prevents reported memory leaks, but isn't strictly necessary. |
de155ca994d4
Ask glpk to free all resources used after solving problem.
Rik <rik@octave.org>
parents:
21301
diff
changeset
|
296 // The memory blocks use are allocated once and don't grow with further |
21604
d7a268e68e69
maint: Strip trailing whitespace from source files.
John W. Eaton <jwe@octave.org>
parents:
21445
diff
changeset
|
297 // calls to glpk so they would be reclaimed anyways when Octave exits. |
21445
de155ca994d4
Ask glpk to free all resources used after solving problem.
Rik <rik@octave.org>
parents:
21301
diff
changeset
|
298 glp_free_env (); |
5234 | 299 |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
300 return errnum; |
5232 | 301 } |
302 | |
5235 | 303 #endif |
304 | |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
305 #define OCTAVE_GLPK_GET_REAL_PARAM(NAME, VAL) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
306 do \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
307 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
308 octave_value tmp = PARAM.getfield (NAME); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
309 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
310 if (tmp.is_defined ()) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
311 { \ |
23577
80c42f4cca13
maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents:
23455
diff
changeset
|
312 if (! tmp.isempty ()) \ |
20704
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
313 VAL = tmp.xscalar_value ("glpk: invalid value in PARAM" NAME); \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
314 else \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
315 error ("glpk: invalid value in PARAM" NAME); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
316 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
317 } \ |
5240 | 318 while (0) |
319 | |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
320 #define OCTAVE_GLPK_GET_INT_PARAM(NAME, VAL) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
321 do \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
322 { \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
323 octave_value tmp = PARAM.getfield (NAME); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
324 \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
325 if (tmp.is_defined ()) \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
326 { \ |
23577
80c42f4cca13
maint: Deprecate is_empty and replace with isempty.
Rik <rik@octave.org>
parents:
23455
diff
changeset
|
327 if (! tmp.isempty ()) \ |
20704
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
328 VAL = tmp.xint_value ("glpk: invalid value in PARAM" NAME); \ |
22197
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
329 else \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
330 error ("glpk: invalid value in PARAM" NAME); \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
331 } \ |
e43d83253e28
refill multi-line macro definitions
John W. Eaton <jwe@octave.org>
parents:
21966
diff
changeset
|
332 } \ |
5240 | 333 while (0) |
334 | |
5235 | 335 DEFUN_DLD (__glpk__, args, , |
21966
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
336 doc: /* -*- texinfo -*- |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
337 @deftypefn {} {[@var{values}] =} __glpk__ (@var{args}) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
338 Undocumented internal function. |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21782
diff
changeset
|
339 @end deftypefn */) |
5232 | 340 { |
5235 | 341 #if defined (HAVE_GLPK) |
342 | |
20812
d9ca869ca124
maint: Clean-up more instances of print_usage().
Rik <rik@octave.org>
parents:
20790
diff
changeset
|
343 // FIXME: Should we even need checking for an internal function? |
20818
cef0448a6ed2
eliminate unnecessary uses of nargin
John W. Eaton <jwe@octave.org>
parents:
20812
diff
changeset
|
344 if (args.length () != 9) |
20790
c2d9556d51d0
eliminate return statements after calls to print_usage
John W. Eaton <jwe@octave.org>
parents:
20704
diff
changeset
|
345 print_usage (); |
5234 | 346 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20867
diff
changeset
|
347 // 1nd Input. A column array containing the objective function coefficients. |
21090
93d294511277
don't use setjmp/longjmp to handle error in glpk
John W. Eaton <jwe@octave.org>
parents:
21082
diff
changeset
|
348 int mrowsc = args(0).rows (); |
5234 | 349 |
20704
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
350 Matrix C = args(0).xmatrix_value ("__glpk__: invalid value of C"); |
5240 | 351 |
5234 | 352 double *c = C.fortran_vec (); |
5455 | 353 Array<int> rn; |
354 Array<int> cn; | |
355 ColumnVector a; | |
21090
93d294511277
don't use setjmp/longjmp to handle error in glpk
John W. Eaton <jwe@octave.org>
parents:
21082
diff
changeset
|
356 int mrowsA; |
93d294511277
don't use setjmp/longjmp to handle error in glpk
John W. Eaton <jwe@octave.org>
parents:
21082
diff
changeset
|
357 int nz = 0; |
5232 | 358 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20867
diff
changeset
|
359 // 2nd Input. A matrix containing the constraints coefficients. |
5234 | 360 // If matrix A is NOT a sparse matrix |
5631 | 361 if (args(1).is_sparse_type ()) |
5455 | 362 { |
20704
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
363 SparseMatrix A = args(1).xsparse_matrix_value ("__glpk__: invalid value of A"); |
5234 | 364 |
5455 | 365 mrowsA = A.rows (); |
366 octave_idx_type Anc = A.cols (); | |
10527
b4d2080b6df7
Replace nzmax by nnz as needed
David Bateman <dbateman@free.fr>
parents:
10350
diff
changeset
|
367 octave_idx_type Anz = A.nnz (); |
11574
a83bad07f7e3
attempt better backward compatibility for Array resize functions
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
368 rn.resize (dim_vector (Anz+1, 1)); |
a83bad07f7e3
attempt better backward compatibility for Array resize functions
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
369 cn.resize (dim_vector (Anz+1, 1)); |
5455 | 370 a.resize (Anz+1, 0.0); |
371 | |
372 if (Anc != mrowsc) | |
20825
66cd994d1b79
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20818
diff
changeset
|
373 error ("__glpk__: invalid value of A"); |
5455 | 374 |
375 for (octave_idx_type j = 0; j < Anc; j++) | |
14854
5ae9f0f77635
maint: Use Octave coding conventions for coddling parenthis is DLD-FUNCTIONS directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
376 for (octave_idx_type i = A.cidx (j); i < A.cidx (j+1); i++) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9003
diff
changeset
|
377 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9003
diff
changeset
|
378 nz++; |
14854
5ae9f0f77635
maint: Use Octave coding conventions for coddling parenthis is DLD-FUNCTIONS directory
Rik <octave@nomad.inbox5.com>
parents:
14846
diff
changeset
|
379 rn(nz) = A.ridx (i) + 1; |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9003
diff
changeset
|
380 cn(nz) = j + 1; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9003
diff
changeset
|
381 a(nz) = A.data(i); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9003
diff
changeset
|
382 } |
5455 | 383 } |
5631 | 384 else |
385 { | |
20704
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
386 Matrix A = args(1).xmatrix_value ("__glpk__: invalid value of A"); |
5631 | 387 |
388 mrowsA = A.rows (); | |
11574
a83bad07f7e3
attempt better backward compatibility for Array resize functions
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
389 rn.resize (dim_vector (mrowsA*mrowsc+1, 1)); |
a83bad07f7e3
attempt better backward compatibility for Array resize functions
John W. Eaton <jwe@octave.org>
parents:
11570
diff
changeset
|
390 cn.resize (dim_vector (mrowsA*mrowsc+1, 1)); |
5631 | 391 a.resize (mrowsA*mrowsc+1, 0.0); |
392 | |
393 for (int i = 0; i < mrowsA; i++) | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9003
diff
changeset
|
394 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9003
diff
changeset
|
395 for (int j = 0; j < mrowsc; j++) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9003
diff
changeset
|
396 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9003
diff
changeset
|
397 if (A(i,j) != 0) |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9003
diff
changeset
|
398 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9003
diff
changeset
|
399 nz++; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9003
diff
changeset
|
400 rn(nz) = i + 1; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9003
diff
changeset
|
401 cn(nz) = j + 1; |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9003
diff
changeset
|
402 a(nz) = A(i,j); |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9003
diff
changeset
|
403 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9003
diff
changeset
|
404 } |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9003
diff
changeset
|
405 } |
5631 | 406 |
407 } | |
5232 | 408 |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21724
diff
changeset
|
409 // 3rd Input. A column array containing the right-hand side value |
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21724
diff
changeset
|
410 // for each constraint in the constraint matrix. |
20704
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
411 Matrix B = args(2).xmatrix_value ("__glpk__: invalid value of B"); |
5240 | 412 |
5234 | 413 double *b = B.fortran_vec (); |
414 | |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21724
diff
changeset
|
415 // 4th Input. An array of length mrowsc containing the lower |
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21724
diff
changeset
|
416 // bound on each of the variables. |
20704
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
417 Matrix LB = args(3).xmatrix_value ("__glpk__: invalid value of LB"); |
5240 | 418 |
20704
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
419 if (LB.numel () < mrowsc) |
20825
66cd994d1b79
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20818
diff
changeset
|
420 error ("__glpk__: invalid dimensions for LB"); |
5240 | 421 |
5234 | 422 double *lb = LB.fortran_vec (); |
423 | |
20946 | 424 // LB argument, default: Free |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
425 Array<int> freeLB (dim_vector (mrowsc, 1)); |
5234 | 426 for (int i = 0; i < mrowsc; i++) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
427 { |
21782
2aef506f3fec
use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
428 if (octave::math::isinf (lb[i])) |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
429 { |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
430 freeLB(i) = 1; |
21723
bae585228161
use namespace for numeric_limits
John W. Eaton <jwe@octave.org>
parents:
21721
diff
changeset
|
431 lb[i] = -octave::numeric_limits<double>::Inf (); |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
432 } |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
433 else |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
434 freeLB(i) = 0; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
435 } |
5234 | 436 |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21724
diff
changeset
|
437 // 5th Input. An array of at least length numcols containing the upper |
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21724
diff
changeset
|
438 // bound on each of the variables. |
20704
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
439 Matrix UB = args(4).xmatrix_value ("__glpk__: invalid value of UB"); |
5234 | 440 |
20704
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
441 if (UB.numel () < mrowsc) |
20825
66cd994d1b79
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20818
diff
changeset
|
442 error ("__glpk__: invalid dimensions for UB"); |
5240 | 443 |
5234 | 444 double *ub = UB.fortran_vec (); |
5232 | 445 |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
446 Array<int> freeUB (dim_vector (mrowsc, 1)); |
5234 | 447 for (int i = 0; i < mrowsc; i++) |
448 { | |
21782
2aef506f3fec
use namespace for lo-mappers.h functions
John W. Eaton <jwe@octave.org>
parents:
21751
diff
changeset
|
449 if (octave::math::isinf (ub[i])) |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9003
diff
changeset
|
450 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9003
diff
changeset
|
451 freeUB(i) = 1; |
21723
bae585228161
use namespace for numeric_limits
John W. Eaton <jwe@octave.org>
parents:
21721
diff
changeset
|
452 ub[i] = octave::numeric_limits<double>::Inf (); |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9003
diff
changeset
|
453 } |
5234 | 454 else |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9003
diff
changeset
|
455 freeUB(i) = 0; |
5234 | 456 } |
457 | |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21724
diff
changeset
|
458 // 6th Input. A column array containing the sense of each constraint |
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21724
diff
changeset
|
459 // in the constraint matrix. |
21091
72eefc36c6b7
use correct value extractor functions in glpk
John W. Eaton <jwe@octave.org>
parents:
21090
diff
changeset
|
460 charMatrix CTYPE = args(5).xchar_matrix_value ("__glpk__: invalid value of CTYPE"); |
5240 | 461 |
5237 | 462 char *ctype = CTYPE.fortran_vec (); |
463 | |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21724
diff
changeset
|
464 // 7th Input. A column array containing the types of the variables. |
21091
72eefc36c6b7
use correct value extractor functions in glpk
John W. Eaton <jwe@octave.org>
parents:
21090
diff
changeset
|
465 charMatrix VTYPE = args(6).xchar_matrix_value ("__glpk__: invalid value of VARTYPE"); |
5240 | 466 |
11570
57632dea2446
attempt better backward compatibility for Array constructors
John W. Eaton <jwe@octave.org>
parents:
11553
diff
changeset
|
467 Array<int> vartype (dim_vector (mrowsc, 1)); |
21090
93d294511277
don't use setjmp/longjmp to handle error in glpk
John W. Eaton <jwe@octave.org>
parents:
21082
diff
changeset
|
468 int isMIP = 0; |
5234 | 469 for (int i = 0; i < mrowsc ; i++) |
470 { | |
471 if (VTYPE(i,0) == 'I') | |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9003
diff
changeset
|
472 { |
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9003
diff
changeset
|
473 isMIP = 1; |
17180
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
474 vartype(i) = GLP_IV; |
10154
40dfc0c99116
DLD-FUNCTIONS/*.cc: untabify
John W. Eaton <jwe@octave.org>
parents:
9003
diff
changeset
|
475 } |
5234 | 476 else |
17180
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
477 vartype(i) = GLP_CV; |
5234 | 478 } |
479 | |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21724
diff
changeset
|
480 // 8th Input. Sense of optimization. |
21090
93d294511277
don't use setjmp/longjmp to handle error in glpk
John W. Eaton <jwe@octave.org>
parents:
21082
diff
changeset
|
481 int sense; |
93d294511277
don't use setjmp/longjmp to handle error in glpk
John W. Eaton <jwe@octave.org>
parents:
21082
diff
changeset
|
482 double SENSE = args(7).xscalar_value ("__glpk__: invalid value of SENSE"); |
5240 | 483 |
5237 | 484 if (SENSE >= 0) |
485 sense = 1; | |
486 else | |
487 sense = -1; | |
488 | |
21751
b571fc85953f
maint: Use two spaces after period to indicate sentence break.
Rik <rik@octave.org>
parents:
21724
diff
changeset
|
489 // 9th Input. A structure containing the control parameters. |
20704
571508c1ed06
eliminate more uses of error_state
John W. Eaton <jwe@octave.org>
parents:
20232
diff
changeset
|
490 octave_scalar_map PARAM = args(8).xscalar_map_value ("__glpk__: invalid value of PARAM"); |
5240 | 491 |
17180
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
492 control_params par; |
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
493 |
20946 | 494 // Integer parameters |
5234 | 495 |
20946 | 496 // Level of messages output by the solver |
17180
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
497 par.msglev = 1; |
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
498 OCTAVE_GLPK_GET_INT_PARAM ("msglev", par.msglev); |
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
499 if (par.msglev < 0 || par.msglev > 3) |
20825
66cd994d1b79
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20818
diff
changeset
|
500 error ("__glpk__: PARAM.msglev must be 0 (no output) or 1 (error and warning messages only [default]) or 2 (normal output) or 3 (full output)"); |
5232 | 501 |
20946 | 502 // scaling option |
21090
93d294511277
don't use setjmp/longjmp to handle error in glpk
John W. Eaton <jwe@octave.org>
parents:
21082
diff
changeset
|
503 int scale = 16; |
17180
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
504 OCTAVE_GLPK_GET_INT_PARAM ("scale", scale); |
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
505 if (scale < 0 || scale > 128) |
20825
66cd994d1b79
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20818
diff
changeset
|
506 error ("__glpk__: PARAM.scale must either be 128 (automatic selection of scaling options), or a bitwise or of: 1 (geometric mean scaling), 16 (equilibration scaling), 32 (round scale factors to power of two), 64 (skip if problem is well scaled"); |
5232 | 507 |
20946 | 508 // Dual simplex option |
17180
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
509 par.dual = 1; |
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
510 OCTAVE_GLPK_GET_INT_PARAM ("dual", par.dual); |
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
511 if (par.dual < 1 || par.dual > 3) |
20825
66cd994d1b79
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20818
diff
changeset
|
512 error ("__glpk__: PARAM.dual must be 1 (use two-phase primal simplex [default]) or 2 (use two-phase dual simplex) or 3 (use two-phase dual simplex, and if it fails, switch to the primal simplex)"); |
5232 | 513 |
20946 | 514 // Pricing option |
17180
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
515 par.price = 34; |
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
516 OCTAVE_GLPK_GET_INT_PARAM ("price", par.price); |
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
517 if (par.price != 17 && par.price != 34) |
20825
66cd994d1b79
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20818
diff
changeset
|
518 error ("__glpk__: PARAM.price must be 17 (textbook pricing) or 34 (steepest edge pricing [default])"); |
5234 | 519 |
20946 | 520 // Simplex iterations limit |
17195
2899d110c178
Use std::numeric_limits instead of INT_MAX in __glpk__ (bug #39715).
Rik <rik@octave.org>
parents:
17181
diff
changeset
|
521 par.itlim = std::numeric_limits<int>::max (); |
17180
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
522 OCTAVE_GLPK_GET_INT_PARAM ("itlim", par.itlim); |
5234 | 523 |
20946 | 524 // Output frequency, in iterations |
17180
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
525 par.outfrq = 200; |
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
526 OCTAVE_GLPK_GET_INT_PARAM ("outfrq", par.outfrq); |
5234 | 527 |
20946 | 528 // Branching heuristic option |
17180
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
529 par.branch = 4; |
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
530 OCTAVE_GLPK_GET_INT_PARAM ("branch", par.branch); |
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
531 if (par.branch < 1 || par.branch > 5) |
20825
66cd994d1b79
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20818
diff
changeset
|
532 error ("__glpk__: PARAM.branch must be 1 (first fractional variable) or 2 (last fractional variable) or 3 (most fractional variable) or 4 (heuristic by Driebeck and Tomlin [default]) or 5 (hybrid pseudocost heuristic)"); |
5232 | 533 |
20946 | 534 // Backtracking heuristic option |
17180
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
535 par.btrack = 4; |
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
536 OCTAVE_GLPK_GET_INT_PARAM ("btrack", par.btrack); |
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
537 if (par.btrack < 1 || par.btrack > 4) |
20825
66cd994d1b79
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20818
diff
changeset
|
538 error ("__glpk__: PARAM.btrack must be 1 (depth first search) or 2 (breadth first search) or 3 (best local bound) or 4 (best projection heuristic [default]"); |
5232 | 539 |
20946 | 540 // Presolver option |
17180
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
541 par.presol = 1; |
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
542 OCTAVE_GLPK_GET_INT_PARAM ("presol", par.presol); |
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
543 if (par.presol < 0 || par.presol > 1) |
20825
66cd994d1b79
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20818
diff
changeset
|
544 error ("__glpk__: PARAM.presol must be 0 (do NOT use LP presolver) or 1 (use LP presolver [default])"); |
5234 | 545 |
20946 | 546 // LPsolver option |
21090
93d294511277
don't use setjmp/longjmp to handle error in glpk
John W. Eaton <jwe@octave.org>
parents:
21082
diff
changeset
|
547 int lpsolver = 1; |
5240 | 548 OCTAVE_GLPK_GET_INT_PARAM ("lpsolver", lpsolver); |
549 if (lpsolver < 1 || lpsolver > 2) | |
20825
66cd994d1b79
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20818
diff
changeset
|
550 error ("__glpk__: PARAM.lpsolver must be 1 (simplex method) or 2 (interior point method)"); |
5237 | 551 |
20946 | 552 // Ratio test option |
17180
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
553 par.rtest = 34; |
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
554 OCTAVE_GLPK_GET_INT_PARAM ("rtest", par.rtest); |
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
555 if (par.rtest != 17 && par.rtest != 34) |
20825
66cd994d1b79
eliminate return statements after calls to error
John W. Eaton <jwe@octave.org>
parents:
20818
diff
changeset
|
556 error ("__glpk__: PARAM.rtest must be 17 (standard ratio test) or 34 (Harris' two-pass ratio test [default])"); |
17180
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
557 |
17195
2899d110c178
Use std::numeric_limits instead of INT_MAX in __glpk__ (bug #39715).
Rik <rik@octave.org>
parents:
17181
diff
changeset
|
558 par.tmlim = std::numeric_limits<int>::max (); |
17180
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
559 OCTAVE_GLPK_GET_INT_PARAM ("tmlim", par.tmlim); |
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
560 |
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
561 par.outdly = 0; |
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
562 OCTAVE_GLPK_GET_INT_PARAM ("outdly", par.outdly); |
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
563 |
20946 | 564 // Save option |
21090
93d294511277
don't use setjmp/longjmp to handle error in glpk
John W. Eaton <jwe@octave.org>
parents:
21082
diff
changeset
|
565 int save_pb = 0; |
5240 | 566 OCTAVE_GLPK_GET_INT_PARAM ("save", save_pb); |
567 save_pb = save_pb != 0; | |
5237 | 568 |
20946 | 569 // Real parameters |
5234 | 570 |
20946 | 571 // Relative tolerance used to check if the current basic solution |
572 // is primal feasible | |
17180
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
573 par.tolbnd = 1e-7; |
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
574 OCTAVE_GLPK_GET_REAL_PARAM ("tolbnd", par.tolbnd); |
5234 | 575 |
20946 | 576 // Absolute tolerance used to check if the current basic solution |
577 // is dual feasible | |
17180
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
578 par.toldj = 1e-7; |
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
579 OCTAVE_GLPK_GET_REAL_PARAM ("toldj", par.toldj); |
5232 | 580 |
20946 | 581 // Relative tolerance used to choose eligible pivotal elements of |
582 // the simplex table in the ratio test | |
17180
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
583 par.tolpiv = 1e-10; |
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
584 OCTAVE_GLPK_GET_REAL_PARAM ("tolpiv", par.tolpiv); |
5234 | 585 |
17180
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
586 par.objll = -std::numeric_limits<double>::max (); |
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
587 OCTAVE_GLPK_GET_REAL_PARAM ("objll", par.objll); |
5232 | 588 |
17180
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
589 par.objul = std::numeric_limits<double>::max (); |
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
590 OCTAVE_GLPK_GET_REAL_PARAM ("objul", par.objul); |
5234 | 591 |
17180
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
592 par.tolint = 1e-5; |
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
593 OCTAVE_GLPK_GET_REAL_PARAM ("tolint", par.tolint); |
5234 | 594 |
17180
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
595 par.tolobj = 1e-7; |
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
596 OCTAVE_GLPK_GET_REAL_PARAM ("tolobj", par.tolobj); |
5234 | 597 |
20946 | 598 // Assign pointers to the output parameters |
8068
e3e3d12364b0
make glpk return NA values for unfeasible problems
Jaroslav Hajek <highegg@gmail.com>
parents:
8036
diff
changeset
|
599 ColumnVector xmin (mrowsc, octave_NA); |
11048
10c65e01f042
__glpk__.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
11047
diff
changeset
|
600 double fmin = octave_NA; |
8068
e3e3d12364b0
make glpk return NA values for unfeasible problems
Jaroslav Hajek <highegg@gmail.com>
parents:
8036
diff
changeset
|
601 ColumnVector lambda (mrowsA, octave_NA); |
e3e3d12364b0
make glpk return NA values for unfeasible problems
Jaroslav Hajek <highegg@gmail.com>
parents:
8036
diff
changeset
|
602 ColumnVector redcosts (mrowsc, octave_NA); |
11048
10c65e01f042
__glpk__.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
11047
diff
changeset
|
603 double time; |
19779
166051951878
avoid warning from GCC about variables possibly clobbered by longjmp
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
604 int status; |
5232 | 605 |
21090
93d294511277
don't use setjmp/longjmp to handle error in glpk
John W. Eaton <jwe@octave.org>
parents:
21082
diff
changeset
|
606 int errnum = glpk (sense, mrowsc, mrowsA, c, nz, rn.fortran_vec (), |
93d294511277
don't use setjmp/longjmp to handle error in glpk
John W. Eaton <jwe@octave.org>
parents:
21082
diff
changeset
|
607 cn.fortran_vec (), a.fortran_vec (), b, ctype, |
21091
72eefc36c6b7
use correct value extractor functions in glpk
John W. Eaton <jwe@octave.org>
parents:
21090
diff
changeset
|
608 freeLB.fortran_vec (), lb, freeUB.fortran_vec (), |
72eefc36c6b7
use correct value extractor functions in glpk
John W. Eaton <jwe@octave.org>
parents:
21090
diff
changeset
|
609 ub, vartype.fortran_vec (), isMIP, lpsolver, |
72eefc36c6b7
use correct value extractor functions in glpk
John W. Eaton <jwe@octave.org>
parents:
21090
diff
changeset
|
610 save_pb, scale, &par, xmin.fortran_vec (), &fmin, |
72eefc36c6b7
use correct value extractor functions in glpk
John W. Eaton <jwe@octave.org>
parents:
21090
diff
changeset
|
611 &status, lambda.fortran_vec (), |
72eefc36c6b7
use correct value extractor functions in glpk
John W. Eaton <jwe@octave.org>
parents:
21090
diff
changeset
|
612 redcosts.fortran_vec (), &time); |
5232 | 613 |
11048
10c65e01f042
__glpk__.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
11047
diff
changeset
|
614 octave_scalar_map extra; |
5234 | 615 |
5238 | 616 if (! isMIP) |
617 { | |
11048
10c65e01f042
__glpk__.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
11047
diff
changeset
|
618 extra.assign ("lambda", lambda); |
10c65e01f042
__glpk__.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
11047
diff
changeset
|
619 extra.assign ("redcosts", redcosts); |
5238 | 620 } |
621 | |
11048
10c65e01f042
__glpk__.cc: use octave_scalar_map instead of Octave_map
John W. Eaton <jwe@octave.org>
parents:
11047
diff
changeset
|
622 extra.assign ("time", time); |
17180
54e251e699bb
Use the new GLPK API (bug #39038).
Sébastien Villemot <sebastien@debian.org>
parents:
15213
diff
changeset
|
623 extra.assign ("status", status); |
5232 | 624 |
20939
b17fda023ca6
maint: Use new C++ archetype in more files.
Rik <rik@octave.org>
parents:
20867
diff
changeset
|
625 return ovl (xmin, fmin, errnum, extra); |
5234 | 626 |
5235 | 627 #else |
21691
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21604
diff
changeset
|
628 |
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21604
diff
changeset
|
629 octave_unused_parameter (args); |
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21604
diff
changeset
|
630 |
21100
e39e05d90788
Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents:
21091
diff
changeset
|
631 err_disabled_feature ("glpk", "GNU Linear Programming Kit"); |
21691
263d18409fdf
Eliminate unused variable warnings for conditionally compiled code.
John W. Eaton <jwe@octave.org>
parents:
21604
diff
changeset
|
632 |
5235 | 633 #endif |
5232 | 634 } |
12805
3641167e5b75
codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
635 |
3641167e5b75
codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
636 /* |
3641167e5b75
codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
637 ## No test needed for internal helper function. |
3641167e5b75
codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
638 %!assert (1) |
3641167e5b75
codesprint: *.cc helper functions do not need tests
Rik <octave@nomad.inbox5.com>
parents:
11586
diff
changeset
|
639 */ |