AFLOW
 
Loading...
Searching...
No Matches
aurostd_xcombos.h
Go to the documentation of this file.
1// ***************************************************************************
2// * *
3// * Aflow STEFANO CURTAROLO - Duke University 2003-2024 *
4// * *
5// ***************************************************************************
6
7#ifndef _AUROSTD_XCOMBOS_H_
8#define _AUROSTD_XCOMBOS_H_
9
10#include <vector>
11
12enum algorithm_xcombos { // DX20210111
13 shen_alg_xcombos, // lexicographical order (left to right); Shen, MK. BIT (1962) 2(228). doi:10.1007/BF01940170
14 heap_alg_xcombos // swap left-most positions first (fast); Heap, B.R. (1963): https://en.wikipedia.org/wiki/Heap%27s_algorithm
15};
16
17namespace aurostd {
18 class xcombos {
19 // Written by Corey Oses corey.oses@duke.edu
20 private:
21 // NECESSARY PRIVATE CLASS METHODS - START
22 void free();
23 void copy(const xcombos& b);
24 // NECESSARY PRIVATE CLASS METHODS - END
25
27 std::vector<int> m_input;
29 bool m_sort;
30
32 bool m_exhausted; // all possibilities explored
33 char m_mode; // C: combinations, E: enumeration, P: permutations,
34 algorithm_xcombos m_algorithm; // allow use of different algorithms (Shen, Heap, etc.) //DX20201222
35
36 // for permutations
37 std::vector<int> m_current;
38
39 // for combinations
40 std::vector<int> m_p;
41 int m_x, m_y;
42 bool m_repeat; // Set to true if repetitions are allowed
43
44 // for enumerations
45 std::vector<int> m_sets;
46
52 void getNextEnumeration(); // ME20180529
54 void initialize();
55
56 public:
57 // NECESSARY PUBLIC CLASS METHODS - START
58 // constructors - START
59 xcombos();
60 xcombos(const std::vector<int>& vec, bool sort = true, char mode = 'P', algorithm_xcombos algorithm = shen_alg_xcombos); // permutations //DX20201222 - added algorithm
61 xcombos(int choice_count, int choose_count, char mode = 'C', bool rpt = false); // combinations, m choose n, m=choice_count, n=choose_count
62 xcombos(const std::vector<int>& vec, char mode); // enumerations
63 xcombos(const xcombos& b);
64 // constructors - END
65 ~xcombos();
66 std::vector<int> m_indices; // Keeps track of in which position original indices are in current permutation
67 const xcombos& operator=(const xcombos& other);
69 void reset(); // reset with same parameters
70 void reset(std::vector<int> vec, bool sort = true, char mode = 'P', algorithm_xcombos algorithm = shen_alg_xcombos); // reset with permutations //DX20201222 - added algorithm
71 void reset(int choice_count, int choose_count, char mode = 'C', bool rpt = false); // reset with combinations
72 void reset(std::vector<int> vec, char mode); // reset with enumerations
73 [[nodiscard]] const std::vector<int>& getCombo() const; // grab current possibility - ME20190703 use const & (faster)
74 [[nodiscard]] int getN() const; // grab n (total count)
75 [[nodiscard]] int getM() const; // grab m (choose)
76 [[nodiscard]] std::vector<int> getIndices() const; // get which indicies are 1
77 template <class utype> [[nodiscard]] std::vector<utype> applyCombo(const std::vector<utype>& v_items) const;
78 template <class utype> [[nodiscard]] std::vector<utype> applyCombo(const std::vector<std::vector<utype>>& v_items) const;
79 bool increment(); // nice wrapper for ++, returns m_exhausted
80 // NECESSARY PUBLIC CLASS METHODS - STOP
81 };
82} // namespace aurostd
83
84#endif // _AUROSTD_XCOMBOS_H_
85// ***************************************************************************
86// * *
87// * Aflow STEFANO CURTAROLO - Duke University 2003-2024 *
88// * *
89// ***************************************************************************
algorithm_xcombos
@ heap_alg_xcombos
@ shen_alg_xcombos
void setCombinationsIncrementParameters()
std::vector< int > m_p
const std::vector< int > & getCombo() const
std::vector< int > m_sets
algorithm_xcombos m_algorithm
void getNextEnumerationEqual()
std::vector< int > getIndices() const
std::vector< int > m_indices
void copy(const xcombos &b)
const xcombos & operator=(const xcombos &other)
std::vector< int > m_input
std::vector< int > m_current
std::vector< utype > applyCombo(const std::vector< utype > &v_items) const
utype mode(const xvector< utype > &a)
void sort(vector< utype1 > &arr)