Skip to content

Commit

Permalink
Merge pull request #1067 from JuliaReach/mforets/1066
Browse files Browse the repository at this point in the history
#1066 - Add linear map for a halfspace
  • Loading branch information
mforets authored Jan 25, 2019
2 parents f1c3f1f + c932c8e commit 959028d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/src/lib/representations.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ constrained_dimensions(::HalfSpace{N}) where {N<:Real}
halfspace_left(::AbstractVector{N}, ::AbstractVector{N}) where {N<:Real}
halfspace_right(::AbstractVector{N}, ::AbstractVector{N}) where {N<:Real}
tosimplehrep(::AbstractVector{HalfSpace{N}}) where {N<:Real}
linear_map(::AbstractMatrix{N}, ::HalfSpace{N}) where {N}
```
Inherited from [`LazySet`](@ref):
* [`norm`](@ref norm(::LazySet, ::Real))
Expand Down
21 changes: 20 additions & 1 deletion src/HalfSpace.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import Base: rand,
export HalfSpace, LinearConstraint,
an_element,
constrained_dimensions,
halfspace_left, halfspace_right
halfspace_left, halfspace_right,
linear_map

"""
HalfSpace{N<:Real} <: LazySet{N}
Expand Down Expand Up @@ -356,3 +357,21 @@ function halfspace_right(p::AbstractVector{N},
q::AbstractVector{N})::HalfSpace{N} where {N<:Real}
return halfspace_left(q, p)
end

"""
linear_map(M::AbstractMatrix{N}, hs::HalfSpace{N}) where {N}
Return the concrete linear map of a half-space.
### Input
- `M` -- matrix
- `hs` -- half-space
### Output
The half-space obtained by applying the given linear map to the half-space.
"""
function linear_map(M::AbstractMatrix{N}, hs::HalfSpace{N}) where {N}
return linear_map(M, HPolyhedron([hs]))
end
6 changes: 6 additions & 0 deletions test/unit_HalfSpace.jl
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,10 @@ for N in [Float64, Rational{Int}, Float32]
hs4 = HalfSpace(N[-1, 0], N(0)) # x >= 0
empty_intersection, v = is_intersection_empty(hs1, hs4, true)
@test !is_intersection_empty(hs1, hs4) && !empty_intersection && v hs1 && v hs4

# test linear map of a half-space
H = HalfSpace(N[1.0, -1.0], N(0.0)) # x <= y
M = Matrix(-N(1.0)*I, 2, 2)
MH = linear_map(M, H)
@test constraints_list(MH)[1] == HalfSpace(N[-1.0, 1.0], N(0.0)) # x >= y
end

0 comments on commit 959028d

Please sign in to comment.