Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#1802 - Concretely type linear constraint arrays #1803

Merged
merged 8 commits into from
Dec 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
4 changes: 2 additions & 2 deletions src/Interfaces/AbstractHyperrectangle.jl
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,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 Expand Up @@ -332,7 +332,7 @@ This implementation uses the fact that the maximum is achieved in the vertex
``c + \\text{diag}(\\text{sign}(c)) r``, for any ``p``-norm, hence it suffices to
take the ``p``-norm of this particular vertex. This statement is proved below.
Note that, in particular, there is no need to compute the ``p``-norm for *each*
vertex, which can be very expensive.
vertex, which can be very expensive.

If ``X`` is an axis-aligned hyperrectangle and the ``n``-dimensional vectors center
and radius of the hyperrectangle are denoted ``c`` and ``r`` respectively, then
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