Skip to content

Commit

Permalink
Fix certificate generation with empty constraint matrix (#188)
Browse files Browse the repository at this point in the history
* Fix certificate generation with empty constraint matrix

* Update infeasibility_certificates.jl
  • Loading branch information
odow authored Jun 2, 2021
1 parent 79588c1 commit 83e31ee
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "GLPK"
uuid = "60bf3e95-4087-53dc-ae20-288a0d20c6a6"
repo = "https://github.com/jump-dev/GLPK.jl.git"
version = "0.14.11"
version = "0.14.12"

[deps]
BinaryProvider = "b99e7846-7c00-51b0-8f62-c81ae34c0232"
Expand Down
6 changes: 6 additions & 0 deletions src/MOI_wrapper/infeasibility_certificates.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ found.
Assumes `ray` has been initialized to all `0.0`s.
"""
function _get_infeasibility_ray(model::Optimizer, ray::Vector{Float64})
if glp_get_num_nz(model) == 0
return false # GLPK aborts if you try to factorize an empty problem.
end
m = glp_get_num_rows(model)
n = glp_get_num_cols(model)
@assert length(ray) == m
Expand Down Expand Up @@ -74,6 +77,9 @@ Assumes the primal has been solved with primal simplex and is proven unbounded.
Assumes `ray` has been initialized to all `0.0`s.
"""
function _get_unbounded_ray(model::Optimizer, ray::Vector{Float64})
if glp_get_num_nz(model) == 0
return false # GLPK aborts if you try to factorize an empty problem.
end
m = glp_get_num_rows(model)
n = glp_get_num_cols(model)
@assert length(ray) == n
Expand Down
36 changes: 36 additions & 0 deletions test/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -818,3 +818,39 @@ end
MOI.optimize!(model)
@test MOI.get(model, MOI.TerminationStatus()) == MOI.OPTIMAL
end

@testset "empty_problem_infeasible" begin
model = GLPK.Optimizer()
x = MOI.add_variable(model)
MOI.add_constraint(
model,
MOI.ScalarAffineFunction([MOI.ScalarAffineTerm(0.0, x)], 0.0),
MOI.GreaterThan(1.0),
)
MOI.add_constraint(
model,
MOI.ScalarAffineFunction([MOI.ScalarAffineTerm(0.0, x)], 0.0),
MOI.EqualTo(0.0),
)
MOI.optimize!(model)
@test MOI.get(model, MOI.TerminationStatus()) == MOI.INFEASIBLE
@test MOI.get(model, MOI.PrimalStatus()) == MOI.NO_SOLUTION
@test MOI.get(model, MOI.DualStatus()) == MOI.NO_SOLUTION
end

@testset "empty_problem_unbounded" begin
model = GLPK.Optimizer()
x = MOI.add_variable(model)
MOI.add_constraint(
model,
MOI.ScalarAffineFunction([MOI.ScalarAffineTerm(0.0, x)], 0.0),
MOI.EqualTo(0.0),
)
f = MOI.ScalarAffineFunction([MOI.ScalarAffineTerm(1.0, x)], 0.0)
MOI.set(model, MOI.ObjectiveFunction{typeof(f)}(), f)
MOI.set(model, MOI.ObjectiveSense(), MOI.MAX_SENSE)
MOI.optimize!(model)
@test MOI.get(model, MOI.TerminationStatus()) == MOI.DUAL_INFEASIBLE
@test MOI.get(model, MOI.PrimalStatus()) == MOI.NO_SOLUTION
@test MOI.get(model, MOI.DualStatus()) == MOI.NO_SOLUTION
end

2 comments on commit 83e31ee

@odow
Copy link
Member Author

@odow odow commented on 83e31ee Jun 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/38054

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.14.12 -m "<description of version>" 83e31ee1e9e0cef5b2001b51f072d030c26cfcda
git push origin v0.14.12

Please sign in to comment.