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.

127 lines
3.4 KiB

  1. #pragma once
  2. #include <algorithm>
  3. #include <functional>
  4. #include <unordered_map>
  5. #include <vector>
  6. #include "storm-dft/builder/DftExplorationHeuristic.h"
  7. namespace storm {
  8. namespace storage {
  9. /*!
  10. * Priority queue based on buckets.
  11. * Can be used to keep track of states during state space exploration.
  12. * @tparam PriorityType Underlying priority data type
  13. */
  14. template<class PriorityType>
  15. class BucketPriorityQueue {
  16. using PriorityTypePointer = std::shared_ptr<PriorityType>;
  17. public:
  18. /*!
  19. * Create new priority queue.
  20. * @param nrBuckets
  21. * @param lowerValue
  22. * @param ratio
  23. * @param higher
  24. */
  25. explicit BucketPriorityQueue(size_t nrBuckets, double lowerValue, double ratio, bool higher);
  26. BucketPriorityQueue(BucketPriorityQueue const& queue) = default;
  27. virtual ~BucketPriorityQueue() = default;
  28. void fix();
  29. /*!
  30. * Check whether queue is empty.
  31. * @return True iff queue is empty.
  32. */
  33. bool empty() const;
  34. /*!
  35. * Return number of entries.
  36. * @return Size of queue.
  37. */
  38. std::size_t size() const;
  39. /*!
  40. * Get element with highest priority.
  41. * @return Top element.
  42. */
  43. PriorityTypePointer const& top() const;
  44. /*!
  45. * Add element.
  46. * @param item Element.
  47. */
  48. void push(PriorityTypePointer const& item);
  49. /*!
  50. * Update existing element.
  51. * @param item Element with changes.
  52. * @param oldPriority Old priority.
  53. */
  54. void update(PriorityTypePointer const& item, double oldPriority);
  55. /*!
  56. * Get element with highest priority and remove it from the queue.
  57. * @return Top element.
  58. */
  59. PriorityTypePointer pop();
  60. /*!
  61. * Print info about priority queue.
  62. * @param out Output stream.
  63. */
  64. void print(std::ostream& out) const;
  65. /*!
  66. * Print sizes of buckets.
  67. * @param out Output stream.
  68. */
  69. void printSizes(std::ostream& out) const;
  70. private:
  71. /*!
  72. * Get bucket for given priority.
  73. * @param priority Priority.
  74. * @return Bucket containing the priority.
  75. */
  76. size_t getBucket(double priority) const;
  77. // List of buckets
  78. std::vector<std::vector<PriorityTypePointer>> buckets;
  79. // Bucket containing all items which should be considered immediately
  80. std::vector<PriorityTypePointer> immediateBucket;
  81. // Index of first bucket which contains items
  82. size_t currentBucket;
  83. // Number of unsorted items in current bucket
  84. size_t nrUnsortedItems;
  85. // Comparison function for priorities
  86. std::function<bool(PriorityTypePointer, PriorityTypePointer)> compare;
  87. // Minimal value
  88. double lowerValue;
  89. bool higher;
  90. bool AUTOSORT = false;
  91. double logBase;
  92. // Number of available buckets
  93. size_t nrBuckets;
  94. };
  95. }
  96. }