AIToolbox
A library that offers tools for AI problem solving.
|
Go to the documentation of this file. 1 #ifndef AI_TOOLBOX_UTILS_COMBINATORICS_HEADER_FILE
2 #define AI_TOOLBOX_UTILS_COMBINATORICS_HEADER_FILE
12 unsigned nChooseK(
unsigned n,
unsigned k);
20 unsigned starsBars(
unsigned stars,
unsigned bars);
32 unsigned ballsBins(
unsigned balls,
unsigned bins);
58 template <
typename Index>
71 lowerBound_(lowerBound), upperBound_(upperBound), ids_(elementsN)
73 if constexpr (std::is_integral_v<Index>) {
74 assert(upperBound_ > lowerBound_);
75 assert(
static_cast<size_t>(upperBound_ - lowerBound_) >= elementsN);
77 assert(
static_cast<size_t>(std::distance(lowerBound_, upperBound_)) >= elementsN);
108 auto current = ids_.size() - 1;
109 auto ub = upperBound_ - 1;
110 while (current && ids_[current] == ub) --current, --ub;
112 auto lowest = current;
113 ub = ++ids_[current];
115 while (++current != ids_.size()) ids_[current] = ++ub;
124 return ids_.back() < upperBound_;
131 std::iota(std::begin(ids_), std::end(ids_), lowerBound_);
138 if constexpr (std::is_integral_v<Index>)
139 return nChooseK(upperBound_ - lowerBound_, ids_.size());
141 return nChooseK(std::distance(lowerBound_, upperBound_), ids_.size());
147 auto size()
const {
return ids_.size(); }
175 Index lowerBound_, upperBound_;