permutation.h 670 B

1234567891011121314151617181920212223
  1. #ifndef PERMUTATION_H
  2. #define PERMUTATION_H
  3. #include <vector>
  4. // permutation with fixpoint pi[0]=0
  5. class permutation {
  6. public:
  7. permutation(int size); // initialize to identity
  8. void transpose(int i, int j);
  9. void random();
  10. int operator[](int i); // return the image of i (i and its image 0-based)
  11. bool check(); // check invariant : sigma[0] = 0 and it is a permutation
  12. int get_size();
  13. friend permutation permutation_crossover(permutation &a, permutation &b);
  14. protected:
  15. int size;
  16. std::vector<int> sigma; // sigma[i] is the image of i
  17. };
  18. permutation permutation_crossover(permutation &a, permutation &b);
  19. #endif // PERMUTATION_H