Skip to content

Commit

Permalink
support overapproximate of unions instead of convex hulls
Browse files Browse the repository at this point in the history
  • Loading branch information
schillic committed Mar 9, 2024
1 parent 985d938 commit f02ccbe
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions src/Approximations/overapproximate_zonotope.jl
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,17 @@ constructed in the first phase.
CAV 2009.
"""
function overapproximate(X::ConvexHull{N,<:AbstractZonotope,<:AbstractZonotope},
::Type{<:Zonotope};
algorithm="mean") where {N}
::Type{<:Zonotope}; algorithm="mean") where {N}
return _overapproximate_convex_hull_zonotope(X, algorithm)
end

function overapproximate(X::UnionSet{N,<:AbstractZonotope,<:AbstractZonotope},
::Type{<:Zonotope}; algorithm="mean") where {N}
return _overapproximate_convex_hull_zonotope(X, algorithm)
end

function _overapproximate_convex_hull_zonotope(X::ConvexHull{N,<:AbstractZonotope,<:AbstractZonotope},
::Type{<:Zonotope}) where {N}
# execute specific algorithm
if algorithm == "mean"
return _overapproximate_convex_hull_zonotope_G05(X)
Expand All @@ -124,7 +133,7 @@ function overapproximate(X::ConvexHull{N,<:AbstractZonotope,<:AbstractZonotope},
end
end

function _overapproximate_convex_hull_zonotope_G05(ch::ConvexHull{N}) where {N}
function _overapproximate_convex_hull_zonotope_G05(ch::LazySet{N}) where {N}
# reduce to the same order if possible
X, Y = first(ch), second(ch)
m1, m2 = ngens(X), ngens(Y)
Expand Down Expand Up @@ -165,7 +174,7 @@ function _overapproximate_convex_hull_zonotope_G05(ch::ConvexHull{N}) where {N}
return remove_zero_generators(Z)
end

function _overapproximate_convex_hull_zonotope_GGP09(ch::ConvexHull{N}) where {N}
function _overapproximate_convex_hull_zonotope_GGP09(ch::LazySet{N}) where {N}
Z1, Z2 = first(ch), second(ch)
m = min(ngens(Z1), ngens(Z2))
G1, G2 = genmat(Z1), genmat(Z2)
Expand Down Expand Up @@ -1071,16 +1080,22 @@ A zonotope overapproximation of the convex hull array of zonotopic sets.
This method iteratively applies the overapproximation algorithm to the
convex hull of two zonotopic sets from the given array of zonotopic sets.
"""
function overapproximate(CHA::ConvexHullArray{N,<:AbstractZonotope},
::Type{<:Zonotope}) where {N}
arr = array(CHA)
function overapproximate(CHA::ConvexHullArray{N,<:AbstractZonotope}, ::Type{<:Zonotope}) where {N}
return _overapproximate_union_zonotope(array(CHA))
end

function overapproximate(X::UnionSetArray{N,<:AbstractZonotope}, ::Type{<:Zonotope}) where {N}
return _overapproximate_union_zonotope(array(X))
end

function _overapproximate_union_zonotope(arr)
n = length(arr)
if n == 1
return convert(Zonotope, arr[1])
else
Zaux = overapproximate(ConvexHull(arr[1], arr[2]), Zonotope)
Zaux = overapproximate(UnionSet(arr[1], arr[2]), Zonotope)
for k in 3:n
Zaux = overapproximate(ConvexHull(Zaux, arr[k]), Zonotope)
Zaux = overapproximate(UnionSet(Zaux, arr[k]), Zonotope)
end
return Zaux
end
Expand Down

0 comments on commit f02ccbe

Please sign in to comment.