From b2c598e7d1dd83f928ce345cd3e8b6cfa33a2b54 Mon Sep 17 00:00:00 2001 From: odow Date: Wed, 26 Apr 2023 11:59:28 +1200 Subject: [PATCH 1/2] [Bridges] add tests for deleting variable in bridged objective --- test/Bridges/Constraint/quad_to_soc.jl | 44 ++++++++++++++++++++++++++ test/Bridges/Objective/slack.jl | 13 ++++++++ 2 files changed, 57 insertions(+) diff --git a/test/Bridges/Constraint/quad_to_soc.jl b/test/Bridges/Constraint/quad_to_soc.jl index 2176fe8242..6b648075be 100644 --- a/test/Bridges/Constraint/quad_to_soc.jl +++ b/test/Bridges/Constraint/quad_to_soc.jl @@ -278,6 +278,50 @@ function test_copy_to_start() @test MOI.get(dest, MOI.VariablePrimalStart(), index_map[x]) == -1.0 end +function test_deletion_of_variable_in_bridged_constraint() + inner = MOI.Utilities.Model{Float64}() + model = MOI.Bridges.Constraint.QuadtoSOC{Float64}(inner) + x = MOI.add_variables(model, 2) + MOI.set(model, MOI.VariableName(), x, ["x", "y"]) + f = 1.0 * x[1] * x[1] + 1.0 * x[2] * x[2] + c = MOI.add_constraint(model, f, MOI.LessThan(1.0)) + MOI.delete(model, x[1]) + @test MOI.get(model, MOI.ConstraintFunction(), c) ≈ 1.0 * x[2] * x[2] + return +end + +MOI.Utilities.@model( + Model2153, + (), + (MOI.EqualTo,), + (MOI.RotatedSecondOrderCone,), + (), + (), + (MOI.ScalarAffineFunction,), + (MOI.VectorOfVariables,), + (), +) + +function MOI.supports( + ::Model2153{T}, + ::MOI.ObjectiveFunction{MOI.ScalarQuadraticFunction{T}}, +) where {T} + return false +end + +function test_deletion_of_variable_in_bridged_slacked_objective() + model = MOI.Bridges.full_bridge_optimizer(Model2153{Float64}(), Float64) + MOI.Bridges.add_bridge(model, MOI.Bridges.Constraint.QuadtoSOCBridge{Float64}) + x = MOI.add_variables(model, 2) + MOI.set(model, MOI.VariableName(), x, ["x", "y"]) + f = 1.0 * x[1] * x[1] + 1.0 * x[2] * x[2] + MOI.set(model, MOI.ObjectiveSense(), MOI.MIN_SENSE) + MOI.set(model, MOI.ObjectiveFunction{typeof(f)}(), f) + MOI.delete(model, x[1]) + @test MOI.get(model, MOI.ObjectiveFunction{typeof(f)}()) ≈ 1.0 * x[2] * x[2] + return +end + end # module TestConstraintQuadToSOC.runtests() diff --git a/test/Bridges/Objective/slack.jl b/test/Bridges/Objective/slack.jl index a84b8a5066..6b95a6bbcd 100644 --- a/test/Bridges/Objective/slack.jl +++ b/test/Bridges/Objective/slack.jl @@ -489,6 +489,19 @@ function test_complex_objective() return end +function test_deletion_of_variable_in_slacked_objective() + inner = MOI.Utilities.Model{Float64}() + model = MOI.Bridges.Objective.Slack{Float64}(inner) + x = MOI.add_variables(model, 2) + MOI.set(model, MOI.VariableName(), x, ["x", "y"]) + f = 1.0 * x[1] * x[1] + 1.0 * x[2] * x[2] + MOI.set(model, MOI.ObjectiveSense(), MOI.MIN_SENSE) + MOI.set(model, MOI.ObjectiveFunction{typeof(f)}(), f) + MOI.delete(model, x[1]) + @test MOI.get(model, MOI.ObjectiveFunction{typeof(f)}()) ≈ 1.0 * x[2] * x[2] + return +end + end # module TestObjectiveSlack.runtests() From 5cc247eb6bbfde007d5b0d6347fb0d5d7f88ca24 Mon Sep 17 00:00:00 2001 From: Oscar Dowson Date: Wed, 26 Apr 2023 12:09:21 +1200 Subject: [PATCH 2/2] Update test/Bridges/Constraint/quad_to_soc.jl --- test/Bridges/Constraint/quad_to_soc.jl | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/Bridges/Constraint/quad_to_soc.jl b/test/Bridges/Constraint/quad_to_soc.jl index 6b648075be..4ca792bb7e 100644 --- a/test/Bridges/Constraint/quad_to_soc.jl +++ b/test/Bridges/Constraint/quad_to_soc.jl @@ -311,7 +311,10 @@ end function test_deletion_of_variable_in_bridged_slacked_objective() model = MOI.Bridges.full_bridge_optimizer(Model2153{Float64}(), Float64) - MOI.Bridges.add_bridge(model, MOI.Bridges.Constraint.QuadtoSOCBridge{Float64}) + MOI.Bridges.add_bridge( + model, + MOI.Bridges.Constraint.QuadtoSOCBridge{Float64}, + ) x = MOI.add_variables(model, 2) MOI.set(model, MOI.VariableName(), x, ["x", "y"]) f = 1.0 * x[1] * x[1] + 1.0 * x[2] * x[2]