You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
889 B

  1. from . import action
  2. class State:
  3. """ Represents a state in the model """
  4. def __init__(self, id, model):
  5. """ Initialize
  6. :param id: Id of the state
  7. :param model: Corresponding model
  8. """
  9. self.id = id - 1
  10. self.model = model
  11. def __iter__(self):
  12. return self
  13. def __next__(self):
  14. if self.id >= self.model.nr_states - 1:
  15. raise StopIteration
  16. else:
  17. self.id += 1
  18. return self
  19. def __str__(self):
  20. return "{}".format(self.id)
  21. def actions(self):
  22. """ Get actions associated with the state
  23. :return List of actions
  24. """
  25. row_group_indices = self.model.transition_matrix._row_group_indices
  26. start = row_group_indices[self.id]
  27. end = row_group_indices[self.id+1]
  28. return action.Action(start, end, 0, self.model)