Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#600 - Specialized support function computations #1454

Merged
merged 5 commits into from
Jun 21, 2019
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
2 changes: 2 additions & 0 deletions docs/src/lib/interfaces.md
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ This interface defines the following functions:
norm(::AbstractHyperrectangle, ::Real=Inf)
radius(::AbstractHyperrectangle, ::Real=Inf)
σ(::AbstractVector{N}, ::AbstractHyperrectangle{N}) where {N<:Real}
ρ(::AbstractVector{N}, ::AbstractHyperrectangle{N}) where {N<:Real}
∈(::AbstractVector{N}, ::AbstractHyperrectangle{N}) where {N<:Real}
vertices_list(::AbstractHyperrectangle{N}) where {N<:Real}
constraints_list(::AbstractHyperrectangle{N}) where {N<:Real}
Expand All @@ -262,6 +263,7 @@ This interface defines the following functions:

```@docs
σ(::AbstractVector{N}, ::AbstractSingleton{N}) where {N<:Real}
ρ(::AbstractVector{N}, ::AbstractSingleton{N}) where {N<:Real}
∈(::AbstractVector{N}, ::AbstractSingleton{N}) where {N<:Real}
an_element(::AbstractSingleton{N}) where {N<:Real}
center(::AbstractSingleton{N}) where {N<:Real}
Expand Down
5 changes: 5 additions & 0 deletions docs/src/lib/representations.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ Inherited from [`AbstractZonotope`](@ref):

Inherited from [`AbstractHyperrectangle`](@ref):
* [`σ`](@ref σ(::AbstractVector{N}, ::AbstractHyperrectangle{N}) where {N<:Real})
* [`ρ`](@ref σ(::AbstractVector{N}, ::AbstractHyperrectangle{N}) where {N<:Real})
* [`∈`](@ref ∈(::AbstractVector{N}, ::AbstractHyperrectangle{N}) where {N<:Real})
* [`norm`](@ref norm(::AbstractHyperrectangle, ::Real))
* [`vertices_list`](@ref vertices_list(::AbstractHyperrectangle{N}) where {N<:Real})
Expand Down Expand Up @@ -151,6 +152,7 @@ EmptySet
dim(::EmptySet)
σ(::AbstractVector{N}, ::EmptySet{N}) where {N<:Real}
ρ(::AbstractVector{N}, ::EmptySet{N}) where {N<:Real}
∈(::AbstractVector{N}, ::EmptySet{N}) where {N<:Real}
an_element(::EmptySet)
rand(::Type{EmptySet})
Expand Down Expand Up @@ -245,6 +247,7 @@ Inherited from [`AbstractZonotope`](@ref):

Inherited from [`AbstractHyperrectangle`](@ref):
* [`σ`](@ref σ(::AbstractVector{N}, ::AbstractHyperrectangle{N}) where {N<:Real})
* [`ρ`](@ref σ(::AbstractVector{N}, ::AbstractHyperrectangle{N}) where {N<:Real})
* [`∈`](@ref ∈(::AbstractVector{N}, ::AbstractHyperrectangle{N}) where {N<:Real})
* [`norm`](@ref norm(::AbstractHyperrectangle, ::Real))
* [`radius`](@ref radius(::AbstractHyperrectangle, ::Real))
Expand All @@ -260,6 +263,7 @@ Inherited from [`AbstractHyperrectangle`](@ref):
Interval
dim(::Interval)
σ(::AbstractVector{N}, ::Interval{N}) where {N<:Real}
ρ(::AbstractVector{N}, ::Interval{N}) where {N<:Real}
∈(::AbstractVector{N}, ::Interval{N}) where {N<:Real}
∈(::N, ::Interval{N}) where {N<:Real}
an_element(::Interval{N}) where {N<:Real}
Expand Down Expand Up @@ -633,6 +637,7 @@ translate(::Universe{N}, ::AbstractVector{N}) where {N<:Real}
ZeroSet
dim(::ZeroSet)
σ(::AbstractVector{N}, ::ZeroSet{N}) where {N<:Real}
ρ(::AbstractVector{N}, ::ZeroSet{N}) where {N<:Real}
∈(::AbstractVector{N}, ::ZeroSet{N}) where {N<:Real}
rand(::Type{ZeroSet})
element(::ZeroSet{N}) where {N<:Real}
Expand Down
29 changes: 29 additions & 0 deletions src/AbstractHyperrectangle.jl
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,35 @@ function σ(d::AbstractVector{N}, H::AbstractHyperrectangle{N}) where {N<:Real}
return center(H) .+ sign_cadlag.(d) .* radius_hyperrectangle(H)
end

"""
ρ(d::AbstractVector{N}, H::AbstractHyperrectangle{N}) where {N<:Real}

Evaluate the support function of a hyperrectangular set in a given direction.

### Input

- `d` -- direction
- `H` -- hyperrectangular set

### Output

Evaluation of the support function in the given direction.
"""
function ρ(d::AbstractVector{N}, H::AbstractHyperrectangle{N}) where {N<:Real}
@assert length(d) == dim(H) "a $(length(d))-dimensional vector is " *
"incompatible with a $(dim(H))-dimensional set"
c = center(H)
res = zero(N)
@inbounds for (i, di) in enumerate(d)
if di < zero(N)
res += di * (c[i] - radius_hyperrectangle(H, i))
elseif di > zero(N)
res += di * (c[i] + radius_hyperrectangle(H, i))
end
end
return res
end

"""
norm(H::AbstractHyperrectangle, [p]::Real=Inf)::Real

Expand Down
17 changes: 17 additions & 0 deletions src/AbstractSingleton.jl
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,23 @@ function σ(d::AbstractVector{N}, S::AbstractSingleton{N}) where {N<:Real}
return element(S)
end

"""
ρ(d::AbstractVector{N}, S::AbstractSingleton{N}) where {N<:Real}

Evaluate the support function of a set with a single value in a given direction.

### Input

- `d` -- direction
- `S` -- set with a single value

### Output

Evaluation of the support function in the given direction.
"""
function ρ(d::AbstractVector{N}, S::AbstractSingleton{N}) where {N<:Real}
return dot(d, element(S))
end

"""
∈(x::AbstractVector{N}, S::AbstractSingleton{N})::Bool where {N<:Real}
Expand Down
20 changes: 19 additions & 1 deletion src/EmptySet.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Return the support vector of an empty set.
### Input

- `d` -- direction
- `∅` -- an empty set
- `∅` -- empty set

### Output

Expand All @@ -62,6 +62,24 @@ function σ(d::AbstractVector{N}, ∅::EmptySet{N}) where {N<:Real}
error("the support vector of an empty set does not exist")
end

"""
ρ(d::AbstractVector{N}, ∅::EmptySet{N}) where {N<:Real}

Evaluate the support function of an empty set in a given direction.

### Input

- `d` -- direction
- `∅` -- empty set

### Output

An error.
"""
function ρ(d::AbstractVector{N}, ∅::EmptySet{N}) where {N<:Real}
error("the support function of an empty set does not exist")
end

"""
isbounded(∅::EmptySet)::Bool

Expand Down
23 changes: 21 additions & 2 deletions src/Interval.jl
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ dim(x::Interval)::Int = 1
"""
σ(d::AbstractVector{N}, x::Interval{N}) where {N<:Real}

Return the support vector of an ellipsoid in a given direction.
Return the support vector of an interval in a given direction.

### Input

Expand All @@ -136,7 +136,26 @@ Support vector in the given direction.
"""
function σ(d::AbstractVector{N}, x::Interval{N}) where {N<:Real}
@assert length(d) == dim(x)
return d[1] > 0 ? [x.dat.hi] : [x.dat.lo]
return d[1] > zero(N) ? high(x) : low(x)
end

"""
ρ(d::AbstractVector{N}, x::Interval{N}) where {N<:Real}

Evaluate the support function of an interval in a given direction.

### Input

- `d` -- direction
- `x` -- interval

### Output

Evaluation of the support function in the given direction.
"""
function ρ(d::AbstractVector{N}, x::Interval{N}) where {N<:Real}
@assert length(d) == dim(x)
return d[1] * (d[1] > zero(N) ? max(x) : min(x))
end

"""
Expand Down
20 changes: 20 additions & 0 deletions src/ZeroSet.jl
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ Return the support vector of a zero set.

### Input

- `d` -- direction
- `Z` -- a zero set, i.e., a set that only contains the origin

### Output
Expand All @@ -99,6 +100,25 @@ function σ(d::AbstractVector{N}, Z::ZeroSet{N}) where {N<:Real}
return element(Z)
end

"""
ρ(d::AbstractVector{N}, Z::ZeroSet{N}) where {N<:Real}

Evaluate the support function of a zero set in a given direction.

### Input

- `d` -- direction
- `Z` -- a zero set, i.e., a set that only contains the origin

### Output

`0`.
"""
function ρ(d::AbstractVector{N}, Z::ZeroSet{N}) where {N<:Real}
@assert length(d) == dim(Z) "the direction has the wrong dimension"
return zero(N)
end

"""
∈(x::AbstractVector{N}, Z::ZeroSet{N})::Bool where {N<:Real}

Expand Down