-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #537 from JuliaReach/mforets/TMJets
Add TMJets algorithm
- Loading branch information
Showing
10 changed files
with
169 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
export TMJets | ||
|
||
using IntervalArithmetic: IntervalBox | ||
|
||
struct TMJets <: ContinuousPost | ||
options::TwoLayerOptions | ||
|
||
function TMJets(𝑂::Options) | ||
𝑂new = validate_and_wrap_options(𝑂, options_TMJets()) | ||
return new(𝑂new) | ||
end | ||
end | ||
|
||
# convenience constructor from pairs of symbols | ||
TMJets(𝑂::Pair{Symbol, <:Any}...) = TMJets(Options(Dict{Symbol, Any}(𝑂))) | ||
|
||
# default options (they are added in the function validate_and_wrap_options) | ||
TMJets() = TMJets(Options()) | ||
|
||
include("init.jl") | ||
include("post.jl") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# out-of-place initialization | ||
init(𝒫::TMJets, 𝑆::AbstractSystem, 𝑂::Options) = init!(𝒫, 𝑆, copy(𝑂)) | ||
|
||
function options_TMJets() | ||
|
||
𝑂spec = Vector{OptionSpec}() | ||
|
||
# step size and termination criteria | ||
push!(𝑂spec, OptionSpec(:abs_tol, 1e-10, domain=Float64, info="absolute tolerance")) | ||
push!(𝑂spec, OptionSpec(:max_steps, 500, domain=Int, info="use this maximum number of steps in the validated integration")) | ||
|
||
# approximation options | ||
push!(𝑂spec, OptionSpec(:orderT, 10, domain=Int, info="order of the Taylor model in t")) | ||
push!(𝑂spec, OptionSpec(:orderQ, 2, domain=Int, info="order of the Taylor model for Jet transport variables")) | ||
|
||
return 𝑂spec | ||
end | ||
|
||
# in-place initialization | ||
function init!(𝒫::TMJets, 𝑆::AbstractSystem, 𝑂::Options) | ||
|
||
# state dimension | ||
𝑂[:n] = statedim(𝑆) | ||
|
||
# adds default values for unspecified options | ||
𝑂init = validate_solver_options_and_add_default_values!(𝑂) | ||
|
||
return 𝑂init | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
using TaylorModels: validated_integ | ||
using TaylorSeries: set_variables | ||
using LazySets.Approximations: box_approximation | ||
|
||
function post(𝒜::TMJets, | ||
𝑃::InitialValueProblem{<:Union{BBCS, CBBCS, CBBCCS}, <:LazySet}, | ||
𝑂_global::Options) | ||
|
||
# ================================== | ||
# Initialization | ||
# ================================== | ||
|
||
𝑂 = merge(𝒜.options.defaults, 𝑂_global, 𝒜.options.specified) | ||
|
||
# system of ODEs | ||
f! = 𝑃.s.f | ||
n = statedim(𝑃) | ||
|
||
# initial time and time horizon | ||
t0 = 0.0 | ||
T = 𝑂[:T] | ||
|
||
# maximum allowed number of steps | ||
max_steps = 𝑂[:max_steps] | ||
|
||
# unrap algorithm-specific options | ||
abs_tol, orderQ, orderT = 𝑂[:abs_tol], 𝑂[:orderQ], 𝑂[:orderT] | ||
|
||
# initial sets | ||
box_x0 = box_approximation(𝑃.x0) | ||
q0 = center(box_x0) | ||
δq0 = IntervalBox(low(box_x0)-q0, high(box_x0)-q0) | ||
|
||
# fix the working variables and maximum order in the global | ||
# parameters struct (_params_TaylorN_) | ||
set_variables("x", numvars=length(q0), order=2*orderQ) | ||
|
||
# define the property | ||
if 𝑂[:mode] == "check" | ||
property = 𝑂[:property] | ||
elseif 𝑂[:mode] == "reach" | ||
property = (t, x) -> true | ||
end | ||
|
||
# ===================== | ||
# Flowpipe computation | ||
# ===================== | ||
|
||
info("Reachable States Computation...") | ||
@timing begin | ||
tTM, xTM = validated_integ(f!, q0, δq0, t0, T, orderQ, orderT, abs_tol, | ||
maxsteps=max_steps, check_property=property) | ||
end | ||
|
||
# convert to hyperrectangle and wrap around the reach solution | ||
N = length(xTM) | ||
Rsets = Vector{ReachSet{Hyperrectangle, Float64}}(undef, N-1) | ||
@inbounds for i in 1:N-1 | ||
Hi = convert(Hyperrectangle, xTM[i]) | ||
t0 = tTM[i]; t1 = tTM[i+1] | ||
Rsets[i] = ReachSet{Hyperrectangle, Float64}(Hi, t0, t1) | ||
end | ||
|
||
Rsol = ReachSolution(Rsets, 𝑂) | ||
|
||
# =========== | ||
# Projection | ||
# =========== | ||
|
||
if 𝑂[:project_reachset] | ||
info("Projection...") | ||
Rsol = @timing project(Rsol) | ||
end | ||
|
||
return Rsol | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters