Skip to content

Commit

Permalink
remove redundant vertices of LinearMap (#1428)
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastianGuadalupe authored and mforets committed Jun 12, 2019
1 parent 6d58c75 commit a7e8305
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/LinearMap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -316,13 +316,14 @@ function isempty(lm::LinearMap)::Bool
end

"""
vertices_list(lm::LinearMap{N})::Vector{Vector{N}} where {N<:Real}
vertices_list(lm::LinearMap{N}; prune::Bool=true)::Vector{Vector{N}} where {N<:Real}
Return the list of vertices of a (polyhedral) linear map.
### Input
- `lm` -- linear map
- `prune` -- (optional, default: `true`) if true removes redundant vertices
### Output
Expand All @@ -333,7 +334,7 @@ A list of vertices.
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}
function vertices_list(lm::LinearMap{N}; prune::Bool=true)::Vector{Vector{N}} where {N<:Real}
# for a zero map, the result is just the list containing the origin
if iszero(lm.M)
return [zeros(N, dim(lm))]
Expand All @@ -349,7 +350,7 @@ function vertices_list(lm::LinearMap{N})::Vector{Vector{N}} where {N<:Real}
push!(vlist, lm.M * v)
end

return vlist
return prune ? convex_hull(vlist) : vlist
end

"""
Expand Down
5 changes: 5 additions & 0 deletions test/unit_LinearMap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ for N in [Float64, Rational{Int}, Float32]
vlist = vertices_list(LinearMap(M, b))
@test vlist == [zeros(N, 2)]

# test that redundant vertices are removed by default (see #1355)
X = Interval(N(0), N(1)) × ZeroSet{N}(1)
M = N[0 1; 0 2]
@test vertices_list(M * X) == [N[0, 0]]

if test_suite_polyhedra
# constraints_list
b = BallInf(N[0, 0], N(1))
Expand Down

0 comments on commit a7e8305

Please sign in to comment.