From fadc3ee55534e418661fdf7dc817059fa632cd40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Legat?= Date: Tue, 17 Dec 2024 12:38:13 +0100 Subject: [PATCH 1/2] Simplify test_conic_linear with forced bridging --- src/Test/test_conic.jl | 74 +++++++++++------------------------------- 1 file changed, 19 insertions(+), 55 deletions(-) diff --git a/src/Test/test_conic.jl b/src/Test/test_conic.jl index b2dca3f3da..0115c8f1f8 100644 --- a/src/Test/test_conic.jl +++ b/src/Test/test_conic.jl @@ -5,15 +5,9 @@ # in the LICENSE.md file or at https://opensource.org/licenses/MIT. """ - _test_conic_linear_helper( - model::MOI.ModelLike, - config::Config, - use_VectorOfVariables::Bool, - ) - -A helper function for writing other conic tests. + test_conic_linear_VectorOfVariables(model::MOI.ModelLike, config::Config) -Constructs the problem: +Test a conic formulation of a linear program using standard conic form of the problem: ``` min -3x - 2y - 4z st x + y + z == 3 @@ -21,31 +15,23 @@ st x + y + z == 3 x>=0 y>=0 z>=0 Opt obj = -11, soln x = 1, y = 0, z = 2 ``` + """ -function _test_conic_linear_helper( +function test_conic_linear_VectorOfVariables( model::MOI.ModelLike, - config::Config{T}, - use_VectorOfVariables::Bool, -) where {T<:Real} + config::Config, +) @requires MOI.supports_incremental_interface(model) @requires MOI.supports( model, MOI.ObjectiveFunction{MOI.ScalarAffineFunction{T}}(), ) @requires MOI.supports(model, MOI.ObjectiveSense()) - if use_VectorOfVariables - @requires MOI.supports_constraint( - model, - MOI.VectorOfVariables, - MOI.Nonnegatives, - ) - else - @requires MOI.supports_constraint( - model, - MOI.VectorAffineFunction{T}, - MOI.Nonnegatives, - ) - end + @requires MOI.supports_constraint( + model, + MOI.VectorOfVariables, + MOI.Nonnegatives, + ) @requires MOI.supports_constraint( model, MOI.VectorAffineFunction{T}, @@ -54,15 +40,7 @@ function _test_conic_linear_helper( v = MOI.add_variables(model, 3) @test MOI.get(model, MOI.NumberOfVariables()) == 3 vov = MOI.VectorOfVariables(v) - if use_VectorOfVariables - vc = MOI.add_constraint(model, vov, MOI.Nonnegatives(3)) - else - vc = MOI.add_constraint( - model, - MOI.VectorAffineFunction{T}(vov), - MOI.Nonnegatives(3), - ) - end + vc = MOI.add_constraint(model, vov, MOI.Nonnegatives(3)) c = MOI.add_constraint( model, MOI.VectorAffineFunction( @@ -78,8 +56,7 @@ function _test_conic_linear_helper( @test MOI.get( model, MOI.NumberOfConstraints{ - use_VectorOfVariables ? MOI.VectorOfVariables : - MOI.VectorAffineFunction{T}, + MOI.VectorOfVariables, MOI.Nonnegatives, }(), ) == 1 @@ -91,8 +68,7 @@ function _test_conic_linear_helper( loc = MOI.get(model, MOI.ListOfConstraintTypesPresent()) @test length(loc) == 2 @test ( - use_VectorOfVariables ? MOI.VectorOfVariables : - MOI.VectorAffineFunction{T}, + MOI.VectorOfVariables, MOI.Nonnegatives, ) in loc @test (MOI.VectorAffineFunction{T}, MOI.Zeros) in loc @@ -129,19 +105,6 @@ function _test_conic_linear_helper( return end -""" - test_conic_linear_VectorOfVariables(model::MOI.ModelLike, config::Config) - -Test a conic formulation of a linear program using standard conic form. -""" -function test_conic_linear_VectorOfVariables( - model::MOI.ModelLike, - config::Config, -) - _test_conic_linear_helper(model, config, true) - return -end - function setup_test( ::typeof(test_conic_linear_VectorOfVariables), model::MOIU.MockOptimizer, @@ -161,13 +124,14 @@ end """ test_conic_linear_VectorAffineFunction(model::MOI.ModelLike, config::Config) -Test a conic formulation of a linear program using geometric conic form. +Test a conic formulation of a linear program using geometric conic form of +the same problem as [`test_conic_linear_VectorOfVariables`](@ref). """ function test_conic_linear_VectorAffineFunction( model::MOI.ModelLike, - config::Config, -) - _test_conic_linear_helper(model, config, false) + config::Config{T}, +) where {T} + test_conic_linear_VectorOfVariables(MOI.Bridges.Constraint.VectorFunctionize{T}(model), config) return end From 8abc958113335fb29d53b3e343de766eb744b4ac Mon Sep 17 00:00:00 2001 From: Oscar Dowson Date: Thu, 19 Dec 2024 14:55:33 +1300 Subject: [PATCH 2/2] Update test_conic.jl --- src/Test/test_conic.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Test/test_conic.jl b/src/Test/test_conic.jl index 0115c8f1f8..6a56b9b77f 100644 --- a/src/Test/test_conic.jl +++ b/src/Test/test_conic.jl @@ -19,8 +19,8 @@ Opt obj = -11, soln x = 1, y = 0, z = 2 """ function test_conic_linear_VectorOfVariables( model::MOI.ModelLike, - config::Config, -) + config::Config{T}, +) where {T} @requires MOI.supports_incremental_interface(model) @requires MOI.supports( model,