#include "prism.h" #include #include #include #include "src/helpers.h" #include #include #include #include #include #include #include #include "storm/exceptions/NotSupportedException.h" #include #include "storm/exceptions/InvalidTypeException.h" #include "storm/exceptions/InvalidStateException.h" #include "storm/exceptions/InvalidAccessException.h" #include using namespace storm::prism; template void define_stateGeneration(py::module& m); void define_prism(py::module& m) { py::class_> program(m, "PrismProgram", "A Prism Program"); program.def_property_readonly("constants", &Program::getConstants, "Get Program Constants") .def_property_readonly("global_boolean_variables", &Program::getGlobalBooleanVariables, "Retrieves the global boolean variables of the program") .def_property_readonly("global_integer_variables", &Program::getGlobalIntegerVariables, "Retrieves the global integer variables of the program") .def_property_readonly("nr_modules", &storm::prism::Program::getNumberOfModules, "Number of modules") .def_property_readonly("modules", &storm::prism::Program::getModules, "Modules in the program") .def_property_readonly("model_type", &storm::prism::Program::getModelType, "Model type") .def_property_readonly("has_undefined_constants", &storm::prism::Program::hasUndefinedConstants, "Flag if program has undefined constants") .def_property_readonly("undefined_constants_are_graph_preserving", &storm::prism::Program::undefinedConstantsAreGraphPreserving, "Flag if the undefined constants do not change the graph structure") .def("substitute_constants", &Program::substituteConstants, "Substitute constants within program") .def("substitute_formulas", &Program::substituteFormulas, "Substitute formulas within program") .def("define_constants", &Program::defineUndefinedConstants, "Define constants") .def("restrict_commands", &Program::restrictCommands, "Restrict commands") .def("simplify", &Program::simplify, "Simplify") .def("used_constants",&Program::usedConstants, "Compute Used Constants") .def("get_constant", &Program::getConstant, py::arg("name")) .def_property_readonly("reward_models", &Program::getRewardModels, "The defined reward models") .def("get_module", [](Program const& prog, std::string const& name) {return prog.getModule(name);}, py::arg("module_name")) // TODO the following is a duplicate and should be deprecated. .def_property_readonly("hasUndefinedConstants", &Program::hasUndefinedConstants, "Does the program have undefined constants?") .def_property_readonly("isDeterministicModel", &Program::isDeterministicModel, "Does the program describe a deterministic model?") .def_property_readonly("expression_manager", &Program::getManager, "Get the expression manager for expressions in this program") .def("get_synchronizing_action_indices", &Program::getSynchronizingActionIndices, "Get the synchronizing action indices") .def("get_action_name", &Program::getActionName, py::arg("action_index"), "Get the action name for a given action index") .def("get_module_indices_by_action_index", &Program::getModuleIndicesByActionIndex, py::arg("action_index"), "get all modules that have a particular action index") .def_property_readonly("number_of_unlabeled_commands", &Program::getNumberOfUnlabeledCommands, "Gets the number of commands that are not labelled") .def("flatten", &Program::flattenModules, "Put program into a single module", py::arg("smt_factory")=std::shared_ptr(new storm::utility::solver::SmtSolverFactory())) .def("to_jani", [](storm::prism::Program const& program, std::vector const& properties, bool allVariablesGlobal, std::string suffix) { return program.toJani(properties, allVariablesGlobal, suffix); }, "Transform to Jani program", py::arg("properties"), py::arg("all_variables_global") = true, py::arg("suffix") = "") .def("__str__", &streamToString) .def_property_readonly("variables", &Program::getAllExpressionVariables, "Get all Expression Variables used by the program") .def("get_label_expression", [](storm::prism::Program const& program, std::string const& label){ return program.getLabelExpression(label); }, "Get the expression of the given label.", py::arg("label")) .def_property_readonly("labels", &Program::getLabels, "Get all labels in the program") ; py::class_ module(m, "PrismModule", "A module in a Prism program"); module.def_property_readonly("commands", [](Module const& module) {return module.getCommands();}, "Commands in the module") .def_property_readonly("name", &Module::getName, "Name of the module") .def_property_readonly("integer_variables", &Module::getIntegerVariables, "All integer Variables of this module") .def_property_readonly("boolean_variables", &Module::getBooleanVariables, "All boolean Variables of this module") .def("get_integer_variable", &Module::getIntegerVariable, py::arg("variable_name")) .def("get_boolean_variable", &Module::getBooleanVariable, py::arg("variable_name")) .def("get_command_indices_by_action_index", &Module::getCommandIndicesByActionIndex, py::arg("action_index")) .def("__str__", &streamToString) ; py::class_ command(m, "PrismCommand", "A command in a Prism program"); command.def_property_readonly("global_index", &Command::getGlobalIndex, "Get global index") .def_property_readonly("labeled", &Command::isLabeled, "Is the command labeled") .def_property_readonly("action_index", &Command::getActionIndex, "What is the action index of the command") .def_property_readonly("guard_expression", &Command::getGuardExpression, "Get guard expression") .def_property_readonly("is_labeled", &Command::isLabeled, "Retrieves whether the command possesses a synchronization label") .def_property_readonly("action_name", &Command::getActionName, "Retrieves the action name of this command") .def_property_readonly("updates", [](Command const& command) { return command.getUpdates(); }, "Updates in the command") .def("__str__", &streamToString) ; py::class_ update(m, "PrismUpdate", "An update in a Prism command"); update.def(py::init const&>()) .def_property_readonly("assignments", [](Update const& update) { return update.getAssignments(); }, "Assignments in the update") .def_property_readonly("probability_expression", &Update::getLikelihoodExpression, "The probability expression for this update") .def_property_readonly("global_index", &Update::getGlobalIndex, "Retrieves the global index of the update, that is, a unique index over all modules") .def("substitute", &Update::substitute, "Substitutes all identifiers in the update according to the given map") .def("simplify", &Update::simplify, "Simplifies the update in various ways (also removes identity assignments)") .def("get_assignment", &Update::getAssignment, py::arg("variable_name"), "Retrieves a reference to the assignment for the variable with the given name") .def("get_as_variable_to_expression_map", &Update::getAsVariableToExpressionMap, "Creates a mapping representation of this update") .def("__str__", &streamToString) ; py::class_ assignment(m, "PrismAssignment", "An assignment in prism"); assignment.def(py::init()) .def_property_readonly("variable", &Assignment::getVariable, "Variable that is updated") .def_property_readonly("expression", &Assignment::getExpression, "Expression for the update") .def("__str__", &streamToString) ; py::class_