Created
April 10, 2014 15:49
-
-
Save joehuchette/10396014 to your computer and use it in GitHub Desktop.
cddwrap.jl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I written a Julia wrapper for cddlib.
You can now do it with