Skip to content

Commit

Permalink
normalize and reassign ids can be set individually
Browse files Browse the repository at this point in the history
  • Loading branch information
PimLeerkes committed Nov 3, 2024
1 parent a315fab commit 0c6fe4a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions stormvogel/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,9 @@ def new_action(self, name: str, labels: frozenset[str] | None = None) -> Action:
self.actions[name] = action
return action

def remove_state(self, state: State, normalize_and_reassign_ids: bool = True):
def remove_state(
self, state: State, normalize: bool = True, reassign_ids: bool = True
):
"""properly removes a state, it can optionally normalize the model and reassign ids automatically"""
if state in self.states.values():
# we remove the state from the transitions
Expand Down Expand Up @@ -620,9 +622,11 @@ def remove_state(self, state: State, normalize_and_reassign_ids: bool = True):
self.markovian_states.remove(state)

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

# we reassign the ids if specified to do so
if reassign_ids:
self.states = {
new_id: value
for new_id, (old_id, value) in enumerate(
Expand Down
2 changes: 1 addition & 1 deletion tests/test_model_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def test_normalize():
def test_remove_state():
# we make a normal ctmc and remove a state
ctmc = examples.nuclear_fusion_ctmc.create_nuclear_fusion_ctmc()
ctmc.remove_state(ctmc.get_state_by_id(3), True)
ctmc.remove_state(ctmc.get_state_by_id(3), True, True)

# we make a ctmc with the state already missing
new_ctmc = stormvogel.model.new_ctmc("Nuclear fusion")
Expand Down

0 comments on commit 0c6fe4a

Please sign in to comment.