Skip to content
This repository was archived by the owner on Apr 25, 2026. It is now read-only.
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
dec9647
Add schedule synthesis with SHT
shengjiex98 Mar 10, 2023
a837ba7
Merge branch 'work-conserve-schedule' into sampler-weakly-hard
shengjiex98 Mar 15, 2023
8934b61
Merge branch 'main' into sampler-weakly-hard
shengjiex98 Mar 15, 2023
849b055
Add verification for SHT schedule synthesis
shengjiex98 Mar 16, 2023
d142b49
Add export for new functions
shengjiex98 Mar 16, 2023
a15f309
Merge branch 'work-conserve-schedule' into sampler-weakly-hard
shengjiex98 Mar 19, 2023
835e028
H is required
shengjiex98 Mar 19, 2023
8a94d2f
Add `fullresults` options for constraint synthesis
shengjiex98 Mar 19, 2023
68a7dbb
Collections now have the correct type for items
shengjiex98 Mar 19, 2023
a49722e
Merge branch 'work-conserve-schedule' into sampler-weakly-hard
shengjiex98 Mar 22, 2023
8269d09
Bayes factor is now calculate with uniform prior
shengjiex98 Apr 4, 2023
427a7a0
Revert "Bayes factor is now calculate with uniform prior"
shengjiex98 Apr 5, 2023
112b005
Fix bound error when bounded_runs_iter() returns early
shengjiex98 Apr 11, 2023
f73d2f0
Minor changes
shengjiex98 Jun 29, 2023
8099240
Only use abstract types for function argument
shengjiex98 Jun 29, 2023
37a01f9
Merge branch 'main' into sampler-weakly-hard
shengjiex98 Jun 29, 2023
21ed0c9
Update function docstrings and tests.
shengjiex98 Jun 30, 2023
a802338
Should pass all tests now!
shengjiex98 Jul 4, 2023
3a81e3d
Ignoring all manifest files
shengjiex98 Jul 5, 2023
6d76cd2
Change `bounded-runs-iter()` to use H instead of t
shengjiex98 Jul 5, 2023
38a1afa
Fix typo in array slicing
shengjiex98 Jul 5, 2023
0a092da
Change all references to `bounded_runs_iter()`
shengjiex98 Jul 5, 2023
c2a20ef
Two more changes
shengjiex98 Jul 5, 2023
e1d144c
Return types should be Int64 instead of Integer
shengjiex98 Jul 5, 2023
3966531
Last commit was almost correct :/
shengjiex98 Jul 5, 2023
1356fee
Update documentation for new functions
shengjiex98 Jul 6, 2023
57311ba
Merge branch 'h-over-t-bounded-runs-iter' into period_boosting
shengjiex98 Jul 6, 2023
269596c
Use Real for `bounded_runs_iter()`
shengjiex98 Jul 6, 2023
30e2d05
Constraint synthesis returns deviations
shengjiex98 Jul 6, 2023
4cae901
Nominal trajectory can now be specified for constraint synthesis
shengjiex98 Jul 6, 2023
c5e2c9d
Issue recreated
shengjiex98 Jul 6, 2023
fc93e24
Minor updates to error reproduction
shengjiex98 Sep 26, 2023
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
/Manifest.toml
Manifest.toml
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,12 @@ zs = zero_skip_next(sys, K, max_misses)

To run the Bounded Runs Iteration algorithm for this automaton, first create
the initial set, then run the algorithm for a given per-iteration run
length `n` and number of iterations `t`:
length `n` to produce the reachable set of length `H`. The number of iterations
is the smallest integer `t` such that `n`×`t`≥`H`.

```julia
augbounds = augment(automaton, bounds)
all_bounds = bounded_runs_iter(automaton, augbounds, n, t)
all_bounds = bounded_runs_iter(automaton, augbounds, n, H)
```

The deviation at each time step can then be computed thusly:
Expand Down
5 changes: 3 additions & 2 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@ zs = zero_skip_next(sys, K, max_misses)

To run the Bounded Runs Iteration algorithm for this automaton, first create
the initial set, then run the algorithm for a given per-iteration run
length `n` and number of iterations `t`:
length `n` to produce the reachable set of length `H`. The number of iterations
is the smallest integer `t` such that `n`×`t`≥`H`.

```julia
augbounds = augment(automaton, bounds)
all_bounds = bounded_runs_iter(automaton, augbounds, n, t)
all_bounds = bounded_runs_iter(automaton, augbounds, n, H)
```

The deviation at each time step can then be computed thusly:
Expand Down
22 changes: 19 additions & 3 deletions docs/src/schedule_synthesis.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,30 @@
# Schedule Synthesis

