From 010f846896ac34517ea3e3081263486ece98a120 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Legat?= Date: Wed, 20 Dec 2023 01:11:52 +0100 Subject: [PATCH] [Bridges] refactor SDPAModel to separate file (#2364) --- test/Bridges/lazy_bridge_optimizer.jl | 101 +----------------------- test/Bridges/sdpa_models.jl | 107 ++++++++++++++++++++++++++ 2 files changed, 108 insertions(+), 100 deletions(-) create mode 100644 test/Bridges/sdpa_models.jl diff --git a/test/Bridges/lazy_bridge_optimizer.jl b/test/Bridges/lazy_bridge_optimizer.jl index a81d45b159..8c27bd80f9 100644 --- a/test/Bridges/lazy_bridge_optimizer.jl +++ b/test/Bridges/lazy_bridge_optimizer.jl @@ -22,6 +22,7 @@ function runtests() end include("utilities.jl") +include("sdpa_models.jl") function test_add_remove_has_bridges() T = Int @@ -309,106 +310,6 @@ function test_MOI_runtests_LPModel() return end -# Model similar to SDPA format, it gives a good example because it does not -# support a lot hence need a lot of bridges -MOI.Utilities.@model( - StandardSDPAModel, - (), - (MOI.EqualTo,), - (MOI.Nonnegatives, MOI.PositiveSemidefiniteConeTriangle), - (), - (), - (MOI.ScalarAffineFunction,), - (MOI.VectorOfVariables,), - () -) - -function MOI.supports_constraint( - ::StandardSDPAModel{T}, - ::Type{MOI.VariableIndex}, - ::Type{ - <:Union{ - MOI.GreaterThan{T}, - MOI.LessThan{T}, - MOI.EqualTo{T}, - MOI.Interval{T}, - MOI.ZeroOne, - MOI.Integer, - }, - }, -) where {T} - return false -end - -function MOI.supports_constraint( - ::StandardSDPAModel{T}, - ::Type{MOI.VectorOfVariables}, - ::Type{MOI.Reals}, -) where {T} - return false -end - -function MOI.supports_add_constrained_variables( - ::StandardSDPAModel, - ::Type{<:Union{MOI.Nonnegatives,MOI.PositiveSemidefiniteConeTriangle}}, -) - return true -end - -function MOI.supports_add_constrained_variables( - ::StandardSDPAModel, - ::Type{MOI.Reals}, -) - return false -end - -function MOI.supports( - ::StandardSDPAModel{T}, - ::MOI.ObjectiveFunction{ - <:Union{MOI.VariableIndex,MOI.ScalarQuadraticFunction{T}}, - }, -) where {T} - return false -end - -MOI.Utilities.@model( - GeometricSDPAModel, - (), - (), - (MOI.Zeros, MOI.Nonnegatives, MOI.PositiveSemidefiniteConeTriangle), - (), - (), - (), - (), - (MOI.VectorAffineFunction,) -) - -function MOI.supports_constraint( - ::GeometricSDPAModel{T}, - ::Type{MOI.VariableIndex}, - ::Type{ - <:Union{ - MOI.GreaterThan{T}, - MOI.LessThan{T}, - MOI.EqualTo{T}, - MOI.Interval{T}, - MOI.ZeroOne, - MOI.Integer, - }, - }, -) where {T} - return false -end - -function MOI.supports( - ::GeometricSDPAModel{T}, - ::MOI.ObjectiveFunction{ - <:Union{MOI.VariableIndex,MOI.ScalarQuadraticFunction{T}}, - }, -) where {T} - return false -end - function test_MOI_runtests_StandardSDPAModel() model = StandardSDPAModel{Float64}() bridged = MOI.Bridges.full_bridge_optimizer(model, Float64) diff --git a/test/Bridges/sdpa_models.jl b/test/Bridges/sdpa_models.jl new file mode 100644 index 0000000000..d947394318 --- /dev/null +++ b/test/Bridges/sdpa_models.jl @@ -0,0 +1,107 @@ +# Copyright (c) 2017: Miles Lubin and contributors +# Copyright (c) 2017: Google Inc. +# +# Use of this source code is governed by an MIT-style license that can be found +# in the LICENSE.md file or at https://opensource.org/licenses/MIT. + +# This file implements models similar to the SDPA format. It gives a good +# example because it does not support a lot of functions, hence the need for +# a lot of bridges. + +MOI.Utilities.@model( + StandardSDPAModel, + (), + (MOI.EqualTo,), + (MOI.Nonnegatives, MOI.PositiveSemidefiniteConeTriangle), + (), + (), + (MOI.ScalarAffineFunction,), + (MOI.VectorOfVariables,), + () +) + +function MOI.supports_constraint( + ::StandardSDPAModel{T}, + ::Type{MOI.VariableIndex}, + ::Type{ + <:Union{ + MOI.GreaterThan{T}, + MOI.LessThan{T}, + MOI.EqualTo{T}, + MOI.Interval{T}, + MOI.ZeroOne, + MOI.Integer, + }, + }, +) where {T} + return false +end + +function MOI.supports_constraint( + ::StandardSDPAModel{T}, + ::Type{MOI.VectorOfVariables}, + ::Type{MOI.Reals}, +) where {T} + return false +end + +function MOI.supports_add_constrained_variables( + ::StandardSDPAModel, + ::Type{<:Union{MOI.Nonnegatives,MOI.PositiveSemidefiniteConeTriangle}}, +) + return true +end + +function MOI.supports_add_constrained_variables( + ::StandardSDPAModel, + ::Type{MOI.Reals}, +) + return false +end + +function MOI.supports( + ::StandardSDPAModel{T}, + ::MOI.ObjectiveFunction{ + <:Union{MOI.VariableIndex,MOI.ScalarQuadraticFunction{T}}, + }, +) where {T} + return false +end + +MOI.Utilities.@model( + GeometricSDPAModel, + (), + (), + (MOI.Zeros, MOI.Nonnegatives, MOI.PositiveSemidefiniteConeTriangle), + (), + (), + (), + (), + (MOI.VectorAffineFunction,) +) + +function MOI.supports_constraint( + ::GeometricSDPAModel{T}, + ::Type{MOI.VariableIndex}, + ::Type{ + <:Union{ + MOI.GreaterThan{T}, + MOI.LessThan{T}, + MOI.EqualTo{T}, + MOI.Interval{T}, + MOI.ZeroOne, + MOI.Integer, + }, + }, +) where {T} + return false +end + +function MOI.supports( + ::GeometricSDPAModel{T}, + ::MOI.ObjectiveFunction{ + <:Union{MOI.VariableIndex,MOI.ScalarQuadraticFunction{T}}, + }, +) where {T} + return false +end