1 #ifndef _CombinationGenerator_H_
2 #define _CombinationGenerator_H_
31 std::vector<Combination>
38 if (prev_permutation(sorted.begin(), sorted.end())) {
39 sort(sorted.begin(), sorted.end());
44 std::vector< std::vector<PartitionGenerator::Partition> > partitions
48 for (std::vector<PartitionGenerator::Partition>::const_iterator idiv
49 = partitions[numberOfCollections-1].
begin();
50 idiv != partitions[numberOfCollections-1].end(); idiv++) {
53 std::vector<Combination> subCombinations
55 for (
typename std::vector<Combination>::const_iterator iComb
56 = subCombinations.begin();
57 iComb != subCombinations.end(); iComb++) {
58 combinations.push_back(*iComb);
68 std::vector<Combination>
78 for (PartitionGenerator::Partition::const_iterator
iSize
79 = partition.begin();
iSize != partition.end();
iSize++) {
82 if (nElts != data.size())
return combinations;
86 if (prev_permutation(sortedData.begin(), sortedData.end())) {
87 sort(sortedData.begin(), sortedData.end());
92 comb.push_back(sortedData);
93 if (partition.size() == 1) {
95 combinations.push_back(comb);
98 std::stack<Combination> cStack;
105 sort(sortedPartition.begin(), sortedPartition.end(), std::greater_equal<int>());
107 while (!cStack.empty()) {
110 Combination combination = cStack.top(); cStack.pop();
117 int k = sortedPartition.size() - combination.size();
119 for (
int iColl = 0; iColl !=
k; iColl++) {
120 size += sortedPartition[iColl];
123 biPartition[0] =
size;
124 biPartition[1] = sortedPartition[
k];
128 for (
typename std::vector<Combination>::const_iterator iComb = subCombinations.begin();
129 iComb != subCombinations.end(); iComb++) {
132 if (combination.size() > 1) {
133 if ((*iComb)[1].size() == combination[1].size()) {
135 adjBins.push_back((*iComb)[1][0]);
136 adjBins.push_back(combination[1][0]);
139 if (prev_permutation(adjBins.begin(), adjBins.end()))
continue;
145 typename Combination::const_iterator it = combination.begin(); it++;
146 for ( ; it != combination.end(); it++) { merged.push_back(*it); }
150 if (merged.size() == sortedPartition.size()) {
151 combinations.push_back(merged);
169 if (prev_permutation(sorted.begin(), sorted.end())) {
170 sort(sorted.begin(), sorted.end());
174 std::vector<PartitionGenerator::Partition> partitions
175 = aPartitionGenerator.
partitions(data.size());
177 for (std::vector<PartitionGenerator::Partition>::const_iterator idiv
178 = partitions.begin(); idiv != partitions.end(); idiv++) {
181 std::vector<Combination> subCombinations
183 for (
typename std::vector<Combination>::const_iterator iComb
184 = subCombinations.begin();
185 iComb != subCombinations.end(); iComb++) {
186 combinations.push_back(*iComb);
202 std::stack<Combination> cStack;
208 while (!cStack.empty()) {
215 for (
typename std::vector<Combination>::const_iterator iComb = subCombinations.begin();
216 iComb != subCombinations.end(); iComb++) {
219 second.push_back((*iComb)[1][0]);
223 bool ordered = !prev_permutation(second.begin(), second.end());
224 if (!ordered)
continue;
225 next_permutation(second.begin(), second.end());
227 if ((*iComb)[0].size() == second.size()) {
229 adjBins.push_back((*iComb)[0][0]);
230 adjBins.push_back(second[0]);
233 if (prev_permutation(adjBins.begin(), adjBins.end()))
continue;
237 stored.push_back((*iComb)[0]);
238 stored.push_back(second);
240 if (stored[0].
size() == sizeFirst) {
241 combinations.push_back(stored);
256 for (
typename Collection::const_iterator
i = data.begin();
i != data.end();
i++) {
260 typename Collection::const_iterator
j = data.begin();
261 for ( ; j !=
i; j++) { coll.push_back(*j); }
263 for ( ; j != data.end(); j++) { coll.push_back(*j); }
264 comb.push_back(coll); comb.push_back(single);
265 combinations.push_back(comb);
std::vector< std::vector< Partition > > sortedPartitions(int collectionSize, int minCollectionSize=1) const
VectorOfCombinations splitInTwoCollections(const Collection &data, int sizeFirst) const
U second(std::pair< T, U > const &p)
std::vector< Partition > partitions(int collectionSize, int minCollectionSize=1) const
std::vector< Combination > combinations(const Collection &data, int numberOfCollections) const
std::vector< Collection > Combination
std::vector< Combination > combinations(const Collection &data, const PartitionGenerator::Partition &partition) const
std::vector< int > Partition
std::vector< T > Collection
std::vector< Combination > VectorOfCombinations
std::vector< Combination > combinations(const Collection &data) const
char data[epos_bytes_allocation]
std::vector< Combination > separateOneElement(const Collection &data) const
tuple size
Write out results.