CMS 3D CMS Logo

PartitionGenerator.cc
Go to the documentation of this file.
2 #include <algorithm>
3 
4 using namespace std;
5 
6 vector<PartitionGenerator::Partition> PartitionGenerator::partitions(int collectionSize, int minCollectionSize) const {
7  std::vector<Partition> partitions;
8 
9  // at the very least, we have a single bag of size 'collectionSize'
10  partitions.push_back(Partition(1, collectionSize));
11 
12  int first = collectionSize - minCollectionSize, second = minCollectionSize;
13  while (first >= second) {
14  // try to further divide the first
15  std::vector<Partition> subPartitions = this->partitions(first, second);
16  std::vector<Partition>::iterator isub;
17  for (isub = subPartitions.begin(); isub != subPartitions.end(); isub++) {
18  const Partition& sub = *isub;
19  // reject subPartitions of first with a last element smaller than second
20  if (sub.back() < second)
21  continue;
22  Partition partition(sub.size() + 1);
23  copy(sub.begin(), sub.end(), partition.begin());
24  partition[partition.size() - 1] = second;
25  partitions.push_back(partition);
26  }
27  first--;
28  second++;
29  }
30 
31  return partitions;
32 }
33 
34 vector<std::vector<PartitionGenerator::Partition> > PartitionGenerator::sortedPartitions(int collectionSize,
35  int minCollectionSize) const {
36  std::vector<Partition> partitions = this->partitions(collectionSize, minCollectionSize);
37  sort(partitions.begin(), partitions.end(), LessCollections());
38 
39  std::vector<std::vector<Partition> > sortedPartitions;
40  sortedPartitions.resize(partitions.rbegin()->size());
41 
42  for (std::vector<Partition>::const_iterator i = partitions.begin(); i != partitions.end(); i++) {
43  sortedPartitions[(*i).size() - 1].push_back(*i);
44  }
45 
46  return sortedPartitions;
47 }
mps_fire.i
i
Definition: mps_fire.py:428
PartitionGenerator::sortedPartitions
std::vector< std::vector< Partition > > sortedPartitions(int collectionSize, int minCollectionSize=1) const
Definition: PartitionGenerator.cc:34
filterCSVwithJSON.copy
copy
Definition: filterCSVwithJSON.py:36
edm::second
U second(std::pair< T, U > const &p)
Definition: ParameterSet.cc:222
AlignmentPI::partitions
partitions
Definition: AlignmentPayloadInspectorHelper.h:48
dqmdumpme.first
first
Definition: dqmdumpme.py:55
PartitionGenerator.h
Partition
Partition
Definition: HLTHPDFilter.cc:32
PartitionGenerator::partitions
std::vector< Partition > partitions(int collectionSize, int minCollectionSize=1) const
Definition: PartitionGenerator.cc:6
PartitionGenerator::Partition
std::vector< int > Partition
Definition: PartitionGenerator.h:14
PartitionGenerator::LessCollections
Definition: PartitionGenerator.h:28
std
Definition: JetResolutionObject.h:76