Main Page
Namespaces
Classes
Package Documentation
CommonTools
Statistics
src
SequentialPartitionGenerator.cc
Go to the documentation of this file.
1
#include "
CommonTools/Statistics/interface/SequentialPartitionGenerator.h
"
2
3
SequentialPartitionGenerator::SequentialPartitionGenerator
(
int
n
,
int
k
,
int
pmin ) :
4
the_n(n), the_k(k), the_pmin(pmin), the_pmax(n) {}
5
6
SequentialPartitionGenerator::SequentialPartitionGenerator
(
int
n
,
int
k
,
int
pmin,
int
pmax) :
7
the_n
(n),
the_k
(k),
the_pmin
(pmin),
the_pmax
(pmax) {}
8
9
SequentialPartitionGenerator::Partition
SequentialPartitionGenerator::next_partition
()
10
{
11
bool
done=
next_part
(
the_part
);
12
if
(done)
13
{
14
return
the_part
;
15
};
16
SequentialPartitionGenerator::Partition
empty
;
17
return
empty
;
18
}
19
20
bool
SequentialPartitionGenerator::first_part
(
21
SequentialPartitionGenerator::Partition
&
p
,
int
k
,
int
n
,
int
pmin,
int
pmax )
const
22
{
23
n_first
++;
24
bool
done=
false
;
25
switch
(k) {
26
case
1:
27
p[0]=
std::min
(pmax,n);
28
return
(n<=pmax && p[0]>=pmin);
29
case
2:
30
for
(
int
i
=
std::min
(pmax,n-1);
i
>=pmin;
i
--) {
31
if
((done=(
i
>=n-
i
&& n-
i
>=pmin))) {p[0]=
i
;p[1]=n-
i
;}
32
return
done;
33
}
34
default
:
35
Partition
pp
(p.begin()+1,p.end());
36
for
(
int
i
=
std::min
(pmax,n-k+1);
i
>=pmin;
i
--) {
37
p[0]=
i
;
38
done=this->
first_part
(
pp
,k-1,n-p[0],pmin,p[0]);
39
if
(done) {
copy
(
pp
.begin(),
pp
.end(),p.begin()+1);}
40
return
done;
41
}
42
}
43
return
done;
44
}
45
46
bool
SequentialPartitionGenerator::next_part
(
47
SequentialPartitionGenerator::Partition
&
p
)
const
48
{
49
n_next
++;
50
bool
done=
false
;
51
int
k
=p.size();
52
switch
(k) {
53
case
0:
// empty partition: first call to next_part, initialize
54
p.insert(p.begin(),
the_k
,0);
55
return
this->
first_part
(p,
the_k
,
the_n
,
the_pmin
,
the_pmax
);
56
case
1:
57
return
false
;
58
default
:
59
int
n
=0;
60
for
(
int
i
=0;
i
<
k
;
i
++) n=n+p[
i
];
61
SequentialPartitionGenerator::Partition
pp
(p.begin()+1,p.end());
62
done = (
pp
.size()>1 ? this->
next_part
(
pp
) :
false
);
63
if
(done)
64
{
65
copy
(
pp
.begin(),
pp
.end(),p.begin()+1);
66
}
else
{
67
done = (p[0]==1 ?
false
:
68
this->
first_part
(
pp
,k-1,n-p[0]+1,
the_pmin
,p[0]-1));
69
if
(done) { --p[0];
copy
(
pp
.begin(),
pp
.end(),p.begin()+1); }
70
};
71
return
done;
72
};
73
return
done;
74
}
relativeConstraints.empty
bool empty
Definition:
relativeConstraints.py:46
mps_fire.i
i
Definition:
mps_fire.py:329
AlCaHLTBitMon_ParallelJobs.p
p
Definition:
AlCaHLTBitMon_ParallelJobs.py:153
popcon2dropbox.copy
def copy(args, dbName)
Definition:
popcon2dropbox.py:122
SequentialPartitionGenerator::the_part
Partition the_part
Definition:
SequentialPartitionGenerator.h:33
SequentialPartitionGenerator::SequentialPartitionGenerator
SequentialPartitionGenerator(int n, int k, int pmin=1)
Definition:
SequentialPartitionGenerator.cc:3
SequentialPartitionGenerator::the_pmax
int the_pmax
Definition:
SequentialPartitionGenerator.h:32
SequentialPartitionGenerator.h
SequentialPartitionGenerator::n_next
int n_next
Definition:
SequentialPartitionGenerator.h:35
min
T min(T a, T b)
Definition:
MathUtil.h:58
SequentialPartitionGenerator::next_part
bool next_part(Partition &p) const
Definition:
SequentialPartitionGenerator.cc:46
gen::k
int k[5][pyjets_maxn]
Definition:
Cascade2Hadronizer.cc:79
SequentialPartitionGenerator::first_part
bool first_part(Partition &p, int k, int n, int pmin, int pmax) const
Definition:
SequentialPartitionGenerator.cc:20
SequentialPartitionGenerator::the_pmin
int the_pmin
Definition:
SequentialPartitionGenerator.h:31
SequentialPartitionGenerator::Partition
std::vector< int > Partition
Definition:
SequentialPartitionGenerator.h:12
SequentialPartitionGenerator::next_partition
Partition next_partition()
Definition:
SequentialPartitionGenerator.cc:9
gen::n
int n
Definition:
Cascade2Hadronizer.cc:79
createTree.pp
pp
Definition:
createTree.py:16
SequentialPartitionGenerator::the_k
int the_k
Definition:
SequentialPartitionGenerator.h:30
SequentialPartitionGenerator::n_first
int n_first
Definition:
SequentialPartitionGenerator.h:34
SequentialPartitionGenerator::the_n
int the_n
Definition:
SequentialPartitionGenerator.h:29
Generated for CMSSW Reference Manual by
1.8.11