Skip to content

Commit

Permalink
Merge pull request #1013 from JuliaReach/mforets/1011
Browse files Browse the repository at this point in the history
#1011 - Convert to Vector in polyhedron's LP
  • Loading branch information
mforets authored Jan 16, 2019
2 parents 0eaec7a + 675a995 commit 3ff5b21
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/HPolyhedron.jl
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,23 @@ function σ(d::AbstractVector{N}, P::HPoly{N}) where {N<:Real}
end
end

@inline function _to_minus_vector(d::SparseVector{N}) where {N}
c = zeros(N, length(d))
for (ni, i) in enumerate(d.nzind)
@inbounds c[i] = -d.nzval[ni]
end
return c
end

@inline function _to_minus_vector(d::AbstractVector{N}) where {N}
return convert(Vector{N}, -d)
end

function σ_helper(d::AbstractVector{N}, P::HPoly{N}) where {N<:Real}
c = -d

# let c = -d as a Vector, since GLPK doesn't accept sparse vectors (see #1011)
c = _to_minus_vector(d)

(A, b) = tosimplehrep(P)
if length(b) == 0
unbounded = true
Expand Down
6 changes: 6 additions & 0 deletions test/unit_Polytope.jl
Original file line number Diff line number Diff line change
Expand Up @@ -274,3 +274,9 @@ if test_suite_polyhedra
@test ispermutation(vl, [N[0, 0, 2], N[1, 1, 2]])
end
end

# test that one can pass a sparse vector as the direction (see #1011)
P = HPolytope([HalfSpace([1.0, 0.0], 1.0),
HalfSpace([0.0, 1.0], 1.0),
HalfSpace([-1.0, -1.0], -1.0)])
@test an_element(P) P

0 comments on commit 3ff5b21

Please sign in to comment.