Skip to content

Commit ae65225

Browse files
authored
Merge pull request #40 from chriscoey/nofeasfix
if have no feasible solution, return NaN objective value and solution
2 parents ab5988f + 1089a35 commit ae65225

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

src/GLPKInterfaceMIP.jl

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,12 @@ function Base.copy(m::GLPKMathProgModelMIP)
7777

7878
m2.param = deepcopy(m.param)
7979
m2.smplxparam = deepcopy(m.smplxparam)
80-
80+
8181
m.lazycb == nothing || Base.warn_once("Callbacks can't be copied, lazy callback ignored")
8282
m.cutcb == nothing || Base.warn_once("Callbacks can't be copied, cut callback ignored")
8383
m.heuristiccb == nothing || Base.warn_once("Callbacks can't be copied, heuristic callback ignored")
8484
m.infocb == nothing || Base.warn_once("Callbacks can't be copied, info callback ignored")
85-
85+
8686
m2.objbound = m.objbound
8787

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

542-
getobjval(lpm::GLPKMathProgModelMIP) = GLPK.mip_obj_val(lpm.inner)
542+
function getobjval(lpm::GLPKMathProgModelMIP)
543+
status = GLPK.mip_status(lpm.inner)
544+
if status == GLPK.UNDEF || status == GLPK.NOFEAS
545+
# no feasible solution so objective is NaN
546+
return NaN
547+
end
548+
549+
return GLPK.mip_obj_val(lpm.inner)
550+
end
543551

544552
function getobjbound(lpm::GLPKMathProgModelMIP)
545553
# This is a hack. We observed some cases where mip_status == OPT
@@ -556,6 +564,11 @@ end
556564
function getsolution(lpm::GLPKMathProgModelMIP)
557565
lp = lpm.inner
558566
n = GLPK.get_num_cols(lp)
567+
status = GLPK.mip_status(lpm.inner)
568+
if status == GLPK.UNDEF || status == GLPK.NOFEAS
569+
# no feasible solution to return
570+
return fill(NaN, n)
571+
end
559572

560573
x = Array{Float64}(n)
561574
for c = 1:n

0 commit comments

Comments
 (0)