Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#1066 - Add linear map for a halfspace #1067

Merged
merged 2 commits into from
Jan 25, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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], 0.0) # x <= y
mforets marked this conversation as resolved.
Show resolved Hide resolved
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