From 48d99422659a35afc7a7931261e387756cab196c Mon Sep 17 00:00:00 2001 From: Benjamin Lorenz Date: Tue, 20 Aug 2024 18:06:59 +0200 Subject: [PATCH] polyhedral: use dehomogenize from polymake (#4028) * polyhedral: use dehomogenize from polymake and directly use entries for linear objective test for dehomogenized rel_int_point with non-normalized first coordinate * Update test/PolyhedralGeometry/polyhedron.jl * Update test/PolyhedralGeometry/polyhedron.jl --- src/PolyhedralGeometry/helpers.jl | 3 +-- src/PolyhedralGeometry/linear_program.jl | 2 +- src/PolyhedralGeometry/mixed_integer_linear_program.jl | 4 ++-- test/PolyhedralGeometry/polyhedron.jl | 6 ++++++ 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/PolyhedralGeometry/helpers.jl b/src/PolyhedralGeometry/helpers.jl index 0df7324f58f6..c537f858051e 100644 --- a/src/PolyhedralGeometry/helpers.jl +++ b/src/PolyhedralGeometry/helpers.jl @@ -294,8 +294,7 @@ homogenized_matrix(x::AbstractVector, val::Number) = permutedims(homogenize(x, v homogenized_matrix(x::AbstractVector{<:AbstractVector}, val::Number) = stack((homogenize(x[i], val) for i in 1:length(x))...) -dehomogenize(vec::AbstractVector) = vec[2:end] -dehomogenize(mat::AbstractMatrix) = mat[:, 2:end] +dehomogenize(vm::AbstractVecOrMat) = Polymake.call_function(:polytope, :dehomogenize, vm) unhomogenized_matrix(x::AbstractVector) = assure_matrix_polymake(stack(x)) unhomogenized_matrix(x::AbstractMatrix) = assure_matrix_polymake(x) diff --git a/src/PolyhedralGeometry/linear_program.jl b/src/PolyhedralGeometry/linear_program.jl index eb1b135da360..5d170dd421f9 100644 --- a/src/PolyhedralGeometry/linear_program.jl +++ b/src/PolyhedralGeometry/linear_program.jl @@ -98,7 +98,7 @@ The allowed values for `as` are function objective_function(lp::LinearProgram{T}; as::Symbol=:pair) where {T<:scalar_types} if as == :pair cf = coefficient_field(lp) - return T[cf(x) for x in dehomogenize(lp.polymake_lp.LINEAR_OBJECTIVE)], + return T[cf(x) for x in lp.polymake_lp.LINEAR_OBJECTIVE[2:end]], cf.(lp.polymake_lp.LINEAR_OBJECTIVE[1]) elseif as == :function (c, k) = objective_function(lp; as=:pair) diff --git a/src/PolyhedralGeometry/mixed_integer_linear_program.jl b/src/PolyhedralGeometry/mixed_integer_linear_program.jl index b3038e88484c..5b6c085bc981 100644 --- a/src/PolyhedralGeometry/mixed_integer_linear_program.jl +++ b/src/PolyhedralGeometry/mixed_integer_linear_program.jl @@ -77,7 +77,7 @@ pm_object(milp::MixedIntegerLinearProgram) = milp.polymake_milp ############################################################################### ############################################################################### function describe(io::IO, MILP::MixedIntegerLinearProgram) - c = dehomogenize(MILP.polymake_milp.LINEAR_OBJECTIVE) + c = MILP.polymake_milp.LINEAR_OBJECTIVE[2:end] k = MILP.polymake_milp.LINEAR_OBJECTIVE[1] print(io, "The mixed integer linear program\n") if MILP.convention == :max @@ -128,7 +128,7 @@ function objective_function( milp::MixedIntegerLinearProgram{T}; as::Symbol=:pair ) where {T<:scalar_types} if as == :pair - return Vector{T}(dehomogenize(milp.polymake_milp.LINEAR_OBJECTIVE)), + return Vector{T}(milp.polymake_milp.LINEAR_OBJECTIVE[2:end]), convert(T, milp.polymake_milp.LINEAR_OBJECTIVE[1]) elseif as == :function (c, k) = objective_function(milp; as=:pair) diff --git a/test/PolyhedralGeometry/polyhedron.jl b/test/PolyhedralGeometry/polyhedron.jl index e5d742777787..61a15c61af39 100644 --- a/test/PolyhedralGeometry/polyhedron.jl +++ b/test/PolyhedralGeometry/polyhedron.jl @@ -236,6 +236,12 @@ @test n_rays(Q1) == 1 @test lineality_dim(Q2) == 1 @test relative_interior_point(Q0) == [1//3, 1//3] + + # issue #4024 + let op = Polyhedron{T}(Polymake.polytope.Polytope{Oscar._scalar_type_to_polymake(T)}(REL_INT_POINT=f.([1//3, -1, -2, -4//3]), CONE_AMBIENT_DIM=4), f) + @test relative_interior_point(op) == point_vector(f, [-3,-6,-4]) + end + @test facet_sizes(Q0)[1] == 2 @test sum(facet_sizes(Q1)) == 6 @test facet_sizes(Q2)[1] == 1