Browse Source

toposort bindings

refactoring
Sebastian Junges 6 years ago
parent
commit
9970aa391f
  1. 15
      lib/stormpy/__init__.py
  2. 6
      src/storage/matrix.cpp

15
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.")

6
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<typename ValueType> using SparseMatrix = storm::storage::SparseMatrix<ValueType>;
@ -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<double>& matrix, std::vector<uint64_t> 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<storm::RationalFunction>& matrix, std::vector<uint64_t> initial) { return storm::utility::graph::getTopologicalSort(matrix, initial); }, "matrix"_a, "initial"_a, "get topological sort w.r.t. a transition matrix");
py::class_<SparseMatrix<RationalFunction>>(m, "ParametricSparseMatrix", "Parametric sparse matrix")
.def("__iter__", [](SparseMatrix<RationalFunction>& matrix) {
return py::make_iterator(matrix.begin(), matrix.end());

Loading…
Cancel
Save