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

AbstractPolynomialZonotope: add linear_combination and convex_hull #3778

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
5 changes: 3 additions & 2 deletions docs/src/lib/interfaces/AbstractPolynomialZonotope.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ This interface defines the following functions:
```@docs
ngens(::AbstractPolynomialZonotope)
order(::AbstractPolynomialZonotope)
convex_hull(::AbstractPolynomialZonotope, ::AbstractPolynomialZonotope)
```

```@meta
Expand All @@ -44,10 +45,12 @@ CurrentModule = LazySets.API
Undocumented implementations:

* [`center`](@ref center(::LazySet, ::Int))
* [`convex_hull`](@ref convex_hull(::LazySet))
* [`dim`](@ref dim(::LazySet))
* [`isboundedtype`](@ref isboundedtype(::Type{LazySet}))
* [`isempty`](@ref isempty(::LazySet))
* [`isuniversal`](@ref isuniversal(::LazySet))
* [`linear_combination`](@ref linear_combination(::LazySet, ::LazySet))

```@meta
CurrentModule = LazySets
Expand All @@ -60,7 +63,6 @@ Inherited from [`LazySet`](@ref):
* [`complement`](@ref complement(::LazySet))
* [`concretize`](@ref concretize(::LazySet))
* [`constraints`](@ref constraints(::LazySet))
* [`convex_hull`](@ref convex_hull(::LazySet))
* `copy(::Type{LazySet})`
* [`diameter`](@ref diameter(::LazySet, ::Real=Inf))
* [`eltype`](@ref eltype(::Type{<:LazySet}))
Expand Down Expand Up @@ -93,7 +95,6 @@ Inherited from [`LazySet`](@ref):
* [`ρ`](@ref ρ(::AbstractVector, ::LazySet))
* [`translate`](@ref translate(::LazySet, ::AbstractVector))
* [`cartesian_product`](@ref cartesian_product(::LazySet, ::LazySet))
* [`convex_hull`](@ref convex_hull(::LazySet, ::LazySet))
* [`exact_sum`](@ref exact_sum(::LazySet, ::LazySet))
* [`≈`](@ref ≈(::LazySet, ::LazySet))
* [`isdisjoint`](@ref isdisjoint(::LazySet, ::LazySet))
Expand Down
6 changes: 3 additions & 3 deletions docs/src/lib/sets/DensePolynomialZonotope.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ Inherited from [`LazySet`](@ref):
* [`complement`](@ref complement(::LazySet))
* [`concretize`](@ref concretize(::LazySet))
* [`constraints`](@ref constraints(::LazySet))
* [`convex_hull`](@ref convex_hull(::LazySet))
* `copy(::Type{LazySet})`
* [`diameter`](@ref diameter(::LazySet, ::Real=Inf))
* [`eltype`](@ref eltype(::Type{<:LazySet}))
Expand Down Expand Up @@ -70,23 +69,24 @@ Inherited from [`LazySet`](@ref):
* [`ρ`](@ref ρ(::AbstractVector, ::LazySet))
* [`translate`](@ref translate(::LazySet, ::AbstractVector))
* [`cartesian_product`](@ref cartesian_product(::LazySet, ::LazySet))
* [`convex_hull`](@ref convex_hull(::LazySet, ::LazySet))
* [`exact_sum`](@ref exact_sum(::LazySet, ::LazySet))
* [`≈`](@ref ≈(::LazySet, ::LazySet))
* [`isdisjoint`](@ref isdisjoint(::LazySet, ::LazySet))
* [`==`](@ref ==(::LazySet, ::LazySet))
* [`isequivalent`](@ref isequivalent(::LazySet, ::LazySet))
* [`⊂`](@ref ⊂(::LazySet, ::LazySet))
* [`⊆`](@ref ⊆(::LazySet, ::LazySet))
* [`linear_combination`](@ref linear_combination(::LazySet, ::LazySet))
* [`minkowski_difference`](@ref minkowski_difference(::LazySet, ::LazySet))
* [`minkowski_sum`](@ref minkowski_sum(::LazySet, ::LazySet))

