Skip to content

Commit 04ee25b

Browse files
committed
fix tests
1 parent 639a4bb commit 04ee25b

2 files changed

Lines changed: 70 additions & 6 deletions

File tree

src/MOI_wrapper.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -883,10 +883,12 @@ function MOI.delete(
883883
model::Optimizer,
884884
c::MOI.ConstraintIndex{F,S},
885885
) where {F<:MOI.VectorAffineFunction,S<:MOI.AbstractSet}
886-
MOI.delete(model.optimizer, c)
887886
if haskey(model.constraint_outer_to_inner, c)
888887
ci_inner = model.constraint_outer_to_inner[c]
889888
delete!(model.vector_affine_constraint_cache, ci_inner)
889+
MOI.delete(model.optimizer, ci_inner)
890+
else
891+
MOI.delete(model.optimizer, c)
890892
end
891893
delete!(model.constraint_outer_to_inner, c)
892894
return

test/jump_tests.jl

Lines changed: 67 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -758,37 +758,99 @@ function test_jump_dual_delete_constraint_2()
758758
import ParametricOptInterface as POI
759759
model = Model(() -> POI.Optimizer(GLPK.Optimizer()))
760760
@variable(model, α in MOI.Parameter(1.0))
761+
@variable(model, β in MOI.Parameter(0.0))
761762
@variable(model, x)
762763
list = []
763764
cref = @constraint(model, x >= 1 * 1)
764765
push!(list, cref)
765766
cref = @constraint(model, x >= 9 * α)
766767
push!(list, cref)
767-
cref = @constraint(model, x >= 8 * α^2)
768+
cref = @constraint(model, x >= 8 * α + β^2)
768769
push!(list, cref)
769770
cref = @constraint(model, x >= 7 * 1)
770771
push!(list, cref)
771772
cref = @constraint(model, x >= 6 * α)
772773
push!(list, cref)
773-
cref = @constraint(model, x >= 5 * α^2)
774+
cref = @constraint(model, x >= 5 * α + β^2)
774775
push!(list, cref)
775776
cref = @constraint(model, x >= 4 * 1)
776777
push!(list, cref)
777778
cref = @constraint(model, x >= 3 * α)
778779
push!(list, cref)
779-
cref = @constraint(model, x >= 2 * α^2)
780+
cref = @constraint(model, x >= 2 * α + β^2)
780781
push!(list, cref)
781782
@objective(model, Min, x)
782783
cref1 = popfirst!(list)
783-
for i in 9:2
784+
for i in 9:-1:2
784785
JuMP.optimize!(model)
785786
@test JuMP.value(x) == 1.0 * i
786787
@test JuMP.dual(cref1) == 0.0
787788
for con in list[2:end]
788789
@test JuMP.dual(con) == 0.0
789790
end
790791
@test JuMP.dual(list[1]) == 1.0
791-
@test MOI.get(model, POI.ParameterDual(), α) == 1.0 * i
792+
if i in [7, 4]
793+
@test MOI.get(model, POI.ParameterDual(), α) == 0.0
794+
else
795+
@test MOI.get(model, POI.ParameterDual(), α) == 1.0 * i
796+
end
797+
con = popfirst!(list)
798+
JuMP.delete(model, con)
799+
end
800+
return
801+
end
802+
803+
function test_jump_dual_delete_constraint_3()
804+
using Test, JuMP, SCS
805+
import ParametricOptInterface as POI
806+
import MathOptInterface as MOI
807+
cached = MOI.Utilities.CachingOptimizer(
808+
MOI.Utilities.UniversalFallback(MOI.Utilities.Model{Float64}()),
809+
SCS.Optimizer(),
810+
)
811+
optimizer = POI.Optimizer(cached)
812+
model = direct_model(optimizer)
813+
set_silent(model)
814+
list = []
815+
@variable(model, α in MOI.Parameter(1.0))
816+
@variable(model, β in MOI.Parameter(0.0))
817+
@variable(model, x)
818+
cref = @constraint(model, [x - 1 * 1] in MOI.Nonnegatives(1))
819+
push!(list, cref)
820+
cref = @constraint(model, [x - 9 * α] in MOI.Nonnegatives(1))
821+
push!(list, cref)
822+
# cref = @constraint(model, [x - 8 * α + β^2] in MOI.Nonnegatives(1))
823+
cref = @constraint(model, [x - 8 * α + β] in MOI.Nonnegatives(1))
824+
push!(list, cref)
825+
cref = @constraint(model, [x - 7 * 1] in MOI.Nonnegatives(1))
826+
push!(list, cref)
827+
cref = @constraint(model, [x - 6 * α] in MOI.Nonnegatives(1))
828+
push!(list, cref)
829+
# cref = @constraint(model, [x - 5 * α + β^2] in MOI.Nonnegatives(1))
830+
cref = @constraint(model, [x - 5 * α + β] in MOI.Nonnegatives(1))
831+
push!(list, cref)
832+
cref = @constraint(model, [x - 4 * 1] in MOI.Nonnegatives(1))
833+
push!(list, cref)
834+
cref = @constraint(model, [x - 3 * α] in MOI.Nonnegatives(1))
835+
push!(list, cref)
836+
# cref = @constraint(model, [x - 2 * α + β^2] in MOI.Nonnegatives(1))
837+
cref = @constraint(model, [x - 2 * α + β] in MOI.Nonnegatives(1))
838+
push!(list, cref)
839+
@objective(model, Min, 1.0 * x)
840+
cref1 = popfirst!(list)
841+
for i in 9:-1:2
842+
JuMP.optimize!(model)
843+
@test JuMP.value(x) 1.0 * i atol = 1e-5
844+
@test JuMP.dual(cref1)[] 0.0 atol = 1e-5
845+
for con in list[2:end]
846+
@test JuMP.dual(con)[] 0.0 atol = 1e-5
847+
end
848+
@test JuMP.dual(list[1])[] 1.0 atol = 1e-5
849+
if i in [7, 4]
850+
@test MOI.get(model, POI.ParameterDual(), α) 0.0 atol = 1e-5
851+
else
852+
@test MOI.get(model, POI.ParameterDual(), α) 1.0 * i atol = 1e-5
853+
end
792854
con = popfirst!(list)
793855
JuMP.delete(model, con)
794856
end

0 commit comments

Comments
 (0)