1 #ifndef _CombinationGenerator_H_ 2 #define _CombinationGenerator_H_ 28 std::vector<Combination>
combinations(
const Collection&
data,
int numberOfCollections)
const {
30 Collection sorted =
data;
33 if (prev_permutation(sorted.begin(), sorted.end())) {
34 sort(sorted.begin(), sorted.end());
39 std::vector<std::vector<PartitionGenerator::Partition> >
partitions =
40 aPartitionGenerator.sortedPartitions(data.size());
43 for (std::vector<PartitionGenerator::Partition>::const_iterator idiv = partitions[numberOfCollections - 1].
begin();
44 idiv != partitions[numberOfCollections - 1].end();
47 std::vector<Combination> subCombinations = this->
combinations(data, partition);
48 for (
typename std::vector<Combination>::const_iterator iComb = subCombinations.begin();
49 iComb != subCombinations.end();
51 combinations.push_back(*iComb);
66 for (PartitionGenerator::Partition::const_iterator iSize = partition.begin(); iSize != partition.end(); iSize++) {
69 if (nElts != data.size())
72 Collection sortedData =
data;
74 if (prev_permutation(sortedData.begin(), sortedData.end())) {
75 sort(sortedData.begin(), sortedData.end());
80 comb.push_back(sortedData);
81 if (partition.size() == 1) {
83 combinations.push_back(comb);
86 std::stack<Combination> cStack;
93 sort(sortedPartition.begin(), sortedPartition.end(), std::greater_equal<int>());
95 while (!cStack.empty()) {
97 Combination combination = cStack.top();
105 int k = sortedPartition.size() - combination.size();
107 for (
int iColl = 0; iColl !=
k; iColl++) {
108 size += sortedPartition[iColl];
111 biPartition[0] =
size;
112 biPartition[1] = sortedPartition[
k];
115 for (
typename std::vector<Combination>::const_iterator iComb = subCombinations.begin();
116 iComb != subCombinations.end();
119 if (combination.size() > 1) {
120 if ((*iComb)[1].size() == combination[1].size()) {
122 adjBins.push_back((*iComb)[1][0]);
123 adjBins.push_back(combination[1][0]);
126 if (prev_permutation(adjBins.begin(), adjBins.end()))
132 Combination merged = *iComb;
133 typename Combination::const_iterator it = combination.begin();
135 for (; it != combination.end(); it++) {
136 merged.push_back(*it);
141 if (merged.size() == sortedPartition.size()) {
142 combinations.push_back(merged);
155 Collection sorted =
data;
157 if (prev_permutation(sorted.begin(), sorted.end())) {
158 sort(sorted.begin(), sorted.end());
162 std::vector<PartitionGenerator::Partition>
partitions = aPartitionGenerator.partitions(data.size());
164 for (std::vector<PartitionGenerator::Partition>::const_iterator idiv = partitions.begin(); idiv != partitions.end();
168 std::vector<Combination> subCombinations = this->
combinations(data, partition);
169 for (
typename std::vector<Combination>::const_iterator iComb = subCombinations.begin();
170 iComb != subCombinations.end();
172 combinations.push_back(*iComb);
184 std::stack<Combination> cStack;
188 comb.push_back(data);
192 while (!cStack.empty()) {
193 Combination combination = cStack.top();
199 for (
typename std::vector<Combination>::const_iterator iComb = subCombinations.begin();
200 iComb != subCombinations.end();
202 Collection
second = combination[1];
203 second.push_back((*iComb)[1][0]);
207 bool ordered = !prev_permutation(second.begin(), second.end());
210 next_permutation(second.begin(), second.end());
212 if ((*iComb)[0].size() == second.size()) {
214 adjBins.push_back((*iComb)[0][0]);
215 adjBins.push_back(second[0]);
218 if (prev_permutation(adjBins.begin(), adjBins.end()))
223 stored.push_back((*iComb)[0]);
224 stored.push_back(second);
226 if (stored[0].
size() == sizeFirst) {
227 combinations.push_back(stored);
241 for (
typename Collection::const_iterator
i = data.begin();
i != data.end();
i++) {
244 single.push_back(*
i);
246 typename Collection::const_iterator
j = data.begin();
247 for (; j !=
i; j++) {
251 for (; j != data.end(); j++) {
254 comb.push_back(coll);
255 comb.push_back(single);
256 combinations.push_back(comb);
VectorOfCombinations splitInTwoCollections(const Collection &data, int sizeFirst) const
U second(std::pair< T, U > const &p)
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