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
Binary file removed .DS_Store
Binary file not shown.
2 changes: 2 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ jobs:
fail-fast: false
matrix:
version:
- '1.3' # oldest Julia version that works
- '1.8' # newest Julia version that works with ModelingToolkit
- '1'
- 'nightly'
os:
Expand Down
10 changes: 9 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
*.jl.cov
*.jl.*.cov
*.jl.mem
docs/build/
docs/build/

*.DS_Store

coverage/

.vscode

Manifest.toml
14 changes: 10 additions & 4 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# IntervalConstraintProgramming.jl

#v0.11
# v0.11
## Minimum Julia version
- The minimum Julia version supported is now Julia 1.1

##Functionality's are added
## Functionality's are added
- Contractor can be make by just function name only
- New type of Contractor named as `BasicContractor` can be construct which only contain fields of useful data.


# v0.10
## Minimum Julia version
- The minimum Julia version supported is now Julia 1.0.
Expand All @@ -17,6 +17,7 @@

- By the help of `ModelingToolkit.jl` we can construct contractors and separators without the use of macros.


# v0.9
## Minimum Julia version
- The minimum Julia version supported is now Julia 0.7. The package is fully compatible with Julia 1.0.
Expand All @@ -29,12 +30,14 @@
## Minimum Julia version
- The minimum Julia version required has been bumped to 0.6; this will be the last release to support 0.6.


# v0.7

## New dependency: `IntervalContractors.jl`

The reverse functions used for constraint propagation have been factored out into the `IntervalContractors.jl` package.


# v0.6
## Minimum Julia version
- The minimum Julia version required has been bumped to 0.5
Expand All @@ -45,6 +48,7 @@ The reverse functions used for constraint propagation have been factored out int
## Dependency change
- The dependency on `ValidatedNumerics.jl` has been replaced by `IntervalArithmetic.jl` and `IntervalRootFinding.jl`


# v0.5
- API change: Contractors now have their dimension as a type parameter
- Refactoring for type stability
Expand All @@ -53,6 +57,7 @@ The reverse functions used for constraint propagation have been factored out int
- Generated code uses simpler symbols
- Example notebooks have been split out into a separate repository: https://github.com/dpsanders/IntervalConstraintProgrammingNotebooks


# v0.4
- `@function f(x) = 4x` defines a function
- Functions may be used inside constraints
Expand Down Expand Up @@ -84,6 +89,7 @@ C = @constraint (x-$a)^2 + (y-$b)^2
The constraint will *not* change if the constants are changed, but may be
updated (changed) by calling the same `@constraint` command again.


