Skip to content

Commit

Permalink
Prevent cglpk getting stuck with reused basis
Browse files Browse the repository at this point in the history
Try reusing the basis with a 500ms time limit. If it times out, then the
full time limit will be used to solve the problem without the old basis.
  • Loading branch information
aebrahim committed Jan 8, 2015
1 parent 2bc2d03 commit bf28578
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion cobra/solvers/cglpk.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ cdef class GLP:
def solve_problem(self, **solver_parameters):
cdef int result
cdef glp_smcp parameters = self.parameters
cdef int time_limit = parameters.tm_lim
cdef glp_iocp integer_parameters = self.integer_parameters
cdef glp_prob *glp = self.glp

Expand All @@ -255,10 +256,15 @@ cdef class GLP:
# because glpk itself is not thread safe

#with nogil: # we can use this if glpk ever gets thread-safe malloc
# try to solve the problem with the existing basis
# Try to solve the problem with the existing basis, but with
# a time limit in case it gets stuck.
if parameters.tm_lim > 500:
parameters.tm_lim = 500
if glp_simplex(glp, &parameters) != 0:
glp_adv_basis(glp, 0)
parameters.tm_lim = time_limit
check_error(glp_simplex(glp, &parameters))
parameters.tm_lim = time_limit
if self.exact:
check_error(glp_exact(glp, &parameters))
if self.is_mip():
Expand Down

0 comments on commit bf28578

Please sign in to comment.