Sebastian Junges
5 years ago
8 changed files with 153 additions and 3 deletions
-
45examples/pomdp/01-pomdps.py
-
39lib/stormpy/pomdp/__init__.py
-
3src/mod_pomdp.cpp
-
27src/pomdp/memory.cpp
-
4src/pomdp/memory.h
-
35src/pomdp/transformations.cpp
-
1src/pomdp/transformations.h
-
2src/storage/expressions.cpp
@ -0,0 +1,45 @@ |
|||
import stormpy |
|||
import stormpy.core |
|||
import stormpy.info |
|||
|
|||
import pycarl |
|||
import pycarl.core |
|||
|
|||
import stormpy.examples |
|||
import stormpy.examples.files |
|||
|
|||
import stormpy.pomdp |
|||
|
|||
import stormpy._config as config |
|||
|
|||
|
|||
def example_parametric_models_02(): |
|||
# Check support for parameters |
|||
if not config.storm_with_pars: |
|||
print("Support parameters is missing. Try building storm-pars.") |
|||
return |
|||
|
|||
import stormpy.pars |
|||
from pycarl.formula import FormulaType, Relation |
|||
if stormpy.info.storm_ratfunc_use_cln(): |
|||
import pycarl.cln.formula |
|||
else: |
|||
import pycarl.gmp.formula |
|||
|
|||
path = stormpy.examples.files.prism_pomdp_maze |
|||
prism_program = stormpy.parse_prism_program(path) |
|||
|
|||
formula_str = "P=? [\"goal\"]" |
|||
properties = stormpy.parse_properties_for_prism_program(formula_str, prism_program) |
|||
pomdp = stormpy.build_model(prism_program, properties) |
|||
pomdp = stormpy.pomdp.make_canonic(pomdp) |
|||
pomdp = stormpy.pomdp.make_simple(pomdp) |
|||
memory_builder = stormpy.pomdp.PomdpMemoryBuilder() |
|||
memory = memory_builder.build(stormpy.pomdp.PomdpMemoryPattern.selective_counter, 2) |
|||
pomdp = stormpy.pomdp.unfold_memory(pomdp, memory) |
|||
pmc = stormpy.pomdp.apply_unknown_fsc(pomdp, stormpy.pomdp.PomdpFscApplicationMode.simple_linear) |
|||
|
|||
stormpy.export_parametric_to_drn(pmc, "test.out") |
|||
|
|||
if __name__ == '__main__': |
|||
example_parametric_models_02() |
@ -0,0 +1,27 @@ |
|||
#include "memory.h"
|
|||
#include "src/helpers.h"
|
|||
#include <storm-pomdp/storage/PomdpMemory.h>
|
|||
|
|||
|
|||
void define_memory(py::module& m) { |
|||
py::class_<storm::storage::PomdpMemory> memory(m, "PomdpMemory", "Memory for POMDP policies"); |
|||
memory.def_property_readonly("nr_states",&storm::storage::PomdpMemory::getNumberOfStates, "How many states does the memory structure have"); |
|||
|
|||
// Trivial, FixedCounter, SelectiveCounter, FixedRing, SelectiveRing, SettableBits, Full
|
|||
py::enum_<storm::storage::PomdpMemoryPattern>(m, "PomdpMemoryPattern", "Memory pattern for POMDP memory") |
|||
.value("trivial", storm::storage::PomdpMemoryPattern::Trivial) |
|||
.value("fixed_counter", storm::storage::PomdpMemoryPattern::FixedCounter) |
|||
.value("selective_counter", storm::storage::PomdpMemoryPattern::SelectiveCounter) |
|||
.value("fixed_ring", storm::storage::PomdpMemoryPattern::FixedRing) |
|||
.value("selective_ring", storm::storage::PomdpMemoryPattern::SelectiveRing) |
|||
.value("settable_bits", storm::storage::PomdpMemoryPattern::SettableBits) |
|||
.value("full", storm::storage::PomdpMemoryPattern::Full) |
|||
; |
|||
|
|||
|
|||
py::class_<storm::storage::PomdpMemoryBuilder> memorybuilder(m, "PomdpMemoryBuilder", "MemoryBuilder for POMDP policies"); |
|||
memorybuilder.def(py::init<>()); |
|||
memorybuilder.def("build", &storm::storage::PomdpMemoryBuilder::build, py::arg("pattern"), py::arg("nr_states")); |
|||
|
|||
|
|||
} |
@ -0,0 +1,4 @@ |
|||
#pragma once |
|||
#include "common.h" |
|||
|
|||
void define_memory(py::module& m); |