diff --git a/src/LinearMap.jl b/src/LinearMap.jl index 82bcb4e0f7..32d0eba809 100644 --- a/src/LinearMap.jl +++ b/src/LinearMap.jl @@ -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 @@ -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))] @@ -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 """ diff --git a/test/unit_LinearMap.jl b/test/unit_LinearMap.jl index 9b49dcb501..026785998a 100644 --- a/test/unit_LinearMap.jl +++ b/test/unit_LinearMap.jl @@ -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))