Assignment Search Framework
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Pages
combinatorics.h
Go to the documentation of this file.
1 /*
2  * combinatorics.h
3  *
4  * LICENSE HERE
5  *
6  * Created on: 2016-08-29
7  * Author: Rick Valenzano
8  */
16 #ifndef COMBINATORICS_H_
17 #define COMBINATORICS_H_
18 
19 #include <vector>
20 #include <stdlib.h>
21 #include <cstdint>
22 #include <string>
23 
44 bool get_next_combo(std::vector<unsigned> &combo, unsigned k, unsigned n, bool first_combo = false);
45 
51 template<class T>
52 void randomly_reorder(std::vector<T> &vec);
53 
62 void get_rand_permutation(std::vector<unsigned> &perm, unsigned size);
63 
72 uint64_t get_64_bit_factorial(unsigned n);
73 
84 uint64_t get64BitnUpperk(unsigned n, unsigned k);
85 
94 bool read_in_permutations(std::string file_name, std::vector<std::vector<unsigned> > &perms);
95 
96 // Templated function implementations
97 template<class T>
98 void randomly_reorder(std::vector<T>& vec)
99 {
100  unsigned pos = vec.size() - 1;
101  // construct new permutation
102  while(pos > 0) {
103  int r = random();
104  int index = r % (pos + 1);
105 
106  T temp = vec[index];
107  vec[index] = vec[pos];
108  vec[pos] = temp;
109 
110  pos--;
111  }
112 }
113 
114 #endif /* COMBINATORICS_H_ */
uint64_t get64BitnUpperk(unsigned n, unsigned k)
Definition: combinatorics.cpp:113
bool get_next_combo(std::vector< unsigned > &combo, unsigned k, unsigned n, bool first_combo=false)
void get_rand_permutation(std::vector< unsigned > &perm, unsigned size)
uint64_t get_64_bit_factorial(unsigned n)
Definition: combinatorics.cpp:106
void randomly_reorder(std::vector< T > &vec)
Definition: combinatorics.h:98
bool read_in_permutations(std::string file_name, std::vector< std::vector< unsigned > > &perms)