Skip to content

Commit

Permalink
Merge pull request #1442 from JuliaReach/schillic/1364
Browse files Browse the repository at this point in the history
#1364 - Concrete linear map of a translation
  • Loading branch information
schillic authored Jun 14, 2019
2 parents d9da4d4 + 0fd6c1e commit 894fda3
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 4 deletions.
1 change: 1 addition & 0 deletions docs/src/lib/operations.md
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ an_element(::Translation)
isempty(::Translation)
constraints_list(::Translation{N}, ::Val{true}) where {N<:Real}
LinearMap(::AbstractMatrix{N}, ::Translation{N}) where {N<:Real}
linear_map(M::AbstractMatrix{N}, tr::Translation{N}) where {N<:Real}
∈(::AbstractVector{N}, ::Translation{N}) where {N<:Real}
```

Expand Down
29 changes: 28 additions & 1 deletion src/Translation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import Base: isempty

export Translation,
an_element,
constraints_list
constraints_list,
linear_map

"""
Translation{N<:Real, VN<:AbstractVector{N}, S<:LazySet{N}} <: LazySet{N}
Expand Down Expand Up @@ -364,3 +365,29 @@ This implementation relies on the set membership function for the wrapped set
function (x::AbstractVector{N}, tr::Translation{N})::Bool where {N<:Real}
return (x - tr.v, tr.X)
end

"""
linear_map(M::AbstractMatrix{N}, tr::Translation{N}) where {N<:Real}
Concrete linear map of a polyhedron in constraint representation.
### Input
- `M` -- matrix
- `tr` -- translation of a convex set
### Output
A concrete set corresponding to the linear map.
The type of the result depends on the type of the set wrapped by `tr`.
### Algorithm
We compute `translate(linear_map(M, tr.X), M * tr.v)`.
"""
function linear_map(M::AbstractMatrix{N}, tr::Translation{N}) where {N<:Real}
@assert dim(tr) == size(M, 2) "a linear map of size $(size(M)) cannot be " *
"applied to a set of dimension $(dim(tr))"

return translate(linear_map(M, tr.X), M * tr.v)
end
11 changes: 8 additions & 3 deletions test/unit_Translation.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
for N in [Float64, Rational{Int}, Float32]

# ==================================
# Constructor and interface methods
# ==================================

B = BallInf(zeros(N, 3), N(1))
v = N[1, 0, 0] # translation along dimension 1
tr = Translation(B, v)
Expand All @@ -15,7 +14,7 @@ for N in [Float64, Rational{Int}, Float32]

# dimension check
@test_throws AssertionError Translation(B, N[0, 0])

@test dim(tr) == 3

# support vector
Expand All @@ -42,6 +41,12 @@ for N in [Float64, Rational{Int}, Float32]
B = Ball2(zeros(N, 2), N(1))
@test center(B) B zeros(N, 2)

# concrete linear map
B = BallInf(ones(N, 2), N(1))
tr = B N[1, 0]
clm = linear_map(N[1 2; 0 1], tr)
@test ispermutation(vertices_list(clm), [N[5, 2], [1, 0], [3, 0], [7, 2]])

# ==================================
# Type-specific methods
# ==================================
Expand Down

0 comments on commit 894fda3

Please sign in to comment.