Skip to content

Commit

Permalink
constraints_list for LinearMap
Browse files Browse the repository at this point in the history
  • Loading branch information
schillic committed Jan 23, 2019
1 parent 0094cf9 commit d349260
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 3 deletions.
1 change: 1 addition & 0 deletions docs/src/lib/operations.md
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ an_element(::LinearMap{N}) where {N<:Real}
isbounded(::LinearMap)
isempty(::LinearMap)
vertices_list(::LinearMap{N}) where {N<:Real}
constraints_list(::LinearMap{N, S}) where {N<:Real, S<:Union{AbstractPolytope{N}, HPolyhedron{N}}
```
Inherited from [`LazySet`](@ref):
* [`norm`](@ref norm(::LazySet, ::Real))
Expand Down
35 changes: 32 additions & 3 deletions src/LinearMap.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import Base: *, , isempty

export LinearMap,
an_element
an_element,
constraints_list

"""
LinearMap{N<:Real, S<:LazySet{N}, NM, MAT<:AbstractMatrix{NM}} <: LazySet{N}
Expand Down Expand Up @@ -316,7 +317,7 @@ end
"""
vertices_list(lm::LinearMap{N})::Vector{Vector{N}} where {N<:Real}
Return the list of vertices of a (polytopic) linear map.
Return the list of vertices of a (polyhedral) linear map.
### Input
Expand All @@ -328,7 +329,7 @@ A list of vertices.
### Algorithm
We assume that the underlying set `X` is polytopic.
We assume that the underlying set `X` is polyhedral.
Then the result is just the linear map applied to the vertices of `X`.
"""
function vertices_list(lm::LinearMap{N})::Vector{Vector{N}} where {N<:Real}
Expand All @@ -349,3 +350,31 @@ function vertices_list(lm::LinearMap{N})::Vector{Vector{N}} where {N<:Real}

return vlist
end

"""
constraints_list(lm::LinearMap{N, S}) where
{N<:Real, S<:Union{AbstractPolytope{N}, HPolyhedron{N}}}
Return the list of constraints of a (polyhedral) linear map.
### Input
- `lm` -- linear map
### Output
The list of constraints of the linear map.
### Notes
We assume that the underlying set `X` is polyhedral, i.e., offers a method
`constraints_list(X)`.
### Algorithm
We fall back to a concrete set representation and apply `linear_map`.
"""
function constraints_list(lm::LinearMap{N, S}) where
{N<:Real, S<:Union{AbstractPolytope{N}, HPolyhedron{N}}}
return constraints_list(linear_map(lm.M, lm.X))
end
19 changes: 19 additions & 0 deletions test/unit_LinearMap.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import LazySets.Approximations.BoxDiagDirections

for N in [Float64, Rational{Int}, Float32]
# π/2 trigonometric rotation
b = BallInf(N[1, 2], N(1))
Expand Down Expand Up @@ -83,4 +85,21 @@ for N in [Float64, Rational{Int}, Float32]
M = zeros(N, 2, 2)
vlist = vertices_list(LinearMap(M, b))
@test vlist == [zeros(N, 2)]

if test_suite_polyhedra
# constraints_list
b = BallInf(N[0, 0], N(1))
M = N[2 3; 1 2] # invertible
lm1 = LinearMap(M, b)
clist = constraints_list(lm1)
p1 = HPolygon(clist)
M = N[2 3; 0 0] # not invertible
lm2 = LinearMap(M, b)
clist = constraints_list(lm2)
p2 = HPolygon(clist)
for d in BoxDiagDirections{N}(2)
@test ρ(d, lm1) ρ(d, p1)
@test ρ(d, lm2) ρ(d, p2)
end
end
end

0 comments on commit d349260

Please sign in to comment.