Polyhedra.jl icon indicating copy to clipboard operation
Polyhedra.jl copied to clipboard

Volume of H-represenation

Open JohnEdChristensen opened this issue 4 years ago • 2 comments

I'm having difficulty finding the volume of an H-rep

using Polyhedra, QHull
cube = HalfSpace([0,0,1],1)∩HalfSpace([0,0,-1],0)∩HalfSpace([0,1,0],1)∩HalfSpace([0,-1,0],0)∩HalfSpace([1,0,0],1)∩HalfSpace([-1,0,0],0)
p = polyhedron(cube,QHull.Library())
Polyhedra.volume(p)

This throws the following error:

MethodError: no method matching JuMP.Model(::Nothing)
Closest candidates are:
  JuMP.Model(::Any, !Matched::Any, !Matched::Any, !Matched::Any, !Matched::Any, !Matched::Any, !Matched::Any, !Matched::Any) at /home/john/.julia/packages/JuMP/MsUSY/src/JuMP.jl:126
  JuMP.Model(; caching_mode, solver) at /home/john/.julia/packages/JuMP/MsUSY/src/JuMP.jl:163
  JuMP.Model(!Matched::MathOptInterface.AbstractOptimizer, !Matched::Dict{MathOptInterface.ConstraintIndex,JuMP.AbstractShape}, !Matched::Set{Any}, !Matched::Any, !Matched::Any, !Matched::Dict{Symbol,Any}, !Matched::Int64, !Matched::Dict{Symbol,Any}) at /home/john/.julia/packages/JuMP/MsUSY/src/JuMP.jl:126

What would be the correct way of getting the volume?

JohnEdChristensen avatar Jan 22 '20 20:01 JohnEdChristensen

I was able to make it work by converting to a vrep using the doubledescription function:

using Polyhedra, QHull
cube = HalfSpace([0,0,1],1)∩HalfSpace([0,0,-1],0)∩HalfSpace([0,1,0],1)∩HalfSpace([0,-1,0],0)∩HalfSpace([1,0,0],1)∩HalfSpace([-1,0,0],0)
vcube = doubledescription(cube)
p = polyhedron(vcube,QHull.Library())
Polyhedra.volume(p)

Shouldn't you be able to calculate the volume directly from the hrep?

JohnEdChristensen avatar Jan 22 '20 23:01 JohnEdChristensen

What would be the correct way of getting the volume?

The error message should be improved, the issue is that if the origin is not in the interior of the polytope, QHull won't work (since QHull takes a V-Rep so we need to transform the H-Rep to a V-Rep by taking the polar, which requires the origin to be in the interior). So we solve an LP to find the chebyshev center and shift the polytope by this center so that the chebyshev center of the shifted polytope is the origin. Solving this LP requires an LP solver but you did not provide any solver to QHull. You need to do for instance

using JuMP
lib = QHull.Library(with_optimizer(GLPK.Optimizer))

Shouldn't you be able to calculate the volume directly from the hrep?

QHull takes a V-Rep as input and gives as output the H-Rep and the volume. What we do is take a H-Rep, give the V-Rep of the polar to QHull which gives the H-Rep of the polar and the volume of the polar that we transform back into V-Rep and volume of the original polytope. I am not aware of a direct way to obtain the volume with QHull from the H-Rep.

blegat avatar Jan 23 '20 07:01 blegat