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

#943 - Update convexhull #944

Merged
merged 6 commits into from
Dec 18, 2018
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/HPolyhedron.jl
Original file line number Diff line number Diff line change
Expand Up @@ -499,15 +499,18 @@ The `HPolyhedron` (resp. `HPolytope`) obtained by the concrete convex hull of

### Notes

It is suggested to use the `CDDLib.Library()` backend.
schillic marked this conversation as resolved.
Show resolved Hide resolved

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
65 changes: 36 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,47 @@ 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

It is suggested to use the `CDDLib.Library()` backend.
"""
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 +279,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