Skip to content

Commit

Permalink
#2283 - Add concrete projection of a VPolytope (#2284)
Browse files Browse the repository at this point in the history
* add concrete projection of a VPolytope

* add tests

* apply suggestions

* Update test/unit_Polygon.jl

Co-authored-by: Christian Schilling <[email protected]>

* fix test

Co-authored-by: Christian Schilling <[email protected]>
  • Loading branch information
SebastianGuadalupe and schillic authored Jul 28, 2020
1 parent b75844a commit 77e9f6c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Approximations/decompositions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -659,3 +659,11 @@ function project(H::AbstractHyperrectangle, block::AbstractVector{Int})
πr = radius_hyperrectangle(H)[block]
return Hyperrectangle(πc, πr, check_bounds=false)
end

function project(V::Union{<:VPolygon{N}, <:VPolytope{N}},
block::AbstractVector{Int}) where {N}
n = dim(V)
M = projection_matrix(block, n, N)
πvertices = broadcast(v -> M * v, vertices_list(V))
return VPolytope(πvertices)
end
6 changes: 6 additions & 0 deletions test/unit_Polygon.jl
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,12 @@ for N in [Float64, Float32, Rational{Int}]
m = N[4 0; 6 2; 4 4]'
P = VPolygon(m)
@test is_cyclic_permutation(vertices_list(P), [N[4, 0], N[6, 2], N[4, 4]])

# test concrete projection
V = VPolygon([N[0, 1], N[1, 0], N[-1, 0]])
@test project(V, [1]) == VPolytope([N[-1], N[1], N[0]])
V = VPolygon([N[1, 0], N[1, 1]])
@test project(V, [1]) == VPolytope([N[1], N[1]])
end

function same_constraints(v::Vector{<:LinearConstraint{N}})::Bool where N<:Real
Expand Down
5 changes: 5 additions & 0 deletions test/unit_Polytope.jl
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,11 @@ for N in [Float64, Rational{Int}, Float32]
p[1] = N(5)
# test that Pcopy is independent of P ( = deepcopy)
@test Pcopy.vertices[1] == [N(1)]

# test concrete projection
V = VPolytope([N[0, 0, 1], N[0, 1, 0], N[0, -1, 0], N[1, 0, 0]])
@test project(V, [1]) == VPolytope([N[0], N[0], N[0], N[1]])
@test project(V, [1, 2]) == VPolytope([N[0, 0], N[0, 1], N[0, -1], N[1, 0]])
end

# default Float64 constructors
Expand Down

0 comments on commit 77e9f6c

Please sign in to comment.