Skip to content

Commit

Permalink
polyhedral: use dehomogenize from polymake (#4028)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
benlorenz authored Aug 20, 2024
1 parent 6caa552 commit 48d9942
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
3 changes: 1 addition & 2 deletions src/PolyhedralGeometry/helpers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/PolyhedralGeometry/linear_program.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/PolyhedralGeometry/mixed_integer_linear_program.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions test/PolyhedralGeometry/polyhedron.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 48d9942

Please sign in to comment.