CMS 3D CMS Logo

List of all members | Public Types | Public Member Functions | Private Member Functions | Private Attributes
SequentialCombinationGenerator< T > Class Template Reference

#include <SequentialCombinationGenerator.h>

Public Types

typedef std::vector< TCollection
 
typedef std::vector< CollectionCombination
 
typedef SequentialPartitionGenerator::Partition Partition
 
typedef std::vector< int > Vecint
 

Public Member Functions

Combination next_combination (Collection &coll)
 
 SequentialCombinationGenerator (Partition &part)
 

Private Member Functions

Vecint next_combi (Vecint &cold, int n, const Partition &p)
 
Vecint next_subset (const Vecint &_g, const Vecint &_c)
 
void vecprint (const Vecint &v) const
 

Private Attributes

bool dbg
 
Vecint the_comb
 
int the_k
 
int the_n
 
Partition the_part
 

Detailed Description

template<class T>
class SequentialCombinationGenerator< T >

Class to compute all distinct Combinations of a collection 'data' of objects of type 'T'. A Combination is a set of collections, each collection containing one or more objects, with any object in 'data' assigned to exactly one collection.

Definition at line 21 of file SequentialCombinationGenerator.h.

Member Typedef Documentation

template<class T >
typedef std::vector<T> SequentialCombinationGenerator< T >::Collection

Definition at line 24 of file SequentialCombinationGenerator.h.

template<class T >
typedef std::vector<Collection> SequentialCombinationGenerator< T >::Combination

Definition at line 25 of file SequentialCombinationGenerator.h.

Definition at line 23 of file SequentialCombinationGenerator.h.

template<class T >
typedef std::vector<int> SequentialCombinationGenerator< T >::Vecint

Definition at line 26 of file SequentialCombinationGenerator.h.

Constructor & Destructor Documentation

template<class T >
SequentialCombinationGenerator< T >::SequentialCombinationGenerator ( Partition part)
inline

Member Function Documentation

template<class T >
Vecint SequentialCombinationGenerator< T >::next_combi ( Vecint cold,
int  n,
const Partition p 
)
inlineprivate

Definition at line 64 of file SequentialCombinationGenerator.h.

References EnergyCorrector::c, popcon2dropbox::copy(), relativeConstraints::empty, mps_fire::i, gen::k, gen::n, SequentialCombinationGenerator< T >::next_subset(), p1, alignCSCRings::s, and jetUpdater_cfi::sort.

Referenced by SequentialCombinationGenerator< T >::next_combination().

65  {
66  Vecint empty;
67  if (cold.empty()) { // first entry, initialize
68  cold.reserve(n);
69  for (int i=0;i<n;cold.push_back(++i));
70  return cold;
71  }
72  int k=p.size();
73  if (k==1) return empty;
74  Vecint cnew(cold);
75  int n1=n-p[0];
76  Vecint cold1(cold.begin()+p[0],cold.end());
77  Vecint cnew1(n1);
78  Partition p1(p.begin()+1,p.end());
79  cnew1=next_combi(cold1,n1,p1);
80  if (!cnew1.empty()) {
81  copy(cnew1.begin(),cnew1.end(),cnew.begin()+p[0]);
82  return cnew;
83  }
84  Vecint cold2(cold.begin(),cold.begin()+p[0]);
85  Vecint cnew2(p[0]);
86  sort(cold.begin(),cold.end());
87  sort(cold2.begin(),cold2.end());
88  cnew2=next_subset(cold,cold2);
89  if (cnew2.empty()) return empty;
90  copy(cnew2.begin(),cnew2.begin()+p[0],cnew.begin());
91  Vecint ss(n1);
92  set_difference(cold.begin(),cold.end(),
93  cnew2.begin(),cnew2.end(),ss.begin());
94  int ip=p[0];
95  for (int i=1;i<k;i++) {
96  if (p[i]!=p[i-1]) {
97  copy(ss.begin(),ss.end(),&cnew[ip]);
98  return cnew;
99  }
100  int mincnew2=cnew2[0];
101  if (ss[n1-1]<mincnew2) return empty;
102  Vecint::iterator j1=find_if(ss.begin(),ss.end(), [&](auto c) { return c > mincnew2;});
103  if (ss.end()-j1 < p[i]) return empty;
104  Vecint sss(j1,ss.end());
105  for (int j=0;j<p[i];j++){cnew[ip+j]=cnew2[j]=sss[j];}
106  int n2=ss.size()-cnew2.size();
107  if (n2==0) return cnew;
108  Vecint s(n2);
109  set_difference(ss.begin(),ss.end(),cnew2.begin(),cnew2.end(),s.begin());
110  ss=s;
111  ip+=p[i];
112  }
113 
114  return empty;
115 
116  };
Vecint next_subset(const Vecint &_g, const Vecint &_c)
def copy(args, dbName)
Partition
Definition: HLTHPDFilter.cc:32
int k[5][pyjets_maxn]
double p1[4]
Definition: TauolaWrapper.h:89
Vecint next_combi(Vecint &cold, int n, const Partition &p)
template<class T >
Combination SequentialCombinationGenerator< T >::next_combination ( Collection coll)
inline

