From d50789d2762fbe30a213a60efe0d5c0a8dbed549 Mon Sep 17 00:00:00 2001 From: odow Date: Tue, 23 Nov 2021 09:55:29 +1300 Subject: [PATCH 1/2] [Test] add generic number types in test_constraint --- src/Test/test_constraint.jl | 477 ++++++++++++++++++------------------ test/Test/Test.jl | 3 +- 2 files changed, 245 insertions(+), 235 deletions(-) diff --git a/src/Test/test_constraint.jl b/src/Test/test_constraint.jl index 57cca1aa75..fe5d006a2b 100644 --- a/src/Test/test_constraint.jl +++ b/src/Test/test_constraint.jl @@ -1,31 +1,30 @@ """ - test_constraint_get_ConstraintIndex(model::MOI.ModelLike, config::Config) + test_constraint_get_ConstraintIndex( + model::MOI.ModelLike, + config::Config{T}, + ) where {T} Test getting constraints by name. """ -function test_constraint_get_ConstraintIndex(model::MOI.ModelLike, ::Config) - MOIU.loadfromstring!( - model, - """ - variables: x - minobjective: 2.0x - c1: 1.0 * x >= 1.0 - c2: 1.0 * x <= 2.0 -""", - ) - F = MOI.ScalarAffineFunction{Float64} +function test_constraint_get_ConstraintIndex( + model::MOI.ModelLike, + ::Config{T}, +) where {T} + x = MOI.add_variable(model) + c1 = MOI.add_constraint(model, T(1) * x, MOI.GreaterThan(T(1))) + MOI.set(model, MOI.ConstraintName(), c1, "c1") + c2 = MOI.add_constraint(model, T(1) * x, MOI.LessThan(T(2))) + MOI.set(model, MOI.ConstraintName(), c2, "c2") + F = MOI.ScalarAffineFunction{T} @test MOI.get(model, MOI.ConstraintIndex, "c3") === nothing - @test MOI.get(model, MOI.ConstraintIndex{F,MOI.LessThan{Float64}}, "c1") === + @test MOI.get(model, MOI.ConstraintIndex{F,MOI.LessThan{T}}, "c1") === nothing - @test MOI.get( - model, - MOI.ConstraintIndex{F,MOI.GreaterThan{Float64}}, - "c2", - ) === nothing - c1 = MOI.get(model, MOI.ConstraintIndex{F,MOI.GreaterThan{Float64}}, "c1") + @test MOI.get(model, MOI.ConstraintIndex{F,MOI.GreaterThan{T}}, "c2") === + nothing + c1 = MOI.get(model, MOI.ConstraintIndex{F,MOI.GreaterThan{T}}, "c1") @test MOI.get(model, MOI.ConstraintIndex, "c1") == c1 @test MOI.is_valid(model, c1) - c2 = MOI.get(model, MOI.ConstraintIndex{F,MOI.LessThan{Float64}}, "c2") + c2 = MOI.get(model, MOI.ConstraintIndex{F,MOI.LessThan{T}}, "c2") @test MOI.get(model, MOI.ConstraintIndex, "c2") == c2 @test MOI.is_valid(model, c2) return @@ -41,32 +40,32 @@ Add an ScalarAffineFunction-in-LessThan constraint. """ function test_constraint_ScalarAffineFunction_LessThan( model::MOI.ModelLike, - config::Config, -) + config::Config{T}, +) where {T} @requires MOI.supports_constraint( model, - MOI.ScalarAffineFunction{Float64}, - MOI.LessThan{Float64}, + MOI.ScalarAffineFunction{T}, + MOI.LessThan{T}, ) x = MOI.add_variable(model) c = MOI.add_constraint( model, - MOI.ScalarAffineFunction([MOI.ScalarAffineTerm(2.0, x)], 0.0), - MOI.LessThan(1.0), + MOI.ScalarAffineFunction([MOI.ScalarAffineTerm(T(2), x)], T(0)), + MOI.LessThan(T(1)), ) MOI.set(model, MOI.ObjectiveSense(), MOI.MAX_SENSE) MOI.set( model, - MOI.ObjectiveFunction{MOI.ScalarAffineFunction{Float64}}(), - MOI.ScalarAffineFunction([MOI.ScalarAffineTerm(1.0, x)], 0.0), + MOI.ObjectiveFunction{MOI.ScalarAffineFunction{T}}(), + MOI.ScalarAffineFunction([MOI.ScalarAffineTerm(T(1), x)], T(0)), ) _test_model_solution( model, config; - objective_value = 0.5, - variable_primal = [(x, 0.5)], - constraint_primal = [(c, 1.0)], - constraint_dual = [(c, -0.5)], + objective_value = T(1 // 2), + variable_primal = [(x, T(1 // 2))], + constraint_primal = [(c, T(1))], + constraint_dual = [(c, T(-1 // 2))], ) return end @@ -74,17 +73,16 @@ end function setup_test( ::typeof(test_constraint_ScalarAffineFunction_LessThan), model::MOIU.MockOptimizer, - ::Config, -) + ::Config{T}, +) where {T} MOIU.set_mock_optimize!( model, (mock::MOIU.MockOptimizer) -> MOIU.mock_optimize!( mock, MOI.OPTIMAL, - (MOI.FEASIBLE_POINT, [0.5]), + (MOI.FEASIBLE_POINT, T[1//2]), MOI.FEASIBLE_POINT, - (MOI.ScalarAffineFunction{Float64}, MOI.LessThan{Float64}) => - [-0.5], + (MOI.ScalarAffineFunction{T}, MOI.LessThan{T}) => T[-1//2], ), ) return @@ -100,32 +98,32 @@ Add an ScalarAffineFunction-in-GreaterThan constraint. """ function test_constraint_ScalarAffineFunction_GreaterThan( model::MOI.ModelLike, - config::Config, -) + config::Config{T}, +) where {T} @requires MOI.supports_constraint( model, - MOI.ScalarAffineFunction{Float64}, - MOI.GreaterThan{Float64}, + MOI.ScalarAffineFunction{T}, + MOI.GreaterThan{T}, ) x = MOI.add_variable(model) c = MOI.add_constraint( model, - MOI.ScalarAffineFunction([MOI.ScalarAffineTerm(2.0, x)], 0.0), - MOI.GreaterThan(1.0), + MOI.ScalarAffineFunction([MOI.ScalarAffineTerm(T(2), x)], T(0)), + MOI.GreaterThan(T(1)), ) MOI.set(model, MOI.ObjectiveSense(), MOI.MIN_SENSE) MOI.set( model, - MOI.ObjectiveFunction{MOI.ScalarAffineFunction{Float64}}(), - MOI.ScalarAffineFunction([MOI.ScalarAffineTerm(1.0, x)], 0.0), + MOI.ObjectiveFunction{MOI.ScalarAffineFunction{T}}(), + MOI.ScalarAffineFunction([MOI.ScalarAffineTerm(T(1), x)], T(0)), ) _test_model_solution( model, config; - objective_value = 0.5, - variable_primal = [(x, 0.5)], - constraint_primal = [(c, 1.0)], - constraint_dual = [(c, 0.5)], + objective_value = T(1 // 2), + variable_primal = [(x, T(1 // 2))], + constraint_primal = [(c, T(1))], + constraint_dual = [(c, T(1 // 2))], ) return end @@ -133,17 +131,16 @@ end function setup_test( ::typeof(test_constraint_ScalarAffineFunction_GreaterThan), model::MOIU.MockOptimizer, - ::Config, -) + ::Config{T}, +) where {T} MOIU.set_mock_optimize!( model, (mock::MOIU.MockOptimizer) -> MOIU.mock_optimize!( mock, MOI.OPTIMAL, - (MOI.FEASIBLE_POINT, [0.5]), + (MOI.FEASIBLE_POINT, T[1//2]), MOI.FEASIBLE_POINT, - (MOI.ScalarAffineFunction{Float64}, MOI.GreaterThan{Float64}) => - [0.5], + (MOI.ScalarAffineFunction{T}, MOI.GreaterThan{T}) => T[1//2], ), ) return @@ -159,32 +156,32 @@ Add an ScalarAffineFunction-in-EqualTo constraint. """ function test_constraint_ScalarAffineFunction_EqualTo( model::MOI.ModelLike, - config::Config, -) + config::Config{T}, +) where {T} @requires MOI.supports_constraint( model, - MOI.ScalarAffineFunction{Float64}, - MOI.EqualTo{Float64}, + MOI.ScalarAffineFunction{T}, + MOI.EqualTo{T}, ) x = MOI.add_variable(model) c = MOI.add_constraint( model, - MOI.ScalarAffineFunction([MOI.ScalarAffineTerm(2.0, x)], 0.0), - MOI.EqualTo(1.0), + MOI.ScalarAffineFunction([MOI.ScalarAffineTerm(T(2), x)], T(0)), + MOI.EqualTo(T(1)), ) MOI.set(model, MOI.ObjectiveSense(), MOI.MIN_SENSE) MOI.set( model, - MOI.ObjectiveFunction{MOI.ScalarAffineFunction{Float64}}(), - MOI.ScalarAffineFunction([MOI.ScalarAffineTerm(1.0, x)], 0.0), + MOI.ObjectiveFunction{MOI.ScalarAffineFunction{T}}(), + MOI.ScalarAffineFunction([MOI.ScalarAffineTerm(T(1), x)], T(0)), ) _test_model_solution( model, config; - objective_value = 0.5, - variable_primal = [(x, 0.5)], - constraint_primal = [(c, 1.0)], - constraint_dual = [(c, 0.5)], + objective_value = T(1 // 2), + variable_primal = [(x, T(1 // 2))], + constraint_primal = [(c, T(1))], + constraint_dual = [(c, T(1 // 2))], ) return end @@ -192,17 +189,16 @@ end function setup_test( ::typeof(test_constraint_ScalarAffineFunction_EqualTo), model::MOIU.MockOptimizer, - ::Config, -) + ::Config{T}, +) where {T} MOIU.set_mock_optimize!( model, (mock::MOIU.MockOptimizer) -> MOIU.mock_optimize!( mock, MOI.OPTIMAL, - (MOI.FEASIBLE_POINT, [0.5]), + (MOI.FEASIBLE_POINT, T[1//2]), MOI.FEASIBLE_POINT, - (MOI.ScalarAffineFunction{Float64}, MOI.EqualTo{Float64}) => - [0.5], + (MOI.ScalarAffineFunction{T}, MOI.EqualTo{T}) => T[1//2], ), ) return @@ -218,32 +214,32 @@ Add an ScalarAffineFunction-in-Interval constraint. """ function test_constraint_ScalarAffineFunction_Interval( model::MOI.ModelLike, - config::Config, -) + config::Config{T}, +) where {T} @requires MOI.supports_constraint( model, - MOI.ScalarAffineFunction{Float64}, - MOI.Interval{Float64}, + MOI.ScalarAffineFunction{T}, + MOI.Interval{T}, ) x = MOI.add_variable(model) c = MOI.add_constraint( model, - MOI.ScalarAffineFunction([MOI.ScalarAffineTerm(2.0, x)], 0.0), - MOI.Interval(1.0, 4.0), + MOI.ScalarAffineFunction([MOI.ScalarAffineTerm(T(2), x)], T(0)), + MOI.Interval(T(1), T(4)), ) MOI.set(model, MOI.ObjectiveSense(), MOI.MAX_SENSE) MOI.set( model, - MOI.ObjectiveFunction{MOI.ScalarAffineFunction{Float64}}(), - MOI.ScalarAffineFunction([MOI.ScalarAffineTerm(3.0, x)], 0.0), + MOI.ObjectiveFunction{MOI.ScalarAffineFunction{T}}(), + MOI.ScalarAffineFunction([MOI.ScalarAffineTerm(T(3), x)], T(0)), ) _test_model_solution( model, config; - objective_value = 6.0, - variable_primal = [(x, 2.0)], - constraint_primal = [(c, 4.0)], - constraint_dual = [(c, -1.5)], + objective_value = T(6), + variable_primal = [(x, T(2))], + constraint_primal = [(c, T(4))], + constraint_dual = [(c, T(-3 // 2))], ) return end @@ -251,17 +247,16 @@ end function setup_test( ::typeof(test_constraint_ScalarAffineFunction_Interval), model::MOIU.MockOptimizer, - ::Config, -) + ::Config{T}, +) where {T} MOIU.set_mock_optimize!( model, (mock::MOIU.MockOptimizer) -> MOIU.mock_optimize!( mock, MOI.OPTIMAL, - (MOI.FEASIBLE_POINT, [2.0]), + (MOI.FEASIBLE_POINT, T[2]), MOI.FEASIBLE_POINT, - (MOI.ScalarAffineFunction{Float64}, MOI.Interval{Float64}) => - [-1.5], + (MOI.ScalarAffineFunction{T}, MOI.Interval{T}) => T[-3//2], ), ) return @@ -280,26 +275,26 @@ Taken from https://github.com/JuliaOpt/MathOptInterfaceMosek.jl/issues/41 """ function test_constraint_ScalarAffineFunction_duplicate( model::MOI.ModelLike, - config::Config, -) + config::Config{T}, +) where {T} x = MOI.add_variable(model) objective_function = - MOI.ScalarAffineFunction([MOI.ScalarAffineTerm(1.0, x)], 0.0) + MOI.ScalarAffineFunction([MOI.ScalarAffineTerm(T(1), x)], T(0)) MOI.set( model, MOI.ObjectiveFunction{typeof(objective_function)}(), objective_function, ) MOI.set(model, MOI.ObjectiveSense(), MOI.MAX_SENSE) - f = MOI.ScalarAffineFunction(MOI.ScalarAffineTerm.([1.0, 1.0], [x, x]), 0.0) - c = MOI.add_constraint(model, f, MOI.LessThan(1.0)) + f = MOI.ScalarAffineFunction(MOI.ScalarAffineTerm.(T(1), [x, x]), T(0)) + c = MOI.add_constraint(model, f, MOI.LessThan(T(1))) _test_model_solution( model, config; - objective_value = 0.5, - variable_primal = [(x, 0.5)], - constraint_primal = [(c, 1.0)], - constraint_dual = [(c, -0.5)], + objective_value = T(1 // 2), + variable_primal = [(x, T(1 // 2))], + constraint_primal = [(c, T(1))], + constraint_dual = [(c, T(-1 // 2))], ) return end @@ -307,17 +302,16 @@ end function setup_test( ::typeof(test_constraint_ScalarAffineFunction_duplicate), model::MOIU.MockOptimizer, - ::Config, -) + ::Config{T}, +) where {T} MOIU.set_mock_optimize!( model, (mock::MOIU.MockOptimizer) -> MOIU.mock_optimize!( mock, MOI.OPTIMAL, - (MOI.FEASIBLE_POINT, [0.5]), + (MOI.FEASIBLE_POINT, T[1//2]), MOI.FEASIBLE_POINT, - (MOI.ScalarAffineFunction{Float64}, MOI.LessThan{Float64}) => - [-0.5], + (MOI.ScalarAffineFunction{T}, MOI.LessThan{T}) => T[-1//2], ), ) return @@ -334,11 +328,11 @@ in the function. """ function test_constraint_VectorAffineFunction_duplicate( model::MOI.ModelLike, - config::Config, -) + config::Config{T}, +) where {T} x = MOI.add_variable(model) objective_function = - MOI.ScalarAffineFunction([MOI.ScalarAffineTerm(1.0, x)], 0.0) + MOI.ScalarAffineFunction([MOI.ScalarAffineTerm(T(1), x)], T(0)) MOI.set( model, MOI.ObjectiveFunction{typeof(objective_function)}(), @@ -346,17 +340,17 @@ function test_constraint_VectorAffineFunction_duplicate( ) MOI.set(model, MOI.ObjectiveSense(), MOI.MAX_SENSE) f = MOI.VectorAffineFunction( - MOI.VectorAffineTerm.(1, MOI.ScalarAffineTerm.([1.0, 1.0], [x, x])), - [-1.0], + MOI.VectorAffineTerm.(1, MOI.ScalarAffineTerm.(T(1), [x, x])), + T[-1], ) c = MOI.add_constraint(model, f, MOI.Nonpositives(1)) _test_model_solution( model, config; - objective_value = 0.5, - variable_primal = [(x, 0.5)], - constraint_primal = [(c, [0.0])], - constraint_dual = [(c, [-0.5])], + objective_value = T(1 // 2), + variable_primal = [(x, T(1 // 2))], + constraint_primal = [(c, T[0])], + constraint_dual = [(c, T[-1//2])], ) return end @@ -364,24 +358,26 @@ end function setup_test( ::typeof(test_constraint_VectorAffineFunction_duplicate), model::MOIU.MockOptimizer, - ::Config, -) + ::Config{T}, +) where {T} MOIU.set_mock_optimize!( model, (mock::MOIU.MockOptimizer) -> MOIU.mock_optimize!( mock, MOI.OPTIMAL, - (MOI.FEASIBLE_POINT, [0.5]), + (MOI.FEASIBLE_POINT, T[1//2]), MOI.FEASIBLE_POINT, - (MOI.VectorAffineFunction{Float64}, MOI.Nonpositives) => - [[-0.5]], + (MOI.VectorAffineFunction{T}, MOI.Nonpositives) => [T[-1//2]], ), ) return end """ - test_constraint_qcp_duplicate_diagonal(model::MOI.ModelLike, config::Config) + test_constraint_qcp_duplicate_diagonal( + model::MOI.ModelLike, + config::Config{T}, + ) where {T} Test a QCP problem with a duplicate diagonal term. @@ -389,40 +385,40 @@ The problem is `max x + 2y | y + x^2 + x^2 <= 1, x >= 0.5, y >= 0.5`. """ function test_constraint_qcp_duplicate_diagonal( model::MOI.ModelLike, - config::Config, -) + config::Config{T}, +) where {T} @requires MOI.supports_constraint( model, - MOI.ScalarQuadraticFunction{Float64}, - MOI.LessThan{Float64}, + MOI.ScalarQuadraticFunction{T}, + MOI.LessThan{T}, ) x = MOI.add_variables(model, 2) MOI.set(model, MOI.ObjectiveSense(), MOI.MAX_SENSE) MOI.set( model, - MOI.ObjectiveFunction{MOI.ScalarAffineFunction{Float64}}(), - MOI.ScalarAffineFunction(MOI.ScalarAffineTerm.([1.0, 2.0], x), 0.0), + MOI.ObjectiveFunction{MOI.ScalarAffineFunction{T}}(), + MOI.ScalarAffineFunction(MOI.ScalarAffineTerm.(T[1, 2], x), T(0)), ) - vc1 = MOI.add_constraint(model, x[1], MOI.GreaterThan(0.5)) + vc1 = MOI.add_constraint(model, x[1], MOI.GreaterThan(T(1 // 2))) # We test this after the creation of every `VariableIndex` constraint # to ensure a good coverage of corner cases. @test vc1.value == x[1].value - vc2 = MOI.add_constraint(model, x[2], MOI.GreaterThan(0.5)) + vc2 = MOI.add_constraint(model, x[2], MOI.GreaterThan(T(1 // 2))) @test vc2.value == x[2].value MOI.add_constraint( model, MOI.ScalarQuadraticFunction( - MOI.ScalarQuadraticTerm.([2.0, 2.0], [x[1], x[1]], [x[1], x[1]]), # quad - MOI.ScalarAffineTerm.([1.0], [x[2]]), # affine terms - 0.0, # constant + MOI.ScalarQuadraticTerm.(T(2), [x[1], x[1]], [x[1], x[1]]), # quad + MOI.ScalarAffineTerm.(T(1), [x[2]]), # affine terms + T(0), # constant ), - MOI.LessThan(1.0), + MOI.LessThan(T(1)), ) _test_model_solution( model, config; - objective_value = 1.5, - variable_primal = [(x[1], 0.5), (x[2], 0.5)], + objective_value = T(3 // 2), + variable_primal = [(x[1], T(1 // 2)), (x[2], T(1 // 2))], ) return end @@ -430,65 +426,73 @@ end function setup_test( ::typeof(test_constraint_qcp_duplicate_diagonal), model::MOIU.MockOptimizer, - ::Config, -) + ::Config{T}, +) where {T} MOIU.set_mock_optimize!( model, (mock::MOIU.MockOptimizer) -> MOIU.mock_optimize!( mock, MOI.OPTIMAL, - (MOI.FEASIBLE_POINT, [0.5, 0.5]), + (MOI.FEASIBLE_POINT, T[1//2, 1//2]), ), ) return end """ - test_constraint_qcp_duplicate_off_diagonal(model::MOI.ModelLike, config::Config) + test_constraint_qcp_duplicate_off_diagonal( + model::MOI.ModelLike, + config::Config{T}, + ) where {T} Test a QCP problem with a duplicate off-diagonal term. The problem is `max x + 2y | x^2 + 0.25y*x + 0.25x*y + 0.5x*y + y^2 <= 1, x >= 0.5, y >= 0.5`. + +!!! warn + This problem has an irrational solution! Solvers using rational arithmetic + should exclude it. """ function test_constraint_qcp_duplicate_off_diagonal( model::MOI.ModelLike, - config::Config, -) + config::Config{T}, +) where {T} @requires MOI.supports_constraint( model, - MOI.ScalarQuadraticFunction{Float64}, - MOI.LessThan{Float64}, + MOI.ScalarQuadraticFunction{T}, + MOI.LessThan{T}, ) x = MOI.add_variables(model, 2) MOI.set(model, MOI.ObjectiveSense(), MOI.MAX_SENSE) MOI.set( model, - MOI.ObjectiveFunction{MOI.ScalarAffineFunction{Float64}}(), - MOI.ScalarAffineFunction(MOI.ScalarAffineTerm.([1.0, 2.0], x), 0.0), + MOI.ObjectiveFunction{MOI.ScalarAffineFunction{T}}(), + MOI.ScalarAffineFunction(MOI.ScalarAffineTerm.(T[1, 2], x), T(0)), ) - vc1 = MOI.add_constraint(model, x[1], MOI.GreaterThan{Float64}(0.5)) + vc1 = MOI.add_constraint(model, x[1], MOI.GreaterThan{T}(T(1 // 2))) @test vc1.value == x[1].value - vc2 = MOI.add_constraint(model, x[2], MOI.GreaterThan{Float64}(0.5)) + vc2 = MOI.add_constraint(model, x[2], MOI.GreaterThan{T}(T(1 // 2))) @test vc2.value == x[2].value MOI.add_constraint( model, MOI.ScalarQuadraticFunction( MOI.ScalarQuadraticTerm.( - [2.0, 0.25, 0.25, 0.5, 2.0], + T[2, 1//4, 1//4, 1//2, 2], [x[1], x[1], x[2], x[1], x[2]], [x[1], x[2], x[1], x[2], x[2]], ), # quad - MOI.ScalarAffineTerm{Float64}[], # affine terms - 0.0, # constant + MOI.ScalarAffineTerm{T}[], # affine terms + T(0), # constant ), - MOI.LessThan(1.0), + MOI.LessThan(T(1)), ) + x2_solution = (sqrt(T(13)) - T(1)) / T(4) _test_model_solution( model, config; - objective_value = 0.5 + (√13 - 1) / 2, - variable_primal = [(x[1], 0.5), (x[2], (√13 - 1) / 4)], + objective_value = T(1 // 2) + T(2) * x2_solution, + variable_primal = [(x[1], T(1 // 2)), (x[2], x2_solution)], ) return end @@ -496,42 +500,44 @@ end function setup_test( ::typeof(test_constraint_qcp_duplicate_off_diagonal), model::MOIU.MockOptimizer, - ::Config, -) + ::Config{T}, +) where {T} MOIU.set_mock_optimize!( model, (mock::MOIU.MockOptimizer) -> MOIU.mock_optimize!( mock, MOI.OPTIMAL, - (MOI.FEASIBLE_POINT, [0.5, (√13 - 1) / 4]), + (MOI.FEASIBLE_POINT, T[1//2, (sqrt(T(13))-T(1))/T(4)]), ), ) return end """ - test_constraint_ZeroOne_bounds(model::MOI.ModelLike, config::Config) + test_constraint_ZeroOne_bounds( + model::MOI.ModelLike, + config::Config{T}, + ) where {T} Test a problem with a bounded ZeroOne variable. """ -function test_constraint_ZeroOne_bounds(model::MOI.ModelLike, config::Config) +function test_constraint_ZeroOne_bounds( + model::MOI.ModelLike, + config::Config{T}, +) where {T} @requires MOI.supports_constraint(model, MOI.VariableIndex, MOI.ZeroOne) - MOIU.loadfromstring!( - model, - """ - variables: x - maxobjective: 2.0x - x in ZeroOne() - x >= 0.0 - x <= 1.0 -""", - ) - x = MOI.get(model, MOI.VariableIndex, "x") + x = MOI.add_variable(model) + MOI.add_constraint(model, x, MOI.ZeroOne()) + MOI.add_constraint(model, x, MOI.GreaterThan(T(0))) + MOI.add_constraint(model, x, MOI.LessThan(T(1))) + MOI.set(model, MOI.ObjectiveSense(), MOI.MAX_SENSE) + f = T(2) * x + MOI.set(model, MOI.ObjectiveFunction{typeof(f)}(), f) _test_model_solution( model, config; - objective_value = 2.0, - variable_primal = [(x, 1.0)], + objective_value = T(2), + variable_primal = [(x, T(1))], ) return end @@ -539,39 +545,41 @@ end function setup_test( ::typeof(test_constraint_ZeroOne_bounds), model::MOIU.MockOptimizer, - ::Config, -) + ::Config{T}, +) where {T} MOIU.set_mock_optimize!( model, (mock::MOIU.MockOptimizer) -> - MOIU.mock_optimize!(mock, MOI.OPTIMAL, (MOI.FEASIBLE_POINT, [1.0])), + MOIU.mock_optimize!(mock, MOI.OPTIMAL, (MOI.FEASIBLE_POINT, T[1])), ) return end """ - test_constraint_ZeroOne_bounds_2(model::MOI.ModelLike, config::Config) + test_constraint_ZeroOne_bounds_2( + model::MOI.ModelLike, + config::Config{T}, + ) where {T} Test a problem with a ZeroOne and binding fractional upper bound. """ -function test_constraint_ZeroOne_bounds_2(model::MOI.ModelLike, config::Config) +function test_constraint_ZeroOne_bounds_2( + model::MOI.ModelLike, + config::Config{T}, +) where {T} @requires MOI.supports_constraint(model, MOI.VariableIndex, MOI.ZeroOne) - MOIU.loadfromstring!( - model, - """ - variables: x - maxobjective: 2.0x - x in ZeroOne() - x >= 0.0 - x <= 0.5 -""", - ) - x = MOI.get(model, MOI.VariableIndex, "x") + x = MOI.add_variable(model) + MOI.add_constraint(model, x, MOI.ZeroOne()) + MOI.add_constraint(model, x, MOI.GreaterThan(T(0))) + MOI.add_constraint(model, x, MOI.LessThan(T(1 // 2))) + MOI.set(model, MOI.ObjectiveSense(), MOI.MAX_SENSE) + f = T(2) * x + MOI.set(model, MOI.ObjectiveFunction{typeof(f)}(), f) _test_model_solution( model, config; - objective_value = 0.0, - variable_primal = [(x, 0.0)], + objective_value = T(0), + variable_primal = [(x, T(0))], ) return end @@ -579,35 +587,37 @@ end function setup_test( ::typeof(test_constraint_ZeroOne_bounds_2), model::MOIU.MockOptimizer, - ::Config, -) + ::Config{T}, +) where {T} MOIU.set_mock_optimize!( model, (mock::MOIU.MockOptimizer) -> - MOIU.mock_optimize!(mock, MOI.OPTIMAL, (MOI.FEASIBLE_POINT, [0.0])), + MOIU.mock_optimize!(mock, MOI.OPTIMAL, (MOI.FEASIBLE_POINT, T[0])), ) return end """ - test_constraint_ZeroOne_bounds_3(model::MOI.ModelLike, config::Config) + test_constraint_ZeroOne_bounds_3( + model::MOI.ModelLike, + config::Config{T}, + ) where {T} Test a problem with a ZeroOne and infeasible fractional bounds. """ -function test_constraint_ZeroOne_bounds_3(model::MOI.ModelLike, config::Config) +function test_constraint_ZeroOne_bounds_3( + model::MOI.ModelLike, + config::Config{T}, +) where {T} @requires MOI.supports_constraint(model, MOI.VariableIndex, MOI.ZeroOne) @requires _supports(config, MOI.optimize!) - MOIU.loadfromstring!( - model, - """ - variables: x - maxobjective: 2.0x - x in ZeroOne() - x >= 0.2 - x <= 0.5 -""", - ) - x = MOI.get(model, MOI.VariableIndex, "x") + x = MOI.add_variable(model) + MOI.add_constraint(model, x, MOI.ZeroOne()) + MOI.add_constraint(model, x, MOI.GreaterThan(T(1 // 5))) + MOI.add_constraint(model, x, MOI.LessThan(T(1 // 2))) + MOI.set(model, MOI.ObjectiveSense(), MOI.MAX_SENSE) + f = T(2) * x + MOI.set(model, MOI.ObjectiveFunction{typeof(f)}(), f) MOI.optimize!(model) @test MOI.get(model, MOI.TerminationStatus()) == config.infeasible_status return @@ -616,8 +626,8 @@ end function setup_test( ::typeof(test_constraint_ZeroOne_bounds_3), model::MOIU.MockOptimizer, - ::Config, -) + ::Config{T}, +) where {T} MOIU.set_mock_optimize!( model, (mock::MOIU.MockOptimizer) -> MOIU.mock_optimize!(mock, MOI.INFEASIBLE), @@ -646,10 +656,9 @@ function test_constraint_PrimalStart_DualStart_SecondOrderCone( ) @requires _supports(config, MOI.optimize!) x = MOI.add_variable(model) - o = one(T) c = MOI.add_constraint( model, - MOIU.operate(vcat, T, x, o), + MOIU.operate(vcat, T, x, T(1)), MOI.SecondOrderCone(2), ) MOI.set(model, MOI.ObjectiveSense(), MOI.MIN_SENSE) @@ -666,10 +675,10 @@ function test_constraint_PrimalStart_DualStart_SecondOrderCone( _test_model_solution( model, config; - objective_value = o, - variable_primal = [(x, o)], - constraint_primal = [(c, [o, o])], - constraint_dual = [(c, [o, -o])], + objective_value = T(1), + variable_primal = [(x, T(1))], + constraint_primal = [(c, T[1, 1])], + constraint_dual = [(c, T[1, -1])], ) return end @@ -677,17 +686,17 @@ end function setup_test( ::typeof(test_constraint_PrimalStart_DualStart_SecondOrderCone), model::MOIU.MockOptimizer, - ::Config, -) + ::Config{T}, +) where {T} MOIU.set_mock_optimize!( model, (mock::MOIU.MockOptimizer) -> MOIU.mock_optimize!( mock, MOI.OPTIMAL, - (MOI.FEASIBLE_POINT, [1.0]), + (MOI.FEASIBLE_POINT, T[1]), MOI.FEASIBLE_POINT, - (MOI.VectorAffineFunction{Float64}, MOI.SecondOrderCone) => - [[1.0, -1.0]], + (MOI.VectorAffineFunction{T}, MOI.SecondOrderCone) => + [T[1, -1]], ), ) return @@ -717,13 +726,13 @@ function test_constraint_ConstraintPrimalStart( ) x = MOI.add_variable(model) f = MOI.VectorAffineFunction( - [MOI.VectorAffineTerm(1, MOI.ScalarAffineTerm(one(T), x))], - [0.0], + [MOI.VectorAffineTerm(1, MOI.ScalarAffineTerm(T(1), x))], + T[0], ) c = MOI.add_constraint(model, f, MOI.Nonnegatives(1)) @test MOI.get(model, MOI.ConstraintPrimalStart(), c) === nothing - MOI.set(model, MOI.ConstraintPrimalStart(), c, [-one(T)]) - @test MOI.get(model, MOI.ConstraintPrimalStart(), c) == [-one(T)] + MOI.set(model, MOI.ConstraintPrimalStart(), c, T[-1]) + @test MOI.get(model, MOI.ConstraintPrimalStart(), c) == T[-1] MOI.set(model, MOI.ConstraintPrimalStart(), c, nothing) @test MOI.get(model, MOI.ConstraintPrimalStart(), c) === nothing return @@ -753,13 +762,13 @@ function test_constraint_ConstraintDualStart( ) x = MOI.add_variable(model) f = MOI.VectorAffineFunction( - [MOI.VectorAffineTerm(1, MOI.ScalarAffineTerm(one(T), x))], - [0.0], + [MOI.VectorAffineTerm(1, MOI.ScalarAffineTerm(T(1), x))], + T[0], ) c = MOI.add_constraint(model, f, MOI.Nonnegatives(1)) @test MOI.get(model, MOI.ConstraintDualStart(), c) === nothing - MOI.set(model, MOI.ConstraintDualStart(), c, [-one(T)]) - @test MOI.get(model, MOI.ConstraintDualStart(), c) == [-one(T)] + MOI.set(model, MOI.ConstraintDualStart(), c, T[-1]) + @test MOI.get(model, MOI.ConstraintDualStart(), c) == T[-1] MOI.set(model, MOI.ConstraintDualStart(), c, nothing) @test MOI.get(model, MOI.ConstraintDualStart(), c) === nothing return @@ -788,12 +797,12 @@ function test_constraint_Indicator_ConstraintName( MOI.add_constraint(model, x[1], MOI.ZeroOne()) f = MOI.VectorAffineFunction( [ - MOI.VectorAffineTerm(1, MOI.ScalarAffineTerm(1.0, x[1])), - MOI.VectorAffineTerm(2, MOI.ScalarAffineTerm(2.0, x[2])), + MOI.VectorAffineTerm(1, MOI.ScalarAffineTerm(T(1), x[1])), + MOI.VectorAffineTerm(2, MOI.ScalarAffineTerm(T(2), x[2])), ], - [0.0, 0.0], + T[0, 0], ) - s = MOI.Indicator{MOI.ACTIVATE_ON_ONE}(MOI.GreaterThan(1.0)) + s = MOI.Indicator{MOI.ACTIVATE_ON_ONE}(MOI.GreaterThan(T(1))) c = MOI.add_constraint(model, f, s) MOI.set(model, MOI.ConstraintName(), c, "my_indicator") @test MOI.get(model, MOI.ConstraintName(), c) == "my_indicator" @@ -823,12 +832,12 @@ function test_constraint_Indicator_ACTIVATE_ON_ONE( MOI.add_constraint(model, x[1], MOI.ZeroOne()) f = MOI.VectorAffineFunction( [ - MOI.VectorAffineTerm(1, MOI.ScalarAffineTerm(1.0, x[1])), - MOI.VectorAffineTerm(2, MOI.ScalarAffineTerm(2.0, x[2])), + MOI.VectorAffineTerm(1, MOI.ScalarAffineTerm(T(1), x[1])), + MOI.VectorAffineTerm(2, MOI.ScalarAffineTerm(T(2), x[2])), ], - [0.0, 0.0], + T[0, 0], ) - s = MOI.Indicator{MOI.ACTIVATE_ON_ONE}(MOI.GreaterThan(1.0)) + s = MOI.Indicator{MOI.ACTIVATE_ON_ONE}(MOI.GreaterThan(T(1))) c = MOI.add_constraint(model, f, s) @test MOI.get(model, MOI.ConstraintSet(), c) == s @test isapprox(MOI.get(model, MOI.ConstraintFunction(), c), f) @@ -858,12 +867,12 @@ function test_constraint_Indicator_ACTIVATE_ON_ZERO( MOI.add_constraint(model, x[1], MOI.ZeroOne()) f = MOI.VectorAffineFunction( [ - MOI.VectorAffineTerm(1, MOI.ScalarAffineTerm(1.0, x[1])), - MOI.VectorAffineTerm(2, MOI.ScalarAffineTerm(2.0, x[2])), + MOI.VectorAffineTerm(1, MOI.ScalarAffineTerm(T(1), x[1])), + MOI.VectorAffineTerm(2, MOI.ScalarAffineTerm(T(2), x[2])), ], - [0.0, 0.0], + T[0, 0], ) - s = MOI.Indicator{MOI.ACTIVATE_ON_ZERO}(MOI.GreaterThan(1.0)) + s = MOI.Indicator{MOI.ACTIVATE_ON_ZERO}(MOI.GreaterThan(T(1))) c = MOI.add_constraint(model, f, s) @test MOI.get(model, MOI.ConstraintSet(), c) == s @test isapprox(MOI.get(model, MOI.ConstraintFunction(), c), f) diff --git a/test/Test/Test.jl b/test/Test/Test.jl index 4b37d84b24..8ba5c4e1e1 100644 --- a/test/Test/Test.jl +++ b/test/Test/Test.jl @@ -58,8 +58,9 @@ MOI.Test.runtests( MOI.Utilities.UniversalFallback(MOI.Utilities.Model{BigFloat}()), ), MOI.Test.Config(BigFloat), - include = ["test_linear_"], + include = ["test_constraint_", "test_linear_"], exclude = String[ + "test_constraint_qcp_duplicate_off_diagonal", "test_linear_VectorAffineFunction_empty_row", "test_linear_add_constraints", "test_linear_integer_integration", From 131f6ea5a943adba0b4e887861b5095ca99c4f7f Mon Sep 17 00:00:00 2001 From: odow Date: Tue, 23 Nov 2021 10:05:08 +1300 Subject: [PATCH 2/2] Add test_variable --- src/Test/test_variable.jl | 139 +++++++++++++++++++------------------- test/Test/Test.jl | 2 +- 2 files changed, 72 insertions(+), 69 deletions(-) diff --git a/src/Test/test_variable.jl b/src/Test/test_variable.jl index b074868cb9..986ecba3db 100644 --- a/src/Test/test_variable.jl +++ b/src/Test/test_variable.jl @@ -143,7 +143,7 @@ end Test getting variables by name. """ -function test_variable_get_VariableIndex(model::MOI.ModelLike, config::Config) +function test_variable_get_VariableIndex(model::MOI.ModelLike, ::Config) @requires MOI.supports(model, MOI.VariableName(), MOI.VariableIndex) variable = MOI.add_variable(model) MOI.set(model, MOI.VariableName(), variable, "x") @@ -179,23 +179,23 @@ Test setting the upper bound of a variable, confirm that it solves correctly. """ function test_variable_solve_with_upperbound( model::MOI.ModelLike, - config::Config, -) + config::Config{T}, +) where {T} x = MOI.add_variable(model) - c1 = MOI.add_constraint(model, x, MOI.LessThan(1.0)) + c1 = MOI.add_constraint(model, x, MOI.LessThan(T(1))) @test x.value == c1.value - c2 = MOI.add_constraint(model, x, MOI.GreaterThan(0.0)) + c2 = MOI.add_constraint(model, x, MOI.GreaterThan(T(0))) @test x.value == c2.value - f = MOI.ScalarAffineFunction([MOI.ScalarAffineTerm(2.0, x)], 0.0) + f = MOI.ScalarAffineFunction([MOI.ScalarAffineTerm(T(2), x)], T(0)) MOI.set(model, MOI.ObjectiveFunction{typeof(f)}(), f) MOI.set(model, MOI.ObjectiveSense(), MOI.MAX_SENSE) _test_model_solution( model, config; - objective_value = 2.0, - variable_primal = [(x, 1.0)], - constraint_primal = [(c1, 1.0), (c2, 1.0)], - constraint_dual = [(c1, -2.0), (c2, 0.0)], + objective_value = T(2), + variable_primal = [(x, T(1))], + constraint_primal = [(c1, T(1)), (c2, T(1))], + constraint_dual = [(c1, T(-2)), (c2, T(0))], ) return end @@ -203,17 +203,17 @@ end function setup_test( ::typeof(test_variable_solve_with_upperbound), model::MOIU.MockOptimizer, - ::Config, -) + ::Config{T}, +) where {T} MOIU.set_mock_optimize!( model, (mock::MOIU.MockOptimizer) -> MOIU.mock_optimize!( mock, MOI.OPTIMAL, - (MOI.FEASIBLE_POINT, [1]), + (MOI.FEASIBLE_POINT, T[1]), MOI.FEASIBLE_POINT, - (MOI.VariableIndex, MOI.LessThan{Float64}) => [-2.0], - (MOI.VariableIndex, MOI.GreaterThan{Float64}) => [0.0], + (MOI.VariableIndex, MOI.LessThan{T}) => T[-2], + (MOI.VariableIndex, MOI.GreaterThan{T}) => T[0], ), ) model.eval_variable_constraint_dual = false @@ -227,21 +227,21 @@ Test setting the lower bound of a variable, confirm that it solves correctly. """ function test_variable_solve_with_lowerbound( model::MOI.ModelLike, - config::Config, -) + config::Config{T}, +) where {T} x = MOI.add_variable(model) - c1 = MOI.add_constraint(model, x, MOI.GreaterThan(1.0)) - c2 = MOI.add_constraint(model, x, MOI.LessThan(2.0)) - f = MOI.ScalarAffineFunction([MOI.ScalarAffineTerm(2.0, x)], 0.0) + c1 = MOI.add_constraint(model, x, MOI.GreaterThan(T(1))) + c2 = MOI.add_constraint(model, x, MOI.LessThan(T(2))) + f = MOI.ScalarAffineFunction([MOI.ScalarAffineTerm(T(2), x)], T(0)) MOI.set(model, MOI.ObjectiveFunction{typeof(f)}(), f) MOI.set(model, MOI.ObjectiveSense(), MOI.MIN_SENSE) _test_model_solution( model, config; - objective_value = 2.0, - variable_primal = [(x, 1.0)], - constraint_primal = [(c1, 1.0), (c2, 1.0)], - constraint_dual = [(c1, 2.0), (c2, 0.0)], + objective_value = T(2), + variable_primal = [(x, T(1))], + constraint_primal = [(c1, T(1)), (c2, T(1))], + constraint_dual = [(c1, T(2)), (c2, T(0))], ) return end @@ -249,17 +249,17 @@ end function setup_test( ::typeof(test_variable_solve_with_lowerbound), model::MOIU.MockOptimizer, - ::Config, -) + ::Config{T}, +) where {T} MOIU.set_mock_optimize!( model, (mock::MOIU.MockOptimizer) -> MOIU.mock_optimize!( mock, MOI.OPTIMAL, - (MOI.FEASIBLE_POINT, [1]), + (MOI.FEASIBLE_POINT, T[1]), MOI.FEASIBLE_POINT, - (MOI.VariableIndex, MOI.GreaterThan{Float64}) => [2.0], - (MOI.VariableIndex, MOI.LessThan{Float64}) => [0.0], + (MOI.VariableIndex, MOI.GreaterThan{T}) => T[2], + (MOI.VariableIndex, MOI.LessThan{T}) => T[0], ), ) model.eval_variable_constraint_dual = false @@ -276,19 +276,19 @@ Test an integer variable with fractional lower bound. """ function test_variable_solve_Integer_with_lower_bound( model::MOI.ModelLike, - config::Config, -) + config::Config{T}, +) where {T} x = MOI.add_variable(model) - MOI.add_constraint(model, x, MOI.GreaterThan(1.5)) - f = MOI.ScalarAffineFunction([MOI.ScalarAffineTerm(2.0, x)], 0.0) + MOI.add_constraint(model, x, MOI.GreaterThan(T(3 // 2))) + f = MOI.ScalarAffineFunction([MOI.ScalarAffineTerm(T(2), x)], T(0)) MOI.add_constraint(model, x, MOI.Integer()) MOI.set(model, MOI.ObjectiveFunction{typeof(f)}(), f) MOI.set(model, MOI.ObjectiveSense(), MOI.MIN_SENSE) _test_model_solution( model, config; - objective_value = 4.0, - variable_primal = [(x, 2.0)], + objective_value = T(4), + variable_primal = [(x, T(2))], ) return end @@ -296,12 +296,12 @@ end function setup_test( ::typeof(test_variable_solve_Integer_with_lower_bound), model::MOIU.MockOptimizer, - ::Config, -) + ::Config{T}, +) where {T} MOIU.set_mock_optimize!( model, (mock::MOIU.MockOptimizer) -> - MOIU.mock_optimize!(mock, MOI.OPTIMAL, (MOI.FEASIBLE_POINT, [2.0])), + MOIU.mock_optimize!(mock, MOI.OPTIMAL, (MOI.FEASIBLE_POINT, T[2])), ) return end @@ -316,19 +316,19 @@ Test an integer variable with fractional upper bound. """ function test_variable_solve_Integer_with_upper_bound( model::MOI.ModelLike, - config::Config, -) + config::Config{T}, +) where {T} x = MOI.add_variable(model) - MOI.add_constraint(model, x, MOI.LessThan(1.5)) - f = MOI.ScalarAffineFunction([MOI.ScalarAffineTerm(-2.0, x)], 0.0) + MOI.add_constraint(model, x, MOI.LessThan(T(3 // 2))) + f = MOI.ScalarAffineFunction([MOI.ScalarAffineTerm(T(-2), x)], T(0)) MOI.add_constraint(model, x, MOI.Integer()) MOI.set(model, MOI.ObjectiveFunction{typeof(f)}(), f) MOI.set(model, MOI.ObjectiveSense(), MOI.MIN_SENSE) _test_model_solution( model, config; - objective_value = -2.0, - variable_primal = [(x, 1.0)], + objective_value = T(-2), + variable_primal = [(x, T(1))], ) return end @@ -336,12 +336,12 @@ end function setup_test( ::typeof(test_variable_solve_Integer_with_upper_bound), model::MOIU.MockOptimizer, - ::Config, -) + ::Config{T}, +) where {T} MOIU.set_mock_optimize!( model, (mock::MOIU.MockOptimizer) -> - MOIU.mock_optimize!(mock, MOI.OPTIMAL, (MOI.FEASIBLE_POINT, [1.0])), + MOIU.mock_optimize!(mock, MOI.OPTIMAL, (MOI.FEASIBLE_POINT, T[1])), ) return end @@ -356,19 +356,19 @@ Test a binary variable `<= 2`. """ function test_variable_solve_ZeroOne_with_upper_bound( model::MOI.ModelLike, - config::Config, -) + config::Config{T}, +) where {T} x = MOI.add_variable(model) - MOI.add_constraint(model, x, MOI.LessThan(2.0)) - f = MOI.ScalarAffineFunction([MOI.ScalarAffineTerm(-2.0, x)], 0.0) + MOI.add_constraint(model, x, MOI.LessThan(T(2))) + f = MOI.ScalarAffineFunction([MOI.ScalarAffineTerm(T(-2), x)], T(0)) MOI.add_constraint(model, x, MOI.ZeroOne()) MOI.set(model, MOI.ObjectiveFunction{typeof(f)}(), f) MOI.set(model, MOI.ObjectiveSense(), MOI.MIN_SENSE) _test_model_solution( model, config; - objective_value = -2.0, - variable_primal = [(x, 1.0)], + objective_value = T(-2), + variable_primal = [(x, T(1))], ) return end @@ -376,12 +376,12 @@ end function setup_test( ::typeof(test_variable_solve_ZeroOne_with_upper_bound), model::MOIU.MockOptimizer, - ::Config, -) + ::Config{T}, +) where {T} MOIU.set_mock_optimize!( model, (mock::MOIU.MockOptimizer) -> - MOIU.mock_optimize!(mock, MOI.OPTIMAL, (MOI.FEASIBLE_POINT, [1.0])), + MOIU.mock_optimize!(mock, MOI.OPTIMAL, (MOI.FEASIBLE_POINT, T[1])), ) return end @@ -396,19 +396,19 @@ Test a binary variable `<= 0`. """ function test_variable_solve_ZeroOne_with_0_upper_bound( model::MOI.ModelLike, - config::Config, -) + config::Config{T}, +) where {T} x = MOI.add_variable(model) - MOI.add_constraint(model, x, MOI.LessThan(0.0)) - f = MOI.ScalarAffineFunction([MOI.ScalarAffineTerm(1.0, x)], 0.0) + MOI.add_constraint(model, x, MOI.LessThan(T(0))) + f = MOI.ScalarAffineFunction([MOI.ScalarAffineTerm(T(1), x)], T(0)) MOI.add_constraint(model, x, MOI.ZeroOne()) MOI.set(model, MOI.ObjectiveFunction{typeof(f)}(), f) MOI.set(model, MOI.ObjectiveSense(), MOI.MIN_SENSE) _test_model_solution( model, config; - objective_value = 0.0, - variable_primal = [(x, 0.0)], + objective_value = T(0), + variable_primal = [(x, T(0))], ) return end @@ -416,12 +416,12 @@ end function setup_test( ::typeof(test_variable_solve_ZeroOne_with_0_upper_bound), model::MOIU.MockOptimizer, - ::Config, -) + ::Config{T}, +) where {T} MOIU.set_mock_optimize!( model, (mock::MOIU.MockOptimizer) -> - MOIU.mock_optimize!(mock, MOI.OPTIMAL, (MOI.FEASIBLE_POINT, [0.0])), + MOIU.mock_optimize!(mock, MOI.OPTIMAL, (MOI.FEASIBLE_POINT, T[0])), ) return end @@ -431,12 +431,15 @@ end Test VariablePrimalStart """ -function test_model_VariablePrimalStart(model::MOI.ModelLike, ::Config) +function test_model_VariablePrimalStart( + model::MOI.ModelLike, + ::Config{T}, +) where {T} @requires MOI.supports(model, MOI.VariablePrimalStart(), MOI.VariableIndex) x = MOI.add_variable(model) @test MOI.get(model, MOI.VariablePrimalStart(), x) === nothing - MOI.set(model, MOI.VariablePrimalStart(), x, 1.0) - @test MOI.get(model, MOI.VariablePrimalStart(), x) == 1.0 + MOI.set(model, MOI.VariablePrimalStart(), x, T(1)) + @test MOI.get(model, MOI.VariablePrimalStart(), x) == T(1) MOI.set(model, MOI.VariablePrimalStart(), x, nothing) @test MOI.get(model, MOI.VariablePrimalStart(), x) === nothing return diff --git a/test/Test/Test.jl b/test/Test/Test.jl index 8ba5c4e1e1..8697cebf36 100644 --- a/test/Test/Test.jl +++ b/test/Test/Test.jl @@ -58,7 +58,7 @@ MOI.Test.runtests( MOI.Utilities.UniversalFallback(MOI.Utilities.Model{BigFloat}()), ), MOI.Test.Config(BigFloat), - include = ["test_constraint_", "test_linear_"], + include = ["test_constraint_", "test_linear_", "test_variable"], exclude = String[ "test_constraint_qcp_duplicate_off_diagonal", "test_linear_VectorAffineFunction_empty_row",