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

Generalize 1D zonotope constraints_list #2146

Merged
merged 6 commits into from
May 1, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
13 changes: 9 additions & 4 deletions src/Interfaces/AbstractZonotope.jl
Original file line number Diff line number Diff line change
Expand Up @@ -498,12 +498,17 @@ function constraints_list(Z::AbstractZonotope{N}; check_full_rank::Bool=true
# special handling of 1D case
if n == 1
if p > 1
error("1D-zonotope constraints currently only support a single " *
"generator")
Z_1g = remove_zero_generators(Z)
if ngens(Z_1g) > 1
error("1D-zonotope constraints currently only support a " *
"single generator")
end
else
Z_1g = Z
end

c = center(Z)[1]
g = G[:, 1][1]
c = center(Z_1g)[1]
g = genmat(Z_1g)[:, 1][1]
schillic marked this conversation as resolved.
Show resolved Hide resolved
constraints = [LinearConstraint([N(1)], c + g),
LinearConstraint([N(-1)], g - c)]
return constraints
Expand Down
4 changes: 4 additions & 0 deletions test/unit_Zonotope.jl
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,10 @@ for N in [Float64, Rational{Int}, Float32]
B = BallInf(zeros(N, 3), N(1)) # equivalent to Z
constraints = constraints_list(Z)
@test constraints isa Vector{<:HalfSpace{N}} && length(constraints) == 6

# 1D projection removes zero generators automatically
schillic marked this conversation as resolved.
Show resolved Hide resolved
B = BallInf(N[0, 0], N(1))
project(B, [1])
end

for N in [Float64]
Expand Down