Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/contractor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ end

Contractor(expr::Operation) = Contractor([], expr::Operation)

Contractor(vars, g::Function) = Contractor(vars, g(vars...)) #Contractor can be constructed by function name only
Contractor(vars::Array{Variable}, g) = Contractor(vars, g(vars...)) #Contractor can be constructed by function name only

Contractor(vars, f) = Contractor(vars, f([Variable(Symbol(i)) for i in vars]...))#if vars is not vector of variables

function make_contractor(expr::Expr, var = [])
# println("Entering Contractor(ex) with ex=$ex")
Expand Down
10 changes: 7 additions & 3 deletions src/separator.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ function parse_comparison(ex::Expr)
@match ex begin
((a_ <= b_) | (a_ < b_) | (a_ ≤ b_)) => (a, (-∞, b))
((a_ >= b_) | (a_ > b_) | (a_ ≥ b_)) => (a, (b, ∞))

((a_ == b_) | (a_ = b_)) => (a, (b, b))

((a_ <= b_ <= c_)
Expand All @@ -86,7 +85,6 @@ function parse_comparison(ex::Expr)
end

a, b = limits

return (expr, a..b) # expr ∈ [a,b]

end
Expand All @@ -109,6 +107,9 @@ function parse_comparison(ex::Operation)
elseif ex.op == <
a = -Inf
b = ex.args[2].value
else
a = ex.args[2].value
b = ex.args[2].value
end
return (ex.args[1], a..b)
end
Expand Down Expand Up @@ -201,7 +202,10 @@ function Separator(variables, ex::Operation)
end

Separator(ex::Operation) = Separator([], ex)
Separator(vars, f::Function) = Separator(vars, f(vars...))

Separator(vars::Array{Variable}, f) = Separator(vars, f(vars...))

Separator(vars, f) = Separator(vars, f([Variable(Symbol(i)) for i in vars]...)) # if vars is not vector of variables

function show(io::IO, S::Separator)
println(io, "Separator:")
Expand Down
1 change: 1 addition & 0 deletions test/REQUIRE
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
ModelingToolkit
DynamicPolynomials
17 changes: 17 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using IntervalArithmetic
using IntervalConstraintProgramming
using ModelingToolkit
using DynamicPolynomials

using Test

@testset "Utilities" begin
Expand Down Expand Up @@ -62,6 +64,13 @@ end

end

@testset "Contractors for polynamial functions" begin
pvars = @polyvar x y
p(x,y) = x + y
C = Contractor(pvars, p)
@test C(-Inf..1, IntervalBox(0.5..1.5, 2)) == IntervalBox(0.5..0.5, 2)
end

@testset "Separators" begin
II = -100..100
X = IntervalBox(II, II)
Expand Down Expand Up @@ -107,6 +116,14 @@ end

end

@testset "Seperators for polynomial functions" begin
pvars = @polyvar x y
p(x,y) = x + y == 1
S = Separator(pvars, p)

@test S(IntervalBox(0.5..1.5, 2)) == (IntervalBox(0.5..0.5, 2), IntervalBox(0.5..1.5, 2))

end
@testset "pave" begin
S1a = @constraint(x > 0 , [x, y])
S1b = @constraint(y > 0 , [x, y])
Expand Down