Go to the documentation of this file.00001 #include "CommonTools/Statistics/interface/PartitionGenerator.h"
00002 #include <algorithm>
00003
00004 using namespace std;
00005
00006
00007 vector<PartitionGenerator::Partition>
00008 PartitionGenerator::partitions(int collectionSize, int minCollectionSize)
00009 const {
00010
00011 std::vector<Partition> partitions;
00012
00013
00014 partitions.push_back( Partition(1, collectionSize) );
00015
00016 int first = collectionSize - minCollectionSize, second = minCollectionSize;
00017 while( first >= second ) {
00018
00019 std::vector<Partition> subPartitions = this->partitions(first, second);
00020 std::vector<Partition>::iterator isub;
00021 for( isub = subPartitions.begin(); isub != subPartitions.end(); isub++ ) {
00022 const Partition& sub = *isub;
00023
00024 if( sub.back() < second ) continue;
00025 Partition partition( sub.size()+1 );
00026 copy( sub.begin(), sub.end(), partition.begin() );
00027 partition[ partition.size()-1 ] = second;
00028 partitions.push_back( partition );
00029 }
00030 first--; second++;
00031 }
00032
00033 return partitions;
00034 }
00035
00036
00037 vector< std::vector<PartitionGenerator::Partition> >
00038 PartitionGenerator::sortedPartitions(int collectionSize,
00039 int minCollectionSize) const {
00040
00041 std::vector<Partition> partitions
00042 = this->partitions(collectionSize, minCollectionSize);
00043 sort (partitions.begin(), partitions.end(), LessCollections());
00044
00045 std::vector< std::vector<Partition> > sortedPartitions;
00046 sortedPartitions.resize(partitions.rbegin()->size());
00047
00048 for (std::vector<Partition>::const_iterator i = partitions.begin();
00049 i != partitions.end(); i++) {
00050 sortedPartitions[(*i).size() - 1].push_back(*i);
00051 }
00052
00053 return sortedPartitions;
00054 }