Skip to content

Commit

Permalink
convenience constructor for MinkowskiSumArray
Browse files Browse the repository at this point in the history
  • Loading branch information
schillic committed Apr 29, 2023
1 parent 000af4f commit c673230
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 34 deletions.
2 changes: 2 additions & 0 deletions docs/src/lib/lazy_operations/MinkowskiSum.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ Inherited from [`LazySet`](@ref):

```@docs
MinkowskiSumArray
⊕(::LazySet...)
+(::LazySet...)
dim(::MinkowskiSumArray)
ρ(::AbstractVector, ::MinkowskiSumArray)
σ(::AbstractVector, ::MinkowskiSumArray)
Expand Down
50 changes: 16 additions & 34 deletions src/LazyOperations/MinkowskiSum.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,55 +37,37 @@ struct MinkowskiSum{N, S1<:LazySet{N}, S2<:LazySet{N}} <: LazySet{N}
end
end

isoperationtype(::Type{<:MinkowskiSum}) = true

isconvextype(::Type{MinkowskiSum{N, S1, S2}}) where {N, S1, S2} =
isconvextype(S1) && isconvextype(S2)

is_polyhedral(ms::MinkowskiSum) = is_polyhedral(ms.X) && is_polyhedral(ms.Y)

# ZeroSet is the neutral element for MinkowskiSum
@neutral(MinkowskiSum, ZeroSet)

# EmptySet and Universe are the absorbing elements for MinkowskiSum
@absorbing(MinkowskiSum, EmptySet)
# @absorbing(MinkowskiSum, Universe) # TODO problematic

"""
+(X::LazySet, Y::LazySet)
Convenience constructor for the Minkowski sum of two sets.
### Input
- `X` -- set
- `Y` -- set
### Output
The symbolic Minkowski sum of ``X`` and ``Y``.
Alias for the Minkowski sum.
"""
+(X::LazySet, Y::LazySet) = MinkowskiSum(X, Y)

"""
⊕(X::LazySet, Y::LazySet)
Unicode alias constructor ⊕ (`oplus`) for the lazy Minkowski sum operator.
Alias for the Minkowski sum.
### Input
### Notes
- `X` -- set
- `Y` -- set
The function symbol can be typed via `\\oplus[TAB]`.
"""
(X::LazySet, Y::LazySet) = +(X, Y)

### Output
isoperationtype(::Type{<:MinkowskiSum}) = true

isconvextype(::Type{MinkowskiSum{N, S1, S2}}) where {N, S1, S2} =
isconvextype(S1) && isconvextype(S2)

The symbolic Minkowski sum of ``X`` and ``Y``.
is_polyhedral(ms::MinkowskiSum) = is_polyhedral(ms.X) && is_polyhedral(ms.Y)

### Notes
# ZeroSet is the neutral element for MinkowskiSum
@neutral(MinkowskiSum, ZeroSet)

Write `\\oplus[TAB]` to enter this symbol.
"""
(X::LazySet, Y::LazySet) = MinkowskiSum(X, Y)
# EmptySet and Universe are the absorbing elements for MinkowskiSum
@absorbing(MinkowskiSum, EmptySet)
# @absorbing(MinkowskiSum, Universe) # TODO problematic

"""
swap(ms::MinkowskiSum)
Expand Down
23 changes: 23 additions & 0 deletions src/LazyOperations/MinkowskiSumArray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,29 @@ struct MinkowskiSumArray{N, S<:LazySet{N}} <: LazySet{N}
array::Vector{S}
end

"""
+(Xs::LazySet...)
+(Xs::Vector{<:LazySet})
Alias for the n-ary Minkowski sum.
"""
+(Xs::LazySet...) = MinkowskiSumArray(vcat(Xs...))
+(X::LazySet) = X
+(Xs::Vector{<:LazySet}) = MinkowskiSumArray(Xs)

"""
×(Xs::LazySet...)
×(Xs::Vector{<:LazySet})
Alias for the n-ary Minkowski sum.
### Notes
The function symbol can be typed via `\\oplus[TAB]`.
"""
(Xs::LazySet...) = +(Xs...)
(Xs::Vector{<:LazySet}) = +(Xs)

isoperationtype(::Type{<:MinkowskiSumArray}) = true
isconvextype(::Type{MinkowskiSumArray{N, S}}) where {N, S} = isconvextype(S)

Expand Down
6 changes: 6 additions & 0 deletions test/LazyOperations/MinkowskiSum.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ for N in [Float64, Rational{Int}, Float32]
@test X.X == b1
@test X.Y == b2

# convenience constructors
@test b1 + b2 == b1 b2 == X
msa = MinkowskiSumArray([b1, b2, b1])
@test b1 + b2 + b1 == +(b1, b2, b1) == (b1, b2, b1) == +([b1, b2, b1]) == ([b1, b2, b1]) == msa
@test +(b1) == (b1) == b1

# swap
ms2 = swap(X)
@test X.X == ms2.Y && X.Y == ms2.X
Expand Down

0 comments on commit c673230

Please sign in to comment.