Storm 1.14.0.1
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
SubsetEnumerator.h
Go to the documentation of this file.
1#pragma once
2
3#include <cstdint>
4#include <vector>
5
6namespace storm {
7namespace storage {
8namespace geometry {
21template<typename DataType = std::nullptr_t>
23 public:
24 // A typedef for the filter.
25 // Note that the function will be called with subset.size() in {0, ..., k-1}.
26 typedef bool (*SubsetFilter)(std::vector<uint_fast64_t> const& subset, uint_fast64_t const& item, DataType const& data);
27
28 /*
29 * Constructs a subset enumerator that can enumerate all k-sized Subsets of {0,...,n-1}
30 * The given filter can be used to skip certain subsets.
31 * @note call "setToFirstSubset()" before retrieving the first subset
32 */
33 SubsetEnumerator(uint_fast64_t n, uint_fast64_t k, DataType const& data = DataType(), SubsetFilter subsetFilter = trueFilter);
34
36
37 // returns the current subset of size k.
38 // Arbitrary behavior if setToFirstSubset or incrementSubset returned false or have never been executed
39 std::vector<uint_fast64_t> const& getCurrentSubset();
40
41 // Sets the current subset to the very first one.
42 // @note Needs to be called initially.
43 // Returns true iff there actually is a first subset and false if not (e.g. when n<k or the filter answers false in all cases).
44 bool setToFirstSubset();
45
46 // Increments the current subset.
47 // Returns true if there is a new subset and false if the current subset is already the last one.
48 bool incrementSubset();
49
50 // Default filter that returns always true.
51 static bool trueFilter(std::vector<uint_fast64_t> const& subset, uint_fast64_t const& item, DataType const& data);
52
53 private:
54 uint_fast64_t n; // the size of the source set
55 uint_fast64_t k; // the size of the desired subsets
56 DataType const& data; // The data which is given as additional information when invoking the filter
57 SubsetFilter filter; // returns true iff it is okay to insert a new element
58 std::vector<uint_fast64_t> current; // the current subset
59 std::vector<uint_fast64_t> upperBoundaries; // will always be [n-k, ..., n-1]. Used to easily check whether we can increment the subset at a given position
60};
61} // namespace geometry
62} // namespace storage
63} // namespace storm
static bool trueFilter(std::vector< uint_fast64_t > const &subset, uint_fast64_t const &item, DataType const &data)
std::vector< uint_fast64_t > const & getCurrentSubset()
bool(* SubsetFilter)(std::vector< uint_fast64_t > const &subset, uint_fast64_t const &item, DataType const &data)
SubsetEnumerator(uint_fast64_t n, uint_fast64_t k, DataType const &data=DataType(), SubsetFilter subsetFilter=trueFilter)