CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PartitionGenerator.cc
Go to the documentation of this file.
2 #include <algorithm>
3 
4 using namespace std;
5 
6 
7 vector<PartitionGenerator::Partition>
8 PartitionGenerator::partitions(int collectionSize, int minCollectionSize)
9 const {
10 
11  std::vector<Partition> partitions;
12 
13  // at the very least, we have a single bag of size 'collectionSize'
14  partitions.push_back( Partition(1, collectionSize) );
15 
16  int first = collectionSize - minCollectionSize, second = minCollectionSize;
17  while( first >= second ) {
18  // try to further divide the first
19  std::vector<Partition> subPartitions = this->partitions(first, second);
20  std::vector<Partition>::iterator isub;
21  for( isub = subPartitions.begin(); isub != subPartitions.end(); isub++ ) {
22  const Partition& sub = *isub;
23  // reject subPartitions of first with a last element smaller than second
24  if( sub.back() < second ) continue;
25  Partition partition( sub.size()+1 );
26  copy( sub.begin(), sub.end(), partition.begin() );
27  partition[ partition.size()-1 ] = second;
28  partitions.push_back( partition );
29  }
30  first--; second++;
31  }
32 
33  return partitions;
34 }
35 
36 
37 vector< std::vector<PartitionGenerator::Partition> >
39  int minCollectionSize) const {
40 
41  std::vector<Partition> partitions
42  = this->partitions(collectionSize, minCollectionSize);
43  sort (partitions.begin(), partitions.end(), LessCollections());
44 
45  std::vector< std::vector<Partition> > sortedPartitions;
46  sortedPartitions.resize(partitions.rbegin()->size());
47 
48  for (std::vector<Partition>::const_iterator i = partitions.begin();
49  i != partitions.end(); i++) {
50  sortedPartitions[(*i).size() - 1].push_back(*i);
51  }
52 
53  return sortedPartitions;
54 }
std::vector< std::vector< Partition > > sortedPartitions(int collectionSize, int minCollectionSize=1) const
int i
Definition: DBlmapReader.cc:9
U second(std::pair< T, U > const &p)
Partition
Definition: HLTHPDFilter.cc:32
std::vector< Partition > partitions(int collectionSize, int minCollectionSize=1) const
std::vector< int > Partition