Skip to content

Commit

Permalink
Merge pull request #944 from JuliaReach/mforets/943
Browse files Browse the repository at this point in the history
#943 - Update convexhull
  • Loading branch information
mforets authored Dec 18, 2018
2 parents 09a47ff + b27cbd2 commit 5d89265
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 35 deletions.
6 changes: 5 additions & 1 deletion src/HPolyhedron.jl
Original file line number Diff line number Diff line change
Expand Up @@ -499,15 +499,19 @@ The `HPolyhedron` (resp. `HPolytope`) obtained by the concrete convex hull of
### Notes
For performance reasons, it is suggested to use the `CDDLib.Library()` backend
for the `convex_hull`.
For further information on the supported backends see
[Polyhedra's documentation](https://juliapolyhedra.github.io/Polyhedra.jl/).
"""
function convex_hull(P1::HPoly{N},
P2::HPoly{N};
backend=default_polyhedra_backend(P1, N)) where {N}
@assert isdefined(@__MODULE__, :Polyhedra) "the function `convex_hull` needs " *
"the package 'Polyhedra' to be loaded"
"the package 'Polyhedra' to be loaded"
Pch = convexhull(polyhedron(P1; backend=backend), polyhedron(P2; backend=backend))
removehredundancy!(Pch)
return convert(typeof(P1), Pch)
end

Expand Down
66 changes: 37 additions & 29 deletions src/VPolytope.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ using MathProgBase, GLPKMathProgInterface
import Base.rand

export VPolytope,
vertices_list
vertices_list,
convex_hull

"""
VPolytope{N<:Real} <: AbstractPolytope{N}
Expand Down Expand Up @@ -187,16 +188,48 @@ function constraints_list(P::VPolytope{N})::Vector{LinearConstraint{N}} where {N
return constraints_list(tohrep(P))
end

"""
convex_hull(P1::VPolytope{N}, P2::VPolytope{N};
[backend]=default_polyhedra_backend(P1, N)) where {N}
Compute the convex hull of the set union of two polytopes in V-representation.
### Input
- `P1` -- polytope
- `P2` -- another polytope
- `backend` -- (optional, default: `default_polyhedra_backend(P1, N)`) the polyhedral
computations backend, see [Polyhedra's documentation](https://juliapolyhedra.github.io/Polyhedra.jl/latest/installation.html#Getting-Libraries-1)
for further information
### Output
# --- functions that use Polyhedra.jl ---
The `VPolytope` obtained by the concrete convex hull of `P1` and `P2`.
### Notes
For performance reasons, it is suggested to use the `CDDLib.Library()` backend
for the `convex_hull`.
"""
function convex_hull(P1::VPolytope{N}, P2::VPolytope{N};
backend=default_polyhedra_backend(P1, N)) where {N}
@assert isdefined(@__MODULE__, :Polyhedra) "the function `convex_hull` needs " *
"the package 'Polyhedra' to be loaded"
Pch = convexhull(polyhedron(P1; backend=backend),
polyhedron(P2; backend=backend))
removevredundancy!(Pch)
return VPolytope(Pch)
end

# ==========================================
# Lower level methods that use Polyhedra.jl
# ==========================================

function load_polyhedra_vpolytope() # function to be loaded by Requires
return quote
# see the interface file AbstractPolytope.jl for the imports

export convex_hull,
cartesian_product,
export cartesian_product,
vertices_list,
tohrep,
tovrep
Expand Down Expand Up @@ -247,31 +280,6 @@ function polyhedron(P::VPolytope{N};
return polyhedron(Polyhedra.vrep(V), backend)
end

"""
convex_hull(P1::VPolytope{N}, P2::VPolytope{N};
[backend]=default_polyhedra_backend(P1, N)) where {N}
Compute the convex hull of the set union of two polytopes in V-representation.
### Input
- `P1` -- polytope
- `P2` -- another polytope
- `backend` -- (optional, default: `default_polyhedra_backend(P1, N)`) the polyhedral
computations backend, see [Polyhedra's documentation](https://juliapolyhedra.github.io/Polyhedra.jl/latest/installation.html#Getting-Libraries-1)
for further information
### Output
The `VPolytope` obtained by the concrete convex hull of `P1` and `P2`.
"""
function convex_hull(P1::VPolytope{N}, P2::VPolytope{N};
backend=default_polyhedra_backend(P1, N)) where {N}
Pch = convexhull(polyhedron(P1; backend=backend),
polyhedron(P2; backend=backend))
return VPolytope(Pch)
end

"""
cartesian_product(P1::VPolytope{N}, P2::VPolytope{N};
[backend]=default_polyhedra_backend(P1, N)) where {N}
Expand Down
6 changes: 1 addition & 5 deletions test/unit_Polytope.jl
Original file line number Diff line number Diff line change
Expand Up @@ -229,11 +229,7 @@ if test_suite_polyhedra
p2 = VPolytope([v3, v4])
ch = convex_hull(p1, p2)
vl = vertices_list(ch)
@test v1 vl && v2 vl && v3 vl && v4 vl
# Note: The redundant vertex v5 is not removed (see #561).
# This test can be removed (and the length above should be corrected)
# when that issue is resolved.
@test length(vl) == 5 && v5 vl
@test ispermutation(vl, [v1, v2, v3, v4])

# Cartesian product
p1 = VPolytope([N[0, 0], N[1, 1]])
Expand Down

0 comments on commit 5d89265

Please sign in to comment.