CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SequentialPartitionGenerator.cc
Go to the documentation of this file.
2 
4  the_n(n), the_k(k), the_pmin(pmin), the_pmax(n) {}
5 
7  the_n(n), the_k(k), the_pmin(pmin), the_pmax(pmax) {}
8 
10 {
11  bool done=next_part(the_part);
12  if (done)
13  {
14  return the_part;
15  };
17  return empty;
18 }
19 
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 
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 }
int i
Definition: DBlmapReader.cc:9
tuple pp
Definition: createTree.py:15
SequentialPartitionGenerator(int n, int k, int pmin=1)
T min(T a, T b)
Definition: MathUtil.h:58
bool first_part(Partition &p, int k, int n, int pmin, int pmax) const