From 36298c88b0e4b8494777a919f22a0b708da9095e Mon Sep 17 00:00:00 2001 From: PimLeerkes Date: Fri, 28 Jun 2024 14:35:55 +0200 Subject: [PATCH] Simple representation to sparsematrix now works --- stormvogel/map.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 stormvogel/map.py diff --git a/stormvogel/map.py b/stormvogel/map.py new file mode 100644 index 0000000..7d39643 --- /dev/null +++ b/stormvogel/map.py @@ -0,0 +1,42 @@ +from stormpy.core import SparseMatrixBuilder, SparseMatrix +import stormvogel.model + + +def simple_to_matrix(model: stormvogel.model.Model) -> SparseMatrix: + """ + Takes a simple representation as input and outputs a sparsematrix + """ + builder = SparseMatrixBuilder() + + for transition in model.transitions.items(): + for branch in transition[1].transition.values(): + for tuple in branch.branch: + builder.add_next_value( + row=transition[0], column=tuple[1].id, value=tuple[0] + ) + + matrix = builder.build() + return matrix + + +""" +def matrix_to_simple(matrix: stormpy.SparseMatrix) -> stormvogel.model.Model: + + Takes a sparsematrix as input and outputs a simple representation + + + return simple +""" + +if __name__ == "__main__": + # Create a new model with the name "Die" + dtmc = stormvogel.model.new_dtmc("Die") + + init = dtmc.get_initial_state() + + # From the initial state, add the transition to 6 new states with probability 1/6th. + init.set_transitions( + [(1 / 6, dtmc.new_state(f"rolled{i}", {"rolled": i})) for i in range(6)] + ) + + print(simple_to_matrix(dtmc))