Skip to content
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
12 changes: 9 additions & 3 deletions src/Sets/SparsePolynomialZonotope.jl
Original file line number Diff line number Diff line change
Expand Up @@ -413,23 +413,29 @@ This method implements the algorithm described in Proposition 3.1.39 of [1].
"""
function reduce_order(P::SparsePolynomialZonotope, r::Real,
method::AbstractReductionMethod=GIR05())
@assert r ≥ 1
@assert r ≥ 1 "cannot reduce below order 1 (got $r)"

if order(P) <= r
return P
end

n = dim(P)
h = ngens_dep(P)
q = ngens_indep(P)

a = min(h + q, ceil(Int, h + q - n * (r - 1)))
@assert a > 0 # holds because `r > order(P)`

c = center(P)
G = genmat_dep(P)
GI = genmat_indep(P)
E = expmat(P)
idx = indexvector(P)

a = max(0, min(h + q, ceil(Int, h + q - n * (r - 1))))
Gbar = hcat(G, GI)
norms = [norm(g) for g in eachcol(Gbar)]
th = sort(norms)[a]

# TODO: case a = 0
# TODO is constructing an array of booleans the most efficient way?
K = [norms[i] ≤ th for i in 1:h]
Kbar = .!K
Expand Down
5 changes: 5 additions & 0 deletions test/Sets/SparsePolynomialZonotope.jl
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,9 @@ let

@test expmat(Pred) == [1 0 1 2; 0 1 1 0]
@test indexvector(Pred) == [1, 2]

@test order(P) == 4
for r in 4:8
@test reduce_order(P, r) == P
end
end