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>&);
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);
131 virtual void clear();
144 virtual void clear();
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);
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);
298 : block_length(1), multiple_pick(false), sub_problem_blocksize(0)
304 : block_length(1), original(oa), multiple_pick(false), sub_problem_blocksize(0)
333 ++this->vector_generated_called_;
334 if((this->start_==-1 || this->vector_generated_called_ >= this->start_) &&
335 (this->end_==-1 || this->vector_generated_called_ < this->end_)) {
336 std::vector<T> newone(toadd.size()*this->block_length);
337 for(
unsigned int i=0; i<toadd.size(); ++i)
338 for(
unsigned int bl=0; bl<this->block_length; ++bl)
339 newone[i*this->block_length+bl]=this->original[toadd[i]*this->block_length+bl];
340 storage.push_back(newone);
355 vector_generated_called_=-1;
358 current_weight.clear();
359 current_weight.resize(weights.size(), 0);
360 for(
unsigned int i=0; i<weights.size(); ++i)
361 assert(weights[i].size() == original.size()/block_length);
362 if(weights.size()>0) {
363 if(weight_conditions.size()==0)
364 weight_conditions.resize(weights.size(), weight_equals);
365 else assert(weight_conditions.size()==weights.size());
367 else assert(weight_conditions.size()==0);
370 assert(sublengths.size()!=0);
371 unsigned int len=sum_of_sublengths();
374 assert(original.size()%block_length==0);
376 assert(len*block_length<=original.size());
378 for(
unsigned int i=0; i<this->input_asym.size(); ++i)
379 std::sort(this->input_asym[i].begin(), this->input_asym[i].
end());
381 temparr=std::vector<unsigned int>(len);
382 std::vector<bool> algehad(original.size()/block_length,
false);
383 nextstep(0,0,0,algehad);
391 this->input_asym.clear();
395 weight_conditions.clear();
396 sub_problem_blocksize=0;
398 current_weight.clear();
424 assert(i<storage.size());
431 return storage.size();
438 for(
unsigned int i=0; i<sublengths.size(); ++i)
446 return vector_generated_called_+1;
453 for(
unsigned int i=0; i<original.size()/block_length; ++i)
454 sublengths.push_back(1);
460 assert(num<storage.size());
462 storage[num].begin(), storage[num].
end(), this->block_length);
474 unsigned long numerator=1;
475 for(
unsigned int i=0; i<this->input_asym.size(); ++i)
476 numerator*=
fact(this->input_asym[i].size());
478 unsigned long denominator=1;
479 for(
unsigned int i=0; i<this->input_asym.size(); ++i) {
482 unsigned int current=0;
483 for(
unsigned int k=0;
k<this->sublengths.size(); ++
k) {
484 if(this->sublengths[
k]>1) {
485 unsigned int overlap=0;
486 for(
unsigned int slc=0; slc<this->sublengths[
k]; ++slc) {
487 for(
unsigned int j=0; j<this->input_asym[i].size(); ++j) {
488 unsigned int index=0;
489 while(!(stor[current]==this->original[index]))
491 if(index==this->input_asym[i][j])
497 denominator*=
fact(overlap);
506 return numerator/denominator;
512 if(weights.size()==0)
return true;
513 for(
unsigned int cn=0; cn<current_weight.size(); ++cn) {
514 if(weight_conditions[cn]==weight_less)
515 if(current_weight[cn]+weights[cn][i] >= max_weights[cn])
524 for(
unsigned int cn=0; cn<current_weight.size(); ++cn) {
525 switch(weight_conditions[cn]) {
527 if(current_weight[cn]!=max_weights[cn])
533 if(current_weight[cn]<=max_weights[cn])
544 if(weights.size()==0)
return;
545 for(
unsigned int cn=0; cn<current_weight.size(); ++cn)
546 current_weight[cn]+=weights[cn][i];
552 if(weights.size()==0)
return;
553 for(
unsigned int cn=0; cn<current_weight.size(); ++cn)
554 current_weight[cn]-=weights[cn][i];
559 std::vector<bool> algehad)
561 unsigned int grouplen=0;
562 for(
unsigned int i=0; i<=groupindex; ++i)
563 grouplen+=sublengths[i];
564 if(current==grouplen) {
566 if(groupindex==sublengths.size()) {
567 if(final_weight_constraints_check())
568 vector_generated(temparr);
574 unsigned int starti=0, endi=original.size()/block_length;
575 if(sub_problem_blocksize>0) {
576 starti=current-current%sub_problem_blocksize;
577 endi=starti+sub_problem_blocksize;
579 for(
unsigned int i=starti; i<endi; i++) {
580 if(!algehad[i] || multiple_pick) {
582 if(is_allowed_by_weight_constraints(i)) {
584 for(
unsigned k=0;
k<this->input_asym.size(); ++
k) {
585 for(
unsigned int kk=0; kk<this->input_asym[
k].size(); ++kk) {
586 if(i==this->input_asym[
k][kk]) {
590 if(!algehad[this->input_asym[
k][k2]]) {
603 if(i+1>lowest_in_group) {
609 if(entry_accepted(current)) {
610 nextstep(current+1, i, groupindex, algehad);
621 : block_length(1), permutation_sign(1), sh_(*this), svh_(*this)
630 permute_blocks.clear();
631 value_permute.clear();
635 sublengths_scattered.clear();
637 multiplicity.clear();
643 std::cout <<
"collecting" << std::endl;
647 std::multimap<long, unsigned int> hashmap;
648 for(
unsigned int i=0; i<originals.size(); ++i)
649 hashmap.insert(std::pair<long, unsigned int>(
hash(originals[i]), i));
652 std::multimap<long, unsigned int>::iterator it=hashmap.begin(), thisbin1, thisbin2, tmpit;
653 while(it!=hashmap.end()) {
654 long current_hash=it->first;
656 while(thisbin1!=hashmap.end() && thisbin1->first==current_hash) {
659 while(thisbin2!=hashmap.end() && thisbin2->first==current_hash) {
660 if(originals[(*thisbin1).second]==originals[(*thisbin2).second]) {
661 multiplicity[(*thisbin1).second]+=multiplicity[(*thisbin2).second];
662 multiplicity[(*thisbin2).second]=0;
665 hashmap.erase(thisbin2);
675 remove_multiplicity_zero();
681 std::vector<std::vector<T> > new_originals;
682 std::vector<int> new_multiplicity;
683 for(
unsigned int k=0;
k<originals.size(); ++
k) {
684 if(multiplicity[
k]!=0) {
685 new_originals.push_back(originals[
k]);
686 new_multiplicity.push_back(multiplicity[
k]);
689 originals=new_originals;
690 multiplicity=new_multiplicity;
697 unsigned int current_length=originals.size();
698 if(current_length==0) {
699 originals.push_back(original);
700 multiplicity.push_back(1);
705 assert(permute_blocks.size()>0 || value_permute.size()>0);
706 assert(sublengths.size()==0 || sublengths_scattered.size()==0);
708 if(permute_blocks.size()==0) {
709 assert(value_permute.size()!=0);
711 if(input_asym.size()==0 && sublengths_scattered.size()==0) {
717 current_=current_length;
719 svh_.original=value_permute;
720 svh_.input_asym.clear();
721 svh_.sublengths=sublengths;
723 if(svh_.sublengths.size()==0)
724 svh_.set_unit_sublengths();
742 for(
unsigned int i=0; i<current_length; ++i) {
745 assert(sublengths.size()==0);
746 std::vector<unsigned int> my_permute_blocks;
749 for(
unsigned int k=0;
k<value_permute.size(); ++
k) {
750 for(
unsigned int m=0; m<originals[i].size(); ++m) {
751 if(originals[i][m]==value_permute[
k]) {
752 my_permute_blocks.push_back(m);
759 if(sublengths_scattered.size()>0) {
763 sh_.sublengths.clear();
764 std::vector<unsigned int> reordered_permute_blocks;
765 for(
unsigned int m=0; m<sublengths_scattered.size(); ++m) {
767 for(
unsigned int mm=0; mm<sublengths_scattered[m].size(); ++mm) {
769 std::vector<unsigned int>::iterator it=my_permute_blocks.begin();
770 while(it!=my_permute_blocks.end()) {
771 if((*it)==sublengths_scattered[m][mm]) {
773 reordered_permute_blocks.push_back(*it);
774 my_permute_blocks.erase(it);
783 sh_.sublengths.push_back(overlap);
785 std::vector<unsigned int>::iterator it=my_permute_blocks.begin();
786 while(it!=my_permute_blocks.end()) {
787 reordered_permute_blocks.push_back(*it);
789 sh_.sublengths.push_back(1);
792 my_permute_blocks=reordered_permute_blocks;
797 for(
unsigned int k=0;
k<my_permute_blocks.size(); ++
k) {
798 for(
unsigned int kk=0; kk<block_length; ++kk) {
799 sh_.original.push_back(originals[i][my_permute_blocks[
k]+kk]);
804 sh_.current_multiplicity=1;
805 if(input_asym.size()>0) {
809 for(
unsigned int k=0;
k<input_asym.size(); ++
k) {
811 for(
unsigned int m=0; m<input_asym[
k].size(); ++m) {
813 for(
unsigned int kk=0; kk<my_permute_blocks.size(); ++kk)
814 if(my_permute_blocks[kk]==input_asym[
k][m]) {
815 newrange.push_back(kk);
819 if(newrange.size()>1) {
820 subprob_input_asym.push_back(newrange);
821 sh_.current_multiplicity*=
fact(newrange.size());
825 if(sh_.sublengths.size()==0)
826 sh_.set_unit_sublengths();
849 permute_blocks=my_permute_blocks;
850 sh_.block_length=block_length;
851 sh_.input_asym=subprob_input_asym;
856 multiplicity[i]*=sh_.current_multiplicity;
857 permute_blocks.clear();
868 assert(value_permute.size()==0);
869 assert(permute_blocks.size()>0);
873 for(
unsigned int i=0; i<current_length; ++i) {
876 for(
unsigned int k=0;
k<permute_blocks.size(); ++
k) {
877 for(
unsigned int kk=0; kk<block_length; ++kk) {
878 sh_.original.push_back(originals[i][permute_blocks[
k]+kk]);
882 assert(sublengths.size()==0);
884 if(sh_.sublengths.size()==0)
885 sh_.set_unit_sublengths();
886 sh_.block_length=block_length;
887 sh_.input_asym=input_asym;
893 originals.erase(originals.begin());
894 multiplicity.erase(multiplicity.begin());
901 assert(i<originals.size());
908 return originals.size();
915 for(
unsigned int i=0; i<values.size(); ++i) {
917 for(
unsigned int j=0; j<value_permute.size(); ++j) {
919 if(value_permute[i]==value_permute[j]) {
932 : current_multiplicity(1), first_one(true), owner_(tt)
946 ++this->vector_generated_called_;
951 if((this->start_==-1 || this->vector_generated_called_ >= this->start_) &&
952 (this->end_==-1 || this->vector_generated_called_ < this->end_)) {
956 for(
unsigned int i=0; i<owner_.current_; ++i) {
958 owner_.originals.push_back(owner_.originals[i]);
961 int multiplicity=owner_.multiplicity[i] * current_multiplicity;
962 if(owner_.permutation_sign==-1)
963 multiplicity*=
ordersign(vec.begin(), vec.end());
964 owner_.multiplicity.push_back(multiplicity);
968 unsigned int loc=owner_.originals.size()-1;
969 for(
unsigned int j=0; j<vec.size(); ++j) {
970 for(
unsigned int k=0;
k<owner_.originals[i].size(); ++
k) {
971 if(owner_.originals[i][
k]==this->original[j]) {
972 owner_.originals[loc][
k]=this->original[vec[j]];
984 : current_multiplicity(1), first_one(true), owner_(tt)
998 assert(i<multiplicity.size());
999 return multiplicity[i];
1005 assert(i<multiplicity.size());
1006 multiplicity[i]=val;
1012 ++this->vector_generated_called_;
1017 if((this->start_==-1 || this->vector_generated_called_ >= this->start_) &&
1018 (this->end_==-1 || this->vector_generated_called_ < this->end_)) {
1026 owner_.originals.push_back(owner_.originals[owner_.current_]);
1027 unsigned int siz=owner_.originals.size()-1;
1030 int multiplicity=owner_.multiplicity[owner_.current_] * current_multiplicity;
1031 if(owner_.permutation_sign==-1)
1032 multiplicity*=
ordersign(vec.begin(), vec.end());
1033 owner_.multiplicity.push_back(multiplicity);
1035 for(
unsigned int k=0;
k<owner_.permute_blocks.size(); ++
k) {
1036 for(
unsigned int kk=0; kk<owner_.block_length; ++kk) {
1037 assert(owner_.permute_blocks[
k]+kk<owner_.originals[0].size());
1038 owner_.originals[siz][owner_.permute_blocks[
k]+kk]=
1039 owner_.originals[owner_.current_][owner_.permute_blocks[vec[
k]]+kk];
1049 for(
unsigned int i=0; i<sym.
size(); ++i) {
1050 for(
unsigned int j=0; j<sym[i].
size(); ++j) {
1051 str << sym[i][j] <<
" ";
1054 str.setf(std::ios::right, std::ios::adjustfield);
1055 str << std::setw(2) << sym.
signature(i) << std::endl;
Definition: Combinatorics.hh:57
unsigned int block_length
Definition: Combinatorics.hh:73
std::vector< unsigned int > sublengths
Definition: Combinatorics.hh:74
virtual void vector_generated(const std::vector< unsigned int > &)=0
bool multiple_pick
Definition: Combinatorics.hh:77
bool final_weight_constraints_check() const
Definition: Combinatorics.hh:522
void set_unit_sublengths()
Definition: Combinatorics.hh:450
long start_
Definition: Combinatorics.hh:88
virtual void clear()
Definition: Combinatorics.hh:387
std::vector< weights_t > weights
Definition: Combinatorics.hh:78
bool is_allowed_by_weight_constraints(unsigned int i)
Definition: Combinatorics.hh:510
std::vector< unsigned int > temparr
Definition: Combinatorics.hh:86
std::vector< weight_cond > weight_conditions
Definition: Combinatorics.hh:80
unsigned int multiplier(const std::vector< T > &) const
Definition: Combinatorics.hh:472
combinations_base()
Definition: Combinatorics.hh:297
std::vector< int > current_weight
Definition: Combinatorics.hh:89
unsigned int total_permutations() const
Definition: Combinatorics.hh:444
std::vector< int > max_weights
Definition: Combinatorics.hh:79
long vector_generated_called_
Definition: Combinatorics.hh:88
unsigned int sub_problem_blocksize
Definition: Combinatorics.hh:81
virtual void clear_results()
Definition: Combinatorics.hh:402
virtual ~combinations_base()
Definition: Combinatorics.hh:321
long end_
Definition: Combinatorics.hh:88
void nextstep(unsigned int current, unsigned int fromalgehad, unsigned int groupindex, std::vector< bool > algehad)
Definition: Combinatorics.hh:558
void update_weights(unsigned int i)
Definition: Combinatorics.hh:542
unsigned int sum_of_sublengths() const
Definition: Combinatorics.hh:435
range_vector_t input_asym
Definition: Combinatorics.hh:75
void restore_weights(unsigned int i)
Definition: Combinatorics.hh:550
virtual bool entry_accepted(unsigned int current) const
Definition: Combinatorics.hh:345
std::vector< T > original
Definition: Combinatorics.hh:76
void permute(long start=-1, long end=-1)
Definition: Combinatorics.hh:351
weight_cond
Definition: Combinatorics.hh:71
@ weight_equals
Definition: Combinatorics.hh:71
@ weight_greater
Definition: Combinatorics.hh:71
@ weight_less
Definition: Combinatorics.hh:71
Definition: Combinatorics.hh:101
permuted_sets_t::const_iterator const_iterator
Definition: Combinatorics.hh:104
int ordersign(unsigned int) const
Definition: Combinatorics.hh:458
virtual ~combinations()
Definition: Combinatorics.hh:326
unsigned int size() const
Definition: Combinatorics.hh:429
const std::vector< T > & operator[](unsigned int) const
Definition: Combinatorics.hh:422
virtual void clear()
Definition: Combinatorics.hh:408
combinations()
Definition: Combinatorics.hh:309
virtual void vector_generated(const std::vector< unsigned int > &)
Definition: Combinatorics.hh:331
std::vector< std::vector< T > > permuted_sets_t
Definition: Combinatorics.hh:103
virtual void clear_results()
Definition: Combinatorics.hh:415
permuted_sets_t storage
Definition: Combinatorics.hh:121
combinations(const std::vector< T > &)
Definition: Combinatorics.hh:315
unsigned int multiplier(unsigned int) const
Definition: Combinatorics.hh:466
Definition: Combinatorics.hh:128
symm_helper(symmetriser< T > &)
Definition: Combinatorics.hh:983
symmetriser< T > & owner_
Definition: Combinatorics.hh:136
bool first_one
Definition: Combinatorics.hh:135
int current_multiplicity
Definition: Combinatorics.hh:133
virtual void vector_generated(const std::vector< unsigned int > &)
Definition: Combinatorics.hh:1010
virtual void clear()
Definition: Combinatorics.hh:989
Definition: Combinatorics.hh:141
int current_multiplicity
Definition: Combinatorics.hh:146
symm_val_helper(symmetriser< T > &)
Definition: Combinatorics.hh:931
bool first_one
Definition: Combinatorics.hh:148
virtual void clear()
Definition: Combinatorics.hh:937
virtual void vector_generated(const std::vector< unsigned int > &)
Definition: Combinatorics.hh:944
symmetriser< T > & owner_
Definition: Combinatorics.hh:149
Definition: Combinatorics.hh:154
unsigned int size() const
Definition: Combinatorics.hh:906
void clear()
Definition: Combinatorics.hh:626
std::vector< std::vector< T > > originals
Definition: Combinatorics.hh:188
void apply_symmetry(long start=-1, long end=-1)
Definition: Combinatorics.hh:695
symm_helper< T > sh_
Definition: Combinatorics.hh:185
unsigned int current_
Definition: Combinatorics.hh:187
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:912
std::vector< unsigned int > sublengths
Definition: Combinatorics.hh:165
int permutation_sign
Definition: Combinatorics.hh:163
range_vector_t sublengths_scattered
Definition: Combinatorics.hh:167
std::vector< unsigned int > permute_blocks
Definition: Combinatorics.hh:161
std::vector< T > original
Definition: Combinatorics.hh:159
symmetriser()
Definition: Combinatorics.hh:620
range_vector_t input_asym
Definition: Combinatorics.hh:166
std::vector< int > multiplicity
Definition: Combinatorics.hh:189
void collect()
Collect equal entries, and adjust the multiplier field accordingly.
Definition: Combinatorics.hh:641
std::vector< T > value_permute
Definition: Combinatorics.hh:162
void remove_multiplicity_zero()
Definition: Combinatorics.hh:679
const std::vector< T > & operator[](unsigned int) const
Definition: Combinatorics.hh:899
void set_multiplicity(unsigned int pos, int val)
Definition: Combinatorics.hh:1003
unsigned int block_length
Definition: Combinatorics.hh:160
int signature(unsigned int) const
Definition: Combinatorics.hh:996
symm_val_helper< T > svh_
Definition: Combinatorics.hh:186
Definition: Combinatorics.hh:37
std::vector< range_t > range_vector_t
Definition: Combinatorics.hh:40
int determine_intersection_ranges(const range_vector_t &prod, const range_vector_t &indv, range_vector_t &target)
Definition: Combinatorics.cc:32
unsigned long factorial(unsigned int x)
Definition: Combinatorics.cc:23
std::vector< unsigned int > range_t
Definition: Combinatorics.hh:39
unsigned long vector_prod_fact(const std::vector< unsigned int > &)
product of factorials of elements
Definition: Combinatorics.cc:72
std::vector< int > weights_t
Definition: Combinatorics.hh:41
unsigned long vector_prod(const std::vector< unsigned int > &)
product of elements
Definition: Combinatorics.cc:64
std::ostream & operator<<(std::ostream &str, const symmetriser< T > &sym)
Definition: Combinatorics.hh:1047
T fact(T x)
Definition: Combinatorics.hh:283
long vector_sum(const std::vector< int > &)
sum of elements
Definition: Combinatorics.cc:56
bool operator==(const std::vector< unsigned int > &, const std::vector< unsigned int > &)
Definition: Combinatorics.cc:80
long hash(const std::vector< unsigned int > &)
compute a hash value for a vector of unsigned ints
Definition: Combinatorics.cc:90
int ordersign(iterator1 b1, iterator1 e1, iterator2 b2, iterator2 e2, int stepsize=1)
Definition: Combinatorics.hh:224
end
Definition: nevaluate.py:22
start
Definition: nevaluate.py:20
int k
Definition: passing.cc:4