Skip to content

Commit

Permalink
Fix removevredundancy! (#53)
Browse files Browse the repository at this point in the history
* Add test/redund.jl

Tests should fail for this commit

* Translate 0-based indices to Julia's 1-based in removevredundancy!

* Set ?linearitydetected = true in detect?linearity!

* Update to Polyhedra v0.8

* Revert setting ?linearitydetected = true in detect?linearity!
  • Loading branch information
oyamad authored Jan 21, 2025
1 parent 22915a1 commit fc49d96
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Polyhedra = "67491407-f73d-577b-9b50-8179a7c68029"
lrslib_jll = "3873f7d0-7b7c-52c3-bdf4-8ab39b8f337a"

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

Expand Down
8 changes: 3 additions & 5 deletions src/polyhedron.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ function getine(p::Polyhedron)
p.ine = LiftedHRepresentation(getextm(p, :Fresh))
p.inem = nothing
p.hlinearitydetected = true
p.noredundantinequality = true
end
end
return p.ine
Expand All @@ -75,7 +74,6 @@ function getext(p::Polyhedron)
p.ext = LiftedVRepresentation(getinem(p, :Fresh))
p.extm = nothing
p.vlinearitydetected = true
p.noredundantgenerator = true
end
end
return p.ext
Expand Down Expand Up @@ -154,7 +152,7 @@ function Polyhedra.detecthlinearity!(p::Polyhedron)
p.inem = nothing
p.ine = nothing
getine(p)
# getine sets hlinearity as detected and no redundant ineq.
# getine sets hlinearity as detected
end
end
function Polyhedra.detectvlinearity!(p::Polyhedron)
Expand All @@ -163,7 +161,7 @@ function Polyhedra.detectvlinearity!(p::Polyhedron)
p.extm = nothing
p.ext = nothing
getext(p)
# getext sets vlinearity as detected and no redundant gen.
# getext sets vlinearity as detected
end
end
function Polyhedra.removehredundancy!(p::Polyhedron)
Expand All @@ -185,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 = redund(extm)
redset = BitSet(redund(extm) .+ 1)
nonred = setdiff(BitSet(1:size(ext.R, 1)), redset)
nonred = collect(setdiff(nonred, ext.linset))
lin = collect(ext.linset)
Expand Down
28 changes: 28 additions & 0 deletions test/redund.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
@testset "Tests for redundancy removal" begin

@testset "Test for issue #52" begin
A = [0 1 0; -1 0 0; 0 -1 0; 0 0 -1; 1 0 0]
b = [2, -1, -1, -1, 2]
linset = BitSet(5)
hr = hrep(A, b, linset)

V = [2 1 1;
2 2 1]
R = [0 0 1]
exp = vrep(V, R)

@testset "removevredundancy!" begin
p = polyhedron(hr, LRSLib.Library())
removevredundancy!(p)
@test nrays(p) == nrays(exp)
end

@testset "detectvlinearity! and then removevredundancy!" begin
p = polyhedron(hr, LRSLib.Library())
detectvlinearity!(p)
removevredundancy!(p)
@test nrays(p) == nrays(exp)
end
end

end
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ include("matrix.jl")
include("polyhedron.jl")
include("lp.jl")
include("nash.jl")
include("redund.jl")

0 comments on commit fc49d96

Please sign in to comment.