From d349260fdb1e2164ab6d182aae48e1134957faf5 Mon Sep 17 00:00:00 2001 From: schillic Date: Wed, 23 Jan 2019 20:46:25 +0100 Subject: [PATCH] constraints_list for LinearMap --- docs/src/lib/operations.md | 1 + src/LinearMap.jl | 35 ++++++++++++++++++++++++++++++++--- test/unit_LinearMap.jl | 19 +++++++++++++++++++ 3 files changed, 52 insertions(+), 3 deletions(-) diff --git a/docs/src/lib/operations.md b/docs/src/lib/operations.md index 149c0c99db..949b76ccbc 100644 --- a/docs/src/lib/operations.md +++ b/docs/src/lib/operations.md @@ -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)) diff --git a/src/LinearMap.jl b/src/LinearMap.jl index 0b4d156371..30afd81278 100644 --- a/src/LinearMap.jl +++ b/src/LinearMap.jl @@ -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} @@ -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 @@ -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} @@ -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 diff --git a/test/unit_LinearMap.jl b/test/unit_LinearMap.jl index 4002564e12..647a8fc24e 100644 --- a/test/unit_LinearMap.jl +++ b/test/unit_LinearMap.jl @@ -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)) @@ -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