11 changed files with 125 additions and 2 deletions
-
30examples/schedulers/01-schedulers.py
-
5lib/stormpy/__init__.py
-
4lib/stormpy/examples/files.py
-
2src/core/modelchecking.cpp
-
2src/core/result.cpp
-
4src/mod_storage.cpp
-
17src/storage/distribution.cpp
-
6src/storage/distribution.h
-
37src/storage/scheduler.cpp
-
7src/storage/scheduler.h
-
13tests/core/test_modelchecking.py
@ -0,0 +1,30 @@ |
|||
import stormpy |
|||
import stormpy.core |
|||
|
|||
import stormpy.examples |
|||
import stormpy.examples.files |
|||
|
|||
|
|||
def example_schedulers_01(): |
|||
path = stormpy.examples.files.prism_mdp_coin_2_2 |
|||
|
|||
formula_str = "Pmin=? [F \"finished\" & \"all_coins_equal_1\"]" |
|||
|
|||
program = stormpy.parse_prism_program(path) |
|||
formulas = stormpy.parse_properties_for_prism_program(formula_str, program) |
|||
model = stormpy.build_model(program, formulas) |
|||
initial_state = model.initial_states[0] |
|||
assert initial_state == 0 |
|||
result = stormpy.model_checking(model, formulas[0], extract_scheduler = True) |
|||
assert result.has_scheduler |
|||
print(result.scheduler) |
|||
assert result.scheduler.memoryless |
|||
assert result.scheduler.deterministic |
|||
|
|||
for i in range(0,model.nr_states): |
|||
print("In state {} choose action {}".format(i,result.scheduler.get_choice(i).get_deterministic_choice())) |
|||
|
|||
|
|||
|
|||
if __name__ == '__main__': |
|||
example_schedulers_01() |
@ -0,0 +1,17 @@ |
|||
#include "distribution.h"
|
|||
#include "src/helpers.h"
|
|||
|
|||
#include "storm/storage/Distribution.h"
|
|||
|
|||
template<typename ValueType> |
|||
void define_distribution(py::module& m, std::string vt_suffix) { |
|||
using Distrib = storm::storage::Distribution<ValueType, uint32_t>; |
|||
|
|||
std::string distributionClassName = std::string("Distribution") + vt_suffix; |
|||
py::class_<Distrib> distribution(m, distributionClassName.c_str(), "Finite Support Distribution"); |
|||
distribution |
|||
.def("__str__", &streamToString<Distrib>); |
|||
} |
|||
|
|||
|
|||
template void define_distribution<double>(py::module&, std::string vt_suffix); |
@ -0,0 +1,6 @@ |
|||
#pragma once |
|||
|
|||
#include "common.h" |
|||
|
|||
template<typename ValueType> |
|||
void define_distribution(py::module& m, std::string vt_suffix); |
@ -0,0 +1,37 @@ |
|||
#include "scheduler.h"
|
|||
#include "src/helpers.h"
|
|||
|
|||
#include "storm/storage/Scheduler.h"
|
|||
|
|||
template<typename ValueType> |
|||
void define_scheduler(py::module& m, std::string vt_suffix) { |
|||
using Scheduler = storm::storage::Scheduler<ValueType>; |
|||
using SchedulerChoice = storm::storage::SchedulerChoice<ValueType>; |
|||
|
|||
std::string schedulerClassName = std::string("Scheduler") + vt_suffix; |
|||
py::class_<Scheduler, std::shared_ptr<storm::storage::Scheduler<ValueType>>> scheduler(m, schedulerClassName.c_str(), "A Finite Memory Scheduler"); |
|||
scheduler |
|||
.def("__str__", [](Scheduler const& s) { |
|||
std::stringstream str; |
|||
s.printToStream(str); |
|||
return str.str(); |
|||
}) |
|||
.def_property_readonly("memoryless", &Scheduler::isMemorylessScheduler, "Is the scheduler memoryless?") |
|||
.def_property_readonly("memory_size", &Scheduler::getNumberOfMemoryStates, "How much memory does the scheduler take?") |
|||
.def_property_readonly("deterministic", &Scheduler::isDeterministicScheduler, "Is the scheduler deterministic?") |
|||
.def("get_choice", &Scheduler::getChoice, py::arg("state_index"), py::arg("memory_index") = 0) |
|||
; |
|||
|
|||
std::string schedulerChoiceClassName = std::string("SchedulerChoice") + vt_suffix; |
|||
py::class_<SchedulerChoice> schedulerChoice(m, schedulerChoiceClassName.c_str(), "A choice of a finite memory scheduler"); |
|||
schedulerChoice |
|||
.def_property_readonly("defined", &SchedulerChoice::isDefined, "Is the choice defined by the scheduler?") |
|||
.def_property_readonly("deterministic", &SchedulerChoice::isDeterministic, "Is the choice deterministic (given by a Dirac distribution)?") |
|||
.def("get_deterministic_choice", &SchedulerChoice::getDeterministicChoice, "Get the deterministic choice") |
|||
.def("get_choice", &SchedulerChoice::getChoiceAsDistribution, "Get the distribution over the actions") |
|||
.def("__str__", &streamToString<SchedulerChoice>); |
|||
|
|||
} |
|||
|
|||
|
|||
template void define_scheduler<double>(py::module& m, std::string vt_suffix); |
@ -0,0 +1,7 @@ |
|||
#pragma once |
|||
|
|||
#include "common.h" |
|||
|
|||
|
|||
template<typename ValueType> |
|||
void define_scheduler(py::module& m, std::string vt_suffix); |
Write
Preview
Loading…
Cancel
Save
Reference in new issue