static PyObject* LPX_solver_intopt(LPXObject *self) { int retval = lpx_intopt(LP); if (retval != LPX_E_FAULT) self->last_solver = 2; return solver_retval_to_message(retval); }
static PyObject* LPX_solver_interior(LPXObject *self) { int retval = lpx_interior(LP); int status = glp_ipt_status(LP); if (retval != LPX_E_FAULT) self->last_solver = 1; if (retval == LPX_E_OK && status != GLP_OPT) return glpstatus2string(status); else return solver_retval_to_message(retval); }
static PyObject* LPX_solver_integer(LPXObject *self, PyObject *args, PyObject *keywds) { #if GLPK_VERSION(4, 20) PyObject *callback=NULL; struct mip_callback_object*info=NULL; glp_iocp cp; glp_init_iocp(&cp); cp.msg_lev = GLP_MSG_OFF; // Map the keyword arguments to the appropriate entries. static char *kwlist[] = {"msg_lev", "br_tech", "bt_tech", #if GLPK_VERSION(4, 21) "pp_tech", #endif // GLPK_VERSION(4, 21) #if GLPK_VERSION(4, 24) "gmi_cuts", #endif // GLPK_VERSION(4, 24) #if GLPK_VERSION(4, 23) "mir_cuts", "mip_gap", #endif // GLPK_VERSION(4, 23) #if GLPK_VERSION(4, 32) "cov_cuts", "clq_cuts", "presolve", "binarize", #endif // GLPK_VERSION(4, 32) #if GLPK_VERSION(4, 37) "fp_heur", #endif // GLPK_VERSION(4, 37) "tol_int", "tol_obj", "tm_lim", "out_frq", "out_dly", "callback", //"cb_info", "cb_size", NULL}; if (!PyArg_ParseTupleAndKeywords (args, keywds, "|iii" #if GLPK_VERSION(4, 21) "i" #endif // GLPK_VERSION(4, 21) #if GLPK_VERSION(4, 24) "i" #endif // GLPK_VERSION(4, 24) #if GLPK_VERSION(4, 23) "ii" #endif // GLPK_VERSION(4, 23) #if GLPK_VERSION(4, 32) "iiii" #endif // GLPK_VERSION(4, 32) #if GLPK_VERSION(4, 37) "i" #endif // GLPK_VERSION(4, 37) "ddiiiO", kwlist, &cp.msg_lev, &cp.br_tech, &cp.bt_tech, #if GLPK_VERSION(4, 21) &cp.pp_tech, #endif // GLPK_VERSION(4, 21) #if GLPK_VERSION(4, 24) &cp.gmi_cuts, #endif // GLPK_VERSION(4, 24) #if GLPK_VERSION(4, 23) &cp.mir_cuts, &cp.mip_gap, #endif // GLPK_VERSION(4, 23) #if GLPK_VERSION(4, 32) &cp.cov_cuts, &cp.clq_cuts, &cp.presolve, &cp.binarize, #endif // GLPK_VERSION(4, 32) #if GLPK_VERSION(4, 37) &cp.fp_heur, #endif // GLPK_VERSION(4, 37) &cp.tol_int, &cp.tol_obj, &cp.tm_lim, &cp.out_frq, &cp.out_dly, &callback)) { return NULL; } #if GLPK_VERSION(4, 24) cp.gmi_cuts = cp.gmi_cuts ? GLP_ON : GLP_OFF; #endif // GLPK_VERSION(4, 24) #if GLPK_VERSION(4, 23) cp.mir_cuts = cp.mir_cuts ? GLP_ON : GLP_OFF; #endif // GLPK_VERSION(4, 23) #if GLPK_VERSION(4, 32) cp.cov_cuts = cp.cov_cuts ? GLP_ON : GLP_OFF; cp.clq_cuts = cp.clq_cuts ? GLP_ON : GLP_OFF; cp.presolve = cp.presolve ? GLP_ON : GLP_OFF; cp.binarize = cp.binarize ? GLP_ON : GLP_OFF; #endif // GLPK_VERSION(4, 32) #if GLPK_VERSION(4, 37) cp.fp_heur = cp.fp_heur ? GLP_ON : GLP_OFF; #endif // GLPK_VERSION(4, 32) // Do checking on the various entries. #if GLPK_VERSION(4, 32) if (!cp.presolve && glp_get_status(LP) != GLP_OPT) { PyErr_SetString(PyExc_RuntimeError, "integer solver requires " "use of presolver or existing optimal basic solution"); return NULL; } #else if (glp_get_status(LP) != GLP_OPT) { PyErr_SetString(PyExc_RuntimeError, "integer solver requires " "existing optimal basic solution"); return NULL; } #endif switch (cp.msg_lev) { case GLP_MSG_OFF: case GLP_MSG_ERR: case GLP_MSG_ON: case GLP_MSG_ALL: break; default: PyErr_SetString (PyExc_ValueError, "invalid value for msg_lev (LPX.MSG_* are valid values)"); return NULL; } switch (cp.br_tech) { case GLP_BR_FFV: case GLP_BR_LFV: case GLP_BR_MFV: case GLP_BR_DTH: break; default: PyErr_SetString (PyExc_ValueError, "invalid value for br_tech (LPX.BR_* are valid values)"); return NULL; } switch (cp.bt_tech) { case GLP_BT_DFS: case GLP_BT_BFS: case GLP_BT_BLB: case GLP_BT_BPH: break; default: PyErr_SetString (PyExc_ValueError, "invalid value for bt_tech (LPX.BT_* are valid values)"); return NULL; } #if GLPK_VERSION(4, 21) switch (cp.pp_tech) { case GLP_PP_NONE: case GLP_PP_ROOT: case GLP_PP_ALL: break; default: PyErr_SetString (PyExc_ValueError, "invalid value for pp_tech (LPX.PP_* are valid values)"); return NULL; } #endif // GLPK_VERSION(4, 21) if (cp.tol_int<=0 || cp.tol_int>=1) { PyErr_SetString(PyExc_ValueError, "tol_int must obey 0<tol_int<1"); return NULL; } if (cp.tol_obj<=0 || cp.tol_obj>=1) { PyErr_SetString(PyExc_ValueError, "tol_obj must obey 0<tol_obj<1"); return NULL; } if (cp.tm_lim<0) { PyErr_SetString(PyExc_ValueError, "tm_lim must be non-negative"); return NULL; } if (cp.out_frq<=0) { PyErr_SetString(PyExc_ValueError, "out_frq must be positive"); return NULL; } if (cp.out_dly<0) { PyErr_SetString(PyExc_ValueError, "out_dly must be non-negative"); return NULL; } #if GLPK_VERSION(4, 23) if (cp.mip_gap<0) { PyErr_SetString(PyExc_ValueError, "mip_gap must be non-negative"); return NULL; } #endif int retval; if (callback != NULL && callback != Py_None) { info = (struct mip_callback_object*) malloc(sizeof(struct mip_callback_object)); info->callback = callback; info->py_lp = self; cp.cb_info = info; cp.cb_func = mip_callback; } retval = glp_intopt(LP, &cp); if (info) free(info); if (PyErr_Occurred()) { // This should happen only if there was a problem within the // callback function, or if the callback was not appropriate. return NULL; } if (retval!=GLP_EBADB && retval!=GLP_ESING && retval!=GLP_ECOND && retval!=GLP_EBOUND && retval!=GLP_EFAIL) self->last_solver = 2; return glpsolver_retval_to_message(retval); #else int retval = lpx_integer(LP); if (retval!=LPX_E_FAULT) self->last_solver = 2; return solver_retval_to_message(retval); #endif // GLPK_VERSION(4, 20) }
static PyObject* LPX_solver_simplex(LPXObject *self, PyObject *args, PyObject *keywds) { #if GLPK_VERSION(4, 18) glp_smcp cp; // Set all to GLPK defaults, except for the message level, which // inexplicably has a default "verbose" setting. glp_init_smcp(&cp); cp.msg_lev = GLP_MSG_OFF; // Map the keyword arguments to the appropriate entries. 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", NULL}; if (!PyArg_ParseTupleAndKeywords (args, keywds, "|iiiidddddiiiii", kwlist, &cp.msg_lev, &cp.meth, &cp.pricing, &cp.r_test, &cp.tol_bnd, &cp.tol_dj, &cp.tol_piv, &cp.obj_ll, &cp.obj_ul, &cp.it_lim, &cp.tm_lim, &cp.out_frq, &cp.out_dly, &cp.presolve)) { return NULL; } cp.presolve = cp.presolve ? GLP_ON : GLP_OFF; // Do checking on the various entries. switch (cp.msg_lev) { case GLP_MSG_OFF: case GLP_MSG_ERR: case GLP_MSG_ON: case GLP_MSG_ALL: break; default: PyErr_SetString (PyExc_ValueError, "invalid value for msg_lev (LPX.MSG_* are valid values)"); return NULL; } switch (cp.meth) { case GLP_PRIMAL: case GLP_DUALP: break; #if GLPK_VERSION(4, 31) case GLP_DUAL: break; #endif default: PyErr_SetString (PyExc_ValueError, "invalid value for meth (LPX.PRIMAL, LPX.DUAL, " "LPX.DUALP valid values)"); return NULL; } switch (cp.pricing) { case GLP_PT_STD: case GLP_PT_PSE: break; default: PyErr_SetString (PyExc_ValueError, "invalid value for pricing (LPX.PT_STD, LPX.PT_PSE valid values)"); return NULL; } switch (cp.r_test) { case GLP_RT_STD: case GLP_RT_HAR: break; default: PyErr_SetString (PyExc_ValueError, "invalid value for ratio test (LPX.RT_STD, LPX.RT_HAR valid values)"); return NULL; } if (cp.tol_bnd<=0 || cp.tol_bnd>=1) { PyErr_SetString(PyExc_ValueError, "tol_bnd must obey 0<tol_bnd<1"); return NULL; } if (cp.tol_dj<=0 || cp.tol_dj>=1) { PyErr_SetString(PyExc_ValueError, "tol_dj must obey 0<tol_dj<1"); return NULL; } if (cp.tol_piv<=0 || cp.tol_piv>=1) { PyErr_SetString(PyExc_ValueError, "tol_piv must obey 0<tol_piv<1"); return NULL; } if (cp.it_lim<0) { PyErr_SetString(PyExc_ValueError, "it_lim must be non-negative"); return NULL; } if (cp.tm_lim<0) { PyErr_SetString(PyExc_ValueError, "tm_lim must be non-negative"); return NULL; } if (cp.out_frq<=0) { PyErr_SetString(PyExc_ValueError, "out_frq must be positive"); return NULL; } if (cp.out_dly<0) { PyErr_SetString(PyExc_ValueError, "out_dly must be non-negative"); return NULL; } // All the checks are complete. Call the simplex solver. int retval = glp_simplex(LP, &cp); if (retval!=GLP_EBADB && retval!=GLP_ESING && retval!=GLP_ECOND && retval!=GLP_EBOUND && retval!=GLP_EFAIL) self->last_solver = 0; return glpsolver_retval_to_message(retval); #else int retval = lpx_simplex(LP); if (retval!=LPX_E_FAULT) self->last_solver = 0; return solver_retval_to_message(retval); #endif }
static PyObject* LPX_cool_down(LPXObject *self) { //#if GLPK_VERSION(4, 39) glp_std_basis(LP); return solver_retval_to_message(LPX_E_OK); }