# v0.2
- `setinverse` now returns an object of type `Paving` [#17](https://github.com/dpsanders/IntervalConstraintProgramming.jl/pull/17)

Expand All @@ -95,7 +101,7 @@ updated (changed) by calling the same `@constraint` command again.
to eliminate collisions with user-defined variables [#20](https://github.com/dpsanders/IntervalConstraintProgramming.jl/pull/20)


## v0.1.1
# v0.1.1
- Add `sqrtRev` reverse-mode function

- Add solid torus example, including 3D visualization with GLVisualize
Expand Down
15 changes: 3 additions & 12 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,12 @@ version = "0.12.4"
[deps]
IntervalArithmetic = "d1acc4aa-44c8-5952-acd4-ba5d80a2a253"
IntervalContractors = "15111844-de3b-5229-b4ba-526f2f385dc9"
IntervalRootFinding = "d2bf35a9-74e0-55ec-b149-d360ff49b807"
MacroTools = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09"
ModelingToolkit = "961ee093-0014-501f-94e3-6117800e7a78"
Requires = "ae029012-a4dd-5104-9daa-d747884805df"

[compat]
IntervalArithmetic = "0.16, 0.17, 0.18, 0.19, 0.20"
IntervalContractors = "0.4"
IntervalRootFinding = "0.5"
MacroTools = "0.4, 0.5"
ModelingToolkit = "3"
julia = "1.3, 1.4"

[extras]
ModelingToolkit = "961ee093-0014-501f-94e3-6117800e7a78"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test", "ModelingToolkit"]
Requires = "0.5, 1"
julia = "1.3"
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

[![Build Status](https://github.com/JuliaIntervals/IntervalConstraintProgramming.jl/workflows/CI/badge.svg)](https://github.com/JuliaIntervals/IntervalConstraintProgramming.jl/actions/workflows/CI.yml)
[![Docs](https://img.shields.io/badge/docs-stable-blue.svg)](https://juliaintervals.github.io/pages/packages/intervalconstraintprogramming/)
[![coverage](https://codecov.io/gh/JuliaIntervals/IntervalConstraintProgramming.jl/branch/master/graph/badge.svg)](https://codecov.io/gh/JuliaIntervals/IntervalConstraintProgramming.jl)

This Julia package allows us to specify a set of constraints on real-valued variables,
given by inequalities, and
Expand Down
6 changes: 0 additions & 6 deletions REQUIRE

This file was deleted.

16 changes: 7 additions & 9 deletions src/IntervalConstraintProgramming.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ __precompile__()

module IntervalConstraintProgramming

using IntervalArithmetic,
IntervalRootFinding,
IntervalContractors

using ModelingToolkit
using IntervalArithmetic,
IntervalContractors
using Requires
using MacroTools

import Base:
Expand All @@ -18,12 +16,11 @@ export
BasicContractor,
@contractor,
Contractor,
Separator, separator, @separator, @constraint,
Separator, @constraint,
@function,
SubPaving, Paving,
pave, refine!,
Vol,
show_code
pave,
Vol

const reverse_operations = IntervalContractors.reverse_operations

Expand All @@ -35,5 +32,6 @@ include("paving.jl")
include("setinversion.jl")
include("volume.jl")
include("functions.jl")
include("init.jl")

end # module
52 changes: 28 additions & 24 deletions src/ast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -116,23 +116,39 @@ Returns the variable at the top of the current piece of the tree."""

# TODO: Parameters

# numbers:
function flatten!(flatAST::FlatAST, ex::ModelingToolkit.Constant, var)
return ex.value # nothing to do the AST; return the number
function _load_MT_flatten()
return quote
# numbers:
function flatten!(flatAST::FlatAST, ex::Constant, var)
return ex.value # nothing to do the AST; return the number
end

function flatten!(flatAST::FlatAST, ex::Variable, var) # symbols are leaves
if isempty(var)
add_variable!(flatAST, Symbol(ex)) # add the discovered symbol as an input variable
end
return Symbol(ex)
end

function flatten!(flatAST::FlatAST, ex::Operation, var)
# top = process_operation!(flatAST, ex, var)
# set_top!(flatAST, top)

if ex.op isa Variable
return flatten!(flatAST, ex.op, var)
else
top = process_operation!(flatAST, ex, var)
set_top!(flatAST, top)
end
end
end
end

function flatten!(flatAST::FlatAST, ex, var)
return ex # nothing to do to the AST; return the number
end

# symbols:
function flatten!(flatAST::FlatAST, ex::Variable, var) # symbols are leaves
if isempty(var)
add_variable!(flatAST, Symbol(ex)) # add the discovered symbol as an input variable
end
return Symbol(ex)
end

function flatten!(flatAST::FlatAST, ex::Symbol, var)
if isempty(var)
add_variable!(flatAST, ex) # add the discovered symbol as an input variable
Expand Down Expand Up @@ -169,18 +185,6 @@ function flatten!(flatAST::FlatAST, ex::Expr, var = [])
set_top!(flatAST, top)
end

function flatten!(flatAST::FlatAST, ex::Operation, var)
# top = process_operation!(flatAST, ex, var)
# set_top!(flatAST, top)

if ex.op isa Variable
return flatten!(flatAST, ex.op, var)
else
top = process_operation!(flatAST, ex, var)
set_top!(flatAST, top)
end
end


function process_constant!(flatAST::FlatAST, ex)
return esc(ex.args[1]) # interpolate the value of the external constant
Expand Down Expand Up @@ -335,7 +339,7 @@ function process_call!(flatAST::FlatAST, ex, var = [], new_var=nothing)
#@show op

if op ∈ keys(reverse_operations) # standard operator
if new_var == nothing
if isnothing(new_var)
new_var = make_symbol()
end

Expand Down Expand Up @@ -408,7 +412,7 @@ function process_operation!(flatAST::FlatAST, ex, var, new_var=nothing)
#@show op

if Symbol(op) ∈ keys(reverse_operations) # standard operator
if new_var == nothing
if isnothing(new_var)
new_var = make_symbol()
end

Expand Down
86 changes: 44 additions & 42 deletions src/contractor.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@

"""
`Contractor` represents a `Contractor` from ``\\mathbb{R}^N`` to ``\\mathbb{R}^N``.
Nout is the output dimension of the forward part.
"""
abstract type AbstractContractor end

struct Contractor{N, Nout, F1<:Function, F2<:Function, ex<:Union{Operation,Expr}} <:AbstractContractor
struct Contractor{N, Nout, F1<:Function, F2<:Function, ex} <:AbstractContractor
variables::Vector{Symbol} # input variables
forward::GeneratedFunction{F1}
backward::GeneratedFunction{F2}
Expand Down Expand Up @@ -86,70 +85,73 @@ function (C::BasicContractor)(A::IntervalBox{Nout,T}, X::IntervalBox{N,T})where
end

# allow 1D contractors to take Interval instead of IntervalBox for simplicty:
(C::BasicContractor)(A::Interval{T}, X::IntervalBox{N,T}) where {N,Nout,T} = C(IntervalBox(A), X)

""" Contractor can also be construct without the use of macros
vars = @variables x y z
C = Contractor(x + y , vars)
C(-Inf..1, IntervalBox(0.5..1.5,3))
"""
(C::BasicContractor)(A::Interval{T}, X::IntervalBox{N,T}) where {N,T} = C(IntervalBox(A), X)

function Contractor(variables, expr::Operation)

var = [i.op.name for i in variables]
top, linear_AST = flatten(expr, var)
function Base.show(io::IO, C::BasicContractor{F1,F2}) where {F1,F2}
println(io, " Basic version of Contractor")
end

function _load_MT_contractor()
return quote
""" Contractor can also be construct without the use of macros
vars = @variables x y z
C = Contractor(x + y , vars)
C(-Inf..1, IntervalBox(0.5..1.5,3))
"""
function Contractor(variables, expr::Operation)

forward_code, backward_code = forward_backward(linear_AST)
var = [i.op.name for i in variables]
top, linear_AST = flatten(expr, var)


# @show top
forward_code, backward_code = forward_backward(linear_AST)

if isa(top, Symbol)
top = [top]
end

forward = eval(forward_code)
backward = eval(backward_code)
# @show top

Contractor(linear_AST.variables,
top,
GeneratedFunction(forward, forward_code),
GeneratedFunction(backward, backward_code),
expr)
if isa(top, Symbol)
top = [top]
end

end
forward = eval(forward_code)
backward = eval(backward_code)

Contractor(linear_AST.variables,
top,
GeneratedFunction(forward, forward_code),
GeneratedFunction(backward, backward_code),
expr)

function BasicContractor(variables, expr::Operation)
end

var = [i.op.name for i in variables]
top, linear_AST = flatten(expr, var)

forward_code, backward_code = forward_backward(linear_AST)
function BasicContractor(variables, expr::Operation)

forward = eval(forward_code)
backward = eval(backward_code)
var = [i.op.name for i in variables]
top, linear_AST = flatten(expr, var)

BasicContractor{typeof(forward), typeof(backward)}(forward, backward)
end
forward_code, backward_code = forward_backward(linear_AST)

function Base.show(io::IO, C::BasicContractor{F1,F2}) where {F1,F2}
println(io, " Basic version of Contractor")
end
forward = eval(forward_code)
backward = eval(backward_code)

BasicContractor(expr::Operation) = BasicContractor([], expr::Operation)
BasicContractor{typeof(forward), typeof(backward)}(forward, backward)
end

BasicContractor(vars::Union{Vector{Operation}, Tuple{Vararg{Operation,N}}}, g::Function) where N = BasicContractor(vars, g(vars...)) #Contractor can be constructed by function name only
BasicContractor(expr::Operation) = BasicContractor([], expr::Operation)

BasicContractor(vars, f::Function) = BasicContractor([Variable(Symbol(i))() for i in vars], f([Variable(Symbol(i))() for i in vars]...))#if vars is not vector of Operation
BasicContractor(vars::Union{Vector{Operation}, Tuple{Vararg{Operation,N}}}, g::Function) where N = BasicContractor(vars, g(vars...)) #Contractor can be constructed by function name only

BasicContractor(vars, f::Function) = BasicContractor([Variable(Symbol(i))() for i in vars], f([Variable(Symbol(i))() for i in vars]...))#if vars is not vector of Operation

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

Contractor(vars::Union{Vector{Operation}, Tuple{Vararg{Operation,N}}}, g::Function) where N = Contractor(vars, g(vars...)) #Contractor can be constructed by function name only
Contractor(vars::Union{Vector{Operation}, Tuple{Vararg{Operation,N}}}, g::Function) where N = Contractor(vars, g(vars...)) #Contractor can be constructed by function name only

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

function make_contractor(expr::Expr, var = [])
# println("Entering Contractor(ex) with ex=$ex")
Expand Down
2 changes: 0 additions & 2 deletions src/functions.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


"""
A `ConstraintFunction` contains the created forward and backward
code
Expand Down
3 changes: 3 additions & 0 deletions src/init.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function __init__()
@require ModelingToolkit = "961ee093-0014-501f-94e3-6117800e7a78" include("init_ModelingToolkit.jl")
end
Loading