Skip to content

Commit 2e18a76

Browse files
committed
Add stochastic switched system abstraction process + example
1 parent 890e6be commit 2e18a76

8 files changed

+569
-289
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
using LinearAlgebra, LazySets
2+
using IntervalMDP, IntervalSySCoRe
3+
4+
5+
function linear_stochastic_switched_sys(time_horizon)
6+
A1 = [
7+
0.1 0.9;
8+
0.8 0.2
9+
]
10+
B1 = [
11+
0.0;
12+
0.0
13+
][:, :]
14+
w1_stddev = [0.3, 0.2]
15+
mode1 = AffineAdditiveNoiseDynamics(A1, B1, AdditiveDiagonalGaussianNoise(w1_stddev))
16+
17+
A2 = [
18+
0.8 0.2;
19+
0.1 0.9
20+
]
21+
B2 = [
22+
0.0;
23+
0.0
24+
][:, :]
25+
w2_stddev = [0.2, 0.1]
26+
mode2 = AffineAdditiveNoiseDynamics(A2, B2, AdditiveDiagonalGaussianNoise(w2_stddev))
27+
28+
dyn = StochasticSwitchedDynamics([mode1, mode2], [0.7, 0.3])
29+
30+
initial_region = EmptySet(2)
31+
32+
sys = System(dyn, initial_region)
33+
34+
reach_region = Hyperrectangle(; low=[-1.0, -1.0], high=[0.0, 1.0])
35+
avoid_region = Hyperrectangle(; low=[1.0, 0.0], high=[2.0, 1.0])
36+
prop = FiniteTimeRegionReachAvoid(reach_region, avoid_region, time_horizon)
37+
spec = Specification(prop, Pessimistic, Maximize)
38+
39+
return sys, spec
40+
end
41+
42+
function linear_stochastic_switched_direct(time_horizon=10; sparse=false, state_split=(40, 40))
43+
sys, spec = linear_stochastic_switched_sys(time_horizon)
44+
45+
X = Hyperrectangle(; low=[-2.0, -2.0], high=[2.0, 2.0])
46+
state_abs = StateUniformGridSplit(X, state_split)
47+
48+
input_abs = InputDiscrete([Singleton([0.0])])
49+
50+
if sparse
51+
target_model = SparseOrthogonalIMDPTarget()
52+
else
53+
target_model = OrthogonalIMDPTarget()
54+
end
55+
56+
prob = AbstractionProblem(sys, spec)
57+
mdp, abstract_spec = abstraction(prob, state_abs, input_abs, target_model)
58+
59+
upper_bound_spec = Specification(system_property(spec), !satisfaction_mode(spec))
60+
upper_bound_spec = IntervalSySCoRe.convert_specification(upper_bound_spec, state_abs, target_model)
61+
62+
return mdp, abstract_spec, upper_bound_spec
63+
end
64+
65+
function linear_stochastic_switched_mixture(time_horizon=10; sparse=false, state_split=(40, 40))
66+
sys, spec = linear_stochastic_switched_sys(time_horizon)
67+
68+
X = Hyperrectangle(; low=[-2.0, -2.0], high=[2.0, 2.0])
69+
state_abs = StateUniformGridSplit(X, state_split)
70+
71+
input_abs = InputDiscrete([Singleton([0.0])])
72+
73+
if sparse
74+
target_model = SparseMixtureIMDPTarget()
75+
else
76+
target_model = MixtureIMDPTarget()
77+
end
78+
79+
prob = AbstractionProblem(sys, spec)
80+
mdp, abstract_spec = abstraction(prob, state_abs, input_abs, target_model)
81+
82+
upper_bound_spec = Specification(system_property(spec), !satisfaction_mode(spec))
83+
upper_bound_spec = IntervalSySCoRe.convert_specification(upper_bound_spec, state_abs, target_model)
84+
85+
return mdp, abstract_spec, upper_bound_spec
86+
end
87+
88+
function main()
89+
@time "abstraction" mdp, spec, upper_bound_spec = linear_stochastic_switched_mixture(; state_split=(40, 40))
90+
prob = Problem(mdp, spec)
91+
92+
@time "control synthesis" strategy, V_lower, k, res = control_synthesis(prob)
93+
94+
upper_bound_prob = Problem(mdp, upper_bound_spec, strategy)
95+
@time "upper bound" V_upper, _, _ = value_iteration(upper_bound_prob)
96+
97+
# Remove the first state from each axis (the avoid state, whose value is always 0).
98+
V_lower = V_lower[(2:d for d in size(V_lower))...]
99+
V_upper = V_upper[(2:d for d in size(V_upper))...]
100+
101+
return V_lower, V_upper
102+
end

src/IntervalSySCoRe.jl

+3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ include("dynamics/additive_noise.jl")
2424
include("dynamics/AffineAdditiveNoiseDynamics.jl")
2525
include("dynamics/NonlinearAdditiveNoiseDynamics.jl")
2626
include("dynamics/UncertainPWAAdditiveNoiseDynamics.jl")
27+
include("dynamics/StochasticSwitchedDynamics.jl")
2728

2829
include("systems.jl")
2930
include("specification.jl")
@@ -33,6 +34,8 @@ include("abstractions/input_abstraction.jl")
3334
include("abstractions/state_abstraction.jl")
3435
include("abstractions/target.jl")
3536

37+
include("abstractions/abstraction.jl")
3638
include("abstractions/additive_noise.jl")
39+
include("abstractions/mixture.jl")
3740

3841
end

0 commit comments

Comments
 (0)