Skip to content

Commit

Permalink
#1802 - Concretely type linear constraint arrays (#1803)
Browse files Browse the repository at this point in the history
* type constraints_list of hyperrectangular set

* type constraints list of Ball1

* constraints list of cpa

* type for constraints list of ResetMap

* add more type annotations

* more type annotations

* update doctest

* fix last doctest
  • Loading branch information
mforets authored Dec 12, 2019
1 parent 8e5ea27 commit 15eba9d
Show file tree
Hide file tree
Showing 10 changed files with 15 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/Approximations/decompositions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ Now let's take a ball in the infinity norm and remove some constraints:
julia> B = BallInf(zeros(4), 1.0);
julia> c = constraints_list(B)[1:2]
2-element Array{HalfSpace{Float64,VN} where VN<:AbstractArray{Float64,1},1}:
2-element Array{HalfSpace{Float64,LazySets.Arrays.SingleEntryVector{Float64}},1}:
HalfSpace{Float64,LazySets.Arrays.SingleEntryVector{Float64}}([1.0, 0.0, 0.0, 0.0], 1.0)
HalfSpace{Float64,LazySets.Arrays.SingleEntryVector{Float64}}([0.0, 1.0, 0.0, 0.0], 1.0)
Expand Down
7 changes: 4 additions & 3 deletions src/Approximations/iterative_refinement.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,11 @@ Type that represents the polygonal approximation of a convex set.
struct PolygonalOverapproximation{N<:Real}
S::LazySet{N}
approx_stack::Vector{LocalApproximation{N}}
constraints::Vector{LinearConstraint{N}}
constraints::Vector{LinearConstraint{N, Vector{N}}}

PolygonalOverapproximation(S::LazySet{N}) where {N<:Real} = new{N}(
S, Vector{LocalApproximation{N}}(), Vector{LinearConstraint{N}}())
function PolygonalOverapproximation(S::LazySet{N}) where {N<:Real}
return new{N}(S, Vector{LocalApproximation{N}}(), Vector{LinearConstraint{N,Vector{N}}}())
end
end

"""
Expand Down
2 changes: 1 addition & 1 deletion src/Approximations/overapproximate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function overapproximate(S::LazySet{N},
)::HPolygon where {N<:Real}
@assert dim(S) == 2
if ε == Inf
constraints = Vector{LinearConstraint{N}}(undef, 4)
constraints = Vector{LinearConstraint{N, Vector{N}}}(undef, 4)
constraints[1] = LinearConstraint(DIR_EAST(N), ρ(DIR_EAST(N), S))
constraints[2] = LinearConstraint(DIR_NORTH(N), ρ(DIR_NORTH(N), S))
constraints[3] = LinearConstraint(DIR_WEST(N), ρ(DIR_WEST(N), S))
Expand Down
2 changes: 1 addition & 1 deletion src/Interfaces/AbstractHyperrectangle.jl
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ A list of linear constraints.
"""
function constraints_list(H::AbstractHyperrectangle{N}) where {N<:Real}
n = dim(H)
constraints = Vector{LinearConstraint{N}}(undef, 2*n)
constraints = Vector{LinearConstraint{N, SingleEntryVector{N}}}(undef, 2*n)
b, c = high(H), -low(H)
one_N = one(N)
for i in 1:n
Expand Down
5 changes: 2 additions & 3 deletions src/LazyOperations/CartesianProduct.jl
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ number of sets.
A list of constraints.
"""
function constraints_list(cpa::CartesianProductArray{N}) where {N<:Real}
clist = Vector{LinearConstraint{N}}()
clist = Vector{LinearConstraint{N, SparseVector{N, Int}}}()
n = dim(cpa)
sizehint!(clist, n)
prev_step = 1
Expand All @@ -599,8 +599,7 @@ function constraints_list(cpa::CartesianProductArray{N}) where {N<:Real}
indices = prev_step : (dim(c_low_list[1]) + prev_step - 1)
end
for constr in c_low_list
new_constr = LinearConstraint(sparsevec(indices, constr.a, n),
constr.b)
new_constr = LinearConstraint(sparsevec(indices, constr.a, n), constr.b)
push!(clist, new_constr)
end
prev_step += dim(c_low_list[1])
Expand Down
2 changes: 1 addition & 1 deletion src/LazyOperations/ResetMap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ function constraints_list(rm::ResetMap{N, S}
) where {N<:Real, S<:AbstractHyperrectangle}
H = rm.X
n = dim(H)
constraints = Vector{LinearConstraint{N}}(undef, 2*n)
constraints = Vector{LinearConstraint{N, SingleEntryVector{N}}}(undef, 2*n)
j = 1
for i in 1:n
ei = SingleEntryVector(i, n, one(N))
Expand Down
2 changes: 1 addition & 1 deletion src/LazyOperations/Translation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ whose `constraints_list` is available) can be computed from a lazy translation:
```jldoctest translation
julia> constraints_list(tr)
6-element Array{HalfSpace{Float64,VN} where VN<:AbstractArray{Float64,1},1}:
6-element Array{HalfSpace{Float64,LazySets.Arrays.SingleEntryVector{Float64}},1}:
HalfSpace{Float64,LazySets.Arrays.SingleEntryVector{Float64}}([1.0, 0.0, 0.0], 5.0)
HalfSpace{Float64,LazySets.Arrays.SingleEntryVector{Float64}}([0.0, 1.0, 0.0], 3.0)
HalfSpace{Float64,LazySets.Arrays.SingleEntryVector{Float64}}([0.0, 0.0, 1.0], 3.0)
Expand Down
2 changes: 1 addition & 1 deletion src/Sets/Ball1.jl
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ all possible ``d_i``, the function `Iterators.product` is used.
function constraints_list(B::Ball1{N}) where {N<:Real}
n = LazySets.dim(B)
c, r = B.center, B.radius
clist = Vector{LinearConstraint{N}}(undef, 2^n)
clist = Vector{LinearConstraint{N, Vector{N}}}(undef, 2^n)
for (i, di) in enumerate(Iterators.product([[one(N), -one(N)] for i = 1:n]...))
d = collect(di) # tuple -> vector
clist[i] = LinearConstraint(d, dot(d, c) + r)
Expand Down
3 changes: 2 additions & 1 deletion src/Sets/HPolytope.jl
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ return quote
# see the interface file AbstractPolytope.jl for the imports

function convert(::Type{HPolytope{N}}, P::HRep{N}) where {N}
constraints = LinearConstraint{N}[]
VT = Polyhedra.hvectortype(P)
constraints = Vector{LinearConstraint{N, VT}}()
for hi in Polyhedra.allhalfspaces(P)
a, b = hi.a, hi.β
if isapproxzero(norm(a))
Expand Down
2 changes: 1 addition & 1 deletion src/convert.jl
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ A polygon in constraint representation with the minimal number of constraints
"""
function convert(::Type{HPOLYGON}, S::AbstractSingleton{N}
) where {N<:Real, HPOLYGON<:AbstractHPolygon}
constraints_list = Vector{LinearConstraint{N}}(undef, 3)
constraints_list = Vector{LinearConstraint{N, Vector{N}}}(undef, 3)
o = one(N)
z = zero(N)
v = element(S)
Expand Down

0 comments on commit 15eba9d

Please sign in to comment.