@@ -91,8 +91,8 @@ function abstraction(
91
91
92
92
# State pointer
93
93
stateptr = Int32[
94
- [1 , 2 ]
95
- (1 : numregions (state_abstraction)) .* numinputs (input_abstraction) .+ 2
94
+ [1 ]
95
+ (1 : numregions (state_abstraction)) .* numinputs (input_abstraction) .+ 1
96
96
]
97
97
98
98
# Transition probabilities
@@ -108,7 +108,7 @@ function abstraction(
108
108
initial_states = Int32[]
109
109
for (i, source_region) in enumerate (regions (state_abstraction))
110
110
if ! isdisjoint (initial (sys), source_region)
111
- push! (initial_states, i + 1 )
111
+ push! (initial_states, i)
112
112
end
113
113
end
114
114
@@ -121,15 +121,17 @@ function abstraction(
121
121
end
122
122
123
123
function initprob (:: IMDPTarget , nregions, ninputs)
124
- prob_lower = [zeros (Float64, nregions) for _ = 1 : ((nregions- 1 )* ninputs+ 1 )]
125
- prob_upper = [zeros (Float64, nregions) for _ = 1 : ((nregions- 1 )* ninputs+ 1 )]
124
+ nchoices = nregions * ninputs
125
+ prob_lower = zeros (Float64, nregions + 1 , nchoices)
126
+ prob_upper = zeros (Float64, nregions + 1 , nchoices)
126
127
127
128
return prob_lower, prob_upper
128
129
end
129
130
130
131
function initprob (:: SparseIMDPTarget , nregions, ninputs)
131
- prob_lower = [spzeros (Float64, nregions) for _ = 1 : ((nregions- 1 )* ninputs+ 1 )]
132
- prob_upper = [spzeros (Float64, nregions) for _ = 1 : ((nregions- 1 )* ninputs+ 1 )]
132
+ nchoices = nregions * ninputs
133
+ prob_lower = spzeros (Float64, nregions + 1 , nchoices)
134
+ prob_upper = spzeros (Float64, nregions + 1 , nchoices)
133
135
134
136
return prob_lower, prob_upper
135
137
end
@@ -142,13 +144,13 @@ function convert_property(
142
144
prop = system_property (spec)
143
145
144
146
reach_states = Int32[]
145
- avoid_states = Int32[1 ] # Absorbing state
147
+ avoid_states = Int32[numregions (state_abstraction) ] # Absorbing state
146
148
147
149
for (i, source_region) in enumerate (regions (state_abstraction))
148
150
if ispessimistic (spec) && source_region ⊆ reach (prop)
149
- push! (reach_states, i + 1 )
151
+ push! (reach_states, i)
150
152
elseif isoptimistic (spec) && ! iszeromeasure (reach (prop), source_region)
151
- push! (reach_states, i + 1 )
153
+ push! (reach_states, i)
152
154
end
153
155
end
154
156
@@ -163,17 +165,17 @@ function convert_property(
163
165
prop = system_property (spec)
164
166
165
167
reach_states = Int32[]
166
- avoid_states = Int32[1 ] # Absorbing state
168
+ avoid_states = Int32[numregions (state_abstraction) ] # Absorbing state
167
169
168
170
for (i, source_region) in enumerate (regions (state_abstraction))
169
171
if ispessimistic (spec) && ! iszeromeasure (avoid (prop), source_region)
170
- push! (avoid_states, i + 1 )
172
+ push! (avoid_states, i)
171
173
elseif isoptimistic (spec) && source_region ⊆ avoid (prop)
172
- push! (avoid_states, i + 1 )
174
+ push! (avoid_states, i)
173
175
elseif ispessimistic (spec) && source_region ⊆ reach (prop)
174
- push! (reach_states, i + 1 )
176
+ push! (reach_states, i)
175
177
elseif isoptimistic (spec) && ! iszeromeasure (reach (prop), source_region)
176
- push! (reach_states, i + 1 )
178
+ push! (reach_states, i)
177
179
end
178
180
end
179
181
@@ -187,13 +189,13 @@ function convert_property(
187
189
)
188
190
prop = system_property (spec)
189
191
190
- avoid_states = Int32[1 ] # Absorbing state
192
+ avoid_states = Int32[numregions (state_abstraction) ] # Absorbing state
191
193
192
194
for (i, source_region) in enumerate (regions (state_abstraction))
193
195
if ispessimistic (spec) && ! iszeromeasure (avoid (prop), source_region)
194
- push! (avoid_states, i + 1 )
196
+ push! (avoid_states, i)
195
197
elseif isoptimistic (spec) && source_region ⊆ avoid (prop)
196
- push! (avoid_states, i + 1 )
198
+ push! (avoid_states, i)
197
199
end
198
200
end
199
201
@@ -220,14 +222,10 @@ function abstraction(
220
222
221
223
# State pointer
222
224
stateptr = Int32[1 ]
223
- sizehint! (stateptr, prod (splits (state_abstraction) . + 1 ) )
225
+ sizehint! (stateptr, prod (splits (state_abstraction)) + 1 )
224
226
225
- for I in CartesianIndices (splits (state_abstraction) .+ 1 )
226
- if any (Tuple (I) .== 1 )
227
- push! (stateptr, stateptr[end ] + 1 )
228
- else
229
- push! (stateptr, stateptr[end ] + numinputs (input_abstraction))
230
- end
227
+ for I in CartesianIndices (splits (state_abstraction))
228
+ push! (stateptr, stateptr[end ] + numinputs (input_abstraction))
231
229
end
232
230
233
231
interval_prob = transition_prob (
@@ -239,11 +237,11 @@ function abstraction(
239
237
)
240
238
241
239
# Initial states
242
- initial_states = NTuple {dimstate (sys),Int32 }[]
240
+ initial_states = CartesianIndex {dimstate (sys)}[]
243
241
for (I, source_region) in
244
242
zip (CartesianIndices (splits (state_abstraction)), regions (state_abstraction))
245
243
if ! isdisjoint (initial (sys), source_region)
246
- push! (initial_states, Tuple (I) .+ 1 )
244
+ push! (initial_states, I )
247
245
end
248
246
end
249
247
@@ -259,9 +257,7 @@ function initprob(::OrthogonalIMDPTarget, state_abstraction::StateUniformGridSpl
259
257
prob_lower = Matrix{Float64}[]
260
258
prob_upper = Matrix{Float64}[]
261
259
262
- # One action for non-absorbing states is already included in the first term.
263
- nchoices =
264
- prod (splits (state_abstraction) .+ 1 ) + numregions (state_abstraction) * (ninputs - 1 )
260
+ nchoices = numregions (state_abstraction) * ninputs
265
261
266
262
for axisregions in splits (state_abstraction)
267
263
local_prob_lower = zeros (Float64, axisregions + 1 , nchoices)
@@ -282,9 +278,7 @@ function initprob(
282
278
prob_lower = SparseMatrixCSC{Float64, Int32}[]
283
279
prob_upper = SparseMatrixCSC{Float64, Int32}[]
284
280
285
- # One action for non-absorbing states is already included in the first term.
286
- nchoices =
287
- prod (splits (state_abstraction) .+ 1 ) + numregions (state_abstraction) * (ninputs - 1 )
281
+ nchoices = numregions (state_abstraction) * ninputs
288
282
289
283
for axisregions in splits (state_abstraction)
290
284
local_prob_lower = spzeros (Float64, Int32, axisregions + 1 , nchoices)
@@ -304,22 +298,23 @@ function convert_property(
304
298
)
305
299
prop = system_property (spec)
306
300
307
- reach_states = NTuple {dim (prop),Int32 }[]
308
- avoid_states = NTuple {dim (prop),Int32 }[]
301
+ reach_states = CartesianIndex {dim (prop)}[]
302
+ avoid_states = CartesianIndex {dim (prop)}[]
309
303
310
304
# Absorbing states
311
- for I in CartesianIndices (splits (state_abstraction) .+ 1 )
312
- if any (Tuple (I) .== 1 )
313
- push! (avoid_states, Tuple (I))
305
+ extended_states = splits (state_abstraction) .+ 1
306
+ for I in CartesianIndices (extended_states)
307
+ if any (Tuple (I) .== extended_states)
308
+ push! (avoid_states, I)
314
309
end
315
310
end
316
311
317
312
for (I, source_region) in
318
313
zip (CartesianIndices (splits (state_abstraction)), regions (state_abstraction))
319
314
if ispessimistic (spec) && source_region ⊆ reach (prop)
320
- push! (reach_states, Tuple (I) .+ 1 )
315
+ push! (reach_states, I )
321
316
elseif isoptimistic (spec) && ! iszeromeasure (reach (prop), source_region)
322
- push! (reach_states, Tuple (I) .+ 1 )
317
+ push! (reach_states, I )
323
318
end
324
319
end
325
320
@@ -333,26 +328,27 @@ function convert_property(
333
328
)
334
329
prop = system_property (spec)
335
330
336
- reach_states = NTuple {dim (prop),Int32 }[]
337
- avoid_states = NTuple {dim (prop),Int32 }[]
331
+ reach_states = CartesianIndex {dim (prop)}[]
332
+ avoid_states = CartesianIndex {dim (prop)}[]
338
333
339
334
# Absorbing states
340
- for I in CartesianIndices (splits (state_abstraction) .+ 1 )
341
- if any (Tuple (I) .== 1 )
342
- push! (avoid_states, Tuple (I))
335
+ extended_states = splits (state_abstraction) .+ 1
336
+ for I in CartesianIndices (extended_states)
337
+ if any (Tuple (I) .== extended_states)
338
+ push! (avoid_states, I)
343
339
end
344
340
end
345
341
346
342
for (I, source_region) in
347
343
zip (CartesianIndices (splits (state_abstraction)), regions (state_abstraction))
348
344
if ispessimistic (spec) && ! iszeromeasure (avoid (prop), source_region)
349
- push! (avoid_states, Tuple (I) .+ 1 )
345
+ push! (avoid_states, I )
350
346
elseif isoptimistic (spec) && source_region ⊆ avoid (prop)
351
- push! (avoid_states, Tuple (I) .+ 1 )
347
+ push! (avoid_states, I )
352
348
elseif ispessimistic (spec) && source_region ⊆ reach (prop)
353
- push! (reach_states, Tuple (I) .+ 1 )
349
+ push! (reach_states, I )
354
350
elseif isoptimistic (spec) && ! iszeromeasure (reach (prop), source_region)
355
- push! (reach_states, Tuple (I) .+ 1 )
351
+ push! (reach_states, I )
356
352
end
357
353
end
358
354
@@ -366,21 +362,22 @@ function convert_property(
366
362
)
367
363
prop = system_property (spec)
368
364
369
- avoid_states = NTuple {dim (prop),Int32 }[]
365
+ avoid_states = CartesianIndex {dim (prop)}[]
370
366
371
367
# Absorbing states
372
- for I in CartesianIndices (splits (state_abstraction) .+ 1 )
373
- if any (Tuple (I) .== 1 )
374
- push! (avoid_states, Tuple (I))
368
+ extended_states = splits (state_abstraction) .+ 1
369
+ for I in CartesianIndices (extended_states)
370
+ if any (Tuple (I) .== extended_states)
371
+ push! (avoid_states, I)
375
372
end
376
373
end
377
374
378
375
for (I, source_region) in
379
376
zip (CartesianIndices (splits (state_abstraction)), regions (state_abstraction))
380
377
if ispessimistic (spec) && ! iszeromeasure (avoid (prop), source_region)
381
- push! (avoid_states, Tuple (I) .+ 1 )
378
+ push! (avoid_states, I )
382
379
elseif isoptimistic (spec) && source_region ⊆ avoid (prop)
383
- push! (avoid_states, Tuple (I) .+ 1 )
380
+ push! (avoid_states, I )
384
381
end
385
382
end
386
383
@@ -407,14 +404,10 @@ function abstraction(
407
404
408
405
# State pointer
409
406
stateptr = Int32[1 ]
410
- sizehint! (stateptr, prod (splits (state_abstraction) . + 1 ) )
407
+ sizehint! (stateptr, prod (splits (state_abstraction)) + 1 )
411
408
412
- for I in CartesianIndices (splits (state_abstraction) .+ 1 )
413
- if any (Tuple (I) .== 1 )
414
- push! (stateptr, stateptr[end ] + 1 )
415
- else
416
- push! (stateptr, stateptr[end ] + numinputs (input_abstraction))
417
- end
409
+ for I in CartesianIndices (splits (state_abstraction))
410
+ push! (stateptr, stateptr[end ] + numinputs (input_abstraction))
418
411
end
419
412
420
413
# Transition probabilities
@@ -427,11 +420,11 @@ function abstraction(
427
420
)
428
421
429
422
# Initial states
430
- initial_states = NTuple {dimstate (sys),Int32 }[]
423
+ initial_states = CartesianIndex {dimstate (sys)}[]
431
424
for (I, source_region) in
432
425
zip (CartesianIndices (splits (state_abstraction)), regions (state_abstraction))
433
426
if ! isdisjoint (initial (sys), source_region)
434
- push! (initial_states, Tuple (I) .+ 1 )
427
+ push! (initial_states, I )
435
428
end
436
429
end
437
430
0 commit comments