// // Created by Brady Bodily on 3/28/20. // #include "MakePermutationMatrix.h" std::vector> MakePermutationMatrix::MakePermutation(std::vector source, int rank, int size) { std::vector> permutations; std::sort(source.begin(), source.end()); std::vector myPerm = source; std::vector nextPerm = source; auto offset = myPerm.size()/size; if(!rank) std::rotate(nextPerm.begin(), nextPerm.begin()+offset*(rank+1), nextPerm.end()); else nextPerm = source; if(!rank) std::rotate(myPerm.begin(), myPerm.begin()+offset*rank,myPerm.end()); do { std::vector currentPerm; for (int i = 0; i < myPerm.size(); i++) { currentPerm.push_back(myPerm[i]); } permutations.push_back(currentPerm); } while (std::next_permutation(myPerm.begin(), myPerm.end()), myPerm != nextPerm); return permutations; }