39 typedef std::vector<unsigned int>
range_t;
47 unsigned long vector_prod(
const std::vector<unsigned int>&);
51 bool operator==(
const std::vector<unsigned int>&,
const std::vector<unsigned int>&);
54 long hash(
const std::vector<unsigned int>&);
63 void permute(
long start=-1,
long end=-1);
68 unsigned int multiplier(
const std::vector<T>&)
const;
95 void nextstep(
unsigned int current,
unsigned int fromalgehad,
unsigned int groupindex,
96 std::vector<bool> algehad);
110 virtual void clear();
112 const std::vector<T>&
operator[](
unsigned int)
const;
114 unsigned int size()
const;
131 virtual void clear();
144 virtual void clear();
173 const std::vector<T>&
operator[](
unsigned int)
const;
176 unsigned int size()
const;
196 template<
class iterator1,
class iterator2>
197 int ordersign(iterator1 b1, iterator1 e1, iterator2 b2, iterator2 e2,
int stepsize=1);
199 template<
class iterator1>
200 int ordersign(iterator1 b1, iterator1 e1);
206 std::ostream& operator<<(std::ostream& str, const symmetriser<T>& sym);
223 template<
class iterator1,
class iterator2>
224 int ordersign(iterator1 b1, iterator1 e1, iterator2 b2, iterator2 e2,
int stepsize)
227 std::vector<bool> crossedoff(std::distance(b1,e1),
false);
232 if( (*it)==(*b1) && crossedoff[otherpos]==
false) {
233 crossedoff[otherpos]=
true;
237 if(!crossedoff[otherpos])
273 template<
class iterator1>
276 std::vector<unsigned int> fil;
277 for(
int k=0;
k<distance(b1,e1); ++
k)
279 return ordersign(fil.begin(), fil.end(), b1, e1);
287 while(x!=0) { ret*=x--; }
296 : block_length(1), multiple_pick(false), sub_problem_blocksize(0)
302 : block_length(1), original(oa), multiple_pick(false), sub_problem_blocksize(0)
331 ++this->vector_generated_called_;
332 if((this->start_==-1 || this->vector_generated_called_ >= this->start_) &&
333 (this->end_==-1 || this->vector_generated_called_ < this->end_)) {
334 std::vector<T> newone(toadd.size()*this->block_length);
335 for(
unsigned int i=0; i<toadd.size(); ++i)
336 for(
unsigned int bl=0; bl<this->block_length; ++bl)
337 newone[i*this->block_length+bl]=this->original[toadd[i]*this->block_length+bl];
338 storage.push_back(newone);
353 vector_generated_called_=-1;
356 current_weight.clear();
357 current_weight.resize(weights.size(), 0);
358 for(
unsigned int i=0; i<weights.size(); ++i)
359 assert(weights[i].size() == original.size()/block_length);
360 if(weights.size()>0) {
361 if(weight_conditions.size()==0)
362 weight_conditions.resize(weights.size(), weight_equals);
363 else assert(weight_conditions.size()==weights.size());
365 else assert(weight_conditions.size()==0);
368 assert(sublengths.size()!=0);
369 unsigned int len=sum_of_sublengths();
372 assert(original.size()%block_length==0);
374 assert(len*block_length<=original.size());
376 for(
unsigned int i=0; i<this->input_asym.size(); ++i)
377 std::sort(this->input_asym[i].begin(), this->input_asym[i].end());
379 temparr=std::vector<unsigned int>(len);
380 std::vector<bool> algehad(original.size()/block_length,
false);
381 nextstep(0,0,0,algehad);
389 this->input_asym.clear();
393 weight_conditions.clear();
394 sub_problem_blocksize=0;
396 current_weight.clear();
422 assert(i<storage.size());
429 return storage.size();
436 for(
unsigned int i=0; i<sublengths.size(); ++i)
444 return vector_generated_called_+1;
451 for(
unsigned int i=0; i<original.size()/block_length; ++i)
452 sublengths.push_back(1);
458 assert(num<storage.size());
460 storage[num].begin(), storage[num].end(), this->block_length);
472 unsigned long numerator=1;
473 for(
unsigned int i=0; i<this->input_asym.size(); ++i)
474 numerator*=
fact(this->input_asym[i].size());
476 unsigned long denominator=1;
477 for(
unsigned int i=0; i<this->input_asym.size(); ++i) {
480 unsigned int current=0;
481 for(
unsigned int k=0;
k<this->sublengths.size(); ++
k) {
482 if(this->sublengths[
k]>1) {
483 unsigned int overlap=0;
484 for(
unsigned int slc=0; slc<this->sublengths[
k]; ++slc) {
485 for(
unsigned int j=0; j<this->input_asym[i].size(); ++j) {
486 unsigned int index=0;
487 while(!(stor[current]==this->original[index]))
489 if(index==this->input_asym[i][j])
495 denominator*=
fact(overlap);
504 return numerator/denominator;
510 if(weights.size()==0)
return true;
511 for(
unsigned int cn=0; cn<current_weight.size(); ++cn) {
512 if(weight_conditions[cn]==weight_less)
513 if(current_weight[cn]+weights[cn][i] >= max_weights[cn])
522 for(
unsigned int cn=0; cn<current_weight.size(); ++cn) {
523 switch(weight_conditions[cn]) {
525 if(current_weight[cn]!=max_weights[cn])
531 if(current_weight[cn]<=max_weights[cn])
542 if(weights.size()==0)
return;
543 for(
unsigned int cn=0; cn<current_weight.size(); ++cn)
544 current_weight[cn]+=weights[cn][i];
550 if(weights.size()==0)
return;
551 for(
unsigned int cn=0; cn<current_weight.size(); ++cn)
552 current_weight[cn]-=weights[cn][i];
557 std::vector<bool> algehad)
559 unsigned int grouplen=0;
560 for(
unsigned int i=0; i<=groupindex; ++i)
561 grouplen+=sublengths[i];
562 if(current==grouplen) {
564 if(groupindex==sublengths.size()) {
565 if(final_weight_constraints_check())
566 vector_generated(temparr);
572 unsigned int starti=0, endi=original.size()/block_length;
573 if(sub_problem_blocksize>0) {
574 starti=current-current%sub_problem_blocksize;
575 endi=starti+sub_problem_blocksize;
577 for(
unsigned int i=starti; i<endi; i++) {
578 if(!algehad[i] || multiple_pick) {
580 if(is_allowed_by_weight_constraints(i)) {
582 for(
unsigned k=0;
k<this->input_asym.size(); ++
k) {
583 for(
unsigned int kk=0; kk<this->input_asym[
k].size(); ++kk) {
584 if(i==this->input_asym[
k][kk]) {
588 if(!algehad[this->input_asym[
k][k2]]) {
601 if(i+1>lowest_in_group) {
607 if(entry_accepted(current)) {
608 nextstep(current+1, i, groupindex, algehad);
619 : block_length(1), permutation_sign(1), sh_(*this), svh_(*this)
628 permute_blocks.clear();
629 value_permute.clear();
633 sublengths_scattered.clear();
635 multiplicity.clear();
641 std::cout <<
"collecting" << std::endl;
645 std::multimap<long, unsigned int> hashmap;
646 for(
unsigned int i=0; i<originals.size(); ++i)
647 hashmap.insert(std::pair<long, unsigned int>(
hash(originals[i]), i));
650 std::multimap<long, unsigned int>::iterator it=hashmap.begin(), thisbin1, thisbin2, tmpit;
651 while(it!=hashmap.end()) {
652 long current_hash=it->first;
654 while(thisbin1!=hashmap.end() && thisbin1->first==current_hash) {
657 while(thisbin2!=hashmap.end() && thisbin2->first==current_hash) {
658 if(originals[(*thisbin1).second]==originals[(*thisbin2).second]) {
659 multiplicity[(*thisbin1).second]+=multiplicity[(*thisbin2).second];
660 multiplicity[(*thisbin2).second]=0;
663 hashmap.erase(thisbin2);
673 remove_multiplicity_zero();
679 std::vector<std::vector<T> > new_originals;
680 std::vector<int> new_multiplicity;
681 for(
unsigned int k=0;
k<originals.size(); ++
k) {
682 if(multiplicity[
k]!=0) {
683 new_originals.push_back(originals[
k]);
684 new_multiplicity.push_back(multiplicity[k]);
687 originals=new_originals;
688 multiplicity=new_multiplicity;
695 unsigned int current_length=originals.size();
696 if(current_length==0) {
697 originals.push_back(original);
698 multiplicity.push_back(1);
703 assert(permute_blocks.size()>0 || value_permute.size()>0);
704 assert(sublengths.size()==0 || sublengths_scattered.size()==0);
706 if(permute_blocks.size()==0) {
707 assert(value_permute.size()!=0);
709 if(input_asym.size()==0 && sublengths_scattered.size()==0) {
715 current_=current_length;
717 svh_.original=value_permute;
718 svh_.input_asym.clear();
719 svh_.sublengths=sublengths;
721 if(svh_.sublengths.size()==0)
722 svh_.set_unit_sublengths();
724 svh_.permute(start, end);
740 for(
unsigned int i=0; i<current_length; ++i) {
743 assert(sublengths.size()==0);
744 std::vector<unsigned int> my_permute_blocks;
747 for(
unsigned int k=0;
k<value_permute.size(); ++
k) {
748 for(
unsigned int m=0; m<originals[i].size(); ++m) {
749 if(originals[i][m]==value_permute[
k]) {
750 my_permute_blocks.push_back(m);
757 if(sublengths_scattered.size()>0) {
761 sh_.sublengths.clear();
762 std::vector<unsigned int> reordered_permute_blocks;
763 for(
unsigned int m=0; m<sublengths_scattered.size(); ++m) {
765 for(
unsigned int mm=0; mm<sublengths_scattered[m].size(); ++mm) {
767 std::vector<unsigned int>::iterator it=my_permute_blocks.begin();
768 while(it!=my_permute_blocks.end()) {
769 if((*it)==sublengths_scattered[m][mm]) {
771 reordered_permute_blocks.push_back(*it);
772 my_permute_blocks.erase(it);
781 sh_.sublengths.push_back(overlap);
783 std::vector<unsigned int>::iterator it=my_permute_blocks.begin();
784 while(it!=my_permute_blocks.end()) {
785 reordered_permute_blocks.push_back(*it);
787 sh_.sublengths.push_back(1);
790 my_permute_blocks=reordered_permute_blocks;
795 for(
unsigned int k=0;
k<my_permute_blocks.size(); ++
k) {
796 for(
unsigned int kk=0; kk<block_length; ++kk) {
797 sh_.original.push_back(originals[i][my_permute_blocks[
k]+kk]);
802 sh_.current_multiplicity=1;
803 if(input_asym.size()>0) {
807 for(
unsigned int k=0;
k<input_asym.size(); ++
k) {
809 for(
unsigned int m=0; m<input_asym[
k].size(); ++m) {
811 for(
unsigned int kk=0; kk<my_permute_blocks.size(); ++kk)
812 if(my_permute_blocks[kk]==input_asym[
k][m]) {
813 newrange.push_back(kk);
817 if(newrange.size()>1) {
818 subprob_input_asym.push_back(newrange);
819 sh_.current_multiplicity*=
fact(newrange.size());
823 if(sh_.sublengths.size()==0)
824 sh_.set_unit_sublengths();
847 permute_blocks=my_permute_blocks;
848 sh_.block_length=block_length;
849 sh_.input_asym=subprob_input_asym;
850 sh_.permute(start, end);
854 multiplicity[i]*=sh_.current_multiplicity;
855 permute_blocks.clear();
866 assert(value_permute.size()==0);
867 assert(permute_blocks.size()>0);
871 for(
unsigned int i=0; i<current_length; ++i) {
874 for(
unsigned int k=0;
k<permute_blocks.size(); ++
k) {
875 for(
unsigned int kk=0; kk<block_length; ++kk) {
876 sh_.original.push_back(originals[i][permute_blocks[
k]+kk]);
880 assert(sublengths.size()==0);
882 if(sh_.sublengths.size()==0)
883 sh_.set_unit_sublengths();
884 sh_.block_length=block_length;
885 sh_.input_asym=input_asym;
886 sh_.permute(start, end);
891 originals.erase(originals.begin());
892 multiplicity.erase(multiplicity.begin());
899 assert(i<originals.size());
906 return originals.size();
913 for(
unsigned int i=0; i<values.size(); ++i) {
915 for(
unsigned int j=0; j<value_permute.size(); ++j) {
917 if(value_permute[i]==value_permute[j]) {
930 : current_multiplicity(1), first_one(true), owner_(tt)
944 ++this->vector_generated_called_;
949 if((this->start_==-1 || this->vector_generated_called_ >= this->start_) &&
950 (this->end_==-1 || this->vector_generated_called_ < this->end_)) {
954 for(
unsigned int i=0; i<owner_.current_; ++i) {
956 owner_.originals.push_back(owner_.originals[i]);
959 int multiplicity=owner_.multiplicity[i] * current_multiplicity;
960 if(owner_.permutation_sign==-1)
961 multiplicity*=
ordersign(vec.begin(), vec.end());
962 owner_.multiplicity.push_back(multiplicity);
966 unsigned int loc=owner_.originals.size()-1;
967 for(
unsigned int j=0; j<vec.size(); ++j) {
968 for(
unsigned int k=0;
k<owner_.originals[i].size(); ++
k) {
969 if(owner_.originals[i][
k]==this->original[j]) {
970 owner_.originals[loc][
k]=this->original[vec[j]];
982 : current_multiplicity(1), first_one(true), owner_(tt)
996 assert(i<multiplicity.size());
997 return multiplicity[i];
1003 assert(i<multiplicity.size());
1004 multiplicity[i]=val;
1010 ++this->vector_generated_called_;
1015 if((this->start_==-1 || this->vector_generated_called_ >= this->start_) &&
1016 (this->end_==-1 || this->vector_generated_called_ < this->end_)) {
1024 owner_.originals.push_back(owner_.originals[owner_.current_]);
1025 unsigned int siz=owner_.originals.size()-1;
1028 int multiplicity=owner_.multiplicity[owner_.current_] * current_multiplicity;
1029 if(owner_.permutation_sign==-1)
1030 multiplicity*=
ordersign(vec.begin(), vec.end());
1031 owner_.multiplicity.push_back(multiplicity);
1033 for(
unsigned int k=0;
k<owner_.permute_blocks.size(); ++
k) {
1034 for(
unsigned int kk=0; kk<owner_.block_length; ++kk) {
1035 assert(owner_.permute_blocks[
k]+kk<owner_.originals[0].size());
1036 owner_.originals[siz][owner_.permute_blocks[
k]+kk]=
1037 owner_.originals[owner_.current_][owner_.permute_blocks[vec[
k]]+kk];
1045 std::ostream& operator<<(std::ostream& str, const symmetriser<T>& sym)
1047 for(
unsigned int i=0; i<sym.size(); ++i) {
1048 for(
unsigned int j=0; j<sym[i].size(); ++j) {
1049 str << sym[i][j] <<
" ";
1052 str.setf(std::ios::right, std::ios::adjustfield);
1053 str << std::setw(2) << sym.signature(i) << std::endl;
void nextstep(unsigned int current, unsigned int fromalgehad, unsigned int groupindex, std::vector< bool > algehad)
Definition: Combinatorics.hh:556
virtual void clear()
Definition: Combinatorics.hh:406
const std::vector< T > & operator[](unsigned int) const
Definition: Combinatorics.hh:897
virtual void vector_generated(const std::vector< unsigned int > &)
Definition: Combinatorics.hh:329
virtual ~combinations_base()
Definition: Combinatorics.hh:319
const std::vector< T > & operator[](unsigned int) const
Definition: Combinatorics.hh:420
long vector_generated_called_
Definition: Combinatorics.hh:88
range_vector_t sublengths_scattered
Definition: Combinatorics.hh:167
std::vector< std::vector< T > > permuted_sets_t
Definition: Combinatorics.hh:103
std::vector< weight_cond > weight_conditions
Definition: Combinatorics.hh:80
bool first_one
Definition: Combinatorics.hh:135
virtual void clear_results()
Definition: Combinatorics.hh:400
Definition: Combinatorics.hh:141
virtual bool entry_accepted(unsigned int current) const
Definition: Combinatorics.hh:343
virtual void vector_generated(const std::vector< unsigned int > &)
Definition: Combinatorics.hh:1008
Definition: Combinatorics.hh:71
Definition: Combinatorics.hh:125
std::vector< int > current_weight
Definition: Combinatorics.hh:89
int permutation_sign
Definition: Combinatorics.hh:163
symmetriser< T > & owner_
Definition: Combinatorics.hh:149
range_vector_t input_asym
Definition: Combinatorics.hh:75
permuted_sets_t::const_iterator const_iterator
Definition: Combinatorics.hh:104
unsigned long factorial(unsigned int x)
Definition: Combinatorics.cc:23
std::vector< unsigned int > sublengths
Definition: Combinatorics.hh:165
virtual void clear()
Definition: Combinatorics.hh:385
unsigned int block_length
Definition: Combinatorics.hh:160
Definition: Combinatorics.hh:128
weight_cond
Definition: Combinatorics.hh:71
std::vector< unsigned int > permute_blocks
Definition: Combinatorics.hh:161
int ordersign(unsigned int) const
Definition: Combinatorics.hh:456
std::vector< unsigned int > range_t
Definition: Combinatorics.hh:39
bool multiple_pick
Definition: Combinatorics.hh:77
symm_val_helper(symmetriser< T > &)
Definition: Combinatorics.hh:929
void permute(long start=-1, long end=-1)
Definition: Combinatorics.hh:349
Definition: Combinatorics.hh:71
unsigned int size() const
Definition: Combinatorics.hh:427
std::vector< std::vector< T > > originals
Definition: Combinatorics.hh:188
std::vector< T > value_permute
Definition: Combinatorics.hh:162
long vector_sum(const std::vector< int > &)
sum of elements
Definition: Combinatorics.cc:54
int current_multiplicity
Definition: Combinatorics.hh:133
std::vector< weights_t > weights
Definition: Combinatorics.hh:78
std::vector< unsigned int > sublengths
Definition: Combinatorics.hh:74
bool final_weight_constraints_check() const
Definition: Combinatorics.hh:520
void remove_multiplicity_zero()
Definition: Combinatorics.hh:677
symm_helper(symmetriser< T > &)
Definition: Combinatorics.hh:981
long hash(const std::vector< unsigned int > &)
compute a hash value for a vector of unsigned ints
Definition: Combinatorics.cc:88
virtual void clear()
Definition: Combinatorics.hh:935
virtual void clear_results()
Definition: Combinatorics.hh:413
long end_
Definition: Combinatorics.hh:88
std::vector< T > original
Definition: Combinatorics.hh:159
symm_helper< T > sh_
Definition: Combinatorics.hh:185
void update_weights(unsigned int i)
Definition: Combinatorics.hh:540
bool operator==(const std::vector< unsigned int > &, const std::vector< unsigned int > &)
Definition: Combinatorics.cc:78
unsigned int multiplier(const std::vector< T > &) const
Definition: Combinatorics.hh:470
unsigned long vector_prod_fact(const std::vector< unsigned int > &)
product of factorials of elements
Definition: Combinatorics.cc:70
unsigned int current_
Definition: Combinatorics.hh:187
symm_val_helper< T > svh_
Definition: Combinatorics.hh:186
T fact(T x)
Definition: Combinatorics.hh:283
permuted_sets_t storage
Definition: Combinatorics.hh:121
Definition: Combinatorics.hh:57
int k
Definition: passing.cc:4
int determine_intersection_ranges(const range_vector_t &prod, const range_vector_t &indv, range_vector_t &target)
Definition: Combinatorics.cc:30
combinations_base()
Definition: Combinatorics.hh:295
virtual void vector_generated(const std::vector< unsigned int > &)
Definition: Combinatorics.hh:942
void apply_symmetry(long start=-1, long end=-1)
Definition: Combinatorics.hh:693
symmetriser()
Definition: Combinatorics.hh:618
void collect()
Collect equal entries, and adjust the multiplier field accordingly.
Definition: Combinatorics.hh:639
std::vector< T > original
Definition: Combinatorics.hh:76
unsigned int sub_problem_blocksize
Definition: Combinatorics.hh:81
unsigned int size() const
Definition: Combinatorics.hh:904
bool first_one
Definition: Combinatorics.hh:148
void set_unit_sublengths()
Definition: Combinatorics.hh:448
unsigned int sum_of_sublengths() const
Definition: Combinatorics.hh:433
void set_multiplicity(unsigned int pos, int val)
Definition: Combinatorics.hh:1001
long start_
Definition: Combinatorics.hh:88
int current_multiplicity
Definition: Combinatorics.hh:146
int signature(unsigned int) const
Definition: Combinatorics.hh:994
std::vector< int > max_weights
Definition: Combinatorics.hh:79
combinations()
Definition: Combinatorics.hh:307
unsigned int block_length
Definition: Combinatorics.hh:73
std::vector< unsigned int > temparr
Definition: Combinatorics.hh:86
Definition: Combinatorics.hh:101
std::vector< range_t > range_vector_t
Definition: Combinatorics.hh:40
Definition: Combinatorics.hh:71
bool is_allowed_by_weight_constraints(unsigned int i)
Definition: Combinatorics.hh:508
std::vector< int > weights_t
Definition: Combinatorics.hh:41
unsigned long vector_prod(const std::vector< unsigned int > &)
product of elements
Definition: Combinatorics.cc:62
virtual ~combinations()
Definition: Combinatorics.hh:324
void restore_weights(unsigned int i)
Definition: Combinatorics.hh:548
symmetriser< T > & owner_
Definition: Combinatorics.hh:136
void clear()
Definition: Combinatorics.hh:624
unsigned int total_permutations() const
Definition: Combinatorics.hh:442
range_t values_to_locations(const std::vector< T > &values) const
Convert vectors of values to vectors of locations in the original (mainly useful to create input_asym...
Definition: Combinatorics.hh:910
unsigned int multiplier(unsigned int) const
Definition: Combinatorics.hh:464
virtual void vector_generated(const std::vector< unsigned int > &)=0
int ordersign(iterator1 b1, iterator1 e1, iterator2 b2, iterator2 e2, int stepsize=1)
Definition: Combinatorics.hh:224
virtual void clear()
Definition: Combinatorics.hh:987
std::vector< int > multiplicity
Definition: Combinatorics.hh:189
range_vector_t input_asym
Definition: Combinatorics.hh:166