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.

77 lines
2.6 KiB

4 years ago
  1. from . import pomdp
  2. from .pomdp import *
  3. def make_canonic(model):
  4. """
  5. Make the POMDP canonic
  6. :param model:
  7. :return:
  8. """
  9. if model.supports_parameters:
  10. return pomdp._make_canonic_Rf(model)
  11. else:
  12. return pomdp._make_canonic_Double(model)
  13. def make_simple(model, keep_state_valuations=False):
  14. """
  15. Make the POMDP simple (aka alternating), i.e., each state has at most two actions, and if there is nondeterminism, then there is no probabilistic branching,
  16. :param model:
  17. :return:
  18. """
  19. if model.supports_parameters:
  20. return pomdp._make_simple_Rf(model, keep_state_valuations)
  21. else:
  22. return pomdp._make_simple_Double(model, keep_state_valuations)
  23. def unfold_memory(model, memory, add_memory_labels=False, keep_state_valuations=False):
  24. """
  25. Unfold the memory for an FSC into the POMDP
  26. :param model: A pomdp
  27. :param memory: A memory structure
  28. :return: A pomdp that contains states from the product of the original POMDP and the FSC Memory
  29. """
  30. if model.supports_parameters:
  31. return pomdp._unfold_memory_Rf(model, memory, add_memory_labels, keep_state_valuations)
  32. else:
  33. return pomdp._unfold_memory_Double(model, memory, add_memory_labels, keep_state_valuations)
  34. def apply_unknown_fsc(model, mode):
  35. if model.supports_parameters:
  36. return pomdp._apply_unknown_fsc_Rf(model, mode)
  37. else:
  38. return pomdp._apply_unknown_fsc_Double(model, mode)
  39. def create_nondeterminstic_belief_tracker(model, reduction_timeout, track_timeout):
  40. """
  41. :param model: A POMDP
  42. :param reduction_timeout: timeout in milliseconds for the reduction algorithm, 0 for no timeout.
  43. :return:
  44. """
  45. if model.is_exact:
  46. opts = NondeterministicBeliefTrackerExactSparseOptions()
  47. opts.reduction_timeout = reduction_timeout
  48. opts.track_timeout = track_timeout
  49. return pomdp.NondeterministicBeliefTrackerExactSparse(model, opts)
  50. else:
  51. opts = NondeterministicBeliefTrackerDoubleSparseOptions()
  52. opts.reduction_timeout = reduction_timeout
  53. opts.track_timeout = track_timeout
  54. return pomdp.NondeterministicBeliefTrackerDoubleSparse(model, opts)
  55. def create_observation_trace_unfolder(model, risk_assessment, expr_manager):
  56. """
  57. :param model:
  58. :param risk_assessment:
  59. :param expr_manager:
  60. :return:
  61. """
  62. if model.is_exact:
  63. return pomdp.ObservationTraceUnfolderExact(model, risk_assessment, expr_manager)
  64. else:
  65. return pomdp.ObservationTraceUnfolderDouble(model, risk_assessment, expr_manager)