I am trying to implement some sort of local search. For this I have two arrays, which represent a list, that I am trying to optimize. So I have one array as the current best array and the one I am currently analyzing.
At the beginning I am shuffling the array and set the current best array to the shuffled array.
random.shuffle(self.matchOrder)
self.bestMatchOrder = self.matchOrder
Then I am swapping a random neighboured pair in the array.
Now the problem I have is that when I am swapping the values in self.matchOrder, the values in self.bestMatchOrder get swapped.
a = self.matchOrder[index]
self.matchOrder[index] = self.matchOrder[index + 1]
self.matchOrder[index + 1] = a
"index" is given to the function as a parameter, it is just randomly generated number.
I guess I did something wrong assigning the variables, but I can't figure out what. So what can I do to only assign the value of the array to the other array and not make it apply the same changes to it, too?