|
@@ -3,7 +3,6 @@
|
|
|
#include <cstdlib> // rand
|
|
|
#include <cassert>
|
|
|
|
|
|
-// TODO faut-il pi[0] = 0 et pourquoi ???
|
|
|
permutation::permutation(int size) : size(size) {
|
|
|
assert(size > 0);
|
|
|
sigma = new int[size];
|
|
@@ -12,17 +11,17 @@ permutation::permutation(int size) : size(size) {
|
|
|
}
|
|
|
|
|
|
void permutation::transpose(int i, int j) {
|
|
|
- assert(0 <= i && i < size);
|
|
|
- assert(0 <= j && j < size);
|
|
|
+ assert(0 < i && i < size);
|
|
|
+ assert(0 < j && j < size);
|
|
|
std::swap(sigma[i], sigma[j]);
|
|
|
}
|
|
|
|
|
|
+// TODO rapport : dire qu'on garde l'invariant pi[0] = 0
|
|
|
void permutation::random() {
|
|
|
// Knuth shuffle
|
|
|
- // TODO algo plus efficace ?
|
|
|
// there is a bias due to the use of rand()%_
|
|
|
- for(int i = 0; i < size; i++)
|
|
|
- transpose(i, rand()%(i+1));
|
|
|
+ for(int i = 1; i < size; i++)
|
|
|
+ transpose(i, 1+rand()%i);
|
|
|
}
|
|
|
|
|
|
int permutation::operator[](int i) {
|