Skip to content

Commit

Permalink
Merge pull request #3 from JuliaPolyhedra/bl/polyhedron
Browse files Browse the repository at this point in the history
Implement Polyhedra interface
  • Loading branch information
bdoolittle committed Feb 11, 2021
2 parents f10c19a + aca49ab commit 9677e0e
Show file tree
Hide file tree
Showing 11 changed files with 266 additions and 218 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@

porta.log
porta_tmp

Manifest.toml
**/Manifest.toml
69 changes: 0 additions & 69 deletions Manifest.toml

This file was deleted.

7 changes: 5 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@ version = "0.1.1"

[deps]
PORTA_jll = "c3fa2e09-48e0-5371-872a-ed3ac32dd1fc"
Polyhedra = "67491407-f73d-577b-9b50-8179a7c68029"
Suppressor = "fd094767-a336-5f1f-9728-57cf17d0bbfb"

[compat]
julia = "1.4"
Polyhedra = "0.6.13"
Suppressor = "0.2.0"
julia = "1.4"

[extras]
GLPK = "60bf3e95-4087-53dc-ae20-288a0d20c6a6"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test"]
test = ["GLPK", "Test"]
93 changes: 0 additions & 93 deletions docs/Manifest.toml

This file was deleted.

3 changes: 3 additions & 0 deletions src/XPORTA.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ using PORTA_jll

using Suppressor

import Polyhedra

export POI, IEQ # types
export traf, portsort, dim, fmel # xporta methods
export fctp, posie, vint # valid methods
Expand All @@ -49,5 +51,6 @@ include("./filesystem.jl") # utilities for create and removing directories
include("./file_io.jl") # read/write functionality
include("./xporta_subroutines.jl") # wrapper for the xporta binaries.
include("./valid_subroutines.jl") # wrapper for the valid binaries
include("./polyhedron.jl")

end # module
96 changes: 96 additions & 0 deletions src/polyhedron.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
struct Library <: Polyhedra.Library
solver
function Library(solver=nothing)
new(solver)
end
end
Polyhedra.similar_library(::Library, ::Polyhedra.FullDim, ::Type{T}) where T<:Union{Integer,Rational} = Library()
Polyhedra.similar_library(::Library, d::Polyhedra.FullDim, ::Type{T}) where T = Polyhedra.default_library(d, T)

mutable struct Polyhedron <: Polyhedra.Polyhedron{Rational{Int}}
hrep::Union{Nothing, IEQ{Rational{Int}}}
hred::Polyhedra.Redundancy
vrep::Union{Nothing, POI{Rational{Int}}}
vred::Polyhedra.Redundancy
solver
function Polyhedron(h::Union{Nothing, IEQ{Rational{Int}}}, hred::Polyhedra.Redundancy, v::Union{Nothing, POI{Rational{Int}}}, vred::Polyhedra.Redundancy, solver)
new(h, hred, v, vred, solver)
end
end
Polyhedron(h::IEQ{Rational{Int}}, solver) = Polyhedron(h, Polyhedra.UNKNOWN_REDUNDANCY, nothing, Polyhedra.UNKNOWN_REDUNDANCY, solver)
Polyhedron(h::Polyhedra.HRepresentation, solver) = Polyhedron(convert(IEQ{Rational{Int}}, h), solver)
Polyhedron(v::POI{Rational{Int}}, solver) = Polyhedron(nothing, Polyhedra.UNKNOWN_REDUNDANCY, v, Polyhedra.UNKNOWN_REDUNDANCY, solver)
Polyhedron(v::Polyhedra.VRepresentation, solver) = Polyhedron(convert(POI{Rational{Int}}, v), solver)

Polyhedra.FullDim(p::Polyhedron) = Polyhedra.FullDim_rep(p.hrep, p.vrep)
Polyhedra.library(p::Polyhedron) = Library(p.solver)
Polyhedra.default_solver(p::Polyhedron; T=nothing) = p.solver
Polyhedra.supportssolver(::Type{<:Polyhedron}) = true

Polyhedra.hvectortype(::Union{Polyhedron, Type{Polyhedron}}) = Polyhedra.hvectortype(IEQ{Rational{Int}})
Polyhedra.vvectortype(::Union{Polyhedron, Type{Polyhedron}}) = Polyhedra.vvectortype(POI{Rational{Int}})
Polyhedra.similar_type(::Type{<:Polyhedron}, ::Polyhedra.FullDim, ::Type{Rational{Int}}) = Polyhedron
Polyhedra.similar_type(::Type{<:Polyhedron}, d::Polyhedra.FullDim, ::Type{T}) where T = Polyhedra.default_type(d, T)


# Implementation of Polyhedron's mandatory interface
function Polyhedron(d::Polyhedra.FullDim, hits::Polyhedra.HIt...; solver=nothing)
Polyhedron(IEQ{Rational{Int}}(d, hits...), solver)
end
function Polyhedron(d::Polyhedra.FullDim, vits::Polyhedra.VIt...; solver=nothing)
Polyhedron(POI{Rational{Int}}(d, vits...), solver)
end

Polyhedra.polyhedron(rep::Polyhedra.Representation, lib::Library) = Polyhedron(rep, lib.solver)

# We don't copy as we don't implement any mutable operation.
Base.copy(p::Polyhedron) = Polyhedron(p.hrep, p.hred, p.vrep, p.vred, p.solver)

Polyhedra.hredundancy(p::Polyhedron) = p.hred
Polyhedra.vredundancy(p::Polyhedron) = p.vred

Polyhedra.hrepiscomputed(p::Polyhedron) = p.hrep !== nothing
function Polyhedra.computehrep!(p::Polyhedron)
p.hrep = traf(p.vrep)
p.hred = Polyhedra.NO_REDUNDANCY
end
function Polyhedra.hrep(p::Polyhedron)
if !Polyhedra.hrepiscomputed(p)
Polyhedra.computehrep!(p)
end
return p.hrep
end
Polyhedra.vrepiscomputed(p::Polyhedron) = p.vrep !== nothing
function Polyhedra.computevrep!(p::Polyhedron)
p.vrep = traf(p.hrep)
p.vred = Polyhedra.NO_REDUNDANCY
end
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, redundancy = UNKNOWN_REDUNDANCY)
p.hrep = h
p.hred = redundancy
end
function Polyhedra.setvrep!(p::Polyhedron, v::Polyhedra.VRepresentation, redundancy = UNKNOWN_REDUNDANCY)
p.vrep = v
p.vred = redundancy
end
function Polyhedra.resethrep!(p::Polyhedron, h::Polyhedra.HRepresentation, redundancy = UNKNOWN_REDUNDANCY)
p.hrep = h
p.hred = redundancy
p.vrep = nothing
p.vred = Polyhedra.UNKNOWN_REDUNDANCY
end
function Polyhedra.resetvrep!(p::Polyhedron, v::Polyhedra.VRepresentation, redundancy = UNKNOWN_REDUNDANCY)
p.vrep = v
p.vred = redundancy
p.hrep = nothing
p.hred = Polyhedra.UNKNOWN_REDUNDANCY
end

@_norepelem Polyhedron Line
Loading

0 comments on commit 9677e0e

Please sign in to comment.