Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Polyhedra.isredundant #56

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ jobs:
fail-fast: false
matrix:
include:
- version: '1.10'
os: ubuntu-latest
arch: x64
- version: '1'
os: ubuntu-latest
arch: x64
Expand Down
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "LRSLib"
uuid = "262c1cb6-76e2-5873-868b-19ece3183cc5"
repo = "https://github.com/JuliaPolyhedra/LRSLib.jl.git"
version = "0.8.2"
version = "0.9.0"

[deps]
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Expand All @@ -11,7 +11,7 @@ lrslib_jll = "3873f7d0-7b7c-52c3-bdf4-8ab39b8f337a"

[compat]
Polyhedra = "0.7, 0.8"
julia = "1.6"
julia = "1.10"
lrslib_jll = "= 0.3.3"

[extras]
Expand Down
3 changes: 1 addition & 2 deletions src/lp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,7 @@ function print_lpoutput(m::HMatrix, print_solution::Bool=false)
for i in 0:P.d-1
C_i = unsafe_load(P.C, i+1)
Col_i = unsafe_load(P.Col, i+1)
idx = _unsafe_load_inequality(m, C_i)
print(" y_$(idx)=")
print(" y_$(_unsafe_load_inequality(m, C_i).value)=")
temp1 = extractbigint(unsafe_load(Q.Lcm, Col_i+1)) * (-1)
temp1 *= extractbigint(unsafe_load(unsafe_load(P.A, 1), Col_i+1))
temp2 = extractbigint(unsafe_load(Q.Gcd, Col_i+1))
Expand Down
16 changes: 15 additions & 1 deletion src/matrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,21 @@ Base.get(rep::RepMatrix, idx::Polyhedra.Index{Rational{BigInt}}) = Polyhedra.val

function _unsafe_load_inequality(m::RepMatrix, idx)
Q = unsafe_load(m.Q)
return unsafe_load(Q.inequality, idx - Q.lastdv + 1)
_to_index(m, unsafe_load(Q.inequality, idx - Q.lastdv + 1))
end

# For H-rep, LRS internal index `0` corresponds to objective and `1` correspond to the first halfspace/hyperplane
# so it's the same 1-based indexing than `Polyhedra.HIndex`
function _to_index(::HMatrix, i)
T = Rational{BigInt}
return Polyhedra.Index{T,HalfSpace{T,Vector{T}}}(i)
end

# For V-rep, LRS internal index `0` first halfspace/hyperplane
# so it's the 0-based indexing instead of `Polyhedra.HIndex` so we need to do `+1`
function _to_index(::VMatrix, i)
T = Rational{BigInt}
return Polyhedra.Index{T,Vector{T}}(i + 1)
end

# H-representation
Expand Down
4 changes: 2 additions & 2 deletions src/nash.jl
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ function nash2_main(hr1::HMatrix, hr2::HMatrix, linindex::Vector{Clong})
unsafe_load(unsafe_load(P1).B, i+1),
)
if ((unsafe_load(Q1).nlinearity == 0) ||
(j < unsafe_load(unsafe_load(Q1).linearity, 1)))
unsafe_store!(linearity, j, nlinearity+1)
(j.value < unsafe_load(unsafe_load(Q1).linearity, 1)))
unsafe_store!(linearity, j.value, nlinearity+1)
nlinearity += 1
end
end
Expand Down
6 changes: 3 additions & 3 deletions src/polyhedron.jl
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ function Polyhedra.removehredundancy!(p::Polyhedron)
ine = getine(p)
inem = getinem(p, :AlmostFresh) # FIXME does it need to be fresh ?
linset = getinputlinsubset(inem)
redset = redund(inem)
redset = [idx.value for idx in redund(inem)]
nonred = setdiff(BitSet(1:size(ine.A, 1)), redset)
nonred = collect(setdiff(nonred, linset))
lin = collect(linset)
Expand All @@ -183,7 +183,7 @@ function Polyhedra.removevredundancy!(p::Polyhedron)
detectvlinearity!(p)
ext = getext(p)
extm = getextm(p, :AlmostFresh) # FIXME does it need to be fresh ?
redset = BitSet(redund(extm) .+ 1)
redset = [idx.value for idx in redund(extm)]
nonred = setdiff(BitSet(1:size(ext.R, 1)), redset)
nonred = collect(setdiff(nonred, ext.linset))
lin = collect(ext.linset)
Expand All @@ -199,7 +199,7 @@ _getrepfor(p::Polyhedron, ::Polyhedra.HIndex, status::Symbol) = getinem(p, statu
_getrepfor(p::Polyhedron, ::Polyhedra.VIndex, status::Symbol) = getextm(p, status)
function Polyhedra.isredundant(p::Polyhedron, idx::Polyhedra.Index; strongly=false, cert=false, solver=nothing)
@assert !strongly && !cert
redundi(_getrepfor(p, idx, :AlmostFresh), idx.value) # FIXME does it need to be fresh ?
Polyhedra.isredundant(_getrepfor(p, idx, :AlmostFresh), idx) # FIXME does it need to be fresh ?
end
# Optional interface
function Polyhedra.loadpolyhedron!(p::Polyhedron, filename::AbstractString, ::Type{Val{:ext}})
Expand Down
20 changes: 16 additions & 4 deletions src/redund.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
function _inequality_indices(m::HMatrix)
# FIXME Not sure what `lastdv` is doing, isn't it just always zero ?
lastdv = unsafe_load(m.Q).lastdv
return (lastdv + 1):(m_A + d)
end

function _inequality_indices(m::VMatrix)
# FIXME Not sure what `lastdv` is doing, isn't it just always zero ?
lastdv = unsafe_load(m.Q).lastdv
return (lastdv + 2):(m_A + d + 1)
end

function redund(m::RepMatrix)
# if non-negative flag is set, non-negative constraints are not input
# explicitly, and are not checked for redundancy
Expand Down Expand Up @@ -25,19 +37,19 @@ function redund(m::RepMatrix)
# rows 0..lastdv are cost, decision variables, or linearities
# other rows need to be tested

redset = BitSet()
redset = [] # FIXME concrete type
for index in (lastdv + 1):(m_A + d)
ineq = _unsafe_load_inequality(m, index) # the input inequality number corr. to this index

status = checkindex(m, index)
if :redundant == checkindex(m, index)
push!(redset, ineq)
# the input inequality number corr. to this index
push!(redset, _unsafe_load_inequality(m, index))
end
end
redset
end

function redundi(m::RepMatrix, ineq::Int)
function Polyhedra.isredundant(m::RepMatrix, ineq::Polyhedra.Index)
if m.status == :AtNoBasis
getfirstbasis(m)
end
Expand Down
Loading