Combinations¶
Header: fiction/utils/math/combination_utils.hpp
-
inline std::vector<std::vector<std::size_t>> fiction::utils::math::determine_all_combinations_of_distributing_k_entities_on_n_positions(const std::size_t k, const std::size_t n, const std::chrono::steady_clock::time_point deadline = std::chrono::steady_clock::time_point::max())¶
This function generates all possible combinations of distributing k entities onto n positions. Each combination is represented as a vector of indices, where each index indicates the position of an entity.
- Parameters:
k – The number of entities to distribute.
n – The number of positions available for distribution.
deadline – Shared execution deadline; unlimited by default.
- Throws:
std::length_error – if the number of combinations exceeds the vector’s capacity.
timeout_error – if the deadline is reached during enumeration.
- Returns:
A vector of vectors representing all possible combinations of distributing k entities on n positions.
-
template<typename VectorDataType>
inline std::vector<std::vector<VectorDataType>> fiction::utils::math::cartesian_combinations(const std::vector<std::vector<VectorDataType>> &sets) noexcept¶ This function computes the Cartesian product of a list of vectors. Each vector in the input list represents a dimension, and the function produces all possible combinations where each combination consists of one element from each dimension vector.
- Template Parameters:
VectorDataType – The type of elements in the vectors.
- Parameters:
sets – The sets to compute the Cartesian product for. In this implementation, a vector of vectors is utilized for efficiency. Each inner vector represents one dimension. The function generates combinations using one element from each dimension vector.
- Returns:
A vector of vectors, where each inner vector represents a combination of elements, one from each dimension. The total number of combinations is the product of the sizes of the input vectors.