From 6b9e04380a0fe91f08ad185184f03de1df730246 Mon Sep 17 00:00:00 2001 From: schillic Date: Fri, 30 Nov 2018 14:46:40 +0100 Subject: [PATCH 1/2] rename doc header --- src/HalfSpace.jl | 2 +- src/Hyperplane.jl | 2 +- src/Line.jl | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/HalfSpace.jl b/src/HalfSpace.jl index 65bf5604ea..1d56077835 100644 --- a/src/HalfSpace.jl +++ b/src/HalfSpace.jl @@ -210,7 +210,7 @@ Return the indices in which a half-space is constrained. A vector of ascending indices `i` such that the half-space is constrained in dimension `i`. -### Notes +### Examples A 2D half-space with constraint ``x1 ≥ 0`` is constrained in dimension 1 only. """ diff --git a/src/Hyperplane.jl b/src/Hyperplane.jl index b13df55f5b..fee0e4a24f 100644 --- a/src/Hyperplane.jl +++ b/src/Hyperplane.jl @@ -182,7 +182,7 @@ Return the indices in which a hyperplane is constrained. A vector of ascending indices `i` such that the hyperplane is constrained in dimension `i`. -### Notes +### Examples A 2D hyperplane with constraint ``x1 = 0`` is constrained in dimension 1 only. """ diff --git a/src/Line.jl b/src/Line.jl index 9763e24f45..520898a542 100644 --- a/src/Line.jl +++ b/src/Line.jl @@ -248,7 +248,7 @@ Return the indices in which a line is constrained. A vector of ascending indices `i` such that the line is constrained in dimension `i`. -### Notes +### Examples A line with constraint ``x1 = 0`` is constrained in dimension 1 only. """ From 41290c8a4e0e517b240358a188adf25b74b05982 Mon Sep 17 00:00:00 2001 From: schillic Date: Fri, 30 Nov 2018 14:47:41 +0100 Subject: [PATCH 2/2] add constrained_dimensions for HPolyhedron --- docs/src/lib/representations.md | 2 +- src/HPolyhedron.jl | 32 +++++++++++++++++++++++++++++++- test/unit_Polyhedron.jl | 5 +++++ 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/docs/src/lib/representations.md b/docs/src/lib/representations.md index 556c85a3d3..ac56e3fe18 100644 --- a/docs/src/lib/representations.md +++ b/docs/src/lib/representations.md @@ -442,7 +442,6 @@ vertices_list(::HPolytope{N}) where {N<:Real} Inherited from [`AbstractPolytope`](@ref): * [`singleton_list`](@ref singleton_list(::AbstractPolytope{N}) where {N<:Real}) -The following methods are specific for polytopes. #### Polyhedra @@ -452,6 +451,7 @@ The following methods are specific for `HPolyhedron`. rand(::Type{HPolyhedron}) vertices_list(::HPolyhedron{N}) where {N<:Real} singleton_list(::HPolyhedron{N}) where {N<:Real} +constrained_dimensions(::HPolyhedron{N}) where {N<:Real} ``` ### Vertex representation diff --git a/src/HPolyhedron.jl b/src/HPolyhedron.jl index 23332a4156..5fd08339e4 100644 --- a/src/HPolyhedron.jl +++ b/src/HPolyhedron.jl @@ -17,7 +17,8 @@ export HPolyhedron, singleton_list, isempty, remove_redundant_constraints, - remove_redundant_constraints! + remove_redundant_constraints!, + constrained_dimensions """ HPolyhedron{N<:Real} <: LazySet{N} @@ -247,6 +248,35 @@ function rand(::Type{HPolyhedron}; return HPolyhedron(constraints_Q) end +""" + constrained_dimensions(P::HPolyhedron{N})::Vector{Int} where {N<:Real} + +Return the indices in which a polyhedron in constraint representation is +constrained. + +### Input + +- `P` -- polyhedron in constraint representation + +### Output + +A vector of ascending indices `i` such that the polyhedron is constrained in +dimension `i`. + +### Examples + +A 2D polyhedron with constraint ``x1 ≥ 0`` is constrained in dimension 1 only. +""" +function constrained_dimensions(P::HPolyhedron{N})::Vector{Int} where {N<:Real} + zero_indices = zeros(Int, dim(P)) + for constraint in P.constraints + for i in constrained_dimensions(constraint) + zero_indices[i] = i + end + end + return filter(x -> x != 0, zero_indices) +end + # =========================================== # HPolyhedron and HPolytope's shared methods diff --git a/test/unit_Polyhedron.jl b/test/unit_Polyhedron.jl index 38e98f147d..a351289a59 100644 --- a/test/unit_Polyhedron.jl +++ b/test/unit_Polyhedron.jl @@ -45,6 +45,11 @@ for N in [Float64, Rational{Int}, Float32] @test ∈(N[5 / 4, 7 / 4], p) @test !∈(N[4, 1], p) + # constrained dimensions + @test constrained_dimensions(p) == [1, 2] + @test constrained_dimensions( + HPolyhedron{N}([LinearConstraint(N[1, 0], N(1))])) == [1] + if test_suite_polyhedra # conversion to and from Polyhedra's VRep data structure cl = constraints_list(HPolyhedron(polyhedron(p)))