Create combinations obtained by dividing 'coll' according to partition the_part defined by the constructor.

Definition at line 39 of file SequentialCombinationGenerator.h.

References SequentialCombinationGenerator< T >::dbg, relativeConstraints::empty, mps_fire::i, checklumidiff::l, SequentialCombinationGenerator< T >::next_combi(), groupFilesInBlocks::temp, SequentialCombinationGenerator< T >::the_comb, SequentialCombinationGenerator< T >::the_k, SequentialCombinationGenerator< T >::the_n, and SequentialCombinationGenerator< T >::the_part.

40  {
41  dbg=false;
42  Combination comb;
44  the_comb=newcomb;
45  if (newcomb.empty()) {
47  return empty;
48  }
49  int i=0;
50  for (int j=0;j<the_k;j++)
51  {
53  for (int l=0;l<the_part[j];l++)
54  {
55  temp.push_back(coll[the_comb[i]-1]);
56  i++;
57  }
58  comb.push_back(temp);
59  }
60  return comb;
61  };
JetCorrectorParametersCollection coll
Definition: classes.h:10
Vecint next_combi(Vecint &cold, int n, const Partition &p)
template<class T >
Vecint SequentialCombinationGenerator< T >::next_subset ( const Vecint _g,
const Vecint _c 
)
inlineprivate

Definition at line 118 of file SequentialCombinationGenerator.h.

References EnergyCorrector::c, popcon2dropbox::copy(), relativeConstraints::empty, spr::find(), g, diffTwoXMLs::g2, mps_fire::i, gen::k, and gen::n.

Referenced by SequentialCombinationGenerator< T >::next_combi().

119  {
120  Vecint g = _g;
121  Vecint c = _c;
122  Vecint empty;
123  int n=g.size();
124  int k=c.size();
125  typename Vecint::iterator ind;
126  for (int i=k-1;i>=0;i--) {
127  if (c[i]<g[n-k+i]) {
128 
129 
130 // ind=find(&g[0],&g[n-k+i],c[i])+1;
131 
132  Vecint::iterator g2 = g.begin();
133  advance(g2,n-k+i);
134 
135  ind=find(g.begin(),g2,c[i]);
136 
137  ind++;
138 
139 
140 
141  copy(ind,ind+k-i,&c[i]);
142  return c;
143  }
144  }
145  return empty;
146  };
def copy(args, dbName)
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e g
Definition: Activities.doc:4
int k[5][pyjets_maxn]
template<class T >
void SequentialCombinationGenerator< T >::vecprint ( const Vecint v) const
inlineprivate

Definition at line 148 of file SequentialCombinationGenerator.h.

References gather_cfg::cout, mps_fire::i, and gen::n.

149  {
150  int n=v.size();
151  for (int i=0;i<n;std::cout << v[i++]);
152  std::cout << std::endl;
153  };

Member Data Documentation

template<class T >
bool SequentialCombinationGenerator< T >::dbg
mutableprivate
template<class T >
Vecint SequentialCombinationGenerator< T >::the_comb
mutableprivate
template<class T >
int SequentialCombinationGenerator< T >::the_k
private
template<class T >
int SequentialCombinationGenerator< T >::the_n
private
template<class T >
Partition SequentialCombinationGenerator< T >::the_part
private