CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 filterCSVwithJSON::copy, relativeConstraints::empty, i, j, gen::k, n, SequentialCombinationGenerator< T >::next_subset(), p1, alignCSCRings::s, python.multivaluedict::sort(), and contentValuesCheck::ss.

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

65  {
66  Vecint empty;
67  if (cold.size()==0) { // 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.size()!=0) {
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.size()==0) 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(),bind2nd(std::greater<int>(),mincnew2));
103  if (ss.end()-j1 < p[i]) return empty;
104  Vecint sss(j1,ss.end());
105  for (int j=0;j<p[i];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  };
int i
Definition: DBlmapReader.cc:9
Vecint next_subset(const Vecint &_g, const Vecint &_c)
Partition
Definition: HLTHPDFilter.cc:32
int j
Definition: DBlmapReader.cc:9
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 bookConverter::comb, SequentialCombinationGenerator< T >::dbg, relativeConstraints::empty, i, j, ConfigFiles::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;
44  the_comb=newcomb;
45  if (newcomb.size()==0) {
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  };
int i
Definition: DBlmapReader.cc:9
dictionary comb
int j
Definition: DBlmapReader.cc:9
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 trackerHits::c, filterCSVwithJSON::copy, relativeConstraints::empty, spr::find(), g, diffTwoXMLs::g2, i, gen::k, and 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  };
int i
Definition: DBlmapReader.cc:9
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
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, i, and n.

149  {
150  int n=v.size();
151  for (int i=0;i<n;std::cout << v[i++]);
152  std::cout << std::endl;
153  };
int i
Definition: DBlmapReader.cc:9
tuple cout
Definition: gather_cfg.py:121

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