Skip to content
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

Merged
merged 10 commits into from
Sep 13, 2018
Merged

Conversation

mforets
Copy link
Member

@mforets mforets commented Sep 10, 2018

Closes #473.

  • constraints list of AbstractHyperrectangle
  • convert AbstractHyperrectangle to HPolytope
  • add to docs
  • add unit tests
  • same for HPolygon

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)
Copy link
Member

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.

b, c = high(H), -low(H)

for i in 1:n
ei = LazySets.Approximations.UnitVector(i, n, 1.0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1.0one(N)

@mforets
Copy link
Member Author

mforets commented Sep 11, 2018

ready from my side

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]]])
Copy link
Member Author

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

Copy link
Member

@schillic schillic Sep 11, 2018

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.

Copy link
Member

@schillic schillic left a 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?

@@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

H1H

@mforets mforets merged commit c9bdc92 into master Sep 13, 2018
@mforets mforets deleted the mforets/473 branch September 13, 2018 15:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants