Skip to content

Commit

Permalink
return HPolytope in projection of polytope
Browse files Browse the repository at this point in the history
  • Loading branch information
schillic committed Jun 25, 2020
1 parent 55528b6 commit 4895b6a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/Approximations/decompositions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -569,8 +569,10 @@ Concrete projection of a polyhedral set.
### Output
An `HPolyhedron` representing the projection of `P` on the dimensions specified
by `block`.
A polyhedron representing the projection of `P` on the dimensions specified by
`block`.
If `P` was bounded, the result is an `HPolytope`; otherwise the result is an
`HPolyhedron`.
### Algorithm
Expand Down Expand Up @@ -600,7 +602,7 @@ julia> constrained_dimensions(P)
julia> P_1234 = project(P, [1, 2, 3, 4]);
julia> P_1234 == convert(HPolyhedron, P)
julia> P_1234 == convert(HPolytope, P)
true
```
Each constraint of the cross polytope is constrained in all dimensions.
Expand Down Expand Up @@ -641,7 +643,8 @@ function project(P::AbstractPolyhedron{N}, block::AbstractVector{Int}) where {N}
lm = linear_map(M, P)
clist = constraints_list(lm)
end
return HPolyhedron(clist)
T = isbounded(P) ? HPolytope : HPolyhedron
return T(clist)
end

function project(Z::Zonotope{N}, block::AbstractVector{Int}) where {N}
Expand Down
6 changes: 6 additions & 0 deletions test/unit_Polytope.jl
Original file line number Diff line number Diff line change
Expand Up @@ -473,5 +473,11 @@ for N in [Float64]
c3, r = chebyshev_center(P; get_radius=true)
@test c1 == c2 == c3 == center(B) && c1 isa AbstractVector{N}
@test r == B.radius

# concrete projection
πP = project(P, [1])
@test πP isa HPolytope{N}
@test ispermutation(constraints_list(πP), [HalfSpace(N[-1], N(1)),
HalfSpace(N[1], N(1))])
end
end

0 comments on commit 4895b6a

Please sign in to comment.