Skip to content

Commit 6ada936

Browse files
authored
Added support for building Interval POMDPs from DRN (#219)
2 parents 2272f8c + 379797e commit 6ada936

File tree

4 files changed

+50
-0
lines changed

4 files changed

+50
-0
lines changed

lib/stormpy/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,8 @@ def build_interval_model_from_drn(file, options=DirectEncodingParserOptions()):
228228
assert intermediate.supports_uncertainty
229229
if intermediate.model_type == ModelType.MDP:
230230
return intermediate._as_sparse_imdp()
231+
elif intermediate.model_type == ModelType.POMDP:
232+
return intermediate._as_sparse_ipomdp()
231233
else:
232234
raise StormError("Not supported interval model constructed")
233235

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
@type: POMDP
2+
@parameters
3+
4+
@reward_models
5+
6+
@nr_states
7+
4
8+
@nr_choices
9+
5
10+
@model
11+
state 0 {0} init
12+
action 0
13+
1 : [0.2, 0.7]
14+
2 : [0.3, 0.8]
15+
action 1
16+
0 : [0.4, 0.9]
17+
3 : [0.5, 0.8]
18+
state 1 {1} target
19+
action 0
20+
1 : [1, 1]
21+
state 2 {2}
22+
action 0
23+
2 : [1, 1]
24+
state 3 {2}
25+
action 0
26+
0 : [0.5, 1]
27+
3 : [0.1, 0.5]

src/storage/model.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,9 @@ void define_model(py::module& m) {
160160
.def("_as_sparse_ppomdp", [](ModelBase &modelbase) {
161161
return modelbase.as<SparsePomdp<RationalFunction>>();
162162
}, "Get model as sparse pPOMDP")
163+
.def("_as_sparse_ipomdp", [](ModelBase &modelbase) {
164+
return modelbase.as<SparsePomdp<storm::Interval>>();
165+
}, "Get model as sparse interval POMDP")
163166
.def("_as_sparse_ctmc", [](ModelBase &modelbase) {
164167
return modelbase.as<SparseCtmc<double>>();
165168
}, "Get model as sparse CTMC")

tests/storage/test_model.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,3 +272,21 @@ def test_build_ma(self):
272272
formulas = stormpy.parse_properties_for_prism_program("P=? [ F<=2 s=2 ]", program)
273273
with pytest.raises(Exception):
274274
model = stormpy.build_symbolic_model(program, formulas)
275+
276+
def test_build_ipomdp(self):
277+
model = stormpy.build_interval_model_from_drn(get_example_path("ipomdp", "tiny-01.drn"))
278+
assert model.nr_states == 4
279+
assert model.nr_choices == 5
280+
assert model.nr_transitions == 8
281+
assert model.nr_observations == 3
282+
283+
for transition in model.transition_matrix.row_iter(0, 0):
284+
if transition.column == 1:
285+
assert transition.value().lower() == 0.2
286+
assert transition.value().upper() == 0.7
287+
elif transition.column == 2:
288+
assert transition.value().lower() == 0.3
289+
assert transition.value().upper() == 0.8
290+
291+
assert model.model_type == stormpy.ModelType.POMDP
292+
assert type(model) is stormpy.SparseIntervalPomdp

0 commit comments

Comments
 (0)