The main functionality of this section is divided into two functions
The main functionality of this section is divided into three functions
1. [`synthesize_constraints`](@ref): given the dynamics and safety margin of **one**
control task, find all weakly-hard constraints (up to a maximum window size `maxwindow`)
with which the system behaves safely, and
2. [`schedule_xghtc`](@ref): given the lists of safe weakly-hard constraints for **all**
with which the system behaves safely,
2. [`estimate_constraints`](@ref): similar to [`synthesize_constraints`](@ref), but uses
the statistical method [`estimate_deviation`](@ref) to find the deviation upper bound of
each weakly-hard constraints.
3. [`schedule_xghtc`](@ref): given the lists of safe weakly-hard constraints for **all**
control tasks, synthesizes a schedule so that they all behave safely (if such schedules
exist).

```@docs
synthesize_constraints
schedule_xghtc
estimate_constraints
```

## Utility Functions

A few utility functions are exported as well. These support the implementation
of the above functions, and are potentially useful to their callers as well.

```@docs
schedule_to_sequence
verify_schedule
devub
devest
```
3 changes: 1 addition & 2 deletions notebooks/control_timing_safety.jl
Original file line number Diff line number Diff line change
Expand Up @@ -370,11 +370,10 @@ This section illustrates the Bounded Runs Iteration algorithm, used to efficient

# ╔═╡ efc6aa00-cfdb-45fb-809b-f99c663690f6
begin
t_4 = div(time_4, n_4)
all_bounds = let
automaton = strat_map[sim_strategy_4](sysd, K, MissRow(max_miss_4))
augbounds = augment(automaton, bounds)
bounded_runs_iter(automaton, augbounds, n_4, t_4)
bounded_runs_iter(automaton, augbounds, n_4, time_4)
end

md"""
Expand Down
2 changes: 2 additions & 0 deletions src/ControlTimingSafety.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ export maximum_deviation_random, estimate_deviation
include("probablesafety.jl")

export schedule_xghtc, synthesize_constraints
export estimate_constraints, verify_schedule, schedule_to_sequence
export devub, devest
include("schedule_synthesis.jl")

end
22 changes: 12 additions & 10 deletions src/safety.jl
Original file line number Diff line number Diff line change
Expand Up @@ -135,17 +135,19 @@ function bounded_runs(a::Automaton, z_0::AbstractVecOrMat, n::Integer)
end

"""
bounded_runs_iter(a, z_0, n, t)
bounded_runs_iter(a, z_0, n, H)

Iterate [`bounded_runs`](@ref)`(a, z_0, n)` for `t` iterations, returning the reachable
set at each of the `n`×`t+1` time steps.
Iterate [`bounded_runs`](@ref)`(a, z_0, n)` multiple times, returning the reachable set at each
of the `H` time stpes. The number of iterations is the smallest integer `t` such that
`n`×`t`≥`H`.

See also [`deviation`](@ref), which can be called with the result of this function to find
the deviation from a nominal trajectory.
"""
function bounded_runs_iter(a::Automaton, z_0::AbstractVecOrMat, n::Integer, t::Integer; safety_margin::Float64=Inf)
function bounded_runs_iter(a::Automaton, z_0::AbstractVecOrMat, n::Integer, H::Integer; safety_margin::Real=Inf)
t = ceil(Int64, H / n)
# Dimensions: time, augmented state, min/max
all_bounds = Array{Float64}(undef, n*(t+1)+1, a.nz, 2)
all_bounds = Array{Float64}(undef, n*t+1, a.nz, 2)
if isa(z_0, AbstractVector)
all_bounds[1,:,:] = [z_0 z_0]
else
Expand Down Expand Up @@ -176,7 +178,7 @@ function bounded_runs_iter(a::Automaton, z_0::AbstractVecOrMat, n::Integer, t::I

# Dimensions: initial location, final location, time, augmented state, min/max
new_bounds = Array{Float64}(undef, nlocations(a), nlocations(a), n+1, a.nz, 2)
for i in 1:t
for i in 2:t
# Simulate each box from previous iteration
Threads.@threads for i in a.L
new_bounds[i,:,:,:,:] = bounded_runs(A[i], bounds[i,end,:,:], n)
Expand All @@ -186,16 +188,16 @@ function bounded_runs_iter(a::Automaton, z_0::AbstractVecOrMat, n::Integer, t::I
merge_bounds!(view(bounds, i, :, :, :), view(new_bounds, :, i, :, :, :))
end
# Save the bounds
merge_bounds!(view(all_bounds, n*i+1:n*(i+1)+1, :, :), bounds)
merge_bounds!(view(all_bounds, n*(i-1)+1:n*i+1, :, :), bounds)

if isfinite(safety_margin)
d = deviation(a, z_0, all_bounds[n*i+2:n*(i+1)+1,:,:], nominal_trajectory=nom[:,:,n*i+2:n*(i+1)+1])
d = deviation(a, z_0, all_bounds[n*(i-1)+2:n*i+1,:,:], nominal_trajectory=nom[:,:,n*(i-1)+2:n*i+1])
if maximum(d) > safety_margin
return all_bounds[1:n*(i+1)+1,:,:]
return all_bounds[1:n*i+1,:,:]
end
end
end
all_bounds
all_bounds[1:H+1,:,:]
end

"""
Expand Down
Loading