CMS 3D CMS Logo

List of all members | Classes | Public Types | Public Member Functions
PartitionGenerator Class Reference

#include <PartitionGenerator.h>

Classes

class  LessCollections
 

Public Types

typedef std::vector< int > Partition
 

Public Member Functions

std::vector< Partitionpartitions (int collectionSize, int minCollectionSize=1) const
 
std::vector< std::vector< Partition > > sortedPartitions (int collectionSize, int minCollectionSize=1) const
 

Detailed Description

Class to compute the possible partitions of a collection of 'collectionSize' elements. A Partition is a list of subcollection sizes that add up to 'collectionSize', ordered in decreasing order of subcollection size. No subcollection size is less than 'minCollectionSize'.

Definition at line 12 of file PartitionGenerator.h.

Member Typedef Documentation

◆ Partition

typedef std::vector<int> PartitionGenerator::Partition

Definition at line 14 of file PartitionGenerator.h.

Member Function Documentation

◆ partitions()

vector< PartitionGenerator::Partition > PartitionGenerator::partitions ( int  collectionSize,
int  minCollectionSize = 1 
) const

Return partitions in a row.

Definition at line 6 of file PartitionGenerator.cc.

References filterCSVwithJSON::copy, dqmdumpme::first, l1ctLayer1_patternWriters_cff::partition, and edm::second().

Referenced by CombinationGenerator< T >::combinations().

6  {
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 }
U second(std::pair< T, U > const &p)
Partition
Definition: HLTHPDFilter.cc:32
std::vector< int > Partition
std::vector< Partition > partitions(int collectionSize, int minCollectionSize=1) const

◆ sortedPartitions()

vector< std::vector< PartitionGenerator::Partition > > PartitionGenerator::sortedPartitions ( int  collectionSize,
int  minCollectionSize = 1 
) const

Return partitions ordered according to the number of subcollections they have. 'sortedPartitions[N]' = list of partitions with N subcollections.

Definition at line 34 of file PartitionGenerator.cc.

References mps_fire::i, and jetUpdater_cfi::sort.

Referenced by CombinationGenerator< T >::combinations().

35  {
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 }
std::vector< std::vector< Partition > > sortedPartitions(int collectionSize, int minCollectionSize=1) const
std::vector< Partition > partitions(int collectionSize, int minCollectionSize=1) const