Skip to content

Commit

Permalink
add discrete post for GLGM06
Browse files Browse the repository at this point in the history
  • Loading branch information
schillic committed Jul 28, 2024
1 parent 3d9acf3 commit d2b83a9
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 10 deletions.
32 changes: 24 additions & 8 deletions src/Algorithms/GLGM06/post.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# continuous post for GLGM06 using Zonotope set representation
function post(alg::GLGM06{N}, ivp::IVP{<:AbstractContinuousSystem}, tspan;
Δt0::TimeInterval=zeroI, kwargs...) where {N}
@unpack δ, approx_model, max_order, static, dim, ngens,
preallocate, reduction_method, disjointness_method = alg
δ = alg.δ

# TODO move up to main solve function
if haskey(kwargs, :NSTEPS)
Expand All @@ -25,13 +24,30 @@ function post(alg::GLGM06{N}, ivp::IVP{<:AbstractContinuousSystem}, tspan;
end

# discretize system
ivp_discr = discretize(ivp_norm, δ, approx_model)
Φ = state_matrix(ivp_discr)
Ω0 = initial_state(ivp_discr)
X = stateset(ivp_discr)
ivp_discr = discretize(ivp_norm, δ, alg.approx_model)

return post(alg, ivp_discr, NSTEPS; Δt0=Δt0, kwargs...)
end

function post(alg::GLGM06{N}, ivp::IVP{<:AbstractDiscreteSystem}, NSTEPS=nothing;
Δt0::TimeInterval=zeroI, kwargs...) where {N}
@unpack δ, approx_model, max_order, static, dim, ngens,
preallocate, reduction_method, disjointness_method = alg

if isnothing(NSTEPS)
if haskey(kwargs, :NSTEPS)
NSTEPS = kwargs[:NSTEPS]
else
throw(ArgumentError("`NSTEPS` not specified"))
end
end

Φ = state_matrix(ivp)
Ω0 = initial_state(ivp)
X = stateset(ivp)

# true <=> there is no input, i.e. the system is of the form x' = Ax, x ∈ X
got_homogeneous = !hasinput(ivp_discr)
got_homogeneous = !hasinput(ivp)

# this algorithm requires Ω0 to be a zonotope
Ω0 = _convert_or_overapproximate(Zonotope, Ω0)
Expand Down Expand Up @@ -62,7 +78,7 @@ function post(alg::GLGM06{N}, ivp::IVP{<:AbstractContinuousSystem}, tspan;
disjointness_method)
else
# TODO: implement preallocate option for this scenario
U = inputset(ivp_discr)
U = inputset(ivp)
@assert isa(U, LazySet) "expected input of type `<:LazySet`, but got $(typeof(U))"
U = _convert_or_overapproximate(Zonotope, U)
U = _reconvert(U, static, dim, ngens)
Expand Down
11 changes: 9 additions & 2 deletions test/algorithms/GLGM06.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
@testset "GLGM06 algorithm: homogeneous" begin

# one-dimensional
prob, _ = exponential_1d()
sol = solve(prob; T=5.0, alg=GLGM06(; δ=0.01))
ivp, _ = exponential_1d()
alg = GLGM06(; δ=0.01)
# continuous algorithm
sol = solve(ivp; T=5.0, alg=alg)
@test isa(sol.alg, GLGM06)
@test setrep(sol) <: Zonotope
@test setrep(sol) == Zonotope{Float64,Array{Float64,1},Array{Float64,2}}
@test dim(sol) == 1
# discrete algorithm
ivp_norm = ReachabilityAnalysis._normalize(ivp)
ivp_discr = discretize(ivp_norm, alg.δ, alg.approx_model)
NSTEPS = 500
fp_d = ReachabilityAnalysis.post(alg, ivp_discr, NSTEPS)

# higher-dimensional homogeneous
prob, _ = linear5D_homog()
Expand Down

0 comments on commit d2b83a9

Please sign in to comment.