diff --git a/Project.toml b/Project.toml index 841cb24..15b2f6a 100644 --- a/Project.toml +++ b/Project.toml @@ -14,6 +14,8 @@ Ipopt = "0.8, 0.9, 1" JuMP = "0.22, 0.23, 1" MINLPTests = "0.5" MathOptInterface = "0.10.3, 1" +Printf = "<0.0.1, 1.6" +Test = "<0.0.1, 1.6" julia = "1.6" [extras] diff --git a/src/optimize.jl b/src/optimize.jl index e109193..89fd85b 100644 --- a/src/optimize.jl +++ b/src/optimize.jl @@ -502,21 +502,29 @@ function _fix_int_vars( mip_solution, int_indices, ) + F = MOI.VariableIndex for i in int_indices - vi = vars[i] - idx = vi.value - ci = MOI.ConstraintIndex{MOI.VariableIndex,MOI.LessThan{Float64}}(idx) - MOI.is_valid(optimizer, ci) && MOI.delete(optimizer, ci) - ci = - MOI.ConstraintIndex{MOI.VariableIndex,MOI.GreaterThan{Float64}}(idx) - MOI.is_valid(optimizer, ci) && MOI.delete(optimizer, ci) - ci = MOI.ConstraintIndex{MOI.VariableIndex,MOI.EqualTo{Float64}}(idx) + x = vars[i] + # We need to delete any conflicting bound constraints before we set or + # update the x == mip_solution[i] constraint. + ci = MOI.ConstraintIndex{F,MOI.Interval{Float64}}(x.value) + if MOI.is_valid(optimizer, ci) + MOI.delete(optimizer, ci) + end + ci = MOI.ConstraintIndex{F,MOI.LessThan{Float64}}(x.value) + if MOI.is_valid(optimizer, ci) + MOI.delete(optimizer, ci) + end + ci = MOI.ConstraintIndex{F,MOI.GreaterThan{Float64}}(x.value) + if MOI.is_valid(optimizer, ci) + MOI.delete(optimizer, ci) + end + ci = MOI.ConstraintIndex{F,MOI.EqualTo{Float64}}(x.value) set = MOI.EqualTo(mip_solution[i]) - if MOI.is_valid(optimizer, ci) MOI.set(optimizer, MOI.ConstraintSet(), ci, set) else - MOI.add_constraint(optimizer, vi, set) + MOI.add_constraint(optimizer, x, set) end end return