Skip to content

Commit

Permalink
small changes
Browse files Browse the repository at this point in the history
  • Loading branch information
PimLeerkes committed Sep 30, 2024
1 parent 9df560f commit b689c36
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion examples/die.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def create_die_dtmc():
dtmc.add_self_loops()

# test if state deletion works
dtmc.delete_state(dtmc.get_state_by_id(1), True, True)
# dtmc.delete_state(dtmc.get_state_by_id(1), True, True)

return dtmc

Expand Down
1 change: 1 addition & 0 deletions examples/monty_hall_pomdp.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def create_monty_hall_pomdp():
for state in pomdp.states.values():
state.set_observation(0)

# test if the normalize function works
pomdp.normalize()

return pomdp
Expand Down
2 changes: 1 addition & 1 deletion stormvogel/mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def add_labels(model: stormvogel.model.Model) -> stormpy.storage.StateLabeling:
Takes a model creates a state labelling object that determines which states get which labels in the stormpy representation
"""

state_labeling = stormpy.storage.StateLabeling(len(list(model.states.keys())))
state_labeling = stormpy.storage.StateLabeling(len(model.states))

# we first add all the different labels
for label in model.get_labels():
Expand Down
16 changes: 12 additions & 4 deletions stormvogel/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,7 @@ def is_well_defined(self) -> bool:
ModelType.CTMC,
ModelType.MA,
):
# TODO make it work for these models
raise RuntimeError("Not implemented")

return True
Expand All @@ -422,15 +423,19 @@ def normalize(self):
for action in state.available_actions():
sum_prob = 0
for tuple in state.get_outgoing_transitions(action):
if isinstance(tuple[0], float) or isinstance(
tuple[0], Fraction
if (
isinstance(tuple[0], float)
or isinstance(tuple[0], Fraction)
or isinstance(tuple[0], int)
):
sum_prob += tuple[0]

new_transitions = []
for tuple in state.get_outgoing_transitions(action):
if isinstance(tuple[0], float) or isinstance(
tuple[0], Fraction
if (
isinstance(tuple[0], float)
or isinstance(tuple[0], Fraction)
or isinstance(tuple[0], int)
):
normalized_transition = (
tuple[0] / sum_prob,
Expand All @@ -444,6 +449,7 @@ def normalize(self):
ModelType.CTMC,
ModelType.MA,
):
# TODO make it work for these models
raise RuntimeError("Not implemented")

def __free_state_id(self):
Expand Down Expand Up @@ -537,6 +543,7 @@ def delete_state(
if state in self.markovian_states:
self.markovian_states.remove(state)

# we reassign the ids if specified to do so
if reassign_ids:
self.states = {
new_id: value
Expand All @@ -562,6 +569,7 @@ def delete_state(
)
}

# we normalize the model if specified to do so
if normalize:
self.normalize()

Expand Down

0 comments on commit b689c36

Please sign in to comment.