Skip to content

Commit

Permalink
workaround glpk
Browse files Browse the repository at this point in the history
  • Loading branch information
VonAlphaBisZulu committed Sep 21, 2022
1 parent 038e9cb commit 874ac2c
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions straindesign/glpk_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,18 +197,18 @@ def __init__(self, c, A_ineq, b_ineq, A_eq, b_eq, lb, ub, vtype, indic_constr, M
glp_load_matrix(self.glpk, A.nnz, ia, ja, ar)

# not sure if the parameter setup is okay
self.lp_params = glp_smcp()
glp_init_smcp(self.lp_params)
self.max_tlim = self.lp_params.tm_lim
self.lp_params.tol_bnd = 1e-9
self.lp_params.msg_lev = 0
if self.ismilp:
self.milp_params = glp_iocp()
glp_init_iocp(self.milp_params)
self.milp_params.presolve = 1
self.milp_params.tol_int = 1e-12
self.milp_params.tol_obj = 1e-9
self.milp_params.msg_lev = 0
self.lp_params = glp_smcp()
glp_init_smcp(self.lp_params)
self.max_tlim = self.lp_params.tm_lim
self.lp_params.tol_bnd = 1e-9
self.lp_params.msg_lev = 0

# ideally, one would generate random seeds here, but glpk does not seem to
# offer this function
Expand Down Expand Up @@ -483,7 +483,14 @@ def solve_MILP_LP(self) -> Tuple[float, int, bool]:
# MILP solving needs prior solution of the LP-relaxed problem, because occasionally
# the MILP solver interface crashes when a problem is infesible, which, in turn,
# crashes the python program. This connection-loss to the solver can not be captured.
glp_simplex(self.glpk, self.lp_params)
prelim_status = glp_simplex(self.glpk, self.lp_params)
# There is a GLPK bug where feasible LPs fail initialy but can complete when presolved
# in these cases, glp_simplex returns GLP_EFAIL. We capture these cases and solve again
# with prior resolve.
if prelim_status == GLP_EFAIL:
self.lp_params.presolve = 1
glp_simplex(self.glpk, self.lp_params)
self.lp_params.presolve = 0
status = glp_get_status(self.glpk)
if self.ismilp and status not in [GLP_INFEAS, GLP_NOFEAS]:
glp_intopt(self.glpk, self.milp_params)
Expand Down

0 comments on commit 874ac2c

Please sign in to comment.