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

Add discrete post for GLGM06 #861

Merged
merged 1 commit into from
Jan 9, 2025
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
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
Loading