Skip to content

Commit

Permalink
Merge pull request #44 from rdeits/generic-interval
Browse files Browse the repository at this point in the history
make `interval()` generic and export it
  • Loading branch information
rdeits authored May 16, 2018
2 parents 142ecd9 + c70a674 commit b4ae998
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/ConditionalJuMP.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export @disjunction,
@switch,
@ifelse,
warmstart!,
interval,
upperbound,
lowerbound

Expand Down Expand Up @@ -206,6 +207,9 @@ upperbound(x::Number) = x
lowerbound(x::Variable) = JuMP.getlowerbound(x)
upperbound(x::Variable) = JuMP.getupperbound(x)

interval(x::Number, simplify=true) = Interval(x, x)
interval(x::Variable, simplify=true) = Interval(JuMP.getlowerbound(x), JuMP.getupperbound(x))

function interval(e::JuMP.GenericAffExpr, needs_simplification=true)
if needs_simplification
simplify!(e)
Expand Down
14 changes: 14 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using ConditionalJuMP
using ConditionalJuMP: switch!, _getvalue, UnhandledComplementException, hascomplement, getindicator!, disjunction!, isjump, Conditional
using IntervalArithmetic: Interval
using JuMP
using Cbc
using Base.Test
Expand Down Expand Up @@ -68,6 +69,19 @@ end
@test lowerbound(e - 2x) == 1
@test lowerbound(AffExpr(2)) == 2
@test upperbound(AffExpr(2)) == 2

i = interval(e, false)
@test i == Interval(3, 7)
@test lowerbound(i) == lowerbound(e)
@test upperbound(i) == upperbound(e)

i = interval(5.0)
@test lowerbound(i) == 5.0
@test upperbound(i) == 5.0

i = interval(x)
@test lowerbound(i) == 1
@test upperbound(i) == 3
end

@testset "simple model" begin
Expand Down

0 comments on commit b4ae998

Please sign in to comment.