Skip to content

Instantly share code, notes, and snippets.

@joehuchette
Created April 10, 2014 15:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joehuchette/10396014 to your computer and use it in GitHub Desktop.
Save joehuchette/10396014 to your computer and use it in GitHub Desktop.
cddwrap.jl
using PyCall
@pyimport cdd
# returns extreme points of polyhedron Ax <= b
function extremepoints(A,b)
m = cdd.Matrix([b -A], number_type="fraction")
m[:rep_type] = 1 # we're providing H representation
p = cdd.Polyhedron(m)
EPs = p[:get_generators]()
numext = EPs[:row_size]
extpoints = Vector[]
extrays = Vector[]
for i in 1:numext
row = EPs[:__getitem__](i-1)
if row[1] == 0 # extreme ray
push!(extrays, Rational[row[2:end]...])
else
push!(extpoints, Rational[row[2:end]...])
end
end
return extpoints, extrays
end
@blegat
Copy link

blegat commented Jan 13, 2016

I written a Julia wrapper for cddlib.
You can now do it with

using CDD

# returns extreme points of polyhedron Ax <= b
function extremepoints(A,b)
    m = InequalityDescription(A, b)
    p = CDDPolyhedra(m)
    EPs = Description{Rational{BigInt}}(copygenerators(p))
    splitvertexrays!(EPs)
    return EPs.V, EPs.R
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment