Skip to content

Commit

Permalink
Merge pull request #40 from chriscoey/nofeasfix
Browse files Browse the repository at this point in the history
if have no feasible solution, return NaN objective value and solution
  • Loading branch information
mlubin authored Apr 4, 2017
2 parents ab5988f + 1089a35 commit ae65225
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/GLPKInterfaceMIP.jl
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ function Base.copy(m::GLPKMathProgModelMIP)

m2.param = deepcopy(m.param)
m2.smplxparam = deepcopy(m.smplxparam)

m.lazycb == nothing || Base.warn_once("Callbacks can't be copied, lazy callback ignored")
m.cutcb == nothing || Base.warn_once("Callbacks can't be copied, cut callback ignored")
m.heuristiccb == nothing || Base.warn_once("Callbacks can't be copied, heuristic callback ignored")
m.infocb == nothing || Base.warn_once("Callbacks can't be copied, info callback ignored")

m2.objbound = m.objbound

m.cbdata == nothing || Base.warn_once("Callbacks can't be copied, callbackdata ignored")
Expand Down Expand Up @@ -539,7 +539,15 @@ function status(lpm::GLPKMathProgModelMIP)
end
end

getobjval(lpm::GLPKMathProgModelMIP) = GLPK.mip_obj_val(lpm.inner)
function getobjval(lpm::GLPKMathProgModelMIP)
status = GLPK.mip_status(lpm.inner)
if status == GLPK.UNDEF || status == GLPK.NOFEAS
# no feasible solution so objective is NaN
return NaN
end

return GLPK.mip_obj_val(lpm.inner)
end

function getobjbound(lpm::GLPKMathProgModelMIP)
# This is a hack. We observed some cases where mip_status == OPT
Expand All @@ -556,6 +564,11 @@ end
function getsolution(lpm::GLPKMathProgModelMIP)
lp = lpm.inner
n = GLPK.get_num_cols(lp)
status = GLPK.mip_status(lpm.inner)
if status == GLPK.UNDEF || status == GLPK.NOFEAS
# no feasible solution to return
return fill(NaN, n)
end

x = Array{Float64}(n)
for c = 1:n
Expand Down

0 comments on commit ae65225

Please sign in to comment.