Inherited from [`AbstractPolynomialZonotope`](@ref):
* [`center`](@ref center(::AbstractPolynomialZonotope, ::Int))
* [`convex_hull`](@ref convex_hull(::AbstractPolynomialZonotope))
* [`dim`](@ref dim(::AbstractPolynomialZonotope))
* [`isboundedtype`](@ref isboundedtype(::Type{AbstractPolynomialZonotope}))
* [`isempty`](@ref isempty(::AbstractPolynomialZonotope))
* [`isuniversal`](@ref isuniversal(::AbstractPolynomialZonotope))
* [`ngens`](@ref ngens(::AbstractPolynomialZonotope))
* [`order`](@ref dim(::AbstractPolynomialZonotope))
* [`convex_hull`](@ref convex_hull(::AbstractPolynomialZonotope, ::AbstractPolynomialZonotope))
* [`linear_combination`](@ref linear_combination(::AbstractPolynomialZonotope, ::AbstractPolynomialZonotope))
14 changes: 1 addition & 13 deletions docs/src/lib/sets/SimpleSparsePolynomialZonotope.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,6 @@ CurrentModule = LazySets.SimpleSparsePolynomialZonotopeModule
cartesian_product(::SimpleSparsePolynomialZonotope, ::SimpleSparsePolynomialZonotope)
```
```@meta
CurrentModule = LazySets
```
```@docs; canonical=false
convex_hull(::LazySet, ::LazySet)
```
```@meta
CurrentModule = LazySets.SimpleSparsePolynomialZonotopeModule
```
```@docs
convex_hull(::SimpleSparsePolynomialZonotope, ::SimpleSparsePolynomialZonotope)
```
```@meta
CurrentModule = LazySets.API
```
```@docs; canonical=false
Expand Down Expand Up @@ -182,7 +170,6 @@ Inherited from [`LazySet`](@ref):
* [`isequivalent`](@ref isequivalent(::LazySet, ::LazySet))
* [`⊂`](@ref ⊂(::LazySet, ::LazySet))
* [`⊆`](@ref ⊆(::LazySet, ::LazySet))
* [`linear_combination`](@ref linear_combination(::LazySet, ::LazySet))
* [`minkowski_difference`](@ref minkowski_difference(::LazySet, ::LazySet))

Inherited from [`AbstractPolynomialZonotope`](@ref):
Expand All @@ -192,6 +179,7 @@ Inherited from [`AbstractPolynomialZonotope`](@ref):
* [`isempty`](@ref isempty(::AbstractPolynomialZonotope))
* [`isuniversal`](@ref isuniversal(::AbstractPolynomialZonotope))
* [`order`](@ref order(::AbstractPolynomialZonotope))
* [`convex_hull`](@ref convex_hull(::AbstractPolynomialZonotope, ::AbstractPolynomialZonotope))

Inherited from [`AbstractSparsePolynomialZonotope`](@ref):
* [`ngens_dep`](@ref ngens_dep(::AbstractSparsePolynomialZonotope))
Expand Down
6 changes: 3 additions & 3 deletions docs/src/lib/sets/SparsePolynomialZonotope.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ Inherited from [`LazySet`](@ref):
* [`complement`](@ref complement(::LazySet))
* [`concretize`](@ref concretize(::LazySet))
* [`constraints`](@ref constraints(::LazySet))
* [`convex_hull`](@ref convex_hull(::LazySet))
* `copy(::Type{LazySet})`
* [`diameter`](@ref diameter(::LazySet, ::Real=Inf))
* [`eltype`](@ref eltype(::Type{<:LazySet}))
Expand Down Expand Up @@ -134,24 +133,25 @@ Inherited from [`LazySet`](@ref):
* [`sample`](@ref sample(::LazySet, ::Int=1))
* [`scale`](@ref scale(::Real, ::LazySet))
* [`σ`](@ref σ(::AbstractVector, ::LazySet))
* [`convex_hull`](@ref convex_hull(::LazySet, ::LazySet))
* [`≈`](@ref ≈(::LazySet, ::LazySet))
* [`isdisjoint`](@ref isdisjoint(::LazySet, ::LazySet))
* [`==`](@ref ==(::LazySet, ::LazySet))
* [`isequivalent`](@ref isequivalent(::LazySet, ::LazySet))
* [`⊂`](@ref ⊂(::LazySet, ::LazySet))
* [`⊆`](@ref ⊆(::LazySet, ::LazySet))
* [`linear_combination`](@ref linear_combination(::LazySet, ::LazySet))
* [`minkowski_difference`](@ref minkowski_difference(::LazySet, ::LazySet))

Inherited from [`AbstractPolynomialZonotope`](@ref):
* [`center`](@ref center(::AbstractPolynomialZonotope, ::Int))
* [`convex_hull`](@ref convex_hull(::AbstractPolynomialZonotope))
* [`dim`](@ref dim(::AbstractPolynomialZonotope))
* [`isboundedtype`](@ref isboundedtype(::Type{AbstractPolynomialZonotope}))
* [`isempty`](@ref isempty(::AbstractPolynomialZonotope))
* [`isuniversal`](@ref isuniversal(::AbstractPolynomialZonotope))
* [`ngens`](@ref ngens(::AbstractPolynomialZonotope))
* [`order`](@ref order(::AbstractPolynomialZonotope))
* [`convex_hull`](@ref convex_hull(::AbstractPolynomialZonotope, ::AbstractPolynomialZonotope))
* [`linear_combination`](@ref linear_combination(::AbstractPolynomialZonotope, ::AbstractPolynomialZonotope))

