diff --git a/src/CDDLib.jl b/src/CDDLib.jl index 5b34142..efb202a 100644 --- a/src/CDDLib.jl +++ b/src/CDDLib.jl @@ -33,7 +33,7 @@ end @dd_ccall set_global_constants Void () -import Base.show, Base.convert, Base.push!, Base.eltype +import Base.show, Base.convert, Base.push!, Base.eltype, Base.copy include("cddtypes.jl") diff --git a/src/matrix.jl b/src/matrix.jl index 5c46560..c9782aa 100644 --- a/src/matrix.jl +++ b/src/matrix.jl @@ -51,6 +51,13 @@ function dd_setmatrixrepresentationtype(matrix::Ptr{Cdd_MatrixData{GMPRational}} @dd_ccall SetMatrixRepresentationType Void (Ptr{Cdd_MatrixData{GMPRational}}, Cdd_RepresentationType) matrix (inequality ? dd_Inequality : dd_Generator) end +function dd_matrixcopy(matrix::Ptr{Cdd_MatrixData{Cdouble}}) + @ddf_ccall MatrixCopy Ptr{Cdd_MatrixData{Cdouble}} (Ptr{Cdd_MatrixData{Cdouble}},) matrix +end +function dd_matrixcopy(matrix::Ptr{Cdd_MatrixData{GMPRational}}) + @dd_ccall MatrixCopy Ptr{Cdd_MatrixData{GMPRational}} (Ptr{Cdd_MatrixData{GMPRational}},) matrix +end + function initmatrix{T<:MyType}(M::Array{T, 2}, linset, inequality::Bool) m = Cdd_rowrange(size(M, 1)) @@ -99,6 +106,10 @@ end CDDInequalityMatrix{T<:MyType}(matrix::Ptr{Cdd_MatrixData{T}}) = CDDInequalityMatrix{unsafe_load(matrix).colsize-1, T}(matrix) +function Base.copy{N, T}(matrix::CDDInequalityMatrix{N, T}) + CDDInequalityMatrix{N, T}(dd_matrixcopy(matrix.matrix)) +end + function isaninequalityrepresentation(matrix::CDDInequalityMatrix) true end @@ -115,6 +126,10 @@ end CDDGeneratorMatrix{T<:MyType}(matrix::Ptr{Cdd_MatrixData{T}}) = CDDGeneratorMatrix{unsafe_load(matrix).colsize-1, T}(matrix) +function Base.copy{N, T}(matrix::CDDGeneratorMatrix{N, T}) + CDDGeneratorMatrix{N, T}(dd_matrixcopy(matrix.matrix)) +end + function isaninequalityrepresentation(matrix::CDDGeneratorMatrix) false end diff --git a/src/polyhedron.jl b/src/polyhedron.jl index e9ca0e6..b411bc3 100644 --- a/src/polyhedron.jl +++ b/src/polyhedron.jl @@ -84,6 +84,30 @@ function updatepoly!{N}(p::CDDPolyhedron{N}, poly::CDDPolyhedra{N}) p.poly = poly end +function Base.copy{N, T}(p::CDDPolyhedron{N, T}) + pcopy = nothing + if !isnull(p.ine) + pcopy = CDDPolyhedron{N, T}(copy(get(p.ine))) + end + if !isnull(p.ext) + if pcopy == nothing + pcopy = CDDPolyhedron{N, T}(copy(get(p.ext))) + else + pcopy.ext = copy(get(p.ext)) + end + end + if pcopy == nothing + # copy of ine and ext may be not necessary here + # but I do it to be sure + pcopy = CDDPolyhedron{N, T}(copy(getine(p))) + pcopy.ext = copy(getext(p)) + end + pcopy.linearitydetected = p.linearitydetected + pcopy.noredundantinequality = p.noredundantinequality + pcopy.noredundantgenerator = p.noredundantgenerator + pcopy +end + # Implementation of Polyhedron's mandatory interface function polyhedron(desc::Description, lib::CDDLibrary) CDDPolyhedron(desc, lib.precision)