Skip to content

Commit

Permalink
convert from AbstractHyperrectangle to Zonotope
Browse files Browse the repository at this point in the history
  • Loading branch information
schillic committed Feb 7, 2018
1 parent ab5d2c1 commit 32c8451
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 7 deletions.
13 changes: 7 additions & 6 deletions docs/src/lib/representations.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ low(::Hyperrectangle{Float64})
```@docs
LinearConstraint
Line
intersection(::Line{Float64}, L2::Line{Float64})
intersection(::Line{Float64}, ::Line{Float64})
```

## Polygons
Expand Down Expand Up @@ -253,9 +253,10 @@ center(::Zonotope{Float64})
vertices_list(::Zonotope{Float64})
singleton_list(::Zonotope{Float64})
order(::Zonotope{Float64})
minkowski_sum(Z1::Zonotope, Z2::Zonotope)
linear_map(M::AbstractMatrix, Z::Zonotope)
scale(α::Real, Z::Zonotope)
ngens(Z::Zonotope)
reduce_order(Z::Zonotope{Float64}, r)
minkowski_sum(::Zonotope, ::Zonotope)
linear_map(::AbstractMatrix, ::Zonotope)
scale(::Real, ::Zonotope)
ngens(::Zonotope)
reduce_order(::Zonotope{Float64}, r)
convert(::Type{Zonotope}, ::AbstractHyperrectangle{Float64})
```
26 changes: 25 additions & 1 deletion src/Zonotope.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Base.∈
import Base:,
convert

export Zonotope,
order,
Expand Down Expand Up @@ -385,3 +386,26 @@ function reduce_order(Z::Zonotope{N}, r)::Zonotope{N} where {N<:Real}
end
return Zonotope(c, Gred)
end

"""
convert(::Type{Zonotope}, H::AbstractHyperrectangle{N}) where {N}
Converts a hyperrectangular set to a zonotope.
### Input
- `Zonotope`
- `H` -- hyperrectangular set
### Output
A zonotope.
"""
function convert(::Type{Zonotope}, H::AbstractHyperrectangle{N}) where {N}
n = dim(H)
gens = zeros(N, n, n)
for i in 1:n
gens[i, i] = radius_hyperrectangle(H, i)
end
return Zonotope{N}(center(H), gens)
end
4 changes: 4 additions & 0 deletions test/unit_Zonotope.jl
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,8 @@ for N in [Float64, Rational{Int}, Float32]
Zred2 = reduce_order(Z, 2)
@test ngens(Zred2) == 4
@test order(Zred2) == 2

# test conversion from hyperrectangular sets
convert(Zonotope, Hyperrectangle(N[2.,3.], N[4.,5.]))
convert(Zonotope, BallInf(N[5.,3.], N(2.)))
end

0 comments on commit 32c8451

Please sign in to comment.