Inherited from [`AbstractSparsePolynomialZonotope`](@ref):
* [`ngens_dep`](@ref ngens_dep(::AbstractSparsePolynomialZonotope))
Expand Down
13 changes: 13 additions & 0 deletions src/ConcreteOperations/convex_hull.jl
Original file line number Diff line number Diff line change
Expand Up @@ -485,3 +485,16 @@ end
@commutative function convex_hull(X::LazySet, ∅::EmptySet)
return EmptySetModule._convex_hull_emptyset(∅, X)
end

"""
# Extended help

convex_hull(PZ1::AbstractPolynomialZonotope, PZ2::AbstractPolynomialZonotope)

### Output

The tightest convex polynomial zonotope containing `P1` and `P2`.
"""
function convex_hull(PZ1::AbstractPolynomialZonotope, PZ2::AbstractPolynomialZonotope)
return linear_combination(convex_hull(PZ1), convex_hull(PZ2))
end
11 changes: 11 additions & 0 deletions src/ConcreteOperations/linear_combination.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,14 @@ end
@commutative function linear_combination(∅::EmptySet, X::ConvexSet)
return _linear_combination_emptyset(∅, X)
end

function linear_combination(P1::AbstractPolynomialZonotope,
P2::AbstractPolynomialZonotope)
SSPZ1 = convert(SimpleSparsePolynomialZonotope, P1)
SSPZ2 = convert(SimpleSparsePolynomialZonotope, P2)
return linear_combination(SSPZ1, SSPZ2)
end

@commutative function linear_combination(Z::AbstractZonotope, P::AbstractPolynomialZonotope)
return linear_combination(convert(SparsePolynomialZonotope, Z), P)
end
4 changes: 4 additions & 0 deletions src/Interfaces/AbstractPolynomialZonotope.jl
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,7 @@ dim(PZ::AbstractPolynomialZonotope) = length(center(PZ))
isempty(PZ::AbstractPolynomialZonotope) = false

isuniversal(PZ::AbstractPolynomialZonotope) = false

function convex_hull(PZ::AbstractPolynomialZonotope)
return convex_hull(convert(SimpleSparsePolynomialZonotope, PZ))
end
14 changes: 0 additions & 14 deletions src/Sets/SimpleSparsePolynomialZonotope/convex_hull.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,3 @@ The tightest convex simple sparse polynomial zonotope containing `P`.
function convex_hull(P::SimpleSparsePolynomialZonotope)
return linear_combination(P, P)
end

"""
# Extended help

convex_hull(P1::SimpleSparsePolynomialZonotope,
P2::SimpleSparsePolynomialZonotope)

### Output

The tightest convex simple sparse polynomial zonotope containing `P1` and `P2`.
"""
function convex_hull(P1::SimpleSparsePolynomialZonotope, P2::SimpleSparsePolynomialZonotope)
return linear_combination(linear_combination(P1, P1), linear_combination(P2, P2))
end
15 changes: 15 additions & 0 deletions test/Sets/SparsePolynomialZonotope.jl
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,21 @@ for N in [Float64, Float32, Rational{Int}]
@test isequivalent(overapproximate(PZ, Zonotope), Z)
SSPZ2 = convert(SimpleSparsePolynomialZonotope, PZ)
@test isequivalent(overapproximate(SSPZ2, Zonotope, dom2), Z)

# Example 3.1.29 from thesis
PZ1 = SparsePolynomialZonotope(N[-5, 0], N[2 0 2; 0 2 2], Matrix{N}(undef, 2, 0), [1 0 1; 0 1 1])
PZ2 = SparsePolynomialZonotope(N[3, 3], N[1 -2 2; 2 3 1], hcat(N[1//2; 0]), [1 0 2; 0 1 1])
PZ_lc = linear_combination(PZ1, PZ2)
# no reasonable tests available here
@test PZ_lc isa SimpleSparsePolynomialZonotope{N}
@test center(PZ_lc) == N[-1, 3//2]
PZ_ch = convex_hull(PZ1, PZ2)
# no reasonable tests available here
@test PZ_ch isa SimpleSparsePolynomialZonotope{N}
@test center(PZ_ch) == N[-1, 3//2]
# mixed linear_combination
PZ_lc = linear_combination(PZ1, ZeroSet{N}(2))
@test PZ_lc isa SimpleSparsePolynomialZonotope{N}
end

for N in [Float64]
Expand Down
Loading