From 9970aa391f05bdd4a191bdae5620262c4a3663ad Mon Sep 17 00:00:00 2001 From: Sebastian Junges Date: Tue, 2 Oct 2018 18:52:14 +0200 Subject: [PATCH] toposort bindings --- lib/stormpy/__init__.py | 15 +++++++++++++++ src/storage/matrix.cpp | 6 ++++++ 2 files changed, 21 insertions(+) diff --git a/lib/stormpy/__init__.py b/lib/stormpy/__init__.py index 72d0e3e..fa6fabe 100644 --- a/lib/stormpy/__init__.py +++ b/lib/stormpy/__init__.py @@ -397,3 +397,18 @@ def compute_prob01max_states(model, phi_states, psi_states): return core._compute_prob01states_max_rationalfunc(model, phi_states, psi_states) else: return core._compute_prob01states_max_double(model, phi_states, psi_states) + +def topological_sort(model, forward=True, initial=[]): + """ + + :param model: + :param forward: + :return: + """ + matrix = model.transition_matrix if forward else model.backward_transition_matrix + if isinstance(model, storage._SparseParametricModel): + return storage._topological_sort_rf(matrix, initial) + elif isinstance(model, storage._SparseModel): + return storage._topological_sort_double(matrix, initial) + else: + raise StormError("Unknown kind of model.") \ No newline at end of file diff --git a/src/storage/matrix.cpp b/src/storage/matrix.cpp index 19b74d2..a0d87b3 100644 --- a/src/storage/matrix.cpp +++ b/src/storage/matrix.cpp @@ -1,6 +1,8 @@ #include "matrix.h" #include "storm/storage/SparseMatrix.h" #include "storm/storage/BitVector.h" + +#include "storm/utility/graph.h" #include "src/helpers.h" template using SparseMatrix = storm::storage::SparseMatrix; @@ -81,6 +83,10 @@ void define_sparse_matrix(py::module& m) { }, py::return_value_policy::reference, py::keep_alive<1, 0>()) ; + m.def("_topological_sort_double", [](SparseMatrix& matrix, std::vector initial) { return storm::utility::graph::getTopologicalSort(matrix, initial); }, "matrix"_a, "initial"_a, "get topological sort w.r.t. a transition matrix"); + m.def("_topological_sort_rf", [](SparseMatrix& matrix, std::vector initial) { return storm::utility::graph::getTopologicalSort(matrix, initial); }, "matrix"_a, "initial"_a, "get topological sort w.r.t. a transition matrix"); + + py::class_>(m, "ParametricSparseMatrix", "Parametric sparse matrix") .def("__iter__", [](SparseMatrix& matrix) { return py::make_iterator(matrix.begin(), matrix.end());