Skip to content

Commit

Permalink
Pass solver to removehrendundancy
Browse files Browse the repository at this point in the history
  • Loading branch information
blegat committed Jun 19, 2020
1 parent a115e8d commit 514a92a
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 61 deletions.
8 changes: 5 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
name = "QHull"
uuid = "a8468747-bd6f-53ef-9e5c-744dbc5c59e7"
repo = "https://github.com/JuliaPolyhedra/QHull.jl.git"
version = "0.2.0"
version = "0.2.1"

[deps]
Polyhedra = "67491407-f73d-577b-9b50-8179a7c68029"
PyCall = "438e738f-606a-5dbb-bf0a-cddfbfd45ab0"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"

[compat]
Polyhedra = "0.6"
Polyhedra = "0.6.5"
PyCall = "1.91"
StaticArrays = "0.12"
julia = "1"
Expand All @@ -19,8 +19,10 @@ Combinatorics = "861a8166-3701-5b0c-9a16-15d98fcdc6aa"
GLPK = "60bf3e95-4087-53dc-ae20-288a0d20c6a6"
GeometryTypes = "4d00f742-c7ba-57c2-abde-4428a4b178cb"
JuMP = "4076af6c-e467-56ae-b986-b466b2749572"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
RecipesBase = "3cdcf5f2-1ef4-517c-9805-6587b60abb01"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Combinatorics", "GLPK", "Test", "JuMP", "GeometryTypes", "RecipesBase"]
test = ["Combinatorics", "GLPK", "GeometryTypes", "JuMP", "LinearAlgebra", "RecipesBase", "SparseArrays", "Test"]
110 changes: 52 additions & 58 deletions src/polyhedron.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ function Polyhedra.similar_library(l::Library, d::Polyhedra.FullDim, ::Type{Floa
end

mutable struct Polyhedron <: Polyhedra.Polyhedron{Float64}
ine::Union{Nothing, Polyhedra.MixedMatHRep{Float64, Matrix{Float64}}}
ext::Union{Nothing, Polyhedra.MixedMatVRep{Float64, Matrix{Float64}}}
hrep::Union{Nothing, Polyhedra.MixedMatHRep{Float64, Matrix{Float64}}}
vrep::Union{Nothing, Polyhedra.MixedMatVRep{Float64, Matrix{Float64}}}
nohredundancy::Bool
novredundancy::Bool
solver
Expand All @@ -37,7 +37,7 @@ mutable struct Polyhedron <: Polyhedra.Polyhedron{Float64}
end
end

Polyhedra.FullDim(p::Polyhedron) = Polyhedra.FullDim_rep(p.ine, p.ext)
Polyhedra.FullDim(p::Polyhedron) = Polyhedra.FullDim_rep(p.hrep, p.vrep)
Polyhedra.library(p::Polyhedron) = Library(p.solver)
Polyhedra.similar_type(::Type{<:Polyhedron}, d::Polyhedra.FullDim, T::Type) = Polyhedra.default_type(d, T)
function Polyhedra.similar_type(::Type{<:Polyhedron}, d::Polyhedra.FullDim, ::Type{Float64})
Expand All @@ -58,24 +58,25 @@ Polyhedra.vvectortype(::Union{Polyhedron, Type{Polyhedron}}) = Polyhedra.vvector
epsz = 1e-8

function qhull(p::Polyhedron, rep=:Auto)
if rep == :V || (rep == :Auto && (p.ext !== nothing))
p.ext, ine, p.area, p.volume = qhull(getext(p), p.solver)
if p.ine === nothing
if rep == :V || (rep == :Auto && (p.vrep !== nothing))
p.vrep, ine, p.area, p.volume = qhull(Polyhedra.vrep(p), p.solver)
if p.hrep === nothing
# Otherwise, it is not interesting as it may have redundancy
p.ine = ine
p.hrep = ine
end
else
@assert rep == :H || rep == :Auto
p.ine, ext = qhull(getine(p), p.solver)
if p.ext === nothing
p.ext = ext
p.hrep, ext = qhull(Polyhedra.hrep(p), p.solver)
if p.vrep === nothing
p.vrep = ext
end
end
p.nohredundancy = true
p.novredundancy = true
return
end

function qhull(h::Polyhedra.MixedMatVRep{T}, solver=nothing) where T
function qhull(h::Polyhedra.MixedMatVRep{T}, solver) where T
if Polyhedra.hasrays(h)
error("Rays are not supported.")
end
Expand All @@ -90,11 +91,11 @@ function qhull(h::Polyhedra.MixedMatVRep{T}, solver=nothing) where T
# The same facet may be listed several times in case the facet is not
# simplicial, e.g. a quad facet is listed twice as it is made of two
# triangles. After `removeduplicates`, there should be no redundancy.
hnored = Polyhedra.removeduplicates(h)
hnored = Polyhedra.removeduplicates(h, Polyhedra.OppositeMockOptimizer)
vnored, hnored, ch.area, ch.volume
end

function qhull(h::Polyhedra.MixedMatHRep{T}, solver=nothing) where {T<:Real}
function qhull(h::Polyhedra.MixedMatHRep{T}, solver) where {T<:Real}
linset = h.linset
if !isempty(linset)
error("Equalities are not supported.")
Expand Down Expand Up @@ -162,22 +163,9 @@ function qhull(h::Polyhedra.MixedMatHRep{T}, solver=nothing) where {T<:Real}
hnored, vnored
end

function getine(p::Polyhedron)
if p.ine === nothing
qhull(p)
end
p.ine
end
function getext(p::Polyhedron)
if p.ext === nothing
qhull(p)
end
p.ext
end

function clearfield!(p::Polyhedron)
p.ine = nothing
p.ext = nothing
p.hrep = nothing
p.vrep = nothing
p.nohredundancy = false
p.novredundancy = false
end
Expand All @@ -195,41 +183,15 @@ Polyhedron(d::Polyhedra.FullDim, ps::Polyhedra.PointIt, ls::Polyhedra.LineIt, rs

function Base.copy(p::Polyhedron)
ine = nothing
if p.ine !== nothing
ine = copy(p.ine)
if p.hrep !== nothing
ine = copy(p.hrep)
end
ext = nothing
if p.ext !== nothing
ext = copy(p.ext)
if p.vrep !== nothing
ext = copy(p.vrep)
end
Polyhedron(ine, ext, p.nohredundancy, p.novredundancy, p.solver)
end
function Polyhedra.hrepiscomputed(p::Polyhedron)
p.ine !== nothing
end
function Polyhedra.hrep(p::Polyhedron)
getine(p)
end
function Polyhedra.vrepiscomputed(p::Polyhedron)
p.ext !== nothing
end
function Polyhedra.vrep(p::Polyhedron)
getext(p)
end
function Polyhedra.sethrep!(p::Polyhedron, h::Polyhedra.HRepresentation)
p.ine = h
end
function Polyhedra.setvrep!(p::Polyhedron, v::Polyhedra.VRepresentation)
p.ext = v
end
function Polyhedra.resethrep!(p::Polyhedron, h::Polyhedra.HRepresentation)
clearfield!(p)
p.ine = h
end
function Polyhedra.resetvrep!(p::Polyhedron, v::Polyhedra.VRepresentation)
clearfield!(p)
p.ext = v
end
function Polyhedra.removehredundancy!(p::Polyhedron)
if !p.nohredundancy
qhull(p, :H)
Expand All @@ -247,3 +209,35 @@ function Polyhedra.volume(p::Polyhedron)
end
return p.volume
end

Polyhedra.hrepiscomputed(p::Polyhedron) = p.hrep !== nothing
Polyhedra.computehrep!(p::Polyhedron) = qhull(p, :V)
function Polyhedra.hrep(p::Polyhedron)
if !Polyhedra.hrepiscomputed(p)
Polyhedra.computehrep!(p)
end
return p.hrep
end
Polyhedra.vrepiscomputed(p::Polyhedron) = p.vrep !== nothing
Polyhedra.computevrep!(p::Polyhedron) = qhull(p, :H)
function Polyhedra.vrep(p::Polyhedron)
if !Polyhedra.vrepiscomputed(p)
Polyhedra.computevrep!(p)
end
return p.vrep
end

function Polyhedra.sethrep!(p::Polyhedron, h::Polyhedra.HRepresentation)
p.hrep = h
end
function Polyhedra.setvrep!(p::Polyhedron, v::Polyhedra.VRepresentation)
p.vrep = v
end
function Polyhedra.resethrep!(p::Polyhedron, h::Polyhedra.HRepresentation)
clearfield!(p)
p.hrep = h
end
function Polyhedra.resetvrep!(p::Polyhedron, v::Polyhedra.VRepresentation)
clearfield!(p)
p.vrep = v
end

2 comments on commit 514a92a

@blegat
Copy link
Member Author

@blegat blegat commented on 514a92a Jun 19, 2020

Choose a reason for hiding this comment

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

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request created: JuliaRegistries/General/16638

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.2.1 -m "<description of version>" 514a92aaacd394d07a109f49de996588c67e9e94
git push origin v0.2.1

Please sign in to comment.