diff --git a/Project.toml b/Project.toml index 6ff942a2..385dc4df 100644 --- a/Project.toml +++ b/Project.toml @@ -9,5 +9,5 @@ LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [compat] -MathOptInterface = "~0.10" -julia = "^1" +MathOptInterface = "1" +julia = "1" diff --git a/src/Bridges/Constraint/AllDifferent/ad_to_neq.jl b/src/Bridges/Constraint/AllDifferent/ad_to_neq.jl index 75dfef75..6aa91984 100644 --- a/src/Bridges/Constraint/AllDifferent/ad_to_neq.jl +++ b/src/Bridges/Constraint/AllDifferent/ad_to_neq.jl @@ -41,7 +41,7 @@ function MOIBC.bridge_constraint( Tuple{Int, Int}, MOI.ConstraintIndex{MOI.ScalarAffineFunction{T}, CP.DifferentFrom{T}}, }() - sizehint!(cons, dim * (dim - 1) / 2) + sizehint!(cons, div(dim * (dim - 1), 2)) for i in 1:dim for j in (i+1):dim diff --git a/src/Bridges/Constraint/AllDifferentExceptConstants/adec_to_disjunction.jl b/src/Bridges/Constraint/AllDifferentExceptConstants/adec_to_disjunction.jl index dd9aa650..359bb8b4 100644 --- a/src/Bridges/Constraint/AllDifferentExceptConstants/adec_to_disjunction.jl +++ b/src/Bridges/Constraint/AllDifferentExceptConstants/adec_to_disjunction.jl @@ -39,7 +39,7 @@ function MOIBC.bridge_constraint( # Upper-triangular matrix of constraints: i >= j, i.e. d(d-1)/2 elements: # \sum_{i=2}^{d} (n - i + 1) = d (d - 1) / 2 cons = Dict{Tuple{Int, Int}, MOI.ConstraintIndex}() - sizehint!(cons, dim * (dim - 1) / 2) + sizehint!(cons, div(dim * (dim - 1), 2)) for i in 1:dim for j in (i+1):dim diff --git a/src/Bridges/Constraint/AllDifferentExceptConstants/adec_to_reif.jl b/src/Bridges/Constraint/AllDifferentExceptConstants/adec_to_reif.jl index 300e7115..2f6a5ac9 100644 --- a/src/Bridges/Constraint/AllDifferentExceptConstants/adec_to_reif.jl +++ b/src/Bridges/Constraint/AllDifferentExceptConstants/adec_to_reif.jl @@ -78,10 +78,10 @@ function MOIBC.bridge_constraint( cons_different_reif = Dict{Tuple{Int, Int}, MOI.ConstraintIndex{MOI.VectorAffineFunction{T}, CP.Reification{CP.DifferentFrom{T}}}}() cons = Dict{Tuple{Int, Int}, MOI.ConstraintIndex{MOI.ScalarAffineFunction{T}, MOI.GreaterThan{T}}}() - sizehint!(vars_different, s.dimension * (s.dimension - 1) / 2) - sizehint!(vars_different_bin, s.dimension * (s.dimension - 1) / 2) - sizehint!(cons_different_reif, s.dimension * (s.dimension - 1) / 2) - sizehint!(cons, s.dimension * (s.dimension - 1) / 2) + sizehint!(vars_different, div(s.dimension * (s.dimension - 1), 2)) + sizehint!(vars_different_bin, div(s.dimension * (s.dimension - 1), 2)) + sizehint!(cons_different_reif, div(s.dimension * (s.dimension - 1), 2)) + sizehint!(cons, div(s.dimension * (s.dimension - 1), 2)) for i in 1:s.dimension for j in (i+1):s.dimension diff --git a/src/Bridges/Constraint/DifferentFrom_Reify/reif_neq_to_milp.jl b/src/Bridges/Constraint/DifferentFrom_Reify/reif_neq_to_milp.jl index bd95d68c..ecc9e3fa 100644 --- a/src/Bridges/Constraint/DifferentFrom_Reify/reif_neq_to_milp.jl +++ b/src/Bridges/Constraint/DifferentFrom_Reify/reif_neq_to_milp.jl @@ -76,16 +76,14 @@ function MOIBC.bridge_constraint( ) # If the constraint is satisfied, constrain the reified. - smallm = if T <: Int - one(T) - else - T(_REIF_EQTO_FLOAT_EPSILON) - end - con_smallm = MOI.add_constraint( model, - f_scalars[1] - var_abs / smallm, - MOI.LessThan(zero(T)) + if T <: Int + f_scalars[1] - var_abs + else + f_scalars[1] - var_abs / T(_REIF_EQTO_FLOAT_EPSILON) + end, + MOI.LessThan(zero(T)), ) return ReificationDifferentFrom2MILPBridge{T}(var_abs, var_abs_int, con_abs, con_bigm, con_smallm) diff --git a/src/Bridges/Constraint/EqualTo_Reify/reif_eqto_to_milp.jl b/src/Bridges/Constraint/EqualTo_Reify/reif_eqto_to_milp.jl index a2aeec84..d7eb0950 100644 --- a/src/Bridges/Constraint/EqualTo_Reify/reif_eqto_to_milp.jl +++ b/src/Bridges/Constraint/EqualTo_Reify/reif_eqto_to_milp.jl @@ -72,16 +72,14 @@ function MOIBC.bridge_constraint( ) # If the constraint is satisfied, constrain the reified. - smallm = if T <: Int - one(T) - else - T(_REIF_EQTO_FLOAT_EPSILON) - end - con_smallm = MOI.add_constraint( model, - f_scalars[1] - var_abs / smallm, - MOI.LessThan(zero(T)) + if T <: Int + f_scalars[1] - var_abs + else + f_scalars[1] - var_abs / T(_REIF_EQTO_FLOAT_EPSILON) + end, + MOI.LessThan(zero(T)), ) return ReificationEqualTo2MILPBridge{T}(var_abs, var_abs_int, con_abs, con_bigm, con_smallm) diff --git a/src/ConstraintProgrammingExtensions.jl b/src/ConstraintProgrammingExtensions.jl index 24df211d..042309db 100644 --- a/src/ConstraintProgrammingExtensions.jl +++ b/src/ConstraintProgrammingExtensions.jl @@ -23,7 +23,6 @@ include("sets_graph.jl") # Sets that work on graphs. include("sets_reification.jl") # Sets that rely on the concept of reification (also called logical constraints). include("Bridges/Bridges.jl") -include("DeprecatedTest/DeprecatedTest.jl") include("Test/Test.jl") include("FlatZinc/FlatZinc.jl") diff --git a/test/Bridges/Constraint/AllDifferent/ad_to_neq.jl b/test/Bridges/Constraint/AllDifferent/ad_to_neq.jl index ce45fd5f..9ce29b1d 100644 --- a/test/Bridges/Constraint/AllDifferent/ad_to_neq.jl +++ b/test/Bridges/Constraint/AllDifferent/ad_to_neq.jl @@ -44,13 +44,13 @@ @test MOIB.added_constraint_types(typeof(bridge)) == [(MOI.ScalarAffineFunction{T}, CP.DifferentFrom{T})] @test MOI.get(bridge, MOI.NumberOfVariables()) == 0 - @test MOI.get(bridge, MOI.NumberOfConstraints{MOI.ScalarAffineFunction{T}, CP.DifferentFrom{T}}()) == dim * (dim - 1) / 2 + @test MOI.get(bridge, MOI.NumberOfConstraints{MOI.ScalarAffineFunction{T}, CP.DifferentFrom{T}}()) == div(dim * (dim - 1), 2) @test Set(MOI.get(bridge, MOI.ListOfConstraintIndices{MOI.ScalarAffineFunction{T}, CP.DifferentFrom{T}}())) == Set(collect(values(bridge.cons))) end @testset "Set of constraints" begin - @test length(bridge.cons) == dim * (dim - 1) / 2 + @test length(bridge.cons) == div(dim * (dim - 1), 2) for i in 1:dim for j in (i+1):dim @test MOI.is_valid(model, bridge.cons[i, j]) diff --git a/test/Bridges/Constraint/AllDifferentExceptConstants/adec_to_disjunction.jl b/test/Bridges/Constraint/AllDifferentExceptConstants/adec_to_disjunction.jl index 97be755a..dc7d8019 100644 --- a/test/Bridges/Constraint/AllDifferentExceptConstants/adec_to_disjunction.jl +++ b/test/Bridges/Constraint/AllDifferentExceptConstants/adec_to_disjunction.jl @@ -44,13 +44,13 @@ @test MOIB.added_constraint_types(typeof(bridge)) == [(MOI.VectorAffineFunction{T}, CP.Disjunction)] @test MOI.get(bridge, MOI.NumberOfVariables()) == 0 - @test MOI.get(bridge, MOI.NumberOfConstraints{MOI.VectorAffineFunction{T}, CP.Disjunction}()) == dim * (dim - 1) / 2 + @test MOI.get(bridge, MOI.NumberOfConstraints{MOI.VectorAffineFunction{T}, CP.Disjunction}()) == div(dim * (dim - 1), 2) @test Set(MOI.get(bridge, MOI.ListOfConstraintIndices{MOI.VectorAffineFunction{T}, CP.Disjunction}())) == Set(collect(values(bridge.cons))) end @testset "Set of constraints" begin - @test length(bridge.cons) == dim * (dim - 1) / 2 + @test length(bridge.cons) == div(dim * (dim - 1), 2) for i in 1:dim for j in (i+1):dim @test MOI.is_valid(model, bridge.cons[i, j]) diff --git a/test/Bridges/Constraint/AllDifferentExceptConstants/adec_to_reif.jl b/test/Bridges/Constraint/AllDifferentExceptConstants/adec_to_reif.jl index fe7ae382..74585778 100644 --- a/test/Bridges/Constraint/AllDifferentExceptConstants/adec_to_reif.jl +++ b/test/Bridges/Constraint/AllDifferentExceptConstants/adec_to_reif.jl @@ -53,11 +53,11 @@ (MOI.ScalarAffineFunction{T}, MOI.GreaterThan{T}), ] - @test MOI.get(bridge, MOI.NumberOfVariables()) == dim * length(values_set) + dim * (dim - 1) / 2 - @test MOI.get(bridge, MOI.NumberOfConstraints{MOI.VariableIndex, MOI.ZeroOne}()) == dim * length(values_set) + dim * (dim - 1) / 2 + @test MOI.get(bridge, MOI.NumberOfVariables()) == dim * length(values_set) + div(dim * (dim - 1), 2) + @test MOI.get(bridge, MOI.NumberOfConstraints{MOI.VariableIndex, MOI.ZeroOne}()) == dim * length(values_set) + div(dim * (dim - 1), 2) @test MOI.get(bridge, MOI.NumberOfConstraints{MOI.VectorAffineFunction{T}, CP.Reification{MOI.EqualTo{T}}}()) == dim * length(values_set) - @test MOI.get(bridge, MOI.NumberOfConstraints{MOI.ScalarAffineFunction{T}, CP.Reification{CP.DifferentFrom{T}}}()) == dim * (dim - 1) / 2 - @test MOI.get(bridge, MOI.NumberOfConstraints{MOI.ScalarAffineFunction{T}, MOI.GreaterThan{T}}()) == dim * (dim - 1) / 2 + @test MOI.get(bridge, MOI.NumberOfConstraints{MOI.ScalarAffineFunction{T}, CP.Reification{CP.DifferentFrom{T}}}()) == div(dim * (dim - 1), 2) + @test MOI.get(bridge, MOI.NumberOfConstraints{MOI.ScalarAffineFunction{T}, MOI.GreaterThan{T}}()) == div(dim * (dim - 1), 2) @test Set(MOI.get(bridge, MOI.ListOfVariableIndices())) == Set([vec(collect(values(bridge.vars_compare)))..., vec(collect(values(bridge.vars_different)))...]) @test Set(MOI.get(bridge, MOI.ListOfConstraintIndices{MOI.VariableIndex, MOI.ZeroOne}())) == Set([vec(collect(values(bridge.vars_compare_bin)))..., vec(collect(values(bridge.vars_different_bin)))...]) @@ -81,8 +81,8 @@ end end - @test length(bridge.vars_different) == dim * (dim - 1) / 2 - @test length(bridge.vars_different_bin) == dim * (dim - 1) / 2 + @test length(bridge.vars_different) == div(dim * (dim - 1), 2) + @test length(bridge.vars_different_bin) == div(dim * (dim - 1), 2) for i in 1:dim for j in 1:i @@ -121,7 +121,7 @@ end @testset "Compare array variables" begin - @test length(bridge.cons_different_reif) == dim * (dim - 1) / 2 + @test length(bridge.cons_different_reif) == div(dim * (dim - 1), 2) for i in 1:dim for j in (i+1):dim @@ -149,7 +149,7 @@ end @testset "Disjunction" begin - @test length(bridge.cons) == dim * (dim - 1) / 2 + @test length(bridge.cons) == div(dim * (dim - 1), 2) for i in 1:dim for j in (i+1):dim diff --git a/test/runtests.jl b/test/runtests.jl index 62d36fe8..c1b5e50a 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -4,12 +4,10 @@ using Test const CP = ConstraintProgrammingExtensions const COIT = CP.Test -const COIDT = CP.DeprecatedTest const COIB = CP.Bridges const MOI = MathOptInterface const MOIB = MOI.Bridges const MOIBC = MOIB.Constraint -const MOIT = MOI.DeprecatedTest const MOIU = MOI.Utilities include("Bridges/models.jl") @@ -19,6 +17,5 @@ include("Bridges/models.jl") include("moi_traits.jl") include("Bridges/Bridges.jl") include("FlatZinc/FlatZinc.jl") - include("DeprecatedTest/DeprecatedTest.jl") include("Test/Test.jl") end