Skip to content

Commit 0b5dbe8

Browse files
committed
Implement Polyhedra.isredundant
1 parent a0b3bad commit 0b5dbe8

File tree

6 files changed

+38
-11
lines changed

6 files changed

+38
-11
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ jobs:
1212
fail-fast: false
1313
matrix:
1414
include:
15+
- version: '1.10'
16+
os: ubuntu-latest
17+
arch: x64
1518
- version: '1'
1619
os: ubuntu-latest
1720
arch: x64

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "LRSLib"
22
uuid = "262c1cb6-76e2-5873-868b-19ece3183cc5"
33
repo = "https://github.com/JuliaPolyhedra/LRSLib.jl.git"
4-
version = "0.8.2"
4+
version = "0.9.0"
55

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

1212
[compat]
1313
Polyhedra = "0.7, 0.8"
14-
julia = "1.6"
14+
julia = "1.10"
1515
lrslib_jll = "= 0.3.3"
1616

1717
[extras]

src/lp.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,7 @@ function print_lpoutput(m::HMatrix, print_solution::Bool=false)
172172
for i in 0:P.d-1
173173
C_i = unsafe_load(P.C, i+1)
174174
Col_i = unsafe_load(P.Col, i+1)
175-
idx = _unsafe_load_inequality(m, C_i)
176-
print(" y_$(idx)=")
175+
print(" y_$(_unsafe_load_inequality(m, C_i).value)=")
177176
temp1 = extractbigint(unsafe_load(Q.Lcm, Col_i+1)) * (-1)
178177
temp1 *= extractbigint(unsafe_load(unsafe_load(P.A, 1), Col_i+1))
179178
temp2 = extractbigint(unsafe_load(Q.Gcd, Col_i+1))

src/matrix.jl

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,20 @@ Base.get(rep::RepMatrix, idx::Polyhedra.Index{Rational{BigInt}}) = Polyhedra.val
177177

178178
function _unsafe_load_inequality(m::RepMatrix, idx)
179179
Q = unsafe_load(m.Q)
180-
return unsafe_load(Q.inequality, idx - Q.lastdv + 1)
180+
_to_index(m, unsafe_load(Q.inequality, idx - Q.lastdv + 1))
181+
end
182+
183+
# For H-rep, LRS internal index `0` corresponds to objective and `1` correspond to the first halfspace/hyperplane
184+
# so it's the same 1-based indexing than `Polyhedra.HIndex`
185+
_to_index(::HMatrix{T}, i) = Polyhedra.HIndex{T,HalfSpace{T,Vector{T}}}(i)
186+
187+
# For V-rep, LRS internal index `0` first halfspace/hyperplane
188+
# so it's the 0-based indexing instead of `Polyhedra.HIndex` so we need to do `+1`
189+
_to_index(::VMatrix{T}, i) = Polyhedra.VIndex{T,Vector{T}}(i + 1)
190+
191+
function _unsafe_load_inequality(m::VMatrix, Polyhedra.VIndex)
192+
Q = unsafe_load(m.Q)
193+
return unsafe_load(Q.inequality, idx - Q.lastdv)
181194
end
182195

183196
# H-representation

src/nash.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ function nash2_main(hr1::HMatrix, hr2::HMatrix, linindex::Vector{Clong})
125125
unsafe_load(unsafe_load(P1).B, i+1),
126126
)
127127
if ((unsafe_load(Q1).nlinearity == 0) ||
128-
(j < unsafe_load(unsafe_load(Q1).linearity, 1)))
129-
unsafe_store!(linearity, j, nlinearity+1)
128+
(j.value < unsafe_load(unsafe_load(Q1).linearity, 1)))
129+
unsafe_store!(linearity, j.value, nlinearity+1)
130130
nlinearity += 1
131131
end
132132
end

src/redund.jl

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
function _inequality_indices(m::HMatrix)
2+
# FIXME Not sure what `lastdv` is doing, isn't it just always zero ?
3+
lastdv = unsafe_load(m.Q).lastdv
4+
return (lastdv + 1):(m_A + d)
5+
end
6+
7+
function _inequality_indices(m::VMatrix)
8+
# FIXME Not sure what `lastdv` is doing, isn't it just always zero ?
9+
lastdv = unsafe_load(m.Q).lastdv
10+
return (lastdv + 2):(m_A + d + 1)
11+
end
12+
113
function redund(m::RepMatrix)
214
# if non-negative flag is set, non-negative constraints are not input
315
# explicitly, and are not checked for redundancy
@@ -25,19 +37,19 @@ function redund(m::RepMatrix)
2537
# rows 0..lastdv are cost, decision variables, or linearities
2638
# other rows need to be tested
2739

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

3243
status = checkindex(m, index)
3344
if :redundant == checkindex(m, index)
34-
push!(redset, ineq)
45+
# the input inequality number corr. to this index
46+
push!(redset, _unsafe_load_inequality(m, index))
3547
end
3648
end
3749
redset
3850
end
3951

40-
function redundi(m::RepMatrix, ineq::Int)
52+
function Polyhedra.isredundant(m::RepMatrix, ineq::Polyhedra.Index)
4153
if m.status == :AtNoBasis
4254
getfirstbasis(m)
4355
end

0 commit comments

Comments
 (0)