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

#1226 - Convert cartesian product of zonotopes to a new zonotope #1228

Merged
merged 10 commits into from
Mar 12, 2019
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
12 changes: 7 additions & 5 deletions src/convert.jl
Original file line number Diff line number Diff line change
Expand Up @@ -471,17 +471,19 @@ A zonotope.

### Algorithm

This implementation concatenates the centers of each input zonotope.
The resulting generator matrix is such that the generators for each element of the
cartesian product are added along the diagonal.
The cartesian product is obtained by:

- Concatenating the centers of each input zonotope.
- Arranging the generators in block-diagional fashion, and filled with zeros
in the off-diagonal; for this reason, the generator matrix of the returned
zonotope is built as a sparse matrix.
"""
function convert(::Type{Zonotope}, cp::CartesianProduct{N, Zonotope{N}, Zonotope{N}}) where {N<:Real}
Z1, Z2 = cp.X, cp.Y
n1, p1 = size(Z1.generators)
n2, p2 = size(Z2.generators)
c = vcat(Z1.center, Z2.center)
G = [Z1.generators zeros(n1, p2);
zeros(n2, p1) Z2.generators]
G = blockdiag(sparse(Z1.generators), sparse(Z2.generators))
return Zonotope(c, G)
end

Expand Down
2 changes: 1 addition & 1 deletion test/unit_Zonotope.jl
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ for N in [Float64, Rational{Int}, Float32]
Z1 = Zonotope(N[0], hcat(N[1]))
Z2 = Zonotope(N[1/2], hcat(N[1/2]))
Z = convert(Zonotope, Z1×Z2)
@test Z isa Zonotope && Z.center == N[0, 1/2] && Z.generators == N[1 0; 0 1/2]
@test Z isa Zonotope && Z.center == N[0, 1/2] && diag(Z.generators) == N[1, 1/2]
schillic marked this conversation as resolved.
Show resolved Hide resolved

# list of constraints
Z = Zonotope(zeros(N, 3), Matrix(N(1)*I, 3, 3))
Expand Down