From 26498ed6c57d8d798ea24912a05585242ffcb9ec Mon Sep 17 00:00:00 2001 From: schillic Date: Thu, 20 Jun 2019 15:28:45 +0200 Subject: [PATCH 1/5] support function of ZeroSet --- docs/src/lib/representations.md | 1 + src/ZeroSet.jl | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/docs/src/lib/representations.md b/docs/src/lib/representations.md index 2ddc5ce2a9..d2c26573bf 100644 --- a/docs/src/lib/representations.md +++ b/docs/src/lib/representations.md @@ -633,6 +633,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} diff --git a/src/ZeroSet.jl b/src/ZeroSet.jl index 89c4ab4635..9447238a43 100644 --- a/src/ZeroSet.jl +++ b/src/ZeroSet.jl @@ -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 @@ -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} From 3dc4b22e4d8cbbe55df024877c1a16245e7facda Mon Sep 17 00:00:00 2001 From: schillic Date: Thu, 20 Jun 2019 15:30:51 +0200 Subject: [PATCH 2/5] support function of Interval --- docs/src/lib/representations.md | 1 + src/Interval.jl | 23 +++++++++++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/docs/src/lib/representations.md b/docs/src/lib/representations.md index d2c26573bf..5a77cabb58 100644 --- a/docs/src/lib/representations.md +++ b/docs/src/lib/representations.md @@ -260,6 +260,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} diff --git a/src/Interval.jl b/src/Interval.jl index 501185c33e..087744c8e5 100644 --- a/src/Interval.jl +++ b/src/Interval.jl @@ -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 @@ -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 """ From e8d53f0a50b166af9b22a69f711fabc4c5b55613 Mon Sep 17 00:00:00 2001 From: schillic Date: Thu, 20 Jun 2019 15:32:29 +0200 Subject: [PATCH 3/5] support function of EmptySet --- docs/src/lib/representations.md | 1 + src/EmptySet.jl | 20 +++++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/docs/src/lib/representations.md b/docs/src/lib/representations.md index 5a77cabb58..9f805fd331 100644 --- a/docs/src/lib/representations.md +++ b/docs/src/lib/representations.md @@ -151,6 +151,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}) diff --git a/src/EmptySet.jl b/src/EmptySet.jl index 690f44e803..af218bacf1 100644 --- a/src/EmptySet.jl +++ b/src/EmptySet.jl @@ -52,7 +52,7 @@ Return the support vector of an empty set. ### Input - `d` -- direction -- `∅` -- an empty set +- `∅` -- empty set ### Output @@ -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 From 8a2767d7405b7eb80cdba41de89e03c2b7cd510a Mon Sep 17 00:00:00 2001 From: schillic Date: Thu, 20 Jun 2019 15:53:57 +0200 Subject: [PATCH 4/5] support function of AbstractHyperrectangle --- docs/src/lib/interfaces.md | 1 + docs/src/lib/representations.md | 2 ++ src/AbstractHyperrectangle.jl | 29 +++++++++++++++++++++++++++++ 3 files changed, 32 insertions(+) diff --git a/docs/src/lib/interfaces.md b/docs/src/lib/interfaces.md index 5b3bf14d87..d67ca39f69 100644 --- a/docs/src/lib/interfaces.md +++ b/docs/src/lib/interfaces.md @@ -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} diff --git a/docs/src/lib/representations.md b/docs/src/lib/representations.md index 9f805fd331..830151782f 100644 --- a/docs/src/lib/representations.md +++ b/docs/src/lib/representations.md @@ -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}) @@ -246,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)) diff --git a/src/AbstractHyperrectangle.jl b/src/AbstractHyperrectangle.jl index 7b7e1885db..dc9ff7034e 100644 --- a/src/AbstractHyperrectangle.jl +++ b/src/AbstractHyperrectangle.jl @@ -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 From d0f99ca5c43b376694f07de2fae5ff09c8d2b48f Mon Sep 17 00:00:00 2001 From: schillic Date: Thu, 20 Jun 2019 16:13:43 +0200 Subject: [PATCH 5/5] support function of AbstractSingleton --- docs/src/lib/interfaces.md | 1 + src/AbstractSingleton.jl | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/docs/src/lib/interfaces.md b/docs/src/lib/interfaces.md index d67ca39f69..e17fb1531f 100644 --- a/docs/src/lib/interfaces.md +++ b/docs/src/lib/interfaces.md @@ -263,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} diff --git a/src/AbstractSingleton.jl b/src/AbstractSingleton.jl index edfff6f7ed..035d31c264 100644 --- a/src/AbstractSingleton.jl +++ b/src/AbstractSingleton.jl @@ -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}