diff --git a/test/Mock/BPT12e399.jl b/test/Mock/BPT12e399.jl index 0aca9a87..7443f245 100644 --- a/test/Mock/BPT12e399.jl +++ b/test/Mock/BPT12e399.jl @@ -1,5 +1,5 @@ config = MOI.Test.Config() -function optimize!_max_bridged(mock) +function optimize!_max(mock) return MOI.Utilities.mock_optimize!( mock, [6.0, 9.0, 1.0, -3.0 * √2], @@ -7,7 +7,7 @@ function optimize!_max_bridged(mock) (MOI.VectorOfVariables, MOI.RotatedSecondOrderCone) => [[3, 1 / 3, √2]], ) end -function optimize!_min_bridged(mock) +function optimize!_min(mock) return MOI.Utilities.mock_optimize!( mock, [-6.0, 9.0, 1.0, 3.0 * √2], @@ -16,60 +16,26 @@ function optimize!_min_bridged(mock) [[3, 1 / 3, -√2]], ) end -function optimize!_max_cached(mock) - return MOI.Utilities.mock_optimize!( - mock, - [9.0, 1.0, -3.0 * √2, 6.0], - (MOI.VectorAffineFunction{Float64}, MOI.Zeros) => [[1 / 3, 1, 3]], - (MOI.VectorOfVariables, MOI.RotatedSecondOrderCone) => [[1 / 3, 3, √2]], - ) -end -function optimize!_min_cached(mock) - return MOI.Utilities.mock_optimize!( - mock, - [9.0, 1.0, 3.0 * √2, -6.0], - (MOI.VectorAffineFunction{Float64}, MOI.Zeros) => [[1 / 3, -1, 3]], - (MOI.VectorOfVariables, MOI.RotatedSecondOrderCone) => - [[1 / 3, 3, -√2]], - ) -end -for mock in [ - bridged_mock(optimize!_max_bridged, optimize!_min_bridged), - cached_mock(optimize!_max_cached, optimize!_min_cached), -] +for mock in mocks(optimize!_max, optimize!_min) Tests.BPT12e399_rem_test(mock, config) end -function optimize!_max_bridged(mock) +function optimize!_max(mock) return MOI.Utilities.mock_optimize!( mock, [10.0, 5.0, -5.0, 5.0, 0.0, 0.0, 4.0], (MOI.VectorAffineFunction{Float64}, MOI.Zeros) => [[1, 1, 0.0, 1, 0]], ) end -function optimize!_min_bridged(mock) +function optimize!_min(mock) return MOI.Utilities.mock_optimize!( mock, [-10.0, 5.0, 5.0, 5.0, 0.0, 0.0, 4.0], (MOI.VectorAffineFunction{Float64}, MOI.Zeros) => [[1, -1, 0.0, 1, 0]], ) end -function optimize!_max_cached(mock) - return MOI.Utilities.mock_optimize!( - mock, - [5.0, -5.0, 5.0, 0.0, 0.0, 4.0, 10.0], - (MOI.VectorAffineFunction{Float64}, MOI.Zeros) => [[1, 1, 0.0, 1, 0]], - ) -end -function optimize!_min_cached(mock) - return MOI.Utilities.mock_optimize!( - mock, - [5.0, 5.0, 5.0, 0.0, 0.0, 4.0, -10.0], - (MOI.VectorAffineFunction{Float64}, MOI.Zeros) => [[1, -1, 0.0, 1, 0]], - ) -end for mock in [ - bridged_mock(optimize!_max_bridged, optimize!_min_bridged), - cached_mock(optimize!_max_cached, optimize!_min_cached), + bridged_mock(optimize!_max, optimize!_min), + cached_mock(optimize!_max, optimize!_min), ] Tests.BPT12e399_maxdegree_test(mock, config) end diff --git a/test/Mock/chebyshev.jl b/test/Mock/chebyshev.jl index 423c834d..c256b5c6 100644 --- a/test/Mock/chebyshev.jl +++ b/test/Mock/chebyshev.jl @@ -5,6 +5,6 @@ function optimize!(mock) [[128.0, 1.0, -0.0, -32.0, 0.0, 160.0, -0.0, -256.0, 0.0]; zeros(90)], ) end -for mock in [bridged_mock(optimize!), cached_mock(optimize!)] +for mock in mocks(optimize!) Tests.chebyshev_test(mock, config) end diff --git a/test/Mock/concave_then_convex_cubic.jl b/test/Mock/concave_then_convex_cubic.jl index e4a6a0e7..52cb7efb 100644 --- a/test/Mock/concave_then_convex_cubic.jl +++ b/test/Mock/concave_then_convex_cubic.jl @@ -13,17 +13,7 @@ end for mock in mocks(optimize!) Tests.dsos_concave_then_convex_cubic_test(mock, config) end -function optimize_bridged!(mock) - return MOI.Utilities.mock_optimize!( - mock, - vals, - (MOI.ScalarAffineFunction{Float64}, MOI.EqualTo{Float64}) => zeros(4), - (MOI.VectorAffineFunction{Float64}, MOI.Zeros) => [zeros(2), zeros(2)], - (MOI.VectorOfVariables, MOI.RotatedSecondOrderCone) => - [zeros(3) for i in 1:8], - ) -end -function optimize_cached!(mock) +function optimize!(mock) return MOI.Utilities.mock_optimize!( mock, vals, @@ -33,22 +23,10 @@ function optimize_cached!(mock) [zeros(3) for i in 1:8], ) end -for mock in [bridged_mock(optimize_bridged!), cached_mock(optimize_cached!)] +for mock in mocks(optimize!) Tests.sdsos_concave_then_convex_cubic_test(mock, config) end -function optimize_bridged!(mock) - return MOI.Utilities.mock_optimize!( - mock, - vals, - (MOI.ScalarAffineFunction{Float64}, MOI.EqualTo{Float64}) => zeros(4), - (MOI.VectorOfVariables, MOI.PositiveSemidefiniteConeTriangle) => - [zeros(6), zeros(6)], - (MOI.VectorAffineFunction{Float64}, MOI.Zeros) => [zeros(2), zeros(2)], - (MOI.VectorOfVariables, MOI.RotatedSecondOrderCone) => - [zeros(3), zeros(3)], - ) -end -function optimize_cached!(mock) +function optimize!(mock) return MOI.Utilities.mock_optimize!( mock, vals, @@ -60,6 +38,6 @@ function optimize_cached!(mock) [zeros(3), zeros(3)], ) end -for mock in [bridged_mock(optimize_bridged!), cached_mock(optimize_cached!)] +for mock in mocks(optimize!) Tests.sos_concave_then_convex_cubic_test(mock, config) end diff --git a/test/Mock/mock_tests.jl b/test/Mock/mock_tests.jl index 7b0079df..704fdae3 100644 --- a/test/Mock/mock_tests.jl +++ b/test/Mock/mock_tests.jl @@ -6,15 +6,15 @@ using Test, JuMP @testset "Term" begin include("term.jl") end -#@testset "Term fixed" begin -# include("term_fixed.jl") -#end -#@testset "Quartic constant" begin -# include("quartic_constant.jl") -#end -#@testset "Quadratic" begin -# include("quadratic.jl") -#end +@testset "Term fixed" begin + include("term_fixed.jl") +end +@testset "Quartic constant" begin + include("quartic_constant.jl") +end +@testset "Quadratic" begin + include("quadratic.jl") +end @testset "Quartic ideal" begin include("quartic_ideal.jl") end @@ -42,18 +42,18 @@ end @testset "Motzkin" begin include("motzkin.jl") end -#@testset "BPT12e399" begin -# include("BPT12e399.jl") -#end +@testset "BPT12e399" begin + include("BPT12e399.jl") +end @testset "Max Cut" begin include("maxcut.jl") end @testset "Chebyshev" begin include("chebyshev.jl") end -#@testset "Quartic comparison" begin -# include("quartic_comparison.jl") -#end +@testset "Quartic comparison" begin + include("quartic_comparison.jl") +end @testset "SOSDEMO5" begin include("sosdemo5.jl") end diff --git a/test/Mock/quadratic.jl b/test/Mock/quadratic.jl index 97bce3f4..8d927551 100644 --- a/test/Mock/quadratic.jl +++ b/test/Mock/quadratic.jl @@ -1,5 +1,5 @@ -config = MOI.Test.Config() -function optimize_bridged!(mock) +config = MOI.Test.Config(atol = 1e-6) +function optimize!(mock) return MOI.Utilities.mock_optimize!( mock, [2.0, 1.0, 1.0, √2], @@ -8,40 +8,40 @@ function optimize_bridged!(mock) (MOI.VectorAffineFunction{Float64}, MOI.Zeros) => [[1.0, -1.0, 1.0]], ) end -function optimize_cached!(mock) - return MOI.Utilities.mock_optimize!( - mock, - [1.0, 1.0, √2, 2.0], - (MOI.VectorOfVariables, MOI.RotatedSecondOrderCone) => - [[1.0, 1.0, -√2]], - (MOI.VectorAffineFunction{Float64}, MOI.Zeros) => [[1.0, -1.0, 1.0]], - ) -end -for mock in [bridged_mock(optimize_bridged!), cached_mock(optimize_cached!)] +for mock in mocks(optimize!) Tests.sos_univariate_quadratic_test(mock, config) Tests.sos_bivariate_quadratic_test(mock, config) Tests.sdsos_univariate_quadratic_test(mock, config) Tests.sdsos_bivariate_quadratic_test(mock, config) Tests.sos_scaled_univariate_quadratic_test(mock, config) - Tests.sos_scaled_bivariate_quadratic_test(mock, config) Tests.sdsos_scaled_univariate_quadratic_test(mock, config) - Tests.sdsos_scaled_bivariate_quadratic_test(mock, config) Tests.sos_cheby_univariate_quadratic_test(mock, config) Tests.sdsos_cheby_univariate_quadratic_test(mock, config) end +function optimize!(mock) + return MOI.Utilities.mock_optimize!( + mock, + [2.0, 1.0, 1.0, √2], + (MOI.VectorOfVariables, MOI.RotatedSecondOrderCone) => + [[1.0, 1.0, -√2]], + (MOI.VectorAffineFunction{Float64}, MOI.Zeros) => [[1.0, -√2, 1.0]], + ) +end +for mock in mocks(optimize!) + Tests.sos_scaled_bivariate_quadratic_test(mock, config) + Tests.sdsos_scaled_bivariate_quadratic_test(mock, config) +end function optimize!(mock) return MOI.Utilities.mock_optimize!( mock, [2.0, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0], - ( - MOI.VectorOfVariables, - MOI.MathOptInterface.PositiveSemidefiniteConeTriangle, - ) => [[0.0, 0.0, 1.0, 0.0, -1.0, 1.0]], + (MOI.VectorOfVariables, MOI.PositiveSemidefiniteConeTriangle) => + [[0.0, 0.0, 1.0, 0.0, -1.0, 1.0]], (MOI.VectorAffineFunction{Float64}, MOI.Zeros) => [[0.0, 0.0, 0.0, 2.0, -1.0, 2.0]], ) end -for mock in [bridged_mock(optimize!), cached_mock(optimize!)] +for mock in mocks(optimize!) Tests.sos_cheby_bivariate_quadratic_test(mock, config) end function optimize!(mock) @@ -54,7 +54,7 @@ function optimize!(mock) [[0.0, 0.0, 0.0, 2.0, -1.0, 2.0]], ) end -for mock in [bridged_mock(optimize!), cached_mock(optimize!)] +for mock in mocks(optimize!) Tests.sdsos_cheby_bivariate_quadratic_test(mock, config) end function optimize!(mock) @@ -70,7 +70,48 @@ for mock in mocks(optimize!) Tests.dsos_univariate_quadratic_test(mock, config) Tests.dsos_bivariate_quadratic_test(mock, config) Tests.dsos_scaled_univariate_quadratic_test(mock, config) - Tests.dsos_scaled_bivariate_quadratic_test(mock, config) Tests.dsos_cheby_univariate_quadratic_test(mock, config) +end +function optimize!(mock) + return MOI.Utilities.mock_optimize!( + mock, + (MOI.FEASIBLE_POINT, [2.0, 1.0, 1.0, 1.0, 1.0]), + (MOI.ScalarAffineFunction{Float64}, MOI.GreaterThan{Float64}) => + [0.0, 2.0, 1.0, 1.0], + (MOI.VectorAffineFunction{Float64}, MOI.Zeros) => [[1.0, -√2, 1.0]], + ) +end +for mock in mocks(optimize!) + Tests.dsos_scaled_bivariate_quadratic_test(mock, config) +end +function optimize!(mock) + return MOI.Utilities.mock_optimize!( + mock, + ( + MOI.FEASIBLE_POINT, + [2.0, 0.0, 0.0, 1.0, -0.0, 1.0, 1.0, 0.0, 0.0, 1.0], + ), + (MOI.ScalarAffineFunction{Float64}, MOI.GreaterThan{Float64}) => [ + 0.7624324421943409, + 0.7624324421943427, + 0.7624324421943439, + 0.7624324421943471, + 0.0, + 2.0, + 0.5248650317582692, + 1.0, + 1.0, + ], + (MOI.VectorAffineFunction{Float64}, MOI.Zeros) => [[ + 0.5248650317582707, + 0.0, + 0.0, + 1.4751346735031994, + -1.0, + 1.4751346735032143, + ]], + ) +end +for mock in mocks(optimize!) Tests.dsos_cheby_bivariate_quadratic_test(mock, config) end diff --git a/test/Mock/quartic_comparison.jl b/test/Mock/quartic_comparison.jl index 720bf6d4..b2a25641 100644 --- a/test/Mock/quartic_comparison.jl +++ b/test/Mock/quartic_comparison.jl @@ -1,33 +1,21 @@ config = MOI.Test.Config() # The test does not check the solution except the first variable so we just set zeros. -function optimize_bridged!(mock) +function optimize!(mock) return MOI.Utilities.mock_optimize!( mock, [-0.184667; zeros(MOI.get(mock, MOI.NumberOfVariables()) - 1)], ) end -function optimize_cached!(mock) - return MOI.Utilities.mock_optimize!( - mock, - [zeros(MOI.get(mock, MOI.NumberOfVariables()) - 1); -0.184667], - ) -end -for mock in [bridged_mock(optimize_bridged!), cached_mock(optimize_cached!)] +for mock in [bridged_mock(optimize!)] Tests.sos_quartic_comparison_test(mock, config) end -function optimize_bridged!(mock) +function optimize!(mock) return MOI.Utilities.mock_optimize!( mock, [-3.172412; zeros(MOI.get(mock, MOI.NumberOfVariables()) - 1)], ) end -function optimize_cached!(mock) - return MOI.Utilities.mock_optimize!( - mock, - [zeros(MOI.get(mock, MOI.NumberOfVariables()) - 1); -3.172412], - ) -end -for mock in [bridged_mock(optimize_bridged!), cached_mock(optimize_cached!)] +for mock in mocks(optimize!) Tests.sdsos_quartic_comparison_test(mock, config) end function optimize!(mock) diff --git a/test/Mock/quartic_constant.jl b/test/Mock/quartic_constant.jl index cc8f6a3c..4775db53 100644 --- a/test/Mock/quartic_constant.jl +++ b/test/Mock/quartic_constant.jl @@ -1,7 +1,6 @@ config = MOI.Test.Config() -optimize_bridged!(mock) = MOI.Utilities.mock_optimize!(mock, [4.0, 1.0]) -optimize_cached!(mock) = MOI.Utilities.mock_optimize!(mock, [1.0, 4.0]) -for mock in [bridged_mock(optimize_bridged!), cached_mock(optimize_cached!)] +optimize!(mock) = MOI.Utilities.mock_optimize!(mock, [4.0, 1.0]) +for mock in mocks(optimize!) Tests.dsos_quartic_constant_test(mock, config) Tests.sdsos_quartic_constant_test(mock, config) Tests.sos_quartic_constant_test(mock, config) diff --git a/test/Mock/term_fixed.jl b/test/Mock/term_fixed.jl index ae1e9753..f53735af 100644 --- a/test/Mock/term_fixed.jl +++ b/test/Mock/term_fixed.jl @@ -1,5 +1,5 @@ config = MOI.Test.Config() -function optimize_bridged!(mock) +function optimize!(mock) return MOI.Utilities.mock_optimize!( mock, [1.0, 0.0], @@ -7,15 +7,7 @@ function optimize_bridged!(mock) (MOI.VectorAffineFunction{Float64}, MOI.Zeros) => [[1.0]], ) end -function optimize_cached!(mock) - return MOI.Utilities.mock_optimize!( - mock, - [0.0, 1.0], - (MOI.VectorAffineFunction{Float64}, MOI.Nonnegatives) => [[1.0]], - (MOI.VectorAffineFunction{Float64}, MOI.Zeros) => [[1.0]], - ) -end -for mock in [bridged_mock(optimize_bridged!), cached_mock(optimize_cached!)] +for mock in mocks(optimize!) Tests.sos_term_fixed_test(mock, config) Tests.sdsos_term_fixed_test(mock, config) Tests.dsos_term_fixed_test(mock, config) diff --git a/test/Tests/utilities.jl b/test/Tests/utilities.jl index a3786c97..f6179a5d 100644 --- a/test/Tests/utilities.jl +++ b/test/Tests/utilities.jl @@ -116,15 +116,16 @@ function inner_variable_value(model, atol = 1e-4) MOI.VariablePrimal(), MOI.get(inner, MOI.ListOfVariableIndices()), ) - println("optimize!(mock) = MOI.Utilities.mock_optimize!(mock,") - println(JuMP.termination_status(model)) + println("function optimize!(mock)") + println(" return MOI.Utilities.mock_optimize!(mock,") + println(" ", JuMP.termination_status(model), ",") if JuMP.primal_status(model) != MOI.NO_SOLUTION values = MOI.get( inner, MOI.VariablePrimal(), MOI.get(inner, MOI.ListOfVariableIndices()), ) - print("(MOI.FEASIBLE_POINT, [") + print(" (MOI.FEASIBLE_POINT, [") for (i, v) in enumerate(values) if i > 1 print(", ") @@ -138,7 +139,7 @@ function inner_variable_value(model, atol = 1e-4) println(",") if JuMP.dual_status(model) != MOI.NO_SOLUTION for (F, S) in MOI.get(inner, MOI.ListOfConstraintTypesPresent()) - print("($F, $S) => [") + print(" ($F, $S) => [") first = true for ci in MOI.get(inner, MOI.ListOfConstraintIndices{F,S}()) if !first @@ -150,7 +151,9 @@ function inner_variable_value(model, atol = 1e-4) println("],") end end - return println(")") + println(" )") + println("end") + return end # Constraint dual values for inner bridged model function inner_inspect(model, atol = 1e-4)