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

minkowski_sum for SPZ and zonotopic set #3493

Merged
merged 1 commit into from
May 14, 2024
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
21 changes: 20 additions & 1 deletion src/ConcreteOperations/minkowski_sum.jl
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,8 @@ end

# ZeroSet is the neutral element (+ disambiguation)
for T in [:LazySet, :AbstractPolyhedron, :AbstractPolytope, :AbstractZonotope,
:AbstractHyperrectangle, :AbstractSingleton, :DensePolynomialZonotope]
:AbstractHyperrectangle, :AbstractSingleton, :DensePolynomialZonotope,
:SparsePolynomialZonotope]
@eval begin
@commutative minkowski_sum(::ZeroSet, X::$T) = X
end
Expand Down Expand Up @@ -498,6 +499,13 @@ Compute the Minkowski sum of two sparse polyomial zonotopes.
### Output

The Minkowski sum of `P1` and `P2`.

### Algorithm

See Proposition 3.1.19 in [1].

[1] Kochdumper. *Extensions of polynomial zonotopes and their application to
verification of cyber-physical systems.* PhD diss., TU Munich, 2022.
"""
function minkowski_sum(P1::SparsePolynomialZonotope,
P2::SparsePolynomialZonotope)
Expand All @@ -508,6 +516,17 @@ function minkowski_sum(P1::SparsePolynomialZonotope,
return SparsePolynomialZonotope(c, G, GI, E)
end

# See Proposition 3.1.19 in [1].
# [1] Kochdumper. *Extensions of polynomial zonotopes and their application to
# verification of cyber-physical systems.* PhD diss., TU Munich, 2022.
@commutative function minkowski_sum(PZ::SparsePolynomialZonotope, Z::AbstractZonotope)
c = center(PZ) + center(Z)
G = genmat_dep(PZ)
GI = hcat(genmat_indep(PZ), genmat(Z))
E = expmat(PZ)
return SparsePolynomialZonotope(c, G, GI, E)
end

# Given two balls of the same p-norm, their Minkowski sum is again a p-norm ball,
# which can be seen as follows:
#
Expand Down
9 changes: 9 additions & 0 deletions test/ConcreteOperations/minkowski_sum.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ for N in [Float64, Float32, Rational{Int}]
B2 = B(N[4, 5], N(6))
@test minkowski_sum(B1, B2) == B(N[5, 7], N(9))
end

H1 = Hyperrectangle(N[1, 2], N[3, 4])
H2 = Hyperrectangle(N[5, 6], N[7, 8])
@test minkowski_sum(H1, H2) == Hyperrectangle(N[6, 8], N[10, 12])
PZ = minkowski_sum(convert(SparsePolynomialZonotope, H1), H2)
# equality is not required but approximates the equivalence check
@test PZ == SparsePolynomialZonotope(N[6, 8], N[3 0; 0 4], N[7 0; 0 8], [1 0; 0 1], 1:2)
PZ = minkowski_sum(H1, convert(SparsePolynomialZonotope, H2))
@test PZ == SparsePolynomialZonotope(N[6, 8], N[7 0; 0 8], N[3 0; 0 4], [1 0; 0 1], 1:2)
end

for N in [Float64, Float32]
Expand Down
Loading