This commit is contained in:
zenon 2018-05-31 15:00:57 +02:00
parent a0785c17bc
commit 1c913d4b82

View File

@ -195,10 +195,13 @@ void genSolution(int permutation[])
{ {
int r; int r;
// initialize array to indices
for (int i = 0; i < graph.V; i++) { for (int i = 0; i < graph.V; i++) {
permutation[i] = i; permutation[i] = i;
} }
// loop from end to start, choose random and switch
// with number at current index.
for (int i = (graph.V - 1); i > 0; i--) { for (int i = (graph.V - 1); i > 0; i--) {
r = rand() % (i+1); r = rand() % (i+1);
int tmp = permutation[r]; int tmp = permutation[r];