-
Notifications
You must be signed in to change notification settings - Fork 32
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
#473 - Convert AbstractHyperrectangle to HPolytope #615
Conversation
src/AbstractHyperrectangle.jl
Outdated
function constraints_list(H::AbstractHyperrectangle{N})::Vector{LinearConstraint{N}} where {N<:Real} | ||
n = dim(H) | ||
constraints = Vector{LinearConstraint{N}}(2*n) | ||
A, b, c = eye(n), high(H), -low(H) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is cheaper to create the row vectors of A
individually. You could use UnitVector
, see #538.
src/AbstractHyperrectangle.jl
Outdated
b, c = high(H), -low(H) | ||
|
||
for i in 1:n | ||
ei = LazySets.Approximations.UnitVector(i, n, 1.0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1.0
→ one(N)
ready from my side |
test/unit_Polytope.jl
Outdated
P = convert(HPolytope, H1) | ||
vlist = vertices_list(P) | ||
@test length(vlist) == 4 | ||
@test all([vi ∈ vlist for vi in [N[3, 3], N[3, -1], N[-1, -1], N[-1, 3]]]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i added this test here because the conversion and testing for vertices requires to load the package Polyhedra
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You have to add a condition that Polyhedra
is loaded around this test:
if test_suite_polyhedra
Otherwise, vertices_list
is not defined and the test crashes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well done! Add a unit test for constraints_list
of a Hyperrectangle
?
test/unit_Polytope.jl
Outdated
@@ -56,6 +56,13 @@ for N in [Float64, Rational{Int}, Float32] | |||
@test length(p.constraints) == length(cl) | |||
end | |||
|
|||
# convert a hyperrectangle to a HPolytope | |||
H = Hyperrectangle(N[1, 1], N[2, 2]) | |||
P = convert(HPolytope, H1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
H1
→ H
Closes #473.
AbstractHyperrectangle
AbstractHyperrectangle
toHPolytope
HPolygon