1 |
bicatali 14/03/25 01:17:25 |
2 |
|
3 |
Added: cvxopt-1.1.6-glpk449.patch |
4 |
Log: |
5 |
Fixes for glpk-4.53 (bug #501320) and library dupes (bug #505404). Added more EAPI5 changes |
6 |
|
7 |
(Portage version: 2.2.8-prefix/cvs/Linux x86_64, signed Manifest commit with key 0x13CB1360) |
8 |
|
9 |
Revision Changes Path |
10 |
1.1 dev-python/cvxopt/files/cvxopt-1.1.6-glpk449.patch |
11 |
|
12 |
file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/dev-python/cvxopt/files/cvxopt-1.1.6-glpk449.patch?rev=1.1&view=markup |
13 |
plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/dev-python/cvxopt/files/cvxopt-1.1.6-glpk449.patch?rev=1.1&content-type=text/plain |
14 |
|
15 |
Index: cvxopt-1.1.6-glpk449.patch |
16 |
=================================================================== |
17 |
--- src/C/glpk.c.orig 2014-03-24 09:39:39.510214726 -0700 |
18 |
+++ src/C/glpk.c 2014-03-24 09:38:41.251897138 -0700 |
19 |
@@ -23,75 +23,271 @@ |
20 |
#include "misc.h" |
21 |
#include "glpk.h" |
22 |
|
23 |
+ |
24 |
PyDoc_STRVAR(glpk__doc__, |
25 |
"Interface to the simplex and mixed integer LP algorithms in GLPK.\n\n" |
26 |
"The GLPK control parameters have the default values listed in \n" |
27 |
- "the GLPK documentation, except for 'LPX_K_PRESOL', which is set\n" |
28 |
+ "the GLPK documentation, except for 'presolve', which is set\n" |
29 |
"to 1 and cannot be modified. The other parameters can be\n" |
30 |
- "modified by making an entry in the dictionary glpk.options.\n" |
31 |
- "For example, the command glpk.options['LPX_K_MSGLEV'] = 0 turns\n" |
32 |
- "off the printed output during execution of glpk.simplex().\n" |
33 |
+ "modified by passing a smcp or iocp object to the appropriate function\n" |
34 |
+ "For example, the commands param = glpk.smcp(msg_lev = 0), or \n" |
35 |
+ "param=glpk.smcp(); param.msg_lev=1 turn off the printed output during" |
36 |
+ " execution of glpk.simplex().\n" |
37 |
"See the documentation at www.gnu.org/software/glpk/glpk.html for\n" |
38 |
"the list of GLPK control parameters and their default values."); |
39 |
|
40 |
static PyObject *glpk_module; |
41 |
|
42 |
-typedef struct { |
43 |
- char name[20]; |
44 |
- int idx; |
45 |
- char type; |
46 |
-} param_tuple; |
47 |
- |
48 |
-static const param_tuple GLPK_PARAM_LIST[] = { |
49 |
- {"LPX_K_MSGLEV", LPX_K_MSGLEV, 'i'}, |
50 |
- {"LPX_K_SCALE", LPX_K_SCALE, 'i'}, |
51 |
- {"LPX_K_DUAL", LPX_K_DUAL, 'i'}, |
52 |
- {"LPX_K_PRICE", LPX_K_PRICE, 'i'}, |
53 |
- {"LPX_K_RELAX", LPX_K_RELAX, 'f'}, |
54 |
- {"LPX_K_TOLBND", LPX_K_TOLBND, 'f'}, |
55 |
- {"LPX_K_TOLDJ", LPX_K_TOLDJ, 'f'}, |
56 |
- {"LPX_K_TOLPIV", LPX_K_TOLPIV, 'f'}, |
57 |
- {"LPX_K_ROUND", LPX_K_ROUND, 'i'}, |
58 |
- {"LPX_K_OBJLL", LPX_K_OBJLL, 'f'}, |
59 |
- {"LPX_K_OBJUL", LPX_K_OBJUL, 'f'}, |
60 |
- {"LPX_K_ITLIM", LPX_K_ITLIM, 'i'}, |
61 |
- {"LPX_K_ITCNT", LPX_K_ITCNT, 'i'}, |
62 |
- {"LPX_K_TMLIM", LPX_K_TMLIM, 'f'}, |
63 |
- {"LPX_K_OUTFRQ", LPX_K_OUTFRQ, 'i'}, |
64 |
- {"LPX_K_OUTDLY", LPX_K_OUTDLY, 'f'}, |
65 |
- {"LPX_K_BRANCH", LPX_K_BRANCH, 'i'}, |
66 |
- {"LPX_K_BTRACK", LPX_K_BTRACK, 'i'}, |
67 |
- {"LPX_K_TOLINT", LPX_K_TOLINT, 'f'}, |
68 |
- {"LPX_K_TOLOBJ", LPX_K_TOLOBJ, 'f'}, |
69 |
- {"LPX_K_MPSINFO", LPX_K_MPSINFO, 'i'}, |
70 |
- {"LPX_K_MPSOBJ", LPX_K_MPSOBJ, 'i'}, |
71 |
- {"LPX_K_MPSORIG", LPX_K_MPSORIG, 'i'}, |
72 |
- {"LPX_K_MPSWIDE", LPX_K_MPSWIDE, 'i'}, |
73 |
- {"LPX_K_MPSFREE", LPX_K_MPSFREE, 'i'}, |
74 |
- {"LPX_K_MPSSKIP", LPX_K_MPSSKIP, 'i'}, |
75 |
- {"LPX_K_LPTORIG", LPX_K_LPTORIG, 'i'}, |
76 |
- {"LPX_K_PRESOL", LPX_K_PRESOL, 'i'}, |
77 |
-}; /* 28 paramaters */ |
78 |
+/* Wrappers around the option glpk structs */ |
79 |
+typedef struct{ |
80 |
+ PyObject_HEAD |
81 |
+ glp_smcp obj; |
82 |
+} pysmcp; |
83 |
|
84 |
+/* Deallocation of smcp object */ |
85 |
+static void smcp_dealloc(pysmcp* self) |
86 |
+{ |
87 |
+ Py_TYPE(self)->tp_free((PyObject*)self); |
88 |
+} |
89 |
|
90 |
-#if PY_MAJOR_VERSION >= 3 |
91 |
-static int get_param_idx(const char *str, int *idx, char *type) |
92 |
-#else |
93 |
-static int get_param_idx(char *str, int *idx, char *type) |
94 |
-#endif |
95 |
+/* New smcp method */ |
96 |
+static PyObject * |
97 |
+smcp_new(PyTypeObject *type, PyObject *args, PyObject *kwds) |
98 |
{ |
99 |
- int i; |
100 |
+ pysmcp *self; |
101 |
+ self = (pysmcp *)type->tp_alloc(type, 0); |
102 |
+ return (PyObject *)self; |
103 |
+} |
104 |
+ |
105 |
+/* Initialisation of smcp object */ |
106 |
+static int |
107 |
+smcp_init(pysmcp *self, PyObject *args, PyObject *kwds) |
108 |
+{ |
109 |
+ /*static char *kwlist[] = {"number", NULL};*/ |
110 |
+ static char *kwlist[] = { "msg_lev", "meth", "pricing", "r_test", "tol_bnd", "tol_dj", "tol_piv", "obj_ll", "obj_ul", "it_lim", "tm_lim", "out_frq", "out_dly", "presolve" }; |
111 |
+ glp_init_smcp(&self->obj); |
112 |
+ if (! PyArg_ParseTupleAndKeywords(args, kwds, "|iiiidddddiiiii", kwlist, |
113 |
+ &self->obj.msg_lev, |
114 |
+ &self->obj.meth, |
115 |
+ &self->obj.pricing, |
116 |
+ &self->obj.r_test, |
117 |
+ &self->obj.tol_bnd, |
118 |
+ &self->obj.tol_dj, |
119 |
+ &self->obj.tol_piv, |
120 |
+ &self->obj.obj_ll, |
121 |
+ &self->obj.obj_ul, |
122 |
+ &self->obj.it_lim, |
123 |
+ &self->obj.tm_lim, |
124 |
+ &self->obj.out_frq, |
125 |
+ &self->obj.out_dly, |
126 |
+ &self->obj.presolve)) |
127 |
+ return -1; |
128 |
|
129 |
- for (i=0; i<28; i++) { |
130 |
- if (!strcmp(GLPK_PARAM_LIST[i].name, str)) { |
131 |
- *idx = GLPK_PARAM_LIST[i].idx; |
132 |
- *type = GLPK_PARAM_LIST[i].type; |
133 |
- return 1; |
134 |
- } |
135 |
- } |
136 |
return 0; |
137 |
} |
138 |
|
139 |
+/* smcp members declaration */ |
140 |
+static PyMemberDef smcpMembers[] = { |
141 |
+ {"msg_lev", T_INT, offsetof(pysmcp,obj)+offsetof(glp_smcp,msg_lev), 0, "message level: "}, |
142 |
+ {"meth", T_INT, offsetof(pysmcp,obj)+offsetof(glp_smcp,meth), 0, "simplex method option: "}, |
143 |
+ {"pricing", T_INT, offsetof(pysmcp,obj)+offsetof(glp_smcp,pricing), 0, "pricing technique: "}, |
144 |
+ {"r_test", T_INT, offsetof(pysmcp,obj)+offsetof(glp_smcp,r_test), 0, "ratio test technique: "}, |
145 |
+ {"tol_bnd", T_DOUBLE, offsetof(pysmcp,obj)+offsetof(glp_smcp,tol_bnd), 0, "spx.tol_bnd "}, |
146 |
+ {"tol_dj", T_DOUBLE, offsetof(pysmcp,obj)+offsetof(glp_smcp,tol_dj), 0, "spx.tol_dj "}, |
147 |
+ {"tol_piv", T_DOUBLE, offsetof(pysmcp,obj)+offsetof(glp_smcp,tol_piv), 0, "spx.tol_piv "}, |
148 |
+ {"obj_ll", T_DOUBLE, offsetof(pysmcp,obj)+offsetof(glp_smcp,obj_ll), 0, "spx.obj_ll "}, |
149 |
+ {"obj_ul", T_DOUBLE, offsetof(pysmcp,obj)+offsetof(glp_smcp,obj_ul), 0, "spx.obj_ul "}, |
150 |
+ {"it_lim", T_INT, offsetof(pysmcp,obj)+offsetof(glp_smcp,it_lim), 0, "spx.it_lim "}, |
151 |
+ {"tm_lim", T_INT, offsetof(pysmcp,obj)+offsetof(glp_smcp,tm_lim), 0, "spx.tm_lim (milliseconds) "}, |
152 |
+ {"out_frq", T_INT, offsetof(pysmcp,obj)+offsetof(glp_smcp,out_frq), 0, "spx.out_frq "}, |
153 |
+ {"out_dly", T_INT, offsetof(pysmcp,obj)+offsetof(glp_smcp,out_dly), 0, "spx.out_dly (milliseconds) "}, |
154 |
+ {"presolve", T_INT, offsetof(pysmcp,obj)+offsetof(glp_smcp,presolve), 0, "enable/disable using LP presolver "}, |
155 |
+}; |
156 |
+ |
157 |
+static PyTypeObject smcp_t = { |
158 |
+ PyVarObject_HEAD_INIT(NULL, 0) |
159 |
+ "glpk.smcp", /* tp_name */ |
160 |
+ sizeof(pysmcp), /* tp_basicsize */ |
161 |
+ 0, /* tp_itemsize */ |
162 |
+ (destructor)smcp_dealloc, /* tp_dealloc */ |
163 |
+ 0, /* tp_print */ |
164 |
+ 0, /* tp_getattr */ |
165 |
+ 0, /* tp_setattr */ |
166 |
+ 0, /* tp_reserved */ |
167 |
+ 0, /* tp_repr */ |
168 |
+ 0, /* tp_as_number */ |
169 |
+ 0, /* tp_as_sequence */ |
170 |
+ 0, /* tp_as_mapping */ |
171 |
+ 0, /* tp_hash */ |
172 |
+ 0, /* tp_call */ |
173 |
+ 0, /* tp_str */ |
174 |
+ 0, /* tp_getattro */ |
175 |
+ 0, /* tp_setattro */ |
176 |
+ 0, /* tp_as_buffer */ |
177 |
+ Py_TPFLAGS_DEFAULT | |
178 |
+ Py_TPFLAGS_BASETYPE, /* tp_flags */ |
179 |
+ "simplex method control parameters", /* tp_doc */ |
180 |
+ 0, /* tp_traverse */ |
181 |
+ 0, /* tp_clear */ |
182 |
+ 0, /* tp_richcompare */ |
183 |
+ 0, /* tp_weaklistoffset */ |
184 |
+ 0, /* tp_iter */ |
185 |
+ 0, /* tp_iternext */ |
186 |
+ 0, /* tp_methods */ |
187 |
+ smcpMembers, /* tp_members */ |
188 |
+ 0, /* tp_getset */ |
189 |
+ 0, /* tp_base */ |
190 |
+ 0, /* tp_dict */ |
191 |
+ 0, /* tp_descr_get */ |
192 |
+ 0, /* tp_descr_set */ |
193 |
+ 0, /* tp_dictoffset */ |
194 |
+ (initproc)smcp_init, /* tp_init */ |
195 |
+ 0, /* tp_alloc */ |
196 |
+ smcp_new, /* tp_new */ |
197 |
+}; |
198 |
+ |
199 |
+ |
200 |
+/* Wrappers around the option glpk structs */ |
201 |
+typedef struct{ |
202 |
+ PyObject_HEAD |
203 |
+ glp_iocp obj; |
204 |
+} pyiocp; |
205 |
+ |
206 |
+/* Deallocation of iocp object */ |
207 |
+static void iocp_dealloc(pysmcp* self) |
208 |
+{ |
209 |
+ Py_TYPE(self)->tp_free((PyObject*)self); |
210 |
+} |
211 |
+ |
212 |
+/* New iocp method */ |
213 |
+static PyObject * |
214 |
+iocp_new(PyTypeObject *type, PyObject *args, PyObject *kwds) |
215 |
+{ |
216 |
+ pyiocp *self; |
217 |
+ self = (pyiocp *)type->tp_alloc(type, 0); |
218 |
+ return (PyObject *)self; |
219 |
+} |
220 |
+ |
221 |
+/* Initialisation of iocp object */ |
222 |
+static int |
223 |
+iocp_init(pyiocp *self, PyObject *args, PyObject *kwds) |
224 |
+{ |
225 |
+ /*static char *kwlist[] = {"number", NULL};*/ |
226 |
+ static char *kwlist[] = { "msg_lev", "br_tech", "bt_tech", "tol_int", "tol_obj", "tm_lim", "out_frq", "out_dly", "cb_size", "pp_tech", "mip_gap", "mir_cuts", "gmi_cuts", "cov_cuts", "clq_cuts", "presolve", "binarize", "fp_heur", "ps_heur", "ps_tm_lim", "use_sol", "save_sol", "alien",NULL}; |
227 |
+ glp_init_iocp(&self->obj); |
228 |
+ |
229 |
+ if (! PyArg_ParseTupleAndKeywords(args, kwds, "|iiiddiiiiidiiiiiiiiiisi", kwlist, |
230 |
+ &self->obj.msg_lev, |
231 |
+ &self->obj.br_tech, |
232 |
+ &self->obj.bt_tech, |
233 |
+ &self->obj.tol_int, |
234 |
+ &self->obj.tol_obj, |
235 |
+ &self->obj.tm_lim, |
236 |
+ &self->obj.out_frq, |
237 |
+ &self->obj.out_dly, |
238 |
+ &self->obj.cb_size, |
239 |
+ &self->obj.pp_tech, |
240 |
+ &self->obj.mip_gap, |
241 |
+ &self->obj.mir_cuts, |
242 |
+ &self->obj.gmi_cuts, |
243 |
+ &self->obj.cov_cuts, |
244 |
+ &self->obj.clq_cuts, |
245 |
+ &self->obj.presolve, |
246 |
+ &self->obj.binarize, |
247 |
+ &self->obj.fp_heur, |
248 |
+ &self->obj.ps_heur, |
249 |
+ &self->obj.ps_tm_lim, |
250 |
+ &self->obj.use_sol, |
251 |
+ &self->obj.save_sol, |
252 |
+ &self->obj.alien)) |
253 |
+ return -1; |
254 |
+ |
255 |
+ return 0; |
256 |
+} |
257 |
+ |
258 |
+/* iocp members declaration */ |
259 |
+static PyMemberDef iocpMembers[] = { |
260 |
+ {"msg_lev", T_INT, offsetof(pysmcp,obj)+offsetof(glp_iocp,msg_lev), 0, "message level (see glp_smcp) "}, |
261 |
+ {"br_tech", T_INT, offsetof(pysmcp,obj)+offsetof(glp_iocp,br_tech), 0, "branching technique: "}, |
262 |
+ {"bt_tech", T_INT, offsetof(pysmcp,obj)+offsetof(glp_iocp,bt_tech), 0, "backtracking technique: "}, |
263 |
+ {"tol_int", T_DOUBLE, offsetof(pysmcp,obj)+offsetof(glp_iocp,tol_int), 0, "mip.tol_int "}, |
264 |
+ {"tol_obj", T_DOUBLE, offsetof(pysmcp,obj)+offsetof(glp_iocp,tol_obj), 0, "mip.tol_obj "}, |
265 |
+ {"tm_lim", T_INT, offsetof(pysmcp,obj)+offsetof(glp_iocp,tm_lim), 0, "mip.tm_lim (milliseconds) "}, |
266 |
+ {"out_frq", T_INT, offsetof(pysmcp,obj)+offsetof(glp_iocp,out_frq), 0, "mip.out_frq (milliseconds) "}, |
267 |
+ {"out_dly", T_INT, offsetof(pysmcp,obj)+offsetof(glp_iocp,out_dly), 0, "mip.out_dly (milliseconds) "}, |
268 |
+ /*void (*cb_func)(glp_tree *T, void *info); [> mip.cb_func <]*/ |
269 |
+ /*void *cb_info; [> mip.cb_info <]*/ |
270 |
+ {"cb_size", T_INT, offsetof(pysmcp,obj)+offsetof(glp_iocp,cb_size), 0, "mip.cb_size "}, |
271 |
+ {"pp_tech", T_INT, offsetof(pysmcp,obj)+offsetof(glp_iocp,pp_tech), 0, "preprocessing technique: "}, |
272 |
+ {"mip_gap", T_DOUBLE, offsetof(pysmcp,obj)+offsetof(glp_iocp,mip_gap), 0, "relative MIP gap tolerance "}, |
273 |
+ {"mir_cuts", T_INT, offsetof(pysmcp,obj)+offsetof(glp_iocp,mir_cuts), 0, "MIR cuts (GLP_ON/GLP_OFF) "}, |
274 |
+ {"gmi_cuts", T_INT, offsetof(pysmcp,obj)+offsetof(glp_iocp,gmi_cuts), 0, "Gomory's cuts (GLP_ON/GLP_OFF) "}, |
275 |
+ {"cov_cuts", T_INT, offsetof(pysmcp,obj)+offsetof(glp_iocp,cov_cuts), 0, "cover cuts (GLP_ON/GLP_OFF) "}, |
276 |
+ {"clq_cuts", T_INT, offsetof(pysmcp,obj)+offsetof(glp_iocp,clq_cuts), 0, "clique cuts (GLP_ON/GLP_OFF) "}, |
277 |
+ {"presolve", T_INT, offsetof(pysmcp,obj)+offsetof(glp_iocp,presolve), 0, "enable/disable using MIP presolver "}, |
278 |
+ {"binarize", T_INT, offsetof(pysmcp,obj)+offsetof(glp_iocp,binarize), 0, "try to binarize integer variables "}, |
279 |
+ {"fp_heur", T_INT, offsetof(pysmcp,obj)+offsetof(glp_iocp,fp_heur), 0, "feasibility pump heuristic "}, |
280 |
+ {"ps_heur", T_INT, offsetof(pysmcp,obj)+offsetof(glp_iocp,ps_heur), 0, "proximity search heuristic "}, |
281 |
+ {"ps_tm_lim", T_INT, offsetof(pysmcp,obj)+offsetof(glp_iocp,ps_tm_lim), 0, "proxy time limit, milliseconds "}, |
282 |
+ {"use_sol", T_INT, offsetof(pysmcp,obj)+offsetof(glp_iocp,use_sol), 0, "use existing solution "}, |
283 |
+ {"save_sol",T_STRING,offsetof(pysmcp,obj)+offsetof(glp_iocp,save_sol),0, "filename to save every new solution"}, |
284 |
+ {"alien", T_INT, offsetof(pysmcp,obj)+offsetof(glp_iocp,alien), 0, "use alien solver "}, |
285 |
+}; |
286 |
+ |
287 |
+static PyTypeObject iocp_t = { |
288 |
+ PyVarObject_HEAD_INIT(NULL, 0) |
289 |
+ "glpk.iocp", /* tp_name */ |
290 |
+ sizeof(pyiocp), /* tp_basicsize */ |
291 |
+ 0, /* tp_itemsize */ |
292 |
+ (destructor)iocp_dealloc, /* tp_dealloc */ |
293 |
+ 0, /* tp_print */ |
294 |
+ 0, /* tp_getattr */ |
295 |
+ 0, /* tp_setattr */ |
296 |
+ 0, /* tp_reserved */ |
297 |
+ 0, /* tp_repr */ |
298 |
+ 0, /* tp_as_number */ |
299 |
+ 0, /* tp_as_sequence */ |
300 |
+ 0, /* tp_as_mapping */ |
301 |
+ 0, /* tp_hash */ |
302 |
+ 0, /* tp_call */ |
303 |
+ 0, /* tp_str */ |
304 |
+ 0, /* tp_getattro */ |
305 |
+ 0, /* tp_setattro */ |
306 |
+ 0, /* tp_as_buffer */ |
307 |
+ Py_TPFLAGS_DEFAULT | |
308 |
+ Py_TPFLAGS_BASETYPE, /* tp_flags */ |
309 |
+ "integer optimizer control parameters", /* tp_doc */ |
310 |
+ 0, /* tp_traverse */ |
311 |
+ 0, /* tp_clear */ |
312 |
+ 0, /* tp_richcompare */ |
313 |
+ 0, /* tp_weaklistoffset */ |
314 |
+ 0, /* tp_iter */ |
315 |
+ 0, /* tp_iternext */ |
316 |
+ 0, /* tp_methods */ |
317 |
+ iocpMembers, /* tp_members */ |
318 |
+ 0, /* tp_getset */ |
319 |
+ 0, /* tp_base */ |
320 |
+ 0, /* tp_dict */ |
321 |
+ 0, /* tp_descr_get */ |
322 |
+ 0, /* tp_descr_set */ |
323 |
+ 0, /* tp_dictoffset */ |
324 |
+ (initproc)iocp_init, /* tp_init */ |
325 |
+ 0, /* tp_alloc */ |
326 |
+ iocp_new, /* tp_new */ |
327 |
+}; |
328 |
+ |
329 |
+ |
330 |
+ |
331 |
+/* Small helper function to generate the output string of the simplex function */ |
332 |
+inline static void set_output_string(PyObject* t,const char s[]) { |
333 |
+ PyTuple_SET_ITEM(t, 0, (PyObject *) |
334 |
+#if PY_MAJOR_VERSION >= 3 |
335 |
+ PyUnicode_FromString(s)); |
336 |
+#else |
337 |
+ PyString_FromString(s)); |
338 |
+#endif |
339 |
+ } |
340 |
+ |
341 |
|
342 |
static char doc_simplex[] = |
343 |
"Solves a linear program using GLPK.\n\n" |
344 |
@@ -126,21 +322,16 @@ |
345 |
PyObject *kwrds) |
346 |
{ |
347 |
matrix *c, *h, *b=NULL, *x=NULL, *z=NULL, *y=NULL; |
348 |
- PyObject *G, *A=NULL, *t=NULL, *param, *key, *value; |
349 |
- LPX *lp; |
350 |
- int m, n, p, i, j, k, nnz, nnzmax, *rn=NULL, *cn=NULL, param_id; |
351 |
- int_t pos=0; |
352 |
+ PyObject *G, *A=NULL, *t=NULL; |
353 |
+ glp_prob *lp; |
354 |
+ glp_smcp *options = NULL; |
355 |
+ pysmcp *smcpParm = NULL; |
356 |
+ int m, n, p, i, j, k, nnz, nnzmax, *rn=NULL, *cn=NULL; |
357 |
double *a=NULL, val; |
358 |
- char param_type, err_str[100]; |
359 |
-#if PY_MAJOR_VERSION >= 3 |
360 |
- const char *keystr; |
361 |
-#else |
362 |
- char *keystr; |
363 |
-#endif |
364 |
- char *kwlist[] = {"c", "G", "h", "A", "b", NULL}; |
365 |
+ char *kwlist[] = {"c", "G", "h", "A", "b","options", NULL}; |
366 |
|
367 |
- if (!PyArg_ParseTupleAndKeywords(args, kwrds, "OOO|OO", kwlist, &c, |
368 |
- &G, &h, &A, &b)) return NULL; |
369 |
+ if (!PyArg_ParseTupleAndKeywords(args, kwrds, "OOO|OOO!", kwlist, &c, |
370 |
+ &G, &h, &A, &b,&smcp_t,&smcpParm)) return NULL; |
371 |
|
372 |
if ((Matrix_Check(G) && MAT_ID(G) != DOUBLE) || |
373 |
(SpMatrix_Check(G) && SP_ID(G) != DOUBLE) || |
374 |
@@ -182,19 +373,30 @@ |
375 |
PyErr_SetString(PyExc_ValueError, "incompatible dimensions"); |
376 |
return NULL; |
377 |
} |
378 |
+ if(!smcpParm) |
379 |
+ { |
380 |
+ smcpParm = (pysmcp*)malloc(sizeof(*smcpParm)); |
381 |
+ glp_init_smcp(&(smcpParm->obj)); |
382 |
+ } |
383 |
+ if(smcpParm) |
384 |
+ { |
385 |
+ Py_INCREF(smcpParm); |
386 |
+ options = &smcpParm->obj; |
387 |
+ options->presolve = 1; |
388 |
+ } |
389 |
|
390 |
- lp = lpx_create_prob(); |
391 |
- lpx_add_rows(lp, m+p); |
392 |
- lpx_add_cols(lp, n); |
393 |
+ lp = glp_create_prob(); |
394 |
+ glp_add_rows(lp, m+p); |
395 |
+ glp_add_cols(lp, n); |
396 |
|
397 |
for (i=0; i<n; i++){ |
398 |
- lpx_set_obj_coef(lp, i+1, MAT_BUFD(c)[i]); |
399 |
- lpx_set_col_bnds(lp, i+1, LPX_FR, 0.0, 0.0); |
400 |
+ glp_set_obj_coef(lp, i+1, MAT_BUFD(c)[i]); |
401 |
+ glp_set_col_bnds(lp, i+1, GLP_FR, 0.0, 0.0); |
402 |
} |
403 |
for (i=0; i<m; i++) |
404 |
- lpx_set_row_bnds(lp, i+1, LPX_UP, 0.0, MAT_BUFD(h)[i]); |
405 |
+ glp_set_row_bnds(lp, i+1, GLP_UP, 0.0, MAT_BUFD(h)[i]); |
406 |
for (i=0; i<p; i++) |
407 |
- lpx_set_row_bnds(lp, i+m+1, LPX_FX, MAT_BUFD(b)[i], |
408 |
+ glp_set_row_bnds(lp, i+m+1, GLP_FX, MAT_BUFD(b)[i], |
409 |
MAT_BUFD(b)[i]); |
410 |
|
411 |
nnzmax = (SpMatrix_Check(G) ? SP_NNZ(G) : m*n ) + |
412 |
@@ -203,7 +405,7 @@ |
413 |
rn = (int *) calloc(nnzmax+1, sizeof(int)); |
414 |
cn = (int *) calloc(nnzmax+1, sizeof(int)); |
415 |
if (!a || !rn || !cn){ |
416 |
- free(a); free(rn); free(cn); lpx_delete_prob(lp); |
417 |
+ free(a); free(rn); free(cn); glp_delete_prob(lp); |
418 |
return PyErr_NoMemory(); |
419 |
} |
420 |
|
421 |
@@ -242,84 +444,18 @@ |
422 |
nnz++; |
423 |
} |
424 |
|
425 |
- lpx_load_matrix(lp, nnz, rn, cn, a); |
426 |
+ glp_load_matrix(lp, nnz, rn, cn, a); |
427 |
free(rn); free(cn); free(a); |
428 |
|
429 |
if (!(t = PyTuple_New(A ? 4 : 3))){ |
430 |
- lpx_delete_prob(lp); |
431 |
+ glp_delete_prob(lp); |
432 |
return PyErr_NoMemory(); |
433 |
} |
434 |
|
435 |
- if (!(param = PyObject_GetAttrString(glpk_module, "options")) |
436 |
- || !PyDict_Check(param)){ |
437 |
- lpx_delete_prob(lp); |
438 |
- PyErr_SetString(PyExc_AttributeError, |
439 |
- "missing glpk.options dictionary"); |
440 |
- return NULL; |
441 |
- } |
442 |
- |
443 |
- while (PyDict_Next(param, &pos, &key, &value)) |
444 |
-#if PY_MAJOR_VERSION >= 3 |
445 |
- if ((PyUnicode_Check(key)) && |
446 |
- get_param_idx(_PyUnicode_AsString(key), ¶m_id, |
447 |
- ¶m_type)){ |
448 |
- keystr = _PyUnicode_AsString(key); |
449 |
-#else |
450 |
- if ((keystr = PyString_AsString(key)) && get_param_idx(keystr, |
451 |
- ¶m_id, ¶m_type)){ |
452 |
-#endif |
453 |
- if (param_type == 'i'){ |
454 |
-#if PY_MAJOR_VERSION >= 3 |
455 |
- if (!PyLong_Check(value)){ |
456 |
-#else |
457 |
- if (!PyInt_Check(value)){ |
458 |
-#endif |
459 |
- sprintf(err_str, "invalid value for integer " |
460 |
- "GLPK parameter: %-.20s", keystr); |
461 |
- PyErr_SetString(PyExc_ValueError, err_str); |
462 |
- lpx_delete_prob(lp); |
463 |
- Py_DECREF(param); |
464 |
- return NULL; |
465 |
- } |
466 |
- if (!strcmp("LPX_K_PRESOL", keystr) && |
467 |
-#if PY_MAJOR_VERSION >= 3 |
468 |
- PyLong_AS_LONG(value) != 1){ |
469 |
-#else |
470 |
- PyInt_AS_LONG(value) != 1){ |
471 |
-#endif |
472 |
- PyErr_Warn(PyExc_UserWarning, "ignoring value of " |
473 |
- "GLPK parameter 'LPX_K_PRESOL'"); |
474 |
- } |
475 |
- else lpx_set_int_parm(lp, param_id, |
476 |
-#if PY_MAJOR_VERSION >= 3 |
477 |
- PyLong_AS_LONG(value)); |
478 |
-#else |
479 |
- PyInt_AS_LONG(value)); |
480 |
-#endif |
481 |
- } |
482 |
- else { |
483 |
-#if PY_MAJOR_VERSION >= 3 |
484 |
- if (!PyLong_Check(value) && !PyFloat_Check(value)){ |
485 |
-#else |
486 |
- if (!PyInt_Check(value) && !PyFloat_Check(value)){ |
487 |
-#endif |
488 |
- sprintf(err_str, "invalid value for floating point " |
489 |
- "GLPK parameter: %-.20s", keystr); |
490 |
- PyErr_SetString(PyExc_ValueError, err_str); |
491 |
- lpx_delete_prob(lp); |
492 |
- Py_DECREF(param); |
493 |
- return NULL; |
494 |
- } |
495 |
- lpx_set_real_parm(lp, param_id, |
496 |
- PyFloat_AsDouble(value)); |
497 |
- } |
498 |
- } |
499 |
- lpx_set_int_parm(lp, LPX_K_PRESOL, 1); |
500 |
- Py_DECREF(param); |
501 |
|
502 |
- switch (lpx_simplex(lp)){ |
503 |
+ switch (glp_simplex(lp,options)){ |
504 |
|
505 |
- case LPX_E_OK: |
506 |
+ case 0: |
507 |
|
508 |
x = (matrix *) Matrix_New(n,1,DOUBLE); |
509 |
z = (matrix *) Matrix_New(m,1,DOUBLE); |
510 |
@@ -329,65 +465,70 @@ |
511 |
Py_XDECREF(z); |
512 |
Py_XDECREF(y); |
513 |
Py_XDECREF(t); |
514 |
- lpx_delete_prob(lp); |
515 |
+ Py_XDECREF(smcpParm); |
516 |
+ glp_delete_prob(lp); |
517 |
return PyErr_NoMemory(); |
518 |
} |
519 |
|
520 |
- PyTuple_SET_ITEM(t, 0, (PyObject *) |
521 |
-#if PY_MAJOR_VERSION >= 3 |
522 |
- PyUnicode_FromString("optimal")); |
523 |
-#else |
524 |
- PyString_FromString("optimal")); |
525 |
-#endif |
526 |
+ set_output_string(t,"optimal"); |
527 |
|
528 |
for (i=0; i<n; i++) |
529 |
- MAT_BUFD(x)[i] = lpx_get_col_prim(lp, i+1); |
530 |
+ MAT_BUFD(x)[i] = glp_get_col_prim(lp, i+1); |
531 |
PyTuple_SET_ITEM(t, 1, (PyObject *) x); |
532 |
|
533 |
for (i=0; i<m; i++) |
534 |
- MAT_BUFD(z)[i] = -lpx_get_row_dual(lp, i+1); |
535 |
+ MAT_BUFD(z)[i] = -glp_get_row_dual(lp, i+1); |
536 |
PyTuple_SET_ITEM(t, 2, (PyObject *) z); |
537 |
|
538 |
if (A){ |
539 |
for (i=0; i<p; i++) |
540 |
- MAT_BUFD(y)[i] = -lpx_get_row_dual(lp, m+i+1); |
541 |
+ MAT_BUFD(y)[i] = -glp_get_row_dual(lp, m+i+1); |
542 |
PyTuple_SET_ITEM(t, 3, (PyObject *) y); |
543 |
} |
544 |
|
545 |
- lpx_delete_prob(lp); |
546 |
+ Py_XDECREF(smcpParm); |
547 |
+ glp_delete_prob(lp); |
548 |
return (PyObject *) t; |
549 |
- |
550 |
- case LPX_E_NOPFS: |
551 |
- |
552 |
- PyTuple_SET_ITEM(t, 0, (PyObject *) |
553 |
-#if PY_MAJOR_VERSION >= 3 |
554 |
- PyUnicode_FromString("primal infeasible")); |
555 |
-#else |
556 |
- PyString_FromString("primal infeasible")); |
557 |
-#endif |
558 |
+ case GLP_EBADB: |
559 |
+ set_output_string(t,"incorrect initial basis"); |
560 |
break; |
561 |
- |
562 |
- case LPX_E_NODFS: |
563 |
- |
564 |
- PyTuple_SET_ITEM(t, 0, (PyObject *) |
565 |
-#if PY_MAJOR_VERSION >= 3 |
566 |
- PyUnicode_FromString("dual infeasible")); |
567 |
-#else |
568 |
- PyString_FromString("dual infeasible")); |
569 |
-#endif |
570 |
+ case GLP_ESING: |
571 |
+ set_output_string(t,"singular initial basis matrix"); |
572 |
+ break; |
573 |
+ case GLP_ECOND: |
574 |
+ set_output_string(t,"ill-conditioned initial basis matrix"); |
575 |
+ break; |
576 |
+ case GLP_EBOUND: |
577 |
+ set_output_string(t,"incorrect bounds"); |
578 |
+ break; |
579 |
+ case GLP_EFAIL: |
580 |
+ set_output_string(t,"solver failure"); |
581 |
+ break; |
582 |
+ case GLP_EOBJLL: |
583 |
+ set_output_string(t,"objective function reached lower limit"); |
584 |
+ break; |
585 |
+ case GLP_EOBJUL: |
586 |
+ set_output_string(t,"objective function reached upper limit"); |
587 |
+ break; |
588 |
+ case GLP_EITLIM: |
589 |
+ set_output_string(t,"iteration limit exceeded"); |
590 |
+ break; |
591 |
+ case GLP_ETMLIM: |
592 |
+ set_output_string(t,"time limit exceeded"); |
593 |
+ break; |
594 |
+ case GLP_ENOPFS: |
595 |
+ set_output_string(t,"primal infeasible"); |
596 |
+ break; |
597 |
+ case GLP_ENODFS: |
598 |
+ set_output_string(t,"dual infeasible"); |
599 |
break; |
600 |
- |
601 |
default: |
602 |
- |
603 |
- PyTuple_SET_ITEM(t, 0, (PyObject *) |
604 |
-#if PY_MAJOR_VERSION >= 3 |
605 |
- PyUnicode_FromString("unknown")); |
606 |
-#else |
607 |
- PyString_FromString("unknown")); |
608 |
-#endif |
609 |
+ set_output_string(t,"unknown"); |
610 |
+ break; |
611 |
} |
612 |
|
613 |
- lpx_delete_prob(lp); |
614 |
+ Py_XDECREF(smcpParm); |
615 |
+ glp_delete_prob(lp); |
616 |
|
617 |
PyTuple_SET_ITEM(t, 1, Py_BuildValue("")); |
618 |
PyTuple_SET_ITEM(t, 2, Py_BuildValue("")); |
619 |
@@ -427,21 +568,28 @@ |
620 |
{ |
621 |
matrix *c, *h, *b=NULL, *x=NULL; |
622 |
PyObject *G, *A=NULL, *IntSet=NULL, *BinSet = NULL; |
623 |
- PyObject *t=NULL, *param, *key, *value; |
624 |
- LPX *lp; |
625 |
- int m, n, p, i, j, k, nnz, nnzmax, *rn=NULL, *cn=NULL, param_id; |
626 |
- int_t pos=0; |
627 |
+ PyObject *t=NULL; |
628 |
+ pyiocp *iocpParm = NULL;; |
629 |
+ glp_iocp *options = NULL; |
630 |
+ glp_prob *lp; |
631 |
+ int m, n, p, i, j, k, nnz, nnzmax, *rn=NULL, *cn=NULL; |
632 |
double *a=NULL, val; |
633 |
- char param_type, err_str[100]; |
634 |
-#if PY_MAJOR_VERSION >= 3 |
635 |
- const char *keystr; |
636 |
-#else |
637 |
- char *keystr; |
638 |
-#endif |
639 |
- char *kwlist[] = {"c", "G", "h", "A", "b", "I", "B", NULL}; |
640 |
+ char *kwlist[] = {"c", "G", "h", "A", "b", "I", "B","iocp", NULL}; |
641 |
+ |
642 |
+ if (!PyArg_ParseTupleAndKeywords(args, kwrds, "OOO|OOOOO!", kwlist, &c, |
643 |
+ &G, &h, &A, &b, &IntSet, &BinSet,iocp_t,&iocpParm)) return NULL; |
644 |
|
645 |
- if (!PyArg_ParseTupleAndKeywords(args, kwrds, "OOO|OOOO", kwlist, &c, |
646 |
- &G, &h, &A, &b, &IntSet, &BinSet)) return NULL; |
647 |
+ if(!iocpParm) |
648 |
+ { |
649 |
+ iocpParm = (pyiocp*)malloc(sizeof(*iocpParm)); |
650 |
+ glp_init_iocp(&(iocpParm->obj)); |
651 |
+ } |
652 |
+ if(iocpParm) |
653 |
+ { |
654 |
+ Py_INCREF(iocpParm); |
655 |
+ options = &iocpParm->obj; |
656 |
+ options->presolve = 1; |
657 |
+ } |
658 |
|
659 |
if ((Matrix_Check(G) && MAT_ID(G) != DOUBLE) || |
660 |
(SpMatrix_Check(G) && SP_ID(G) != DOUBLE) || |
661 |
@@ -490,18 +638,18 @@ |
662 |
if ((BinSet) && (!PyAnySet_Check(BinSet))) |
663 |
PY_ERR_TYPE("invalid binary index set"); |
664 |
|
665 |
- lp = lpx_create_prob(); |
666 |
- lpx_add_rows(lp, m+p); |
667 |
- lpx_add_cols(lp, n); |
668 |
+ lp = glp_create_prob(); |
669 |
+ glp_add_rows(lp, m+p); |
670 |
+ glp_add_cols(lp, n); |
671 |
|
672 |
for (i=0; i<n; i++){ |
673 |
- lpx_set_obj_coef(lp, i+1, MAT_BUFD(c)[i]); |
674 |
- lpx_set_col_bnds(lp, i+1, LPX_FR, 0.0, 0.0); |
675 |
+ glp_set_obj_coef(lp, i+1, MAT_BUFD(c)[i]); |
676 |
+ glp_set_col_bnds(lp, i+1, GLP_FR, 0.0, 0.0); |
677 |
} |
678 |
for (i=0; i<m; i++) |
679 |
- lpx_set_row_bnds(lp, i+1, LPX_UP, 0.0, MAT_BUFD(h)[i]); |
680 |
+ glp_set_row_bnds(lp, i+1, GLP_UP, 0.0, MAT_BUFD(h)[i]); |
681 |
for (i=0; i<p; i++) |
682 |
- lpx_set_row_bnds(lp, i+m+1, LPX_FX, MAT_BUFD(b)[i], |
683 |
+ glp_set_row_bnds(lp, i+m+1, GLP_FX, MAT_BUFD(b)[i], |
684 |
MAT_BUFD(b)[i]); |
685 |
|
686 |
nnzmax = (SpMatrix_Check(G) ? SP_NNZ(G) : m*n ) + |
687 |
@@ -510,7 +658,7 @@ |
688 |
rn = (int *) calloc(nnzmax+1, sizeof(int)); |
689 |
cn = (int *) calloc(nnzmax+1, sizeof(int)); |
690 |
if (!a || !rn || !cn){ |
691 |
- free(a); free(rn); free(cn); lpx_delete_prob(lp); |
692 |
+ free(a); free(rn); free(cn); glp_delete_prob(lp); |
693 |
return PyErr_NoMemory(); |
694 |
} |
695 |
|
696 |
@@ -549,79 +697,14 @@ |
697 |
nnz++; |
698 |
} |
699 |
|
700 |
- lpx_load_matrix(lp, nnz, rn, cn, a); |
701 |
+ glp_load_matrix(lp, nnz, rn, cn, a); |
702 |
free(rn); free(cn); free(a); |
703 |
|
704 |
if (!(t = PyTuple_New(2))) { |
705 |
- lpx_delete_prob(lp); |
706 |
+ glp_delete_prob(lp); |
707 |
return PyErr_NoMemory(); |
708 |
} |
709 |
|
710 |
- if (!(param = PyObject_GetAttrString(glpk_module, "options")) |
711 |
- || !PyDict_Check(param)){ |
712 |
- lpx_delete_prob(lp); |
713 |
- PyErr_SetString(PyExc_AttributeError, |
714 |
- "missing glpk.options dictionary"); |
715 |
- return NULL; |
716 |
- } |
717 |
- |
718 |
- while (PyDict_Next(param, &pos, &key, &value)) |
719 |
-#if PY_MAJOR_VERSION >= 3 |
720 |
- if ((PyUnicode_Check(key)) && (keystr = PyUnicode_AS_DATA(key)) |
721 |
- && get_param_idx(keystr, ¶m_id, ¶m_type)){ |
722 |
-#else |
723 |
- if ((keystr = PyString_AsString(key)) && get_param_idx(keystr, |
724 |
- ¶m_id, ¶m_type)){ |
725 |
-#endif |
726 |
- if (param_type == 'i'){ |
727 |
-#if PY_MAJOR_VERSION >= 3 |
728 |
- if (!PyLong_Check(value)){ |
729 |
-#else |
730 |
- if (!PyInt_Check(value)){ |
731 |
-#endif |
732 |
- sprintf(err_str, "invalid value for integer " |
733 |
- "GLPK parameter: %-.20s", keystr); |
734 |
- PyErr_SetString(PyExc_ValueError, err_str); |
735 |
- lpx_delete_prob(lp); |
736 |
- Py_DECREF(param); |
737 |
- return NULL; |
738 |
- } |
739 |
- if (!strcmp("LPX_K_PRESOL", keystr) && |
740 |
-#if PY_MAJOR_VERSION >= 3 |
741 |
- PyLong_AS_LONG(value) != 1){ |
742 |
-#else |
743 |
- PyInt_AS_LONG(value) != 1){ |
744 |
-#endif |
745 |
- PyErr_Warn(PyExc_UserWarning, "ignoring value of " |
746 |
- "GLPK parameter 'LPX_K_PRESOL'"); |
747 |
- } |
748 |
- else |
749 |
-#if PY_MAJOR_VERSION >= 3 |
750 |
- lpx_set_int_parm(lp, param_id, PyLong_AS_LONG(value)); |
751 |
-#else |
752 |
- lpx_set_int_parm(lp, param_id, PyInt_AS_LONG(value)); |
753 |
-#endif |
754 |
- } |
755 |
- else { |
756 |
-#if PY_MAJOR_VERSION >= 3 |
757 |
- if (!PyLong_Check(value) && !PyFloat_Check(value)){ |
758 |
-#else |
759 |
- if (!PyInt_Check(value) && !PyFloat_Check(value)){ |
760 |
-#endif |
761 |
- sprintf(err_str, "invalid value for floating point " |
762 |
- "GLPK parameter: %-.20s", keystr); |
763 |
- PyErr_SetString(PyExc_ValueError, err_str); |
764 |
- lpx_delete_prob(lp); |
765 |
- Py_DECREF(param); |
766 |
- return NULL; |
767 |
- } |
768 |
- lpx_set_real_parm(lp, param_id, |
769 |
- PyFloat_AsDouble(value)); |
770 |
- } |
771 |
- } |
772 |
- lpx_set_int_parm(lp, LPX_K_PRESOL, 1); |
773 |
- Py_DECREF(param); |
774 |
- |
775 |
if (IntSet) { |
776 |
PyObject *iter = PySequence_Fast(IntSet, "Critical error: not sequence"); |
777 |
|
778 |
@@ -633,7 +716,7 @@ |
779 |
#else |
780 |
if (!PyInt_Check(tmp)) { |
781 |
#endif |
782 |
- lpx_delete_prob(lp); |
783 |
+ glp_delete_prob(lp); |
784 |
Py_DECREF(iter); |
785 |
PY_ERR_TYPE("non-integer element in I"); |
786 |
} |
787 |
@@ -643,7 +726,7 @@ |
788 |
int k = PyInt_AS_LONG(tmp); |
789 |
#endif |
790 |
if ((k < 0) || (k >= n)) { |
791 |
- lpx_delete_prob(lp); |
792 |
+ glp_delete_prob(lp); |
793 |
Py_DECREF(iter); |
794 |
PY_ERR(PyExc_IndexError, "index element out of range in I"); |
795 |
} |
796 |
@@ -664,7 +747,7 @@ |
797 |
#else |
798 |
if (!PyInt_Check(tmp)) { |
799 |
#endif |
800 |
- lpx_delete_prob(lp); |
801 |
+ glp_delete_prob(lp); |
802 |
Py_DECREF(iter); |
803 |
PY_ERR_TYPE("non-binary element in I"); |
804 |
} |
805 |
@@ -674,7 +757,7 @@ |
806 |
int k = PyInt_AS_LONG(tmp); |
807 |
#endif |
808 |
if ((k < 0) || (k >= n)) { |
809 |
- lpx_delete_prob(lp); |
810 |
+ glp_delete_prob(lp); |
811 |
Py_DECREF(iter); |
812 |
PY_ERR(PyExc_IndexError, "index element out of range in B"); |
813 |
} |
814 |
@@ -686,114 +769,85 @@ |
815 |
} |
816 |
|
817 |
|
818 |
+ switch (glp_intopt(lp,options)){ |
819 |
|
820 |
- switch (lpx_intopt(lp)){ |
821 |
+ case 0: |
822 |
|
823 |
- case LPX_E_OK: |
824 |
+ x = (matrix *) Matrix_New(n,1,DOUBLE); |
825 |
+ if (!x) { |
826 |
+ Py_XDECREF(iocpParm); |
827 |
+ Py_XDECREF(t); |
828 |
+ glp_delete_prob(lp); |
829 |
+ return PyErr_NoMemory(); |
830 |
+ } |
831 |
+ set_output_string(t,"optimal"); |
832 |
+ set_output_string(t,"optimal"); |
833 |
|
834 |
- x = (matrix *) Matrix_New(n,1,DOUBLE); |
835 |
- if (!x) { |
836 |
- Py_XDECREF(t); |
837 |
- lpx_delete_prob(lp); |
838 |
- return PyErr_NoMemory(); |
839 |
- } |
840 |
- PyTuple_SET_ITEM(t, 0, (PyObject *) |
841 |
-#if PY_MAJOR_VERSION >= 3 |
842 |
- PyUnicode_FromString("optimal")); |
843 |
-#else |
844 |
- PyString_FromString("optimal")); |
845 |
-#endif |
846 |
+ for (i=0; i<n; i++) |
847 |
+ MAT_BUFD(x)[i] = glp_mip_col_val(lp, i+1); |
848 |
+ PyTuple_SET_ITEM(t, 1, (PyObject *) x); |
849 |
|
850 |
- for (i=0; i<n; i++) |
851 |
- MAT_BUFD(x)[i] = lpx_mip_col_val(lp, i+1); |
852 |
- PyTuple_SET_ITEM(t, 1, (PyObject *) x); |
853 |
+ Py_XDECREF(iocpParm); |
854 |
+ glp_delete_prob(lp); |
855 |
+ return (PyObject *) t; |
856 |
|
857 |
- lpx_delete_prob(lp); |
858 |
- return (PyObject *) t; |
859 |
+ case GLP_ETMLIM: |
860 |
|
861 |
- case LPX_E_TMLIM: |
862 |
+ x = (matrix *) Matrix_New(n,1,DOUBLE); |
863 |
+ if (!x) { |
864 |
+ Py_XDECREF(t); |
865 |
+ Py_XDECREF(iocpParm); |
866 |
+ glp_delete_prob(lp); |
867 |
+ return PyErr_NoMemory(); |
868 |
+ } |
869 |
+ set_output_string(t,"time limit exceeded"); |
870 |
|
871 |
- x = (matrix *) Matrix_New(n,1,DOUBLE); |
872 |
- if (!x) { |
873 |
- Py_XDECREF(t); |
874 |
- lpx_delete_prob(lp); |
875 |
- return PyErr_NoMemory(); |
876 |
- } |
877 |
- PyTuple_SET_ITEM(t, 0, (PyObject *) |
878 |
-#if PY_MAJOR_VERSION >= 3 |
879 |
- PyUnicode_FromString("time limit exceeded")); |
880 |
-#else |
881 |
- PyString_FromString("time limit exceeded")); |
882 |
-#endif |
883 |
+ for (i=0; i<n; i++) |
884 |
+ MAT_BUFD(x)[i] = glp_mip_col_val(lp, i+1); |
885 |
+ PyTuple_SET_ITEM(t, 1, (PyObject *) x); |
886 |
|
887 |
- for (i=0; i<n; i++) |
888 |
- MAT_BUFD(x)[i] = lpx_mip_col_val(lp, i+1); |
889 |
- PyTuple_SET_ITEM(t, 1, (PyObject *) x); |
890 |
- |
891 |
- lpx_delete_prob(lp); |
892 |
- return (PyObject *) t; |
893 |
+ Py_XDECREF(iocpParm); |
894 |
+ glp_delete_prob(lp); |
895 |
+ return (PyObject *) t; |
896 |
|
897 |
|
898 |
- case LPX_E_FAULT: |
899 |
- PyTuple_SET_ITEM(t, 0, (PyObject *) |
900 |
-#if PY_MAJOR_VERSION >= 3 |
901 |
- PyUnicode_FromString("invalid MIP formulation")); |
902 |
-#else |
903 |
- PyString_FromString("invalid MIP formulation")); |
904 |
-#endif |
905 |
- break; |
906 |
+ case GLP_EBOUND: |
907 |
+ set_output_string(t,"incorrect bounds"); |
908 |
+ break; |
909 |
+ case GLP_EFAIL: |
910 |
+ set_output_string(t,"invalid MIP formulation"); |
911 |
+ break; |
912 |
|
913 |
- case LPX_E_NOPFS: |
914 |
- PyTuple_SET_ITEM(t, 0, (PyObject *) |
915 |
-#if PY_MAJOR_VERSION >= 3 |
916 |
- PyUnicode_FromString("primal infeasible")); |
917 |
-#else |
918 |
- PyString_FromString("primal infeasible")); |
919 |
-#endif |
920 |
- break; |
921 |
+ case GLP_ENOPFS: |
922 |
+ set_output_string(t,"primal infeasible"); |
923 |
+ break; |
924 |
|
925 |
- case LPX_E_NODFS: |
926 |
+ case GLP_ENODFS: |
927 |
+ set_output_string(t,"dual infeasible"); |
928 |
+ break; |
929 |
|
930 |
- PyTuple_SET_ITEM(t, 0, (PyObject *) |
931 |
-#if PY_MAJOR_VERSION >= 3 |
932 |
- PyUnicode_FromString("dual infeasible")); |
933 |
-#else |
934 |
- PyString_FromString("dual infeasible")); |
935 |
-#endif |
936 |
- break; |
937 |
+ case GLP_EMIPGAP: |
938 |
+ set_output_string(t,"Relative mip gap tolerance reached"); |
939 |
+ break; |
940 |
|
941 |
- case LPX_E_ITLIM: |
942 |
+ /*case LPX_E_ITLIM: |
943 |
|
944 |
- PyTuple_SET_ITEM(t, 0, (PyObject *) |
945 |
-#if PY_MAJOR_VERSION >= 3 |
946 |
- PyUnicode_FromString("maxiters exceeded")); |
947 |
-#else |
948 |
- PyString_FromString("maxiters exceeded")); |
949 |
-#endif |
950 |
- break; |
951 |
+ set_output_string(t,"maxiters exceeded"); |
952 |
+ break;*/ |
953 |
|
954 |
- case LPX_E_SING: |
955 |
+ /*case LPX_E_SING: |
956 |
|
957 |
- PyTuple_SET_ITEM(t, 0, (PyObject *) |
958 |
-#if PY_MAJOR_VERSION >= 3 |
959 |
- PyUnicode_FromString("singular or ill-conditioned basis")); |
960 |
-#else |
961 |
- PyString_FromString("singular or ill-conditioned basis")); |
962 |
-#endif |
963 |
- break; |
964 |
+ set_output_string(t,"singular or ill-conditioned basis"); |
965 |
+ break;*/ |
966 |
|
967 |
|
968 |
- default: |
969 |
+ default: |
970 |
|
971 |
- PyTuple_SET_ITEM(t, 0, (PyObject *) |
972 |
-#if PY_MAJOR_VERSION >= 3 |
973 |
- PyUnicode_FromString("unknown")); |
974 |
-#else |
975 |
- PyString_FromString("unknown")); |
976 |
-#endif |
977 |
- } |
978 |
+ set_output_string(t,"unknown"); |
979 |
+ } |
980 |
|
981 |
- lpx_delete_prob(lp); |
982 |
+ Py_XDECREF(iocpParm); |
983 |
+ glp_delete_prob(lp); |
984 |
|
985 |
PyTuple_SET_ITEM(t, 1, Py_BuildValue("")); |
986 |
return (PyObject *) t; |
987 |
@@ -819,10 +873,94 @@ |
988 |
NULL, NULL, NULL, NULL |
989 |
}; |
990 |
|
991 |
+void addglpkConstants (void) |
992 |
+{ |
993 |
+ PyModule_AddIntMacro(glpk_module, GLP_ON); |
994 |
+ PyModule_AddIntMacro(glpk_module,GLP_OFF); |
995 |
+ |
996 |
+ /* reason codes: */ |
997 |
+ PyModule_AddIntMacro(glpk_module,GLP_IROWGEN); |
998 |
+ PyModule_AddIntMacro(glpk_module,GLP_IBINGO); |
999 |
+ PyModule_AddIntMacro(glpk_module,GLP_IHEUR); |
1000 |
+ PyModule_AddIntMacro(glpk_module,GLP_ICUTGEN); |
1001 |
+ PyModule_AddIntMacro(glpk_module,GLP_IBRANCH); |
1002 |
+ PyModule_AddIntMacro(glpk_module,GLP_ISELECT); |
1003 |
+ PyModule_AddIntMacro(glpk_module,GLP_IPREPRO); |
1004 |
+ |
1005 |
+ /* branch selection indicator: */ |
1006 |
+ PyModule_AddIntMacro(glpk_module,GLP_NO_BRNCH); |
1007 |
+ PyModule_AddIntMacro(glpk_module,GLP_DN_BRNCH); |
1008 |
+ PyModule_AddIntMacro(glpk_module,GLP_UP_BRNCH); |
1009 |
+ |
1010 |
+ /* return codes: */ |
1011 |
+ PyModule_AddIntMacro(glpk_module,GLP_EBADB); |
1012 |
+ PyModule_AddIntMacro(glpk_module,GLP_ESING); |
1013 |
+ PyModule_AddIntMacro(glpk_module,GLP_ECOND); |
1014 |
+ PyModule_AddIntMacro(glpk_module,GLP_EBOUND); |
1015 |
+ PyModule_AddIntMacro(glpk_module,GLP_EFAIL); |
1016 |
+ PyModule_AddIntMacro(glpk_module,GLP_EOBJLL); |
1017 |
+ PyModule_AddIntMacro(glpk_module,GLP_EOBJUL); |
1018 |
+ PyModule_AddIntMacro(glpk_module,GLP_EITLIM); |
1019 |
+ PyModule_AddIntMacro(glpk_module,GLP_ETMLIM); |
1020 |
+ PyModule_AddIntMacro(glpk_module,GLP_ENOPFS); |
1021 |
+ PyModule_AddIntMacro(glpk_module,GLP_ENODFS); |
1022 |
+ PyModule_AddIntMacro(glpk_module,GLP_EROOT); |
1023 |
+ PyModule_AddIntMacro(glpk_module,GLP_ESTOP); |
1024 |
+ PyModule_AddIntMacro(glpk_module,GLP_EMIPGAP); |
1025 |
+ PyModule_AddIntMacro(glpk_module,GLP_ENOFEAS); |
1026 |
+ PyModule_AddIntMacro(glpk_module,GLP_ENOCVG); |
1027 |
+ PyModule_AddIntMacro(glpk_module,GLP_EINSTAB); |
1028 |
+ PyModule_AddIntMacro(glpk_module,GLP_EDATA); |
1029 |
+ PyModule_AddIntMacro(glpk_module,GLP_ERANGE); |
1030 |
+ |
1031 |
+ /* condition indicator: */ |
1032 |
+ PyModule_AddIntMacro(glpk_module,GLP_KKT_PE); |
1033 |
+ PyModule_AddIntMacro(glpk_module,GLP_KKT_PB); |
1034 |
+ PyModule_AddIntMacro(glpk_module,GLP_KKT_DE); |
1035 |
+ PyModule_AddIntMacro(glpk_module,GLP_KKT_DB); |
1036 |
+ PyModule_AddIntMacro(glpk_module,GLP_KKT_CS); |
1037 |
+ |
1038 |
+ /* MPS file format: */ |
1039 |
+ PyModule_AddIntMacro(glpk_module,GLP_MPS_DECK); |
1040 |
+ PyModule_AddIntMacro(glpk_module,GLP_MPS_FILE); |
1041 |
+ |
1042 |
+ /* simplex method control parameters */ |
1043 |
+ /* message level: */ |
1044 |
+ PyModule_AddIntMacro(glpk_module,GLP_MSG_OFF); |
1045 |
+ PyModule_AddIntMacro(glpk_module,GLP_MSG_ERR); |
1046 |
+ PyModule_AddIntMacro(glpk_module,GLP_MSG_ON); |
1047 |
+ PyModule_AddIntMacro(glpk_module,GLP_MSG_ALL); |
1048 |
+ PyModule_AddIntMacro(glpk_module,GLP_MSG_DBG); |
1049 |
+ /* simplex method option: */ |
1050 |
+ PyModule_AddIntMacro(glpk_module,GLP_PRIMAL); |
1051 |
+ PyModule_AddIntMacro(glpk_module,GLP_DUALP); |
1052 |
+ PyModule_AddIntMacro(glpk_module,GLP_DUAL); |
1053 |
+ /* pricing technique: */ |
1054 |
+ PyModule_AddIntMacro(glpk_module,GLP_PT_STD); |
1055 |
+ PyModule_AddIntMacro(glpk_module,GLP_PT_PSE); |
1056 |
+ /* ratio test technique: */ |
1057 |
+ PyModule_AddIntMacro(glpk_module,GLP_RT_STD); |
1058 |
+ PyModule_AddIntMacro(glpk_module,GLP_RT_HAR); |
1059 |
+ |
1060 |
+ /* interior-point solver control parameters */ |
1061 |
+ /* ordering algorithm: */ |
1062 |
+ PyModule_AddIntMacro(glpk_module,GLP_ORD_NONE); |
1063 |
+ PyModule_AddIntMacro(glpk_module,GLP_ORD_QMD); |
1064 |
+ PyModule_AddIntMacro(glpk_module,GLP_ORD_AMD); |
1065 |
+ PyModule_AddIntMacro(glpk_module,GLP_ORD_SYMAMD); |
1066 |
+} |
1067 |
+ |
1068 |
PyMODINIT_FUNC PyInit_glpk(void) |
1069 |
{ |
1070 |
if (!(glpk_module = PyModule_Create(&glpk_module_def))) return NULL; |
1071 |
- PyModule_AddObject(glpk_module, "options", PyDict_New()); |
1072 |
+ if (PyType_Ready(&iocp_t) < 0 || (PyType_Ready(&smcp_t) < 0)) return NULL; |
1073 |
+ /* Adding macros */ |
1074 |
+ addglpkConstants(); |
1075 |
+ /* Adding option lists as objects */ |
1076 |
+ Py_INCREF(&smcp_t); |
1077 |
+ PyModule_AddObject(glpk_module,"smcp",(PyObject*)&smcp_t); |
1078 |
+ Py_INCREF(&iocp_t); |
1079 |
+ PyModule_AddObject(glpk_module,"iocp",(PyObject*)&iocp_t); |
1080 |
if (import_cvxopt() < 0) return NULL; |
1081 |
return glpk_module; |
1082 |
} |
1083 |
@@ -832,8 +970,13 @@ |
1084 |
PyMODINIT_FUNC initglpk(void) |
1085 |
{ |
1086 |
glpk_module = Py_InitModule3("cvxopt.glpk", glpk_functions, |
1087 |
- glpk__doc__); |
1088 |
- PyModule_AddObject(glpk_module, "options", PyDict_New()); |
1089 |
+ glpk__doc__); |
1090 |
+ if (PyType_Ready(&iocp_t) < 0 || (PyType_Ready(&smcp_t) < 0)) return NULL; |
1091 |
+ addglpkConstants(); |
1092 |
+ Py_INCREF(&smcp_t); |
1093 |
+ PyModule_AddObject(glpk_module,"smcp",(PyObject*)&smcp_t); |
1094 |
+ Py_INCREF(&iocp_t); |
1095 |
+ PyModule_AddObject(glpk_module,"iocp",(PyObject*)&iocp_t); |
1096 |
if (import_cvxopt() < 0) return; |
1097 |
} |