-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simple representation to sparsematrix now works
- Loading branch information
1 parent
429ef18
commit 36298c8
Showing
1 changed file
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)) |