Skip to content

Commit

Permalink
#58 - modified AbstractPointSymmetricPolytope types
Browse files Browse the repository at this point in the history
  • Loading branch information
schillic committed Dec 20, 2017
1 parent 6fa2e04 commit 7f3a9c9
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 49 deletions.
54 changes: 41 additions & 13 deletions src/Ball1.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Base.∈
export Ball1

"""
Ball1 <: LazySet
Ball1{N<:Real} <: AbstractPointSymmetricPolytope{N}
Type that represents a ball in the 1-norm, also known as Manhattan or Taxicab
norm.
Expand Down Expand Up @@ -40,7 +40,7 @@ julia> σ([0.,1], B)
1.0
```
"""
struct Ball1{N<:Real} <: LazySet
struct Ball1{N<:Real} <: AbstractPointSymmetricPolytope{N}
center::Vector{N}
radius::N

Expand All @@ -51,39 +51,67 @@ end
# type-less convenience constructor
Ball1(center::Vector{N}, radius::N) where {N<:Real} = Ball1{N}(center, radius)


# --- AbstractPointSymmetric interface functions ---


"""
dim(B::Ball1)::Int
center(B::Ball1{N})::Vector{N} where {N<:Real}
Return the dimension of a `Ball1`.
Return the center of a ball in the 1-norm.
### Input
- `B` -- a ball in the 1-norm
- `B` -- ball in the 1-norm
### Output
The ambient dimension of the ball.
The center of the ball in the 1-norm.
"""
function dim(B::Ball1)::Int
return length(B.center)
function center(B::Ball1{N})::Vector{N} where {N<:Real}
return B.center
end


# --- AbstractPolytope interface functions ---


"""
vertices_list(B::Ball1{N})::Vector{Vector{N}} where {N<:Real}
Return the list of vertices of a ball in the 1-norm.
### Input
- `B` -- ball in the 1-norm
### Output
A list containing only a single vertex.
"""
function vertices_list(B::Ball1{N})::Vector{Vector{N}} where {N<:Real}
error("this function is not implemented yet, see issue #84")
end


# --- LazySet interface functions ---


"""
σ(d::AbstractVector{N}, B::Ball1)::AbstractVector{N} where {N<:Real}
Return the support vector of a `Ball1` in a given direction.
Return the support vector of a ball in the 1-norm in a given direction.
### Input
- `d` -- a direction
- `B` -- a ball in the p-norm
- `d` -- direction
- `B` -- ball in the 1-norm
### Output
Support vector in the given direction.
"""
function σ(d::AbstractVector{N},
B::Ball1)::AbstractVector{N} where {N<:AbstractFloat}
function σ(d::AbstractVector{N}, B::Ball1{N})::AbstractVector{N} where {N<:Real}
res = copy(B.center)
imax = indmax(abs.(d))
res[imax] = sign(d[imax]) * B.radius
Expand Down
88 changes: 52 additions & 36 deletions src/Zonotope.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import Base.∈

export Zonotope,
vertices_list,
order

"""
Zonotope{N<:Real} <: LazySet
Zonotope{N<:Real} <: AbstractPointSymmetricPolytope{N}
Type that represents a zonotope.
Expand All @@ -32,7 +31,8 @@ ball in ``\\mathbb{R}^n`` by an affine transformation.
generators::AbstractMatrix{N}) where {N<:Real}`
- `Zonotope(center::AbstractVector{N},
generators_list::AbstractVector{T}) where {N<:Real, T<:AbstractVector{N}}`
generators_list::AbstractVector{T}
) where {N<:Real, T<:AbstractVector{N}}`
### Examples
Expand Down Expand Up @@ -76,7 +76,7 @@ julia> Z.generators
0.0 1.0 1.0
```
"""
struct Zonotope{N<:Real} <: LazySet
struct Zonotope{N<:Real} <: AbstractPointSymmetricPolytope{N}
center::AbstractVector{N}
generators::AbstractMatrix{N}
end
Expand All @@ -85,43 +85,31 @@ Zonotope(center::AbstractVector{N},
generators_list::AbstractVector{T}) where {N<:Real, T<:AbstractVector{N}} =
Zonotope(center, hcat(generators_list...))

"""
dim(Z::Zonotope)::Int

Return the dimension of a zonotope.
# --- AbstractPointSymmetric interface functions ---

### Input

- `Z` -- zonotope
### Output
The ambient dimension of the zonotope.
"""
function dim(Z::Zonotope)::Int
return length(Z.center)
end
center(Z::Zonotope{N})::Vector{N} where {N<:Real}
"""
σ(d::AbstractVector{<:Real}, Z::Zonotope)::AbstractVector{<:Real}
Return the support vector of a zonotope in a given direction.
Return the center of a zonotope.
### Input
- `d` -- direction
- `Z` -- zonotope
### Output
Support vector in the given direction.
If the direction has norm zero, the vertex with ``ξ_i = 1 \\ \\ ∀ i = 1,…, p``
is returned.
The center of the zonotope.
"""
function σ(d::AbstractVector{<:Real}, Z::Zonotope)::AbstractVector{<:Real}
return Z.center .+ Z.generators * sign_cadlag.(Z.generators.' * d)
function center(Z::Zonotope{N})::Vector{N} where {N<:Real}
return Z.center
end


# --- AbstractPolytope interface functions ---


"""
vertices_list(Z::Zonotope{N})::Vector{Vector{N}} where {N<:Real}
Expand Down Expand Up @@ -154,26 +142,28 @@ function vertices_list(Z::Zonotope{N})::Vector{Vector{N}} where {N<:Real}
return convex_hull!(vlist)
end


# --- LazySet interface functions ---


"""
order(Z::Zonotope)::Rational
σ(d::AbstractVector{<:Real}, Z::Zonotope)::AbstractVector{<:Real}
Return the order of a zonotope.
Return the support vector of a zonotope in a given direction.
### Input
- `d` -- direction
- `Z` -- zonotope
### Output
A rational number representing the order of the zonotope.
### Notes
The order of a zonotope is defined as the quotient of its number of generators
and its dimension.
Support vector in the given direction.
If the direction has norm zero, the vertex with ``ξ_i = 1 \\ \\ ∀ i = 1,…, p``
is returned.
"""
function order(Z::Zonotope)::Rational
return size(Z.generators, 2) // dim(Z)
function σ(d::AbstractVector{<:Real}, Z::Zonotope)::AbstractVector{<:Real}
return Z.center .+ Z.generators * sign_cadlag.(Z.generators.' * d)
end

"""
Expand Down Expand Up @@ -239,3 +229,29 @@ function ∈(x::AbstractVector{N}, Z::Zonotope{N})::Bool where {N<:Real}
return false
end
end


# --- Zonotope functions ---


"""
order(Z::Zonotope)::Rational
Return the order of a zonotope.
### Input
- `Z` -- zonotope
### Output
A rational number representing the order of the zonotope.
### Notes
The order of a zonotope is defined as the quotient of its number of generators
and its dimension.
"""
function order(Z::Zonotope)::Rational
return size(Z.generators, 2) // dim(Z)
end

0 comments on commit 7f3a9c9

Please sign in to comment.