Skip to content

Commit

Permalink
AbstractPolynomialZonotope: add 'linear_combination'
Browse files Browse the repository at this point in the history
  • Loading branch information
schillic committed Jan 4, 2025
1 parent b07bb8e commit 9c05b10
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 3 deletions.
1 change: 1 addition & 0 deletions docs/src/lib/interfaces/AbstractPolynomialZonotope.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ Undocumented implementations:
* [`isboundedtype`](@ref isboundedtype(::Type{LazySet}))
* [`isempty`](@ref isempty(::LazySet))
* [`isuniversal`](@ref isuniversal(::LazySet))
* [`linear_combination`](@ref linear_combination(::LazySet, ::LazySet))

```@meta
CurrentModule = LazySets
Expand Down
2 changes: 1 addition & 1 deletion docs/src/lib/sets/DensePolynomialZonotope.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,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))
* [`minkowski_sum`](@ref minkowski_sum(::LazySet, ::LazySet))

Expand All @@ -90,3 +89,4 @@ Inherited from [`AbstractPolynomialZonotope`](@ref):
* [`ngens`](@ref ngens(::AbstractPolynomialZonotope))
* [`order`](@ref dim(::AbstractPolynomialZonotope))
* [`convex_hull`](@ref convex_hull(::AbstractPolynomialZonotope, ::AbstractPolynomialZonotope))
* [`linear_combination`](@ref linear_combination(::AbstractPolynomialZonotope, ::AbstractPolynomialZonotope))
1 change: 0 additions & 1 deletion docs/src/lib/sets/SimpleSparsePolynomialZonotope.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,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 Down
2 changes: 1 addition & 1 deletion docs/src/lib/sets/SparsePolynomialZonotope.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,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 @@ -152,6 +151,7 @@ Inherited from [`AbstractPolynomialZonotope`](@ref):
* [`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
7 changes: 7 additions & 0 deletions src/ConcreteOperations/linear_combination.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,10 @@ 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
12 changes: 12 additions & 0 deletions test/Sets/SparsePolynomialZonotope.jl
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,18 @@ 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]
end

for N in [Float64]
Expand Down

0 comments on commit 9c05b10

Please sign in to comment.