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.

36 lines
1.2 KiB

  1. class Action:
  2. """ Represents an action in the model """
  3. def __init__(self, row_group_start, row_group_end, row, model):
  4. """ Initialize
  5. :param row_group_start: Start index of the row group in the matrix
  6. :param row_group_end: End index of the row group in the matrix
  7. :param row: Index of the corresponding row in the matrix
  8. :param model: Corresponding model
  9. """
  10. self.row_group_start = row_group_start
  11. self.row_group_end = row_group_end
  12. self.row = row - 1
  13. self.model = model
  14. assert row >= -1 and row + row_group_start <= row_group_end
  15. def __iter__(self):
  16. return self
  17. def __next__(self):
  18. if self.row + self.row_group_start >= self.row_group_end - 1:
  19. raise StopIteration
  20. else:
  21. self.row += 1
  22. return self
  23. def __str__(self):
  24. return "{}".format(self.row)
  25. def transitions(self):
  26. """ Get transitions associated with the action
  27. :return List of tranistions
  28. """
  29. row = self.row_group_start + self.row
  30. #return self.model.transition_matrix().get_row(self.row_group_start + self.row)
  31. return self.model.transition_matrix.row_iter(row, row)