Skip to content

Commit

Permalink
simple constraints and vertices iterators
Browse files Browse the repository at this point in the history
  • Loading branch information
schillic committed Jul 23, 2020
1 parent 97cba49 commit f9f97d3
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 1 deletion.
2 changes: 2 additions & 0 deletions docs/src/lib/interfaces.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ support_vector
support_function
σ
singleton_list(::LazySet)
constraints(::LazySet)
vertices(::LazySet)
delaunay
```

Expand Down
46 changes: 45 additions & 1 deletion src/Interfaces/LazySet.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ export LazySet,
area,
surface,
singleton_list,
concretize
concretize,
constraints,
vertices

"""
LazySet{N}
Expand Down Expand Up @@ -1031,6 +1033,48 @@ function concretize(X::LazySet)
return X
end

"""
constraints(X::LazySet)
Construct an iterator over the constraints of a polyhedral set.
### Input
- `X` -- polyhedral set
### Output
An iterator over the constraints of `X`.
"""
function constraints(X::LazySet)
return _constraints_fallback(X)
end

"""
vertices(X::LazySet)
Construct an iterator over the vertices of a polyhedral set.
### Input
- `X` -- polyhedral set
### Output
An iterator over the vertices of `X`.
"""
function vertices(X::LazySet)
return _vertices_fallback(X)
end

function _constraints_fallback(X::LazySet)
return VectorIterator(constraints_list(X))
end

function _vertices_fallback(X::LazySet)
return VectorIterator(vertices_list(X))
end

# =========================
# Code requiring MiniQhull
# =========================
Expand Down
7 changes: 7 additions & 0 deletions test/unit_BallInf.jl
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,14 @@ for N in [Float64, Rational{Int}, Float32]
end

# concretize
B = BallInf(N[0, 0], N(1))
@test concretize(B) === B

# constraints iterator
@test ispermutation(collect(constraints(B)), constraints_list(B))

# vertices iterator
@test ispermutation(collect(vertices(B)), vertices_list(B))
end

# tests that only work with Float64
Expand Down
6 changes: 6 additions & 0 deletions test/unit_Polyhedron.jl
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ for N in [Float64, Rational{Int}, Float32]
[HalfSpace(N[2, 2], N(18)), HalfSpace(N[-3, 3], N(9)),
HalfSpace(N[-1, -1], N(-3)), HalfSpace(N[2, -4], N(-6))])

# constraints iterator
@test ispermutation(collect(constraints(p)), constraints_list(p))

# vertices iterator
@test ispermutation(collect(vertices(p)), vertices_list(p))

if test_suite_polyhedra
# conversion to and from Polyhedra's VRep data structure
cl = constraints_list(HPolyhedron(polyhedron(p)))
Expand Down

0 comments on commit f9f97d3

Please sign in to comment.