diff --git a/Project.toml b/Project.toml index 6725fb41..85a272e8 100644 --- a/Project.toml +++ b/Project.toml @@ -23,7 +23,7 @@ DataFrames = "0.21, 0.22, 1" DelimitedFiles = "1" DocStringExtensions = "0.8, 0.9" HiGHS = "1.4" -IntervalArithmetic = "0.14, 0.15, 0.16, 0.17, 0.18, 0.19, 0.20" +IntervalArithmetic = "0.14, 0.15, 0.16, 0.17, 0.18, 0.19, 0.20, 0.21" JuMP = "0.21.4, 0.21.5, 0.22, 0.23, 1" MAT = "0.5, 0.6, 0.7, 0.8, 0.9, 0.10" MathOptInterface = "0.9, 0.10, 1" diff --git a/src/vendor/ConditionalJuMP.jl b/src/vendor/ConditionalJuMP.jl index 6fccbecf..68e3d6db 100644 --- a/src/vendor/ConditionalJuMP.jl +++ b/src/vendor/ConditionalJuMP.jl @@ -1,5 +1,5 @@ using JuMP -using IntervalArithmetic: Interval +using IntervalArithmetic # We vendor ConditionalJuMP (https://github.com/rdeits/ConditionalJuMP.jl/blob/e0c406077c0b07be76e02f72c3a7a7aa650df82f/src/ConditionalJuMP.jl) # so that we can use JuMP >= 0.2.0 @@ -23,12 +23,15 @@ function owner_model( return nothing end -interval(x::Number) = Interval(x, x) -interval(x::JuMP.VariableRef) = Interval(lower_bound(x), upper_bound(x)) -function interval(e::JuMP.GenericAffExpr) - result = Interval(e.constant, e.constant) +# Supplements constructors in https://github.com/JuliaIntervals/IntervalArithmetic.jl/blob/master/src/intervals/construction.jl. +IntervalArithmetic.interval(x::JuMP.VariableRef) = + IntervalArithmetic.interval(lower_bound(x), upper_bound(x)) +function IntervalArithmetic.interval(e::JuMP.GenericAffExpr) + result = IntervalArithmetic.interval(e.constant) for (var, coef) in e.terms - result += Interval(coef, coef) * Interval(lower_bound(var), upper_bound(var)) + result += + IntervalArithmetic.interval(coef) * + IntervalArithmetic.interval(lower_bound(var), upper_bound(var)) end return result end @@ -37,7 +40,7 @@ lower_bound(x::Number) = x upper_bound(x::Number) = x lower_bound(x::JuMP.VariableRef) = JuMP.lower_bound(x) upper_bound(x::JuMP.VariableRef) = JuMP.upper_bound(x) -lower_bound(e::JuMP.GenericAffExpr) = lower_bound(interval(e)) -upper_bound(e::JuMP.GenericAffExpr) = upper_bound(interval(e)) +lower_bound(e::JuMP.GenericAffExpr) = lower_bound(IntervalArithmetic.interval(e)) +upper_bound(e::JuMP.GenericAffExpr) = upper_bound(IntervalArithmetic.interval(e)) lower_bound(i::Interval) = i.lo upper_bound(i::Interval) = i.hi diff --git a/test/vendor/ConditionalJuMP.jl b/test/vendor/ConditionalJuMP.jl index 14c0439f..da6fcefc 100644 --- a/test/vendor/ConditionalJuMP.jl +++ b/test/vendor/ConditionalJuMP.jl @@ -1,7 +1,8 @@ using Test using JuMP -using MIPVerify: owner_model, interval, lower_bound, upper_bound +using IntervalArithmetic +using MIPVerify: owner_model, lower_bound, upper_bound @isdefined(TestHelpers) || include("../TestHelpers.jl") TestHelpers.@timed_testset "ConditionalJuMP.jl" begin @@ -23,7 +24,7 @@ TestHelpers.@timed_testset "ConditionalJuMP.jl" begin e = 2 * x + 1 @testset "Number" begin - i = interval(5.0) + i = IntervalArithmetic.interval(5.0) @test lower_bound(i) == 5.0 @test upper_bound(i) == 5.0 end @@ -32,7 +33,7 @@ TestHelpers.@timed_testset "ConditionalJuMP.jl" begin @test lower_bound(x) == 1 @test upper_bound(x) == 3 - i = interval(x) + i = IntervalArithmetic.interval(x) @test lower_bound(i) == 1 @test upper_bound(i) == 3 end @@ -50,13 +51,13 @@ TestHelpers.@timed_testset "ConditionalJuMP.jl" begin @test lower_bound(AffExpr(2)) == 2 @test upper_bound(AffExpr(2)) == 2 - i = interval(e) + i = IntervalArithmetic.interval(e) @test lower_bound(i) == lower_bound(e) @test upper_bound(i) == upper_bound(e) end @testset "Interval" begin - i = interval(5.0) + i = IntervalArithmetic.interval(5.0) @test lower_bound(i) == 5.0 @test upper_bound(i) == 5.0 end