Skip to content

Commit

Permalink
Fix fixing int variable constrained to Interval set
Browse files Browse the repository at this point in the history
  • Loading branch information
odow committed Jan 10, 2024
1 parent ac6a3dc commit 4f123c4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
2 changes: 2 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
28 changes: 18 additions & 10 deletions src/optimize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4f123c4

Please sign in to comment.