From 67dbb7c9619b089583b6fdf7a463b45ff7d2d7c4 Mon Sep 17 00:00:00 2001 From: Daisuke Oyama Date: Sat, 18 Jan 2025 00:15:12 +0900 Subject: [PATCH 1/5] Add test/redund.jl Tests should fail for this commit --- test/redund.jl | 28 ++++++++++++++++++++++++++++ test/runtests.jl | 1 + 2 files changed, 29 insertions(+) create mode 100644 test/redund.jl diff --git a/test/redund.jl b/test/redund.jl new file mode 100644 index 0000000..3349f73 --- /dev/null +++ b/test/redund.jl @@ -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 diff --git a/test/runtests.jl b/test/runtests.jl index eda6188..f355eb3 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -10,3 +10,4 @@ include("matrix.jl") include("polyhedron.jl") include("lp.jl") include("nash.jl") +include("redund.jl") From d38598431ac0a62a8bbe65ac72f22b46eed1743c Mon Sep 17 00:00:00 2001 From: Daisuke Oyama Date: Sat, 18 Jan 2025 13:25:59 +0900 Subject: [PATCH 2/5] Translate 0-based indices to Julia's 1-based in removevredundancy! --- src/polyhedron.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/polyhedron.jl b/src/polyhedron.jl index effd529..707d286 100644 --- a/src/polyhedron.jl +++ b/src/polyhedron.jl @@ -185,7 +185,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) From 2fa1210c3a545c5ba5361027a937f7a31fe48804 Mon Sep 17 00:00:00 2001 From: Daisuke Oyama Date: Sat, 18 Jan 2025 13:30:36 +0900 Subject: [PATCH 3/5] Set ?linearitydetected = true in detect?linearity! --- src/polyhedron.jl | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/polyhedron.jl b/src/polyhedron.jl index 707d286..ad5a318 100644 --- a/src/polyhedron.jl +++ b/src/polyhedron.jl @@ -55,8 +55,6 @@ function getine(p::Polyhedron) else p.ine = LiftedHRepresentation(getextm(p, :Fresh)) p.inem = nothing - p.hlinearitydetected = true - p.noredundantinequality = true end end return p.ine @@ -74,8 +72,6 @@ function getext(p::Polyhedron) else p.ext = LiftedVRepresentation(getinem(p, :Fresh)) p.extm = nothing - p.vlinearitydetected = true - p.noredundantgenerator = true end end return p.ext @@ -154,7 +150,7 @@ function Polyhedra.detecthlinearity!(p::Polyhedron) p.inem = nothing p.ine = nothing getine(p) - # getine sets hlinearity as detected and no redundant ineq. + p.hlinearitydetected = true end end function Polyhedra.detectvlinearity!(p::Polyhedron) @@ -163,7 +159,7 @@ function Polyhedra.detectvlinearity!(p::Polyhedron) p.extm = nothing p.ext = nothing getext(p) - # getext sets vlinearity as detected and no redundant gen. + p.vlinearitydetected = true end end function Polyhedra.removehredundancy!(p::Polyhedron) From 1b1e5740cd34042a28ea5e88dfb8ea9f5f673833 Mon Sep 17 00:00:00 2001 From: Daisuke Oyama Date: Sat, 18 Jan 2025 14:03:47 +0900 Subject: [PATCH 4/5] Update to Polyhedra v0.8 --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index f71f33c..14fb66b 100644 --- a/Project.toml +++ b/Project.toml @@ -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" From 6233efea81a4abbf60987fa1853093886a34758e Mon Sep 17 00:00:00 2001 From: Daisuke Oyama Date: Sat, 18 Jan 2025 21:22:09 +0900 Subject: [PATCH 5/5] Revert setting ?linearitydetected = true in detect?linearity! --- src/polyhedron.jl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/polyhedron.jl b/src/polyhedron.jl index ad5a318..9cc56ae 100644 --- a/src/polyhedron.jl +++ b/src/polyhedron.jl @@ -55,6 +55,7 @@ function getine(p::Polyhedron) else p.ine = LiftedHRepresentation(getextm(p, :Fresh)) p.inem = nothing + p.hlinearitydetected = true end end return p.ine @@ -72,6 +73,7 @@ function getext(p::Polyhedron) else p.ext = LiftedVRepresentation(getinem(p, :Fresh)) p.extm = nothing + p.vlinearitydetected = true end end return p.ext @@ -150,7 +152,7 @@ function Polyhedra.detecthlinearity!(p::Polyhedron) p.inem = nothing p.ine = nothing getine(p) - p.hlinearitydetected = true + # getine sets hlinearity as detected end end function Polyhedra.detectvlinearity!(p::Polyhedron) @@ -159,7 +161,7 @@ function Polyhedra.detectvlinearity!(p::Polyhedron) p.extm = nothing p.ext = nothing getext(p) - p.vlinearitydetected = true + # getext sets vlinearity as detected end end function Polyhedra.removehredundancy!(p::Polyhedron)