Skip to content

Commit

Permalink
Fix bug in setting a negative lower bound of a SOC constrained variab…
Browse files Browse the repository at this point in the history
…le with `add_constraints` (#302)

* Adds a test uncovering a bug in SOC constraints. The bug was that defining a negative lower bound on the `t` variable of a SOC constraint by means of `add_constraints` (GreaterThan) silently corrupted the related `VariableInfo` object, but using `add_constraint` worked.

* Solves the bug in SOC constraints. The one uncovered by the test added in the last commit. The bug is solved by reworking many methods to work correctly with batch/vector (that is where the bug appeared) and changing single-element methods to wrap arguments and call the batch/vector variant. This way there will exist no difference in behavior between single-element and batch methods.

* Replace our solution by the one proposed by @odow
  • Loading branch information
henriquebecker91 authored Mar 31, 2020
1 parent 096a1ee commit be598c6
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1091,8 +1091,12 @@ function _set_bounds(
lower, upper = _bounds(s)
info = _info(model, c)
if lower !== nothing
push!(lower_columns, info.column)
push!(lower_values, lower)
if info.num_soc_constraints == 0
push!(lower_columns, info.column)
push!(lower_values, lower)
else
_set_variable_lower_bound(model, info, lower)
end
end
if upper !== nothing
push!(upper_columns, info.column)
Expand Down
25 changes: 25 additions & 0 deletions test/MOI/MOI_wrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,31 @@ end
MOI.optimize!(model)
@test MOI.get(model, MOI.TerminationStatus()) == MOI.DUAL_INFEASIBLE
end
@testset "negative post bound III" begin
# This test was added because add_constraint and add_constraints had
# different implementations and add_constraints failed where
# add_constraint succeeded.
MOI.empty!(model)
t = MOI.add_variable(model)
x = MOI.add_variables(model, 2)
c_soc = MOI.add_constraint(
model, MOI.VectorOfVariables([t; x]), MOI.SecondOrderCone(3)
)
c_lbs = MOI.add_constraints(
model, MOI.SingleVariable.([t; x]), MOI.GreaterThan.([-6.0, 3.0, 4.0])
)
c_lb = first(c_lbs)
MOI.set(model, MOI.ObjectiveFunction{MOI.SingleVariable}(), MOI.SingleVariable(t))
MOI.set(model, MOI.ObjectiveSense(), MOI.MIN_SENSE)
MOI.optimize!(model)
@test MOI.get(model, MOI.VariablePrimal(), t) == 5.0
MOI.delete(model, c_lb)
MOI.optimize!(model)
@test MOI.get(model, MOI.VariablePrimal(), t) == 5.0
MOI.delete(model, c_soc)
MOI.optimize!(model)
@test MOI.get(model, MOI.TerminationStatus()) == MOI.DUAL_INFEASIBLE
end
@testset "2 SOC's" begin
MOI.empty!(model)
t = MOI.add_variable(model)
Expand Down

0 comments on commit be598c6

Please sign in to comment.