Skip to content

Commit

Permalink
add conversion from zonotope to sspz (#2991)
Browse files Browse the repository at this point in the history
* add convertion from zonotope to sspz

* update docs

* Apply suggestions from code review

Co-authored-by: Christian Schilling <[email protected]>

* dispatch on AbstractZonotope

* update docstring

* Update src/convert.jl

Co-authored-by: Christian Schilling <[email protected]>
Co-authored-by: Marcelo Forets <[email protected]>
  • Loading branch information
3 people authored Jul 12, 2022
1 parent 8fc8b1c commit bb3b3dd
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/src/lib/conversion.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,5 @@ convert(::Type{Zonotope}, ::CartesianProductArray{N, AZ}) where {N, AZ<:Abstract
convert(::Type{STAR}, ::AbstractPolyhedron{N}) where {N}
convert(::Type{STAR}, ::Star)
convert(::Type{Star}, ::AbstractPolyhedron{N}) where {N}
convert(::Type{SimpleSparsePolynomialZonotope}, ::AbstractZonotope)
```
22 changes: 22 additions & 0 deletions src/convert.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1225,3 +1225,25 @@ function convert(::Type{Hyperplane}, P::HPolyhedron; skip_check::Bool=false)
c1 = @inbounds first(constraints_list(P))
return Hyperplane(c1.a, c1.b)
end


"""
convert(::Type{SimpleSparsePolynomialZonotope}, Z::Zonotope)
Convert a zonotope to a simple sparse polynomial zonotope.
### Algorithm
This method implements Proposition 3 in [1].
[1] Kochdumper, Althoff. *Sparse polynomial zonotopes - a novel set
representation for reachability analysis*. 2021
"""
function convert(::Type{SimpleSparsePolynomialZonotope}, Z::AbstractZonotope)
c = center(Z)
G = genmat(Z)
n = ngens(Z)
E = Matrix(1 * I, n, n)

return SimpleSparsePolynomialZonotope(c, G, E)
end
7 changes: 7 additions & 0 deletions test/Sets/SimpleSparsePolynomialZonotope.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ for N in [Float64, Float32, Rational{Int}]
@test nparams(S) == 2
@test order(S) == 1 // 1

for Z in [rand(Zonotope), rand(Hyperrectangle)]
ZS = convert(SimpleSparsePolynomialZonotope, Z)
@test center(ZS) == center(Z)
@test genmat(ZS) == genmat(Z)
@test expmat(ZS) == I
end

@test overapproximate(S, Zonotope) == Zonotope(N[3., 1], N[1 1;2 1.])
@test length(overapproximate(S, Zonotope; nsdiv=3)) == 9
@test length(overapproximate(S, Zonotope; partition=(2, 3))) == 6
Expand Down

0 comments on commit bb3b3dd

Please sign in to comment.