1
+ using Revise, Test
2
+ using LinearAlgebra, LazySets
3
+ using IntervalMDP, IntervalMDPAbstractions
4
+
5
+ # System definition
6
+
7
+ # Action 1
8
+ gp_region1_action1 = AbstractedGaussianProcessRegion (
9
+ Hyperrectangle (low = [- 0.5 , - 0.5 ], high = [0.0 , 0.0 ]),
10
+ [- 0.5 , 0.5 ],
11
+ [0.0 , 0.6 ],
12
+ [0.1 , 0.3 ],
13
+ [0.2 , 0.4 ],
14
+ )
15
+ gp_region2_action1 = AbstractedGaussianProcessRegion (
16
+ Hyperrectangle (low = [0.0 , - 0.5 ], high = [0.5 , 0.0 ]),
17
+ [- 0.5 , 0.5 ],
18
+ [0.0 , 0.6 ],
19
+ [0.1 , 0.3 ],
20
+ [0.2 , 0.4 ],
21
+ )
22
+ gp_region3_action1 = AbstractedGaussianProcessRegion (
23
+ Hyperrectangle (low = [- 0.5 , 0.0 ], high = [0.0 , 0.5 ]),
24
+ [- 0.5 , 0.5 ],
25
+ [0.0 , 0.6 ],
26
+ [0.1 , 0.3 ],
27
+ [0.2 , 0.4 ],
28
+ )
29
+ gp_region4_action1 = AbstractedGaussianProcessRegion (
30
+ Hyperrectangle (low = [0.0 , 0.0 ], high = [0.5 , 0.5 ]),
31
+ [- 0.5 , 0.5 ],
32
+ [0.0 , 0.6 ],
33
+ [0.1 , 0.3 ],
34
+ [0.2 , 0.4 ],
35
+ )
36
+
37
+ gp_action1 = [gp_region1_action1, gp_region2_action1, gp_region3_action1, gp_region4_action1]
38
+
39
+ # Action 2
40
+ gp_region1_action2 = AbstractedGaussianProcessRegion (
41
+ Hyperrectangle (low = [- 0.5 , - 0.5 ], high = [0.0 , 0.0 ]),
42
+ [- 0.5 , 0.5 ],
43
+ [0.0 , 0.6 ],
44
+ [0.1 , 0.3 ],
45
+ [0.2 , 0.4 ],
46
+ )
47
+ gp_region2_action2 = AbstractedGaussianProcessRegion (
48
+ Hyperrectangle (low = [0.0 , - 0.5 ], high = [0.5 , 0.0 ]),
49
+ [- 0.5 , 0.5 ],
50
+ [0.0 , 0.6 ],
51
+ [0.1 , 0.3 ],
52
+ [0.2 , 0.4 ],
53
+ )
54
+ gp_region3_action2 = AbstractedGaussianProcessRegion (
55
+ Hyperrectangle (low = [- 0.5 , 0.0 ], high = [0.0 , 0.5 ]),
56
+ [- 0.5 , 0.5 ],
57
+ [0.0 , 0.6 ],
58
+ [0.1 , 0.3 ],
59
+ [0.2 , 0.4 ],
60
+ )
61
+ gp_region4_action2 = AbstractedGaussianProcessRegion (
62
+ Hyperrectangle (low = [0.0 , 0.0 ], high = [0.5 , 0.5 ]),
63
+ [- 0.5 , 0.5 ],
64
+ [0.0 , 0.6 ],
65
+ [0.1 , 0.3 ],
66
+ [0.2 , 0.4 ],
67
+ )
68
+
69
+ gp_action2 = [gp_region1_action2, gp_region2_action2, gp_region3_action2, gp_region4_action2]
70
+
71
+ # Noise
72
+ w_variance = [0.2 , 0.2 ]
73
+ w_stddev = sqrt .(w_variance)
74
+ w = AdditiveDiagonalGaussianNoise (w_stddev)
75
+
76
+ dyn = AbstractedGaussianProcess ([gp_action1, gp_action2])
77
+ initial_region = Hyperrectangle (low = [- 0.1 , - 0.1 ], high = [0.1 , 0.1 ])
78
+ sys = System (dyn, initial_region)
79
+
80
+ horizon = 10
81
+ avoid_region = EmptySet (2 )
82
+ prop = FiniteTimeRegionSafety (avoid_region, horizon)
83
+ spec = Specification (prop, Pessimistic, Maximize)
84
+
85
+ prob = AbstractionProblem (sys, spec)
86
+
87
+ X = Hyperrectangle (; low = [- 0.5 , - 0.5 ], high = [0.5 , 0.5 ])
88
+ state_abs = StateUniformGridSplit (X, (2 , 2 ))
89
+ input_abs = InputDiscrete ([1 , 2 ])
90
+
91
+
92
+ @testset " direct vs decoupled" begin
93
+ # Decoupled
94
+ target_model = OrthogonalIMDPTarget ()
95
+ mdp_decoupled, abstract_spec_decoupled = abstraction (prob, state_abs, input_abs, target_model)
96
+
97
+ @test num_states (mdp_decoupled) == 3 * 3
98
+ @test length (stateptr (mdp_decoupled)) == 5 # 4 non-sink states
99
+ @test stateptr (mdp_decoupled)[end ] == 4 * 2 + 1 # 4 non-sink states, 2 control actions
100
+
101
+ prob_decoupled = Problem (mdp_decoupled, abstract_spec_decoupled)
102
+
103
+ V_decoupled, k, res = value_iteration (prob_decoupled)
104
+ @test k == 10
105
+
106
+ # Direct
107
+ target_model = IMDPTarget ()
108
+ mdp_direct, abstract_spec_direct = abstraction (prob, state_abs, input_abs, target_model)
109
+
110
+ @test num_states (mdp_direct) == 2 * 2 + 1
111
+ @test length (stateptr (mdp_direct)) == 5 # 4 non-sink states
112
+ @test stateptr (mdp_direct)[end ] == 4 * 2 + 1 # 4 non-sink states, 2 control actions
113
+
114
+ prob_direct = Problem (mdp_direct, abstract_spec_direct)
115
+
116
+ V_direct, k, res = value_iteration (prob_direct)
117
+ @test k == 10
118
+
119
+ @test all (V_decoupled[1 : end - 1 , 1 : end - 1 ] .≥ reshape (V_direct[1 : end - 1 ], 2 , 2 ))
120
+ end
0 commit comments