diff --git a/src/Test/config.jl b/src/Test/config.jl index c8f6b044ac..d47b6ad87e 100644 --- a/src/Test/config.jl +++ b/src/Test/config.jl @@ -2,6 +2,7 @@ struct TestConfig{T<:Real} atol::T # absolute tolerance for ... rtol::T # relative tolerance for ... solve::Bool # optimize and test result + query_number_of_constraints::Bool # can get `MOI.NumberOfConstraints` attribute query::Bool # can get objective function, and constraint functions, and constraint sets modify_lhs::Bool # can modify function of a constraint duals::Bool # test dual solutions @@ -15,6 +16,7 @@ struct TestConfig{T<:Real} atol::Real = Base.rtoldefault(T), rtol::Real = Base.rtoldefault(T), solve::Bool = true, + query_number_of_constraints::Bool = true, query::Bool = true, modify_lhs::Bool = true, duals::Bool = true, @@ -27,6 +29,7 @@ struct TestConfig{T<:Real} atol, rtol, solve, + query_number_of_constraints, query, modify_lhs, duals, diff --git a/src/Test/contconic.jl b/src/Test/contconic.jl index 60e77cadea..30c4ca9a1b 100644 --- a/src/Test/contconic.jl +++ b/src/Test/contconic.jl @@ -64,18 +64,23 @@ function _lin1test(model::MOI.ModelLike, config::TestConfig, vecofvars::Bool) ), MOI.Zeros(2), ) - @test MOI.get( - model, - MOI.NumberOfConstraints{ - vecofvars ? MOI.VectorOfVariables : - MOI.VectorAffineFunction{Float64}, - MOI.Nonnegatives, - }(), - ) == 1 - @test MOI.get( - model, - MOI.NumberOfConstraints{MOI.VectorAffineFunction{Float64},MOI.Zeros}(), - ) == 1 + if config.query_number_of_constraints + @test MOI.get( + model, + MOI.NumberOfConstraints{ + vecofvars ? MOI.VectorOfVariables : + MOI.VectorAffineFunction{Float64}, + MOI.Nonnegatives, + }(), + ) == 1 + @test MOI.get( + model, + MOI.NumberOfConstraints{ + MOI.VectorAffineFunction{Float64}, + MOI.Zeros, + }(), + ) == 1 + end loc = MOI.get(model, MOI.ListOfConstraintTypesPresent()) @test length(loc) == 2 @test ( @@ -257,26 +262,31 @@ function _lin2test(model::MOI.ModelLike, config::TestConfig, vecofvars::Bool) ) end - @test MOI.get( - model, - MOI.NumberOfConstraints{MOI.VectorAffineFunction{Float64},MOI.Zeros}(), - ) == 2 - vecofvars - @test MOI.get( - model, - MOI.NumberOfConstraints{ - vecofvars ? MOI.VectorOfVariables : - MOI.VectorAffineFunction{Float64}, - MOI.Nonpositives, - }(), - ) == 1 - @test MOI.get( - model, - MOI.NumberOfConstraints{ - vecofvars ? MOI.VectorOfVariables : - MOI.VectorAffineFunction{Float64}, - MOI.Nonnegatives, - }(), - ) == 1 + if config.query_number_of_constraints + @test MOI.get( + model, + MOI.NumberOfConstraints{ + MOI.VectorAffineFunction{Float64}, + MOI.Zeros, + }(), + ) == 2 - vecofvars + @test MOI.get( + model, + MOI.NumberOfConstraints{ + vecofvars ? MOI.VectorOfVariables : + MOI.VectorAffineFunction{Float64}, + MOI.Nonpositives, + }(), + ) == 1 + @test MOI.get( + model, + MOI.NumberOfConstraints{ + vecofvars ? MOI.VectorOfVariables : + MOI.VectorAffineFunction{Float64}, + MOI.Nonnegatives, + }(), + ) == 1 + end if config.solve @test MOI.get(model, MOI.TerminationStatus()) == MOI.OPTIMIZE_NOT_CALLED @@ -385,20 +395,22 @@ function lin3test(model::MOI.ModelLike, config::TestConfig) MOI.Nonpositives(1), ) - @test MOI.get( - model, - MOI.NumberOfConstraints{ - MOI.VectorAffineFunction{Float64}, - MOI.Nonnegatives, - }(), - ) == 1 - @test MOI.get( - model, - MOI.NumberOfConstraints{ - MOI.VectorAffineFunction{Float64}, - MOI.Nonpositives, - }(), - ) == 1 + if config.query_number_of_constraints + @test MOI.get( + model, + MOI.NumberOfConstraints{ + MOI.VectorAffineFunction{Float64}, + MOI.Nonnegatives, + }(), + ) == 1 + @test MOI.get( + model, + MOI.NumberOfConstraints{ + MOI.VectorAffineFunction{Float64}, + MOI.Nonpositives, + }(), + ) == 1 + end if config.solve @test MOI.get(model, MOI.TerminationStatus()) == MOI.OPTIMIZE_NOT_CALLED @@ -464,17 +476,19 @@ function lin4test(model::MOI.ModelLike, config::TestConfig) MOI.Nonnegatives(1), ) - @test MOI.get( - model, - MOI.NumberOfConstraints{ - MOI.VectorAffineFunction{Float64}, - MOI.Nonnegatives, - }(), - ) == 1 - @test MOI.get( - model, - MOI.NumberOfConstraints{MOI.VectorOfVariables,MOI.Nonpositives}(), - ) == 1 + if config.query_number_of_constraints + @test MOI.get( + model, + MOI.NumberOfConstraints{ + MOI.VectorAffineFunction{Float64}, + MOI.Nonnegatives, + }(), + ) == 1 + @test MOI.get( + model, + MOI.NumberOfConstraints{MOI.VectorOfVariables,MOI.Nonpositives}(), + ) == 1 + end if config.solve @test MOI.get(model, MOI.TerminationStatus()) == MOI.OPTIMIZE_NOT_CALLED @@ -587,18 +601,23 @@ function _norminf1test( ) end - @test MOI.get( - model, - MOI.NumberOfConstraints{MOI.VectorAffineFunction{Float64},MOI.Zeros}(), - ) == 2 - @test MOI.get( - model, - MOI.NumberOfConstraints{ - vecofvars ? MOI.VectorOfVariables : - MOI.VectorAffineFunction{Float64}, - MOI.NormInfinityCone, - }(), - ) == 1 + if config.query_number_of_constraints + @test MOI.get( + model, + MOI.NumberOfConstraints{ + MOI.VectorAffineFunction{Float64}, + MOI.Zeros, + }(), + ) == 2 + @test MOI.get( + model, + MOI.NumberOfConstraints{ + vecofvars ? MOI.VectorOfVariables : + MOI.VectorAffineFunction{Float64}, + MOI.NormInfinityCone, + }(), + ) == 1 + end loc = MOI.get(model, MOI.ListOfConstraintTypesPresent()) @test length(loc) == 2 @test (MOI.VectorAffineFunction{Float64}, MOI.Zeros) in loc @@ -723,27 +742,29 @@ function norminf2test(model::MOI.ModelLike, config::TestConfig) MOI.NormInfinityCone(2), ) - @test MOI.get( - model, - MOI.NumberOfConstraints{ - MOI.VectorAffineFunction{Float64}, - MOI.Nonnegatives, - }(), - ) == 1 - @test MOI.get( - model, - MOI.NumberOfConstraints{ - MOI.VectorAffineFunction{Float64}, - MOI.Nonpositives, - }(), - ) == 1 - @test MOI.get( - model, - MOI.NumberOfConstraints{ - MOI.VectorAffineFunction{Float64}, - MOI.NormInfinityCone, - }(), - ) == 1 + if config.query_number_of_constraints + @test MOI.get( + model, + MOI.NumberOfConstraints{ + MOI.VectorAffineFunction{Float64}, + MOI.Nonnegatives, + }(), + ) == 1 + @test MOI.get( + model, + MOI.NumberOfConstraints{ + MOI.VectorAffineFunction{Float64}, + MOI.Nonpositives, + }(), + ) == 1 + @test MOI.get( + model, + MOI.NumberOfConstraints{ + MOI.VectorAffineFunction{Float64}, + MOI.NormInfinityCone, + }(), + ) == 1 + end if config.solve @test MOI.get(model, MOI.TerminationStatus()) == MOI.OPTIMIZE_NOT_CALLED @@ -805,20 +826,22 @@ function norminf3test(model::MOI.ModelLike, config::TestConfig) ) nonneg = MOI.add_constraint(model, nonneg_vaf, MOI.Nonnegatives(3)) - @test MOI.get( - model, - MOI.NumberOfConstraints{ - MOI.VectorAffineFunction{Float64}, - MOI.NormInfinityCone, - }(), - ) == 1 - @test MOI.get( - model, - MOI.NumberOfConstraints{ - MOI.VectorAffineFunction{Float64}, - MOI.Nonnegatives, - }(), - ) == 1 + if config.query_number_of_constraints + @test MOI.get( + model, + MOI.NumberOfConstraints{ + MOI.VectorAffineFunction{Float64}, + MOI.NormInfinityCone, + }(), + ) == 1 + @test MOI.get( + model, + MOI.NumberOfConstraints{ + MOI.VectorAffineFunction{Float64}, + MOI.Nonnegatives, + }(), + ) == 1 + end loc = MOI.get(model, MOI.ListOfConstraintTypesPresent()) @test length(loc) == 2 @test (MOI.VectorAffineFunction{Float64}, MOI.NormInfinityCone) in loc @@ -943,18 +966,23 @@ function _normone1test( ) end - @test MOI.get( - model, - MOI.NumberOfConstraints{MOI.VectorAffineFunction{Float64},MOI.Zeros}(), - ) == 2 - @test MOI.get( - model, - MOI.NumberOfConstraints{ - vecofvars ? MOI.VectorOfVariables : - MOI.VectorAffineFunction{Float64}, - MOI.NormOneCone, - }(), - ) == 1 + if config.query_number_of_constraints + @test MOI.get( + model, + MOI.NumberOfConstraints{ + MOI.VectorAffineFunction{Float64}, + MOI.Zeros, + }(), + ) == 2 + @test MOI.get( + model, + MOI.NumberOfConstraints{ + vecofvars ? MOI.VectorOfVariables : + MOI.VectorAffineFunction{Float64}, + MOI.NormOneCone, + }(), + ) == 1 + end loc = MOI.get(model, MOI.ListOfConstraintTypesPresent()) @test length(loc) == 2 @test (MOI.VectorAffineFunction{Float64}, MOI.Zeros) in loc @@ -1079,27 +1107,29 @@ function normone2test(model::MOI.ModelLike, config::TestConfig) MOI.NormOneCone(2), ) - @test MOI.get( - model, - MOI.NumberOfConstraints{ - MOI.VectorAffineFunction{Float64}, - MOI.Nonnegatives, - }(), - ) == 1 - @test MOI.get( - model, - MOI.NumberOfConstraints{ - MOI.VectorAffineFunction{Float64}, - MOI.Nonpositives, - }(), - ) == 1 - @test MOI.get( - model, - MOI.NumberOfConstraints{ - MOI.VectorAffineFunction{Float64}, - MOI.NormOneCone, - }(), - ) == 1 + if config.query_number_of_constraints + @test MOI.get( + model, + MOI.NumberOfConstraints{ + MOI.VectorAffineFunction{Float64}, + MOI.Nonnegatives, + }(), + ) == 1 + @test MOI.get( + model, + MOI.NumberOfConstraints{ + MOI.VectorAffineFunction{Float64}, + MOI.Nonpositives, + }(), + ) == 1 + @test MOI.get( + model, + MOI.NumberOfConstraints{ + MOI.VectorAffineFunction{Float64}, + MOI.NormOneCone, + }(), + ) == 1 + end if config.solve @test MOI.get(model, MOI.TerminationStatus()) == MOI.OPTIMIZE_NOT_CALLED @@ -1161,20 +1191,22 @@ function normone3test(model::MOI.ModelLike, config::TestConfig) ) nonneg = MOI.add_constraint(model, nonneg_vaf, MOI.Nonnegatives(3)) - @test MOI.get( - model, - MOI.NumberOfConstraints{ - MOI.VectorAffineFunction{Float64}, - MOI.NormOneCone, - }(), - ) == 1 - @test MOI.get( - model, - MOI.NumberOfConstraints{ - MOI.VectorAffineFunction{Float64}, - MOI.Nonnegatives, - }(), - ) == 1 + if config.query_number_of_constraints + @test MOI.get( + model, + MOI.NumberOfConstraints{ + MOI.VectorAffineFunction{Float64}, + MOI.NormOneCone, + }(), + ) == 1 + @test MOI.get( + model, + MOI.NumberOfConstraints{ + MOI.VectorAffineFunction{Float64}, + MOI.Nonnegatives, + }(), + ) == 1 + end loc = MOI.get(model, MOI.ListOfConstraintTypesPresent()) @test length(loc) == 2 @test (MOI.VectorAffineFunction{Float64}, MOI.NormOneCone) in loc @@ -1286,18 +1318,23 @@ function _soc1test(model::MOI.ModelLike, config::TestConfig, vecofvars::Bool) MOI.Zeros(1), ) - @test MOI.get( - model, - MOI.NumberOfConstraints{MOI.VectorAffineFunction{Float64},MOI.Zeros}(), - ) == 1 - @test MOI.get( - model, - MOI.NumberOfConstraints{ - vecofvars ? MOI.VectorOfVariables : - MOI.VectorAffineFunction{Float64}, - MOI.SecondOrderCone, - }(), - ) == 1 + if config.query_number_of_constraints + @test MOI.get( + model, + MOI.NumberOfConstraints{ + MOI.VectorAffineFunction{Float64}, + MOI.Zeros, + }(), + ) == 1 + @test MOI.get( + model, + MOI.NumberOfConstraints{ + vecofvars ? MOI.VectorOfVariables : + MOI.VectorAffineFunction{Float64}, + MOI.SecondOrderCone, + }(), + ) == 1 + end loc = MOI.get(model, MOI.ListOfConstraintTypesPresent()) @test length(loc) == 2 @test (MOI.VectorAffineFunction{Float64}, MOI.Zeros) in loc @@ -1446,24 +1483,29 @@ function _soc2test(model::MOI.ModelLike, config::TestConfig, nonneg::Bool) MOI.SecondOrderCone(3), ) - @test MOI.get( - model, - MOI.NumberOfConstraints{ - MOI.VectorAffineFunction{Float64}, - nonneg ? MOI.Nonnegatives : MOI.Nonpositives, - }(), - ) == 1 - @test MOI.get( - model, - MOI.NumberOfConstraints{MOI.VectorAffineFunction{Float64},MOI.Zeros}(), - ) == 1 - @test MOI.get( - model, - MOI.NumberOfConstraints{ - MOI.VectorAffineFunction{Float64}, - MOI.SecondOrderCone, - }(), - ) == 1 + if config.query_number_of_constraints + @test MOI.get( + model, + MOI.NumberOfConstraints{ + MOI.VectorAffineFunction{Float64}, + nonneg ? MOI.Nonnegatives : MOI.Nonpositives, + }(), + ) == 1 + @test MOI.get( + model, + MOI.NumberOfConstraints{ + MOI.VectorAffineFunction{Float64}, + MOI.Zeros, + }(), + ) == 1 + @test MOI.get( + model, + MOI.NumberOfConstraints{ + MOI.VectorAffineFunction{Float64}, + MOI.SecondOrderCone, + }(), + ) == 1 + end if config.solve @test MOI.get(model, MOI.TerminationStatus()) == MOI.OPTIMIZE_NOT_CALLED @@ -1582,27 +1624,29 @@ function soc3test(model::MOI.ModelLike, config::TestConfig) MOI.SecondOrderCone(2), ) - @test MOI.get( - model, - MOI.NumberOfConstraints{ - MOI.VectorAffineFunction{Float64}, - MOI.Nonnegatives, - }(), - ) == 1 - @test MOI.get( - model, - MOI.NumberOfConstraints{ - MOI.VectorAffineFunction{Float64}, - MOI.Nonpositives, - }(), - ) == 1 - @test MOI.get( - model, - MOI.NumberOfConstraints{ - MOI.VectorAffineFunction{Float64}, - MOI.SecondOrderCone, - }(), - ) == 1 + if config.query_number_of_constraints + @test MOI.get( + model, + MOI.NumberOfConstraints{ + MOI.VectorAffineFunction{Float64}, + MOI.Nonnegatives, + }(), + ) == 1 + @test MOI.get( + model, + MOI.NumberOfConstraints{ + MOI.VectorAffineFunction{Float64}, + MOI.Nonpositives, + }(), + ) == 1 + @test MOI.get( + model, + MOI.NumberOfConstraints{ + MOI.VectorAffineFunction{Float64}, + MOI.SecondOrderCone, + }(), + ) == 1 + end if config.solve @test MOI.get(model, MOI.TerminationStatus()) == MOI.OPTIMIZE_NOT_CALLED @@ -1677,14 +1721,19 @@ function soc4test(model::MOI.ModelLike, config::TestConfig) MOI.SecondOrderCone(3), ) - @test MOI.get( - model, - MOI.NumberOfConstraints{MOI.VectorAffineFunction{Float64},MOI.Zeros}(), - ) == 1 - @test MOI.get( - model, - MOI.NumberOfConstraints{MOI.VectorOfVariables,MOI.SecondOrderCone}(), - ) == 1 + if config.query_number_of_constraints + @test MOI.get( + model, + MOI.NumberOfConstraints{ + MOI.VectorAffineFunction{Float64}, + MOI.Zeros, + }(), + ) == 1 + @test MOI.get( + model, + MOI.NumberOfConstraints{MOI.VectorOfVariables,MOI.SecondOrderCone}(), + ) == 1 + end MOI.set( model, @@ -1815,17 +1864,20 @@ function _rotatedsoc1test( ) end - @test MOI.get( - model, - MOI.NumberOfConstraints{MOI.SingleVariable,MOI.EqualTo{Float64}}(), - ) == (abvars ? 2 : 0) - @test MOI.get( - model, - MOI.NumberOfConstraints{ - abvars ? MOI.VectorOfVariables : MOI.VectorAffineFunction{Float64}, - MOI.RotatedSecondOrderCone, - }(), - ) == 1 + if config.query_number_of_constraints + @test MOI.get( + model, + MOI.NumberOfConstraints{MOI.SingleVariable,MOI.EqualTo{Float64}}(), + ) == (abvars ? 2 : 0) + @test MOI.get( + model, + MOI.NumberOfConstraints{ + abvars ? MOI.VectorOfVariables : + MOI.VectorAffineFunction{Float64}, + MOI.RotatedSecondOrderCone, + }(), + ) == 1 + end MOI.set( model, @@ -1956,25 +2008,30 @@ function rotatedsoc2test(model::MOI.ModelLike, config::TestConfig) ) @test vc3.value == x[3].value - @test MOI.get( - model, - MOI.NumberOfConstraints{MOI.SingleVariable,MOI.LessThan{Float64}}(), - ) == 1 - @test MOI.get( - model, - MOI.NumberOfConstraints{MOI.SingleVariable,MOI.EqualTo{Float64}}(), - ) == 1 - @test MOI.get( - model, - MOI.NumberOfConstraints{MOI.SingleVariable,MOI.GreaterThan{Float64}}(), - ) == 1 - @test MOI.get( - model, - MOI.NumberOfConstraints{ - MOI.VectorOfVariables, - MOI.RotatedSecondOrderCone, - }(), - ) == 1 + if config.query_number_of_constraints + @test MOI.get( + model, + MOI.NumberOfConstraints{MOI.SingleVariable,MOI.LessThan{Float64}}(), + ) == 1 + @test MOI.get( + model, + MOI.NumberOfConstraints{MOI.SingleVariable,MOI.EqualTo{Float64}}(), + ) == 1 + @test MOI.get( + model, + MOI.NumberOfConstraints{ + MOI.SingleVariable, + MOI.GreaterThan{Float64}, + }(), + ) == 1 + @test MOI.get( + model, + MOI.NumberOfConstraints{ + MOI.VectorOfVariables, + MOI.RotatedSecondOrderCone, + }(), + ) == 1 + end MOI.set( model, @@ -2104,33 +2161,41 @@ function rotatedsoc3test( MOI.RotatedSecondOrderCone(3), ) - @test MOI.get( - model, - MOI.NumberOfConstraints{MOI.SingleVariable,MOI.EqualTo{Float64}}(), - ) == 2 - @test MOI.get( - model, - MOI.NumberOfConstraints{MOI.VectorOfVariables,MOI.Nonnegatives}(), - ) == 1 - @test MOI.get( - model, - MOI.NumberOfConstraints{MOI.SingleVariable,MOI.GreaterThan{Float64}}(), - ) == 1 - @test MOI.get( - model, - MOI.NumberOfConstraints{MOI.SingleVariable,MOI.LessThan{Float64}}(), - ) == 1 - @test MOI.get( - model, - MOI.NumberOfConstraints{MOI.SingleVariable,MOI.GreaterThan{Float64}}(), - ) == 1 - @test MOI.get( - model, - MOI.NumberOfConstraints{ - MOI.VectorAffineFunction{Float64}, - MOI.RotatedSecondOrderCone, - }(), - ) == 2 + if config.query_number_of_constraints + @test MOI.get( + model, + MOI.NumberOfConstraints{MOI.SingleVariable,MOI.EqualTo{Float64}}(), + ) == 2 + @test MOI.get( + model, + MOI.NumberOfConstraints{MOI.VectorOfVariables,MOI.Nonnegatives}(), + ) == 1 + @test MOI.get( + model, + MOI.NumberOfConstraints{ + MOI.SingleVariable, + MOI.GreaterThan{Float64}, + }(), + ) == 1 + @test MOI.get( + model, + MOI.NumberOfConstraints{MOI.SingleVariable,MOI.LessThan{Float64}}(), + ) == 1 + @test MOI.get( + model, + MOI.NumberOfConstraints{ + MOI.SingleVariable, + MOI.GreaterThan{Float64}, + }(), + ) == 1 + @test MOI.get( + model, + MOI.NumberOfConstraints{ + MOI.VectorAffineFunction{Float64}, + MOI.RotatedSecondOrderCone, + }(), + ) == 2 + end MOI.set( model, @@ -2382,21 +2447,23 @@ function _geomean1test( MOI.LessThan(Float64(n)), ) - @test MOI.get( - model, - MOI.NumberOfConstraints{ - vecofvars ? MOI.VectorOfVariables : - MOI.VectorAffineFunction{Float64}, - MOI.GeometricMeanCone, - }(), - ) == 1 - @test MOI.get( - model, - MOI.NumberOfConstraints{ - MOI.ScalarAffineFunction{Float64}, - MOI.LessThan{Float64}, - }(), - ) == 1 + if config.query_number_of_constraints + @test MOI.get( + model, + MOI.NumberOfConstraints{ + vecofvars ? MOI.VectorOfVariables : + MOI.VectorAffineFunction{Float64}, + MOI.GeometricMeanCone, + }(), + ) == 1 + @test MOI.get( + model, + MOI.NumberOfConstraints{ + MOI.ScalarAffineFunction{Float64}, + MOI.LessThan{Float64}, + }(), + ) == 1 + end MOI.set( model, @@ -2507,21 +2574,23 @@ function _geomean2test(model::MOI.ModelLike, config::TestConfig, vecofvars) ) end - @test MOI.get( - model, - MOI.NumberOfConstraints{ - vecofvars ? MOI.VectorOfVariables : - MOI.VectorAffineFunction{Float64}, - MOI.GeometricMeanCone, - }(), - ) == 1 - @test MOI.get( - model, - MOI.NumberOfConstraints{ - MOI.ScalarAffineFunction{Float64}, - MOI.EqualTo{Float64}, - }(), - ) == n + if config.query_number_of_constraints + @test MOI.get( + model, + MOI.NumberOfConstraints{ + vecofvars ? MOI.VectorOfVariables : + MOI.VectorAffineFunction{Float64}, + MOI.GeometricMeanCone, + }(), + ) == 1 + @test MOI.get( + model, + MOI.NumberOfConstraints{ + MOI.ScalarAffineFunction{Float64}, + MOI.EqualTo{Float64}, + }(), + ) == n + end MOI.set( model, @@ -2618,21 +2687,23 @@ function _geomean3test(model::MOI.ModelLike, config::TestConfig, vecofvars) MOI.LessThan(2.0), ) - @test MOI.get( - model, - MOI.NumberOfConstraints{ - vecofvars ? MOI.VectorOfVariables : - MOI.VectorAffineFunction{Float64}, - MOI.GeometricMeanCone, - }(), - ) == 1 - @test MOI.get( - model, - MOI.NumberOfConstraints{ - MOI.ScalarAffineFunction{Float64}, - MOI.LessThan{Float64}, - }(), - ) == 1 + if config.query_number_of_constraints + @test MOI.get( + model, + MOI.NumberOfConstraints{ + vecofvars ? MOI.VectorOfVariables : + MOI.VectorAffineFunction{Float64}, + MOI.GeometricMeanCone, + }(), + ) == 1 + @test MOI.get( + model, + MOI.NumberOfConstraints{ + MOI.ScalarAffineFunction{Float64}, + MOI.LessThan{Float64}, + }(), + ) == 1 + end MOI.set( model, @@ -3978,21 +4049,23 @@ function _psd0test( MOI.EqualTo(1.0), ) - @test MOI.get( - model, - MOI.NumberOfConstraints{ - vecofvars ? MOI.VectorOfVariables : - MOI.VectorAffineFunction{Float64}, - psdcone, - }(), - ) == 1 - @test MOI.get( - model, - MOI.NumberOfConstraints{ - MOI.ScalarAffineFunction{Float64}, - MOI.EqualTo{Float64}, - }(), - ) == 1 + if config.query_number_of_constraints + @test MOI.get( + model, + MOI.NumberOfConstraints{ + vecofvars ? MOI.VectorOfVariables : + MOI.VectorAffineFunction{Float64}, + psdcone, + }(), + ) == 1 + @test MOI.get( + model, + MOI.NumberOfConstraints{ + MOI.ScalarAffineFunction{Float64}, + MOI.EqualTo{Float64}, + }(), + ) == 1 + end MOI.set( model, @@ -4215,25 +4288,27 @@ function _psd1test( ) MOI.set(model, MOI.ObjectiveSense(), MOI.MIN_SENSE) - @test MOI.get( - model, - MOI.NumberOfConstraints{ - vecofvars ? MOI.VectorOfVariables : - MOI.VectorAffineFunction{Float64}, - psdcone, - }(), - ) == 1 - @test MOI.get( - model, - MOI.NumberOfConstraints{ - MOI.ScalarAffineFunction{Float64}, - MOI.EqualTo{Float64}, - }(), - ) == 2 - @test MOI.get( - model, - MOI.NumberOfConstraints{MOI.VectorOfVariables,MOI.SecondOrderCone}(), - ) == 1 + if config.query_number_of_constraints + @test MOI.get( + model, + MOI.NumberOfConstraints{ + vecofvars ? MOI.VectorOfVariables : + MOI.VectorAffineFunction{Float64}, + psdcone, + }(), + ) == 1 + @test MOI.get( + model, + MOI.NumberOfConstraints{ + MOI.ScalarAffineFunction{Float64}, + MOI.EqualTo{Float64}, + }(), + ) == 2 + @test MOI.get( + model, + MOI.NumberOfConstraints{MOI.VectorOfVariables,MOI.SecondOrderCone}(), + ) == 1 + end if config.solve @test MOI.get(model, MOI.TerminationStatus()) == MOI.OPTIMIZE_NOT_CALLED @@ -4399,34 +4474,36 @@ function psdt2test(model::MOI.ModelLike, config::TestConfig) MOI.EqualTo(0.0), ) - @test MOI.get( - model, - MOI.NumberOfConstraints{ - MOI.ScalarAffineFunction{Float64}, - MOI.GreaterThan{Float64}, - }(), - ) == 1 - @test MOI.get( - model, - MOI.NumberOfConstraints{ - MOI.VectorAffineFunction{Float64}, - MOI.Nonpositives, - }(), - ) == 1 - @test MOI.get( - model, - MOI.NumberOfConstraints{ - MOI.VectorAffineFunction{Float64}, - MOI.PositiveSemidefiniteConeTriangle, - }(), - ) == 1 - @test MOI.get( - model, - MOI.NumberOfConstraints{ - MOI.ScalarAffineFunction{Float64}, - MOI.EqualTo{Float64}, - }(), - ) == 1 + if config.query_number_of_constraints + @test MOI.get( + model, + MOI.NumberOfConstraints{ + MOI.ScalarAffineFunction{Float64}, + MOI.GreaterThan{Float64}, + }(), + ) == 1 + @test MOI.get( + model, + MOI.NumberOfConstraints{ + MOI.VectorAffineFunction{Float64}, + MOI.Nonpositives, + }(), + ) == 1 + @test MOI.get( + model, + MOI.NumberOfConstraints{ + MOI.VectorAffineFunction{Float64}, + MOI.PositiveSemidefiniteConeTriangle, + }(), + ) == 1 + @test MOI.get( + model, + MOI.NumberOfConstraints{ + MOI.ScalarAffineFunction{Float64}, + MOI.EqualTo{Float64}, + }(), + ) == 1 + end MOI.set( model, @@ -4697,21 +4774,23 @@ function _det1test( MOI.Nonnegatives(2), ) - @test MOI.get( - model, - MOI.NumberOfConstraints{ - vecofvars ? MOI.VectorOfVariables : - MOI.VectorAffineFunction{Float64}, - detcone, - }(), - ) == 1 - @test MOI.get( - model, - MOI.NumberOfConstraints{ - MOI.VectorAffineFunction{Float64}, - MOI.Nonnegatives, - }(), - ) == 1 + if config.query_number_of_constraints + @test MOI.get( + model, + MOI.NumberOfConstraints{ + vecofvars ? MOI.VectorOfVariables : + MOI.VectorAffineFunction{Float64}, + detcone, + }(), + ) == 1 + @test MOI.get( + model, + MOI.NumberOfConstraints{ + MOI.VectorAffineFunction{Float64}, + MOI.Nonnegatives, + }(), + ) == 1 + end MOI.set( model, @@ -4837,10 +4916,12 @@ function _det2test(model::MOI.ModelLike, config::TestConfig, detcone) constant_vec, ) det_constraint = MOI.add_constraint(model, vaf, detcone(3)) - @test MOI.get( - model, - MOI.NumberOfConstraints{MOI.VectorAffineFunction{Float64},detcone}(), - ) == 1 + if config.query_number_of_constraints + @test MOI.get( + model, + MOI.NumberOfConstraints{MOI.VectorAffineFunction{Float64},detcone}(), + ) == 1 + end if config.solve @test MOI.get(model, MOI.TerminationStatus()) == MOI.OPTIMIZE_NOT_CALLED diff --git a/src/Test/contlinear.jl b/src/Test/contlinear.jl index a5e3284f3a..41671df132 100644 --- a/src/Test/contlinear.jl +++ b/src/Test/contlinear.jl @@ -48,10 +48,15 @@ function linear1test(model::MOI.ModelLike, config::TestConfig{T}) where {T} zero(T), ) c = MOI.add_constraint(model, cf, MOI.LessThan(one(T))) - @test MOI.get( - model, - MOI.NumberOfConstraints{MOI.ScalarAffineFunction{T},MOI.LessThan{T}}(), - ) == 1 + if config.query_number_of_constraints + @test MOI.get( + model, + MOI.NumberOfConstraints{ + MOI.ScalarAffineFunction{T}, + MOI.LessThan{T}, + }(), + ) == 1 + end vc1 = MOI.add_constraint( model, @@ -64,10 +69,12 @@ function linear1test(model::MOI.ModelLike, config::TestConfig{T}) where {T} # test fallback vc2 = MOI.add_constraint(model, v[2], MOI.GreaterThan(zero(T))) @test vc2.value == v[2].value - @test MOI.get( - model, - MOI.NumberOfConstraints{MOI.SingleVariable,MOI.GreaterThan{T}}(), - ) == 2 + if config.query_number_of_constraints + @test MOI.get( + model, + MOI.NumberOfConstraints{MOI.SingleVariable,MOI.GreaterThan{T}}(), + ) == 2 + end # note: adding some redundant zero coefficients to catch solvers that don't handle duplicate coefficients correctly: objf = MOI.ScalarAffineFunction{T}( @@ -216,10 +223,12 @@ function linear1test(model::MOI.ModelLike, config::TestConfig{T}) where {T} MOI.GreaterThan(zero(T)), ) @test vc3.value == v[3].value - @test MOI.get( - model, - MOI.NumberOfConstraints{MOI.SingleVariable,MOI.GreaterThan{T}}(), - ) == 3 + if config.query_number_of_constraints + @test MOI.get( + model, + MOI.NumberOfConstraints{MOI.SingleVariable,MOI.GreaterThan{T}}(), + ) == 3 + end if config.modify_lhs MOI.modify(model, c, MOI.ScalarCoefficientChange{T}(z, one(T))) @@ -238,14 +247,19 @@ function linear1test(model::MOI.ModelLike, config::TestConfig{T}) where {T} MOI.ScalarCoefficientChange{T}(z, T(2)), ) - @test MOI.get( - model, - MOI.NumberOfConstraints{MOI.ScalarAffineFunction{T},MOI.LessThan{T}}(), - ) == 1 - @test MOI.get( - model, - MOI.NumberOfConstraints{MOI.SingleVariable,MOI.GreaterThan{T}}(), - ) == 3 + if config.query_number_of_constraints + @test MOI.get( + model, + MOI.NumberOfConstraints{ + MOI.ScalarAffineFunction{T}, + MOI.LessThan{T}, + }(), + ) == 1 + @test MOI.get( + model, + MOI.NumberOfConstraints{MOI.SingleVariable,MOI.GreaterThan{T}}(), + ) == 3 + end if config.solve MOI.optimize!(model) @@ -326,10 +340,12 @@ function linear1test(model::MOI.ModelLike, config::TestConfig{T}) where {T} MOI.EqualTo(zero(T)), ) @test vc3.value == v[3].value - @test MOI.get( - model, - MOI.NumberOfConstraints{MOI.SingleVariable,MOI.GreaterThan{T}}(), - ) == 2 + if config.query_number_of_constraints + @test MOI.get( + model, + MOI.NumberOfConstraints{MOI.SingleVariable,MOI.GreaterThan{T}}(), + ) == 2 + end if config.solve MOI.optimize!(model) @@ -372,14 +388,22 @@ function linear1test(model::MOI.ModelLike, config::TestConfig{T}) where {T} zero(T), ) c = MOI.add_constraint(model, cf, MOI.EqualTo(T(2))) - @test MOI.get( - model, - MOI.NumberOfConstraints{MOI.ScalarAffineFunction{T},MOI.LessThan{T}}(), - ) == 0 - @test MOI.get( - model, - MOI.NumberOfConstraints{MOI.ScalarAffineFunction{T},MOI.EqualTo{T}}(), - ) == 1 + if config.query_number_of_constraints + @test MOI.get( + model, + MOI.NumberOfConstraints{ + MOI.ScalarAffineFunction{T}, + MOI.LessThan{T}, + }(), + ) == 0 + @test MOI.get( + model, + MOI.NumberOfConstraints{ + MOI.ScalarAffineFunction{T}, + MOI.EqualTo{T}, + }(), + ) == 1 + end if config.solve MOI.optimize!(model) @@ -441,33 +465,41 @@ function linear1test(model::MOI.ModelLike, config::TestConfig{T}) where {T} zero(T), ) c2 = MOI.add_constraint(model, cf2, MOI.GreaterThan(zero(T))) - @test MOI.get( - model, - MOI.NumberOfConstraints{MOI.ScalarAffineFunction{T},MOI.EqualTo{T}}(), - ) == 1 - @test MOI.get( - model, - MOI.NumberOfConstraints{ - MOI.ScalarAffineFunction{T}, - MOI.GreaterThan{T}, - }(), - ) == 1 - @test MOI.get( - model, - MOI.NumberOfConstraints{MOI.ScalarAffineFunction{T},MOI.LessThan{T}}(), - ) == 0 - @test MOI.get( - model, - MOI.NumberOfConstraints{MOI.SingleVariable,MOI.EqualTo{T}}(), - ) == 1 - @test MOI.get( - model, - MOI.NumberOfConstraints{MOI.SingleVariable,MOI.GreaterThan{T}}(), - ) == 2 - @test MOI.get( - model, - MOI.NumberOfConstraints{MOI.SingleVariable,MOI.LessThan{T}}(), - ) == 0 + if config.query_number_of_constraints + @test MOI.get( + model, + MOI.NumberOfConstraints{ + MOI.ScalarAffineFunction{T}, + MOI.EqualTo{T}, + }(), + ) == 1 + @test MOI.get( + model, + MOI.NumberOfConstraints{ + MOI.ScalarAffineFunction{T}, + MOI.GreaterThan{T}, + }(), + ) == 1 + @test MOI.get( + model, + MOI.NumberOfConstraints{ + MOI.ScalarAffineFunction{T}, + MOI.LessThan{T}, + }(), + ) == 0 + @test MOI.get( + model, + MOI.NumberOfConstraints{MOI.SingleVariable,MOI.EqualTo{T}}(), + ) == 1 + @test MOI.get( + model, + MOI.NumberOfConstraints{MOI.SingleVariable,MOI.GreaterThan{T}}(), + ) == 2 + @test MOI.get( + model, + MOI.NumberOfConstraints{MOI.SingleVariable,MOI.LessThan{T}}(), + ) == 0 + end if config.solve MOI.optimize!(model) @@ -529,15 +561,19 @@ function linear1test(model::MOI.ModelLike, config::TestConfig{T}) where {T} # - y >= 0 # y >= 0, z = 0 - @test MOI.get( - model, - MOI.NumberOfConstraints{MOI.SingleVariable,MOI.GreaterThan{T}}(), - ) == 2 + if config.query_number_of_constraints + @test MOI.get( + model, + MOI.NumberOfConstraints{MOI.SingleVariable,MOI.GreaterThan{T}}(), + ) == 2 + end MOI.delete(model, v[1]) - @test MOI.get( - model, - MOI.NumberOfConstraints{MOI.SingleVariable,MOI.GreaterThan{T}}(), - ) == 1 + if config.query_number_of_constraints + @test MOI.get( + model, + MOI.NumberOfConstraints{MOI.SingleVariable,MOI.GreaterThan{T}}(), + ) == 1 + end if config.query err = MOI.InvalidIndex(vc1) @@ -597,10 +633,15 @@ function linear2test(model::MOI.ModelLike, config::TestConfig{T}) where {T} zero(T), ) c = MOI.add_constraint(model, cf, MOI.LessThan(one(T))) - @test MOI.get( - model, - MOI.NumberOfConstraints{MOI.ScalarAffineFunction{T},MOI.LessThan{T}}(), - ) == 1 + if config.query_number_of_constraints + @test MOI.get( + model, + MOI.NumberOfConstraints{ + MOI.ScalarAffineFunction{T}, + MOI.LessThan{T}, + }(), + ) == 1 + end vc1 = MOI.add_constraint( model, @@ -614,10 +655,12 @@ function linear2test(model::MOI.ModelLike, config::TestConfig{T}) where {T} MOI.GreaterThan(zero(T)), ) @test vc2.value == y.value - @test MOI.get( - model, - MOI.NumberOfConstraints{MOI.SingleVariable,MOI.GreaterThan{T}}(), - ) == 2 + if config.query_number_of_constraints + @test MOI.get( + model, + MOI.NumberOfConstraints{MOI.SingleVariable,MOI.GreaterThan{T}}(), + ) == 2 + end objf = MOI.ScalarAffineFunction{T}( MOI.ScalarAffineTerm{T}.([-one(T), zero(T)], [x, y]), @@ -718,17 +761,19 @@ function linear3test(model::MOI.ModelLike, config::TestConfig{T}) where {T} ) c = MOI.add_constraint(model, cf, MOI.GreaterThan(T(3))) - @test MOI.get( - model, - MOI.NumberOfConstraints{MOI.SingleVariable,MOI.GreaterThan{T}}(), - ) == 1 - @test MOI.get( - model, - MOI.NumberOfConstraints{ - MOI.ScalarAffineFunction{T}, - MOI.GreaterThan{T}, - }(), - ) == 1 + if config.query_number_of_constraints + @test MOI.get( + model, + MOI.NumberOfConstraints{MOI.SingleVariable,MOI.GreaterThan{T}}(), + ) == 1 + @test MOI.get( + model, + MOI.NumberOfConstraints{ + MOI.ScalarAffineFunction{T}, + MOI.GreaterThan{T}, + }(), + ) == 1 + end objf = MOI.ScalarAffineFunction{T}( [MOI.ScalarAffineTerm{T}(one(T), x)], @@ -775,14 +820,19 @@ function linear3test(model::MOI.ModelLike, config::TestConfig{T}) where {T} ) c = MOI.add_constraint(model, cf, MOI.LessThan(T(3))) - @test MOI.get( - model, - MOI.NumberOfConstraints{MOI.SingleVariable,MOI.LessThan{T}}(), - ) == 1 - @test MOI.get( - model, - MOI.NumberOfConstraints{MOI.ScalarAffineFunction{T},MOI.LessThan{T}}(), - ) == 1 + if config.query_number_of_constraints + @test MOI.get( + model, + MOI.NumberOfConstraints{MOI.SingleVariable,MOI.LessThan{T}}(), + ) == 1 + @test MOI.get( + model, + MOI.NumberOfConstraints{ + MOI.ScalarAffineFunction{T}, + MOI.LessThan{T}, + }(), + ) == 1 + end objf = MOI.ScalarAffineFunction{T}( [MOI.ScalarAffineTerm{T}(one(T), x)], @@ -967,10 +1017,15 @@ function linear5test(model::MOI.ModelLike, config::TestConfig{T}) where {T} c1 = MOI.add_constraint(model, cf1, MOI.LessThan(T(4))) c2 = MOI.add_constraint(model, cf2, MOI.LessThan(T(4))) - @test MOI.get( - model, - MOI.NumberOfConstraints{MOI.ScalarAffineFunction{T},MOI.LessThan{T}}(), - ) == 2 + if config.query_number_of_constraints + @test MOI.get( + model, + MOI.NumberOfConstraints{ + MOI.ScalarAffineFunction{T}, + MOI.LessThan{T}, + }(), + ) == 2 + end vc1 = MOI.add_constraint( model, @@ -985,10 +1040,12 @@ function linear5test(model::MOI.ModelLike, config::TestConfig{T}) where {T} ) @test vc2.value == y.value - @test MOI.get( - model, - MOI.NumberOfConstraints{MOI.SingleVariable,MOI.GreaterThan{T}}(), - ) == 2 + if config.query_number_of_constraints + @test MOI.get( + model, + MOI.NumberOfConstraints{MOI.SingleVariable,MOI.GreaterThan{T}}(), + ) == 2 + end objf = MOI.ScalarAffineFunction{T}( MOI.ScalarAffineTerm{T}.([one(T), one(T)], [x, y]), diff --git a/src/Test/contquadratic.jl b/src/Test/contquadratic.jl index 55ee0e7f1e..4327dcca02 100644 --- a/src/Test/contquadratic.jl +++ b/src/Test/contquadratic.jl @@ -29,13 +29,15 @@ function qp1test(model::MOI.ModelLike, config::TestConfig) cf1 = MOI.ScalarAffineFunction(MOI.ScalarAffineTerm.([1.0, 2.0, 3.0], v), 0.0) c1 = MOI.add_constraint(model, cf1, MOI.GreaterThan(4.0)) - @test MOI.get( - model, - MOI.NumberOfConstraints{ - MOI.ScalarAffineFunction{Float64}, - MOI.GreaterThan{Float64}, - }(), - ) == 1 + if config.query_number_of_constraints + @test MOI.get( + model, + MOI.NumberOfConstraints{ + MOI.ScalarAffineFunction{Float64}, + MOI.GreaterThan{Float64}, + }(), + ) == 1 + end c2 = MOI.add_constraint( model, @@ -45,13 +47,15 @@ function qp1test(model::MOI.ModelLike, config::TestConfig) ), MOI.GreaterThan(1.0), ) - @test MOI.get( - model, - MOI.NumberOfConstraints{ - MOI.ScalarAffineFunction{Float64}, - MOI.GreaterThan{Float64}, - }(), - ) == 2 + if config.query_number_of_constraints + @test MOI.get( + model, + MOI.NumberOfConstraints{ + MOI.ScalarAffineFunction{Float64}, + MOI.GreaterThan{Float64}, + }(), + ) == 2 + end MOI.set(model, MOI.ObjectiveSense(), MOI.MIN_SENSE) @test MOI.get(model, MOI.ObjectiveSense()) == MOI.MIN_SENSE @@ -140,13 +144,15 @@ function qp2test(model::MOI.ModelLike, config::TestConfig) c1f = MOI.ScalarAffineFunction(MOI.ScalarAffineTerm.([1.0, 2.0, 3.0], v), 0.0) c1 = MOI.add_constraint(model, c1f, MOI.GreaterThan(4.0)) - @test MOI.get( - model, - MOI.NumberOfConstraints{ - MOI.ScalarAffineFunction{Float64}, - MOI.GreaterThan{Float64}, - }(), - ) == 1 + if config.query_number_of_constraints + @test MOI.get( + model, + MOI.NumberOfConstraints{ + MOI.ScalarAffineFunction{Float64}, + MOI.GreaterThan{Float64}, + }(), + ) == 1 + end c2 = MOI.add_constraint( model, @@ -156,13 +162,15 @@ function qp2test(model::MOI.ModelLike, config::TestConfig) ), MOI.GreaterThan(1.0), ) - @test MOI.get( - model, - MOI.NumberOfConstraints{ - MOI.ScalarAffineFunction{Float64}, - MOI.GreaterThan{Float64}, - }(), - ) == 2 + if config.query_number_of_constraints + @test MOI.get( + model, + MOI.NumberOfConstraints{ + MOI.ScalarAffineFunction{Float64}, + MOI.GreaterThan{Float64}, + }(), + ) == 2 + end MOI.set(model, MOI.ObjectiveSense(), MOI.MIN_SENSE) @test MOI.get(model, MOI.ObjectiveSense()) == MOI.MIN_SENSE @@ -448,13 +456,15 @@ function qcp1test(model::MOI.ModelLike, config::TestConfig) ), MOI.Nonnegatives(2), ) - @test MOI.get( - model, - MOI.NumberOfConstraints{ - MOI.VectorAffineFunction{Float64}, - MOI.Nonnegatives, - }(), - ) == 1 + if config.query_number_of_constraints + @test MOI.get( + model, + MOI.NumberOfConstraints{ + MOI.VectorAffineFunction{Float64}, + MOI.Nonnegatives, + }(), + ) == 1 + end c2f = MOI.ScalarQuadraticFunction( [MOI.ScalarAffineTerm(1.0, y)], @@ -462,13 +472,15 @@ function qcp1test(model::MOI.ModelLike, config::TestConfig) 0.0, ) c2 = MOI.add_constraint(model, c2f, MOI.LessThan(2.0)) - @test MOI.get( - model, - MOI.NumberOfConstraints{ - MOI.ScalarQuadraticFunction{Float64}, - MOI.LessThan{Float64}, - }(), - ) == 1 + if config.query_number_of_constraints + @test MOI.get( + model, + MOI.NumberOfConstraints{ + MOI.ScalarQuadraticFunction{Float64}, + MOI.LessThan{Float64}, + }(), + ) == 1 + end MOI.set( model, @@ -563,13 +575,15 @@ function qcp2test(model::MOI.ModelLike, config::TestConfig) 0.0, ) c = MOI.add_constraint(model, cf, MOI.LessThan(2.0)) - @test MOI.get( - model, - MOI.NumberOfConstraints{ - MOI.ScalarQuadraticFunction{Float64}, - MOI.LessThan{Float64}, - }(), - ) == 1 + if config.query_number_of_constraints + @test MOI.get( + model, + MOI.NumberOfConstraints{ + MOI.ScalarQuadraticFunction{Float64}, + MOI.LessThan{Float64}, + }(), + ) == 1 + end MOI.set( model, @@ -641,13 +655,15 @@ function qcp3test(model::MOI.ModelLike, config::TestConfig) 0.0, ) c = MOI.add_constraint(model, cf, MOI.LessThan(2.0)) - @test MOI.get( - model, - MOI.NumberOfConstraints{ - MOI.ScalarQuadraticFunction{Float64}, - MOI.LessThan{Float64}, - }(), - ) == 1 + if config.query_number_of_constraints + @test MOI.get( + model, + MOI.NumberOfConstraints{ + MOI.ScalarQuadraticFunction{Float64}, + MOI.LessThan{Float64}, + }(), + ) == 1 + end MOI.set( model, @@ -732,13 +748,15 @@ function _qcp4test(model::MOI.ModelLike, config::TestConfig, less_than::Bool) MOIU.operate!(-, Float64, cf) end c = MOI.add_constraint(model, cf, quad_set) - @test MOI.get( - model, - MOI.NumberOfConstraints{ - MOI.ScalarQuadraticFunction{Float64}, - typeof(quad_set), - }(), - ) == 1 + if config.query_number_of_constraints + @test MOI.get( + model, + MOI.NumberOfConstraints{ + MOI.ScalarQuadraticFunction{Float64}, + typeof(quad_set), + }(), + ) == 1 + end MOI.set( model, @@ -847,13 +865,15 @@ function ncqcp1test(model::MOI.ModelLike, config::TestConfig) 0.0, ) c = MOI.add_constraint(model, cf, MOI.LessThan(4.0)) - @test MOI.get( - model, - MOI.NumberOfConstraints{ - MOI.ScalarQuadraticFunction{Float64}, - MOI.LessThan{Float64}, - }(), - ) == 1 + if config.query_number_of_constraints + @test MOI.get( + model, + MOI.NumberOfConstraints{ + MOI.ScalarQuadraticFunction{Float64}, + MOI.LessThan{Float64}, + }(), + ) == 1 + end MOI.set( model, @@ -936,13 +956,15 @@ function ncqcp2test(model::MOI.ModelLike, config::TestConfig) ) c2 = MOI.add_constraint(model, cf2, MOI.EqualTo(4.0)) - @test MOI.get( - model, - MOI.NumberOfConstraints{ - MOI.ScalarQuadraticFunction{Float64}, - MOI.EqualTo{Float64}, - }(), - ) == 2 + if config.query_number_of_constraints + @test MOI.get( + model, + MOI.NumberOfConstraints{ + MOI.ScalarQuadraticFunction{Float64}, + MOI.EqualTo{Float64}, + }(), + ) == 2 + end if config.query @test cf ≈ MOI.get(model, MOI.ConstraintFunction(), c) @@ -1022,13 +1044,15 @@ function socp1test(model::MOI.ModelLike, config::TestConfig) c1f = MOI.ScalarAffineFunction(MOI.ScalarAffineTerm.([1.0, 1.0], [x, y]), 0.0) c1 = MOI.add_constraint(model, c1f, MOI.GreaterThan(1.0)) - @test MOI.get( - model, - MOI.NumberOfConstraints{ - MOI.ScalarAffineFunction{Float64}, - MOI.GreaterThan{Float64}, - }(), - ) == 1 + if config.query_number_of_constraints + @test MOI.get( + model, + MOI.NumberOfConstraints{ + MOI.ScalarAffineFunction{Float64}, + MOI.GreaterThan{Float64}, + }(), + ) == 1 + end c2f = MOI.ScalarQuadraticFunction( MOI.ScalarAffineTerm{Float64}[], @@ -1036,21 +1060,28 @@ function socp1test(model::MOI.ModelLike, config::TestConfig) 0.0, ) c2 = MOI.add_constraint(model, c2f, MOI.LessThan(0.0)) - @test MOI.get( - model, - MOI.NumberOfConstraints{ - MOI.ScalarQuadraticFunction{Float64}, - MOI.LessThan{Float64}, - }(), - ) == 1 + if config.query_number_of_constraints + @test MOI.get( + model, + MOI.NumberOfConstraints{ + MOI.ScalarQuadraticFunction{Float64}, + MOI.LessThan{Float64}, + }(), + ) == 1 + end bound = MOI.add_constraint(model, MOI.SingleVariable(t), MOI.GreaterThan(0.0)) @test bound.value == t.value - @test MOI.get( - model, - MOI.NumberOfConstraints{MOI.SingleVariable,MOI.GreaterThan{Float64}}(), - ) == 1 + if config.query_number_of_constraints + @test MOI.get( + model, + MOI.NumberOfConstraints{ + MOI.SingleVariable, + MOI.GreaterThan{Float64}, + }(), + ) == 1 + end MOI.set( model, diff --git a/src/Test/intconic.jl b/src/Test/intconic.jl index 15d925800d..31172f6b48 100644 --- a/src/Test/intconic.jl +++ b/src/Test/intconic.jl @@ -56,14 +56,19 @@ function intsoc1test(model::MOI.ModelLike, config::TestConfig) MOI.SecondOrderCone(3), ) - @test MOI.get( - model, - MOI.NumberOfConstraints{MOI.VectorAffineFunction{Float64},MOI.Zeros}(), - ) == 1 - @test MOI.get( - model, - MOI.NumberOfConstraints{MOI.VectorOfVariables,MOI.SecondOrderCone}(), - ) == 1 + if config.query_number_of_constraints + @test MOI.get( + model, + MOI.NumberOfConstraints{ + MOI.VectorAffineFunction{Float64}, + MOI.Zeros, + }(), + ) == 1 + @test MOI.get( + model, + MOI.NumberOfConstraints{MOI.VectorOfVariables,MOI.SecondOrderCone}(), + ) == 1 + end loc = MOI.get(model, MOI.ListOfConstraintTypesPresent()) @test length(loc) == 2 @test (MOI.VectorAffineFunction{Float64}, MOI.Zeros) in loc diff --git a/src/Test/intlinear.jl b/src/Test/intlinear.jl index c2cb8020e0..5980ea062e 100644 --- a/src/Test/intlinear.jl +++ b/src/Test/intlinear.jl @@ -41,24 +41,28 @@ function int1test(model::MOI.ModelLike, config::TestConfig) cf = MOI.ScalarAffineFunction(MOI.ScalarAffineTerm.([1.0, 1.0, 1.0], v), 0.0) c = MOI.add_constraint(model, cf, MOI.LessThan(10.0)) - @test MOI.get( - model, - MOI.NumberOfConstraints{ - MOI.ScalarAffineFunction{Float64}, - MOI.LessThan{Float64}, - }(), - ) == 1 + if config.query_number_of_constraints + @test MOI.get( + model, + MOI.NumberOfConstraints{ + MOI.ScalarAffineFunction{Float64}, + MOI.LessThan{Float64}, + }(), + ) == 1 + end cf2 = MOI.ScalarAffineFunction(MOI.ScalarAffineTerm.([1.0, 2.0, 1.0], v), 0.0) c2 = MOI.add_constraint(model, cf2, MOI.LessThan(15.0)) - @test MOI.get( - model, - MOI.NumberOfConstraints{ - MOI.ScalarAffineFunction{Float64}, - MOI.LessThan{Float64}, - }(), - ) == 2 + if config.query_number_of_constraints + @test MOI.get( + model, + MOI.NumberOfConstraints{ + MOI.ScalarAffineFunction{Float64}, + MOI.LessThan{Float64}, + }(), + ) == 2 + end vc1 = MOI.add_constraint( model, @@ -68,10 +72,12 @@ function int1test(model::MOI.ModelLike, config::TestConfig) # We test this after the creation of every `SingleVariable` constraint # to ensure a good coverage of corner cases. @test vc1.value == v[1].value - @test MOI.get( - model, - MOI.NumberOfConstraints{MOI.SingleVariable,MOI.Interval{Float64}}(), - ) == 1 + if config.query_number_of_constraints + @test MOI.get( + model, + MOI.NumberOfConstraints{MOI.SingleVariable,MOI.Interval{Float64}}(), + ) == 1 + end vc2 = MOI.add_constraint( model, @@ -79,23 +85,29 @@ function int1test(model::MOI.ModelLike, config::TestConfig) MOI.Interval(0.0, 10.0), ) @test vc2.value == v[2].value - @test MOI.get( - model, - MOI.NumberOfConstraints{MOI.SingleVariable,MOI.Interval{Float64}}(), - ) == 2 + if config.query_number_of_constraints + @test MOI.get( + model, + MOI.NumberOfConstraints{MOI.SingleVariable,MOI.Interval{Float64}}(), + ) == 2 + end vc3 = MOI.add_constraint(model, MOI.SingleVariable(v[2]), MOI.Integer()) @test vc3.value == v[2].value - @test MOI.get( - model, - MOI.NumberOfConstraints{MOI.SingleVariable,MOI.Integer}(), - ) == 1 + if config.query_number_of_constraints + @test MOI.get( + model, + MOI.NumberOfConstraints{MOI.SingleVariable,MOI.Integer}(), + ) == 1 + end vc4 = MOI.add_constraint(model, MOI.SingleVariable(v[3]), MOI.ZeroOne()) @test vc4.value == v[3].value - @test MOI.get( - model, - MOI.NumberOfConstraints{MOI.SingleVariable,MOI.ZeroOne}(), - ) == 1 + if config.query_number_of_constraints + @test MOI.get( + model, + MOI.NumberOfConstraints{MOI.SingleVariable,MOI.ZeroOne}(), + ) == 1 + end objf = MOI.ScalarAffineFunction(MOI.ScalarAffineTerm.([1.1, 2.0, 5.0], v), 0.0) @@ -198,10 +210,15 @@ function int2test(model::MOI.ModelLike, config::TestConfig) MOI.VectorOfVariables([v[1], v[3]]), MOI.SOS1([1.0, 2.0]), ) - @test MOI.get( - model, - MOI.NumberOfConstraints{MOI.VectorOfVariables,MOI.SOS1{Float64}}(), - ) == 2 + if config.query_number_of_constraints + @test MOI.get( + model, + MOI.NumberOfConstraints{ + MOI.VectorOfVariables, + MOI.SOS1{Float64}, + }(), + ) == 2 + end #= To allow for permutations in the sets and variable vectors @@ -539,10 +556,12 @@ function knapsacktest(model::MOI.ModelLike, config::TestConfig) vc = MOI.add_constraint(model, MOI.SingleVariable(vi), MOI.ZeroOne()) @test vc.value == vi.value end - @test MOI.get( - model, - MOI.NumberOfConstraints{MOI.SingleVariable,MOI.ZeroOne}(), - ) == 5 + if config.query_number_of_constraints + @test MOI.get( + model, + MOI.NumberOfConstraints{MOI.SingleVariable,MOI.ZeroOne}(), + ) == 5 + end c = MOI.add_constraint( model, MOI.ScalarAffineFunction( @@ -551,13 +570,15 @@ function knapsacktest(model::MOI.ModelLike, config::TestConfig) ), MOI.LessThan(10.0), ) - @test MOI.get( - model, - MOI.NumberOfConstraints{ - MOI.ScalarAffineFunction{Float64}, - MOI.LessThan{Float64}, - }(), - ) == 1 + if config.query_number_of_constraints + @test MOI.get( + model, + MOI.NumberOfConstraints{ + MOI.ScalarAffineFunction{Float64}, + MOI.LessThan{Float64}, + }(), + ) == 1 + end MOI.set( model, @@ -1074,20 +1095,27 @@ function _semitest( MOI.SingleVariable(v[1]), MOI.Semicontinuous(T(2), T(3)), ) - @test MOI.get( - model, - MOI.NumberOfConstraints{MOI.SingleVariable,MOI.Semicontinuous{T}}(), - ) == 1 + if config.query_number_of_constraints + @test MOI.get( + model, + MOI.NumberOfConstraints{ + MOI.SingleVariable, + MOI.Semicontinuous{T}, + }(), + ) == 1 + end else vc1 = MOI.add_constraint( model, MOI.SingleVariable(v[1]), MOI.Semiinteger(T(2), T(3)), ) - @test MOI.get( - model, - MOI.NumberOfConstraints{MOI.SingleVariable,MOI.Semiinteger{T}}(), - ) == 1 + if config.query_number_of_constraints + @test MOI.get( + model, + MOI.NumberOfConstraints{MOI.SingleVariable,MOI.Semiinteger{T}}(), + ) == 1 + end end vc2 = MOI.add_constraint( @@ -1095,23 +1123,27 @@ function _semitest( MOI.SingleVariable(v[2]), MOI.EqualTo(zero(T)), ) - @test MOI.get( - model, - MOI.NumberOfConstraints{MOI.SingleVariable,MOI.EqualTo{T}}(), - ) == 1 + if config.query_number_of_constraints + @test MOI.get( + model, + MOI.NumberOfConstraints{MOI.SingleVariable,MOI.EqualTo{T}}(), + ) == 1 + end cf = MOI.ScalarAffineFunction{T}( MOI.ScalarAffineTerm{T}.([one(T), -one(T)], v), zero(T), ) c = MOI.add_constraint(model, cf, MOI.GreaterThan(zero(T))) - @test MOI.get( - model, - MOI.NumberOfConstraints{ - MOI.ScalarAffineFunction{T}, - MOI.GreaterThan{T}, - }(), - ) == 1 + if config.query_number_of_constraints + @test MOI.get( + model, + MOI.NumberOfConstraints{ + MOI.ScalarAffineFunction{T}, + MOI.GreaterThan{T}, + }(), + ) == 1 + end objf = MOI.ScalarAffineFunction(MOI.ScalarAffineTerm.([1.0, 0.0], v), 0.0) MOI.set(