The problem comes from the state variable (in args). It is modified in my code (after the new_state modifications). However, I've read that using list() could prevent this kind of problem (it looks like state and new_state have the same reference).
To sum up, if I display the value of state at the beginning of the function, and just before the return, the values are different (and I obviously don't want to change the value of this variable !). How can I solve this problem ?
def successor(self, state, numberClients, numberDepots, Q, dist_table):
succ_list = list()
for i in range(0, len(state)):
for j in range(0, len(state[i])):
switchIndex = 0
while switchIndex < length:
permutationIndex = 0
while permutationIndex < len(state[switchIndex]):
new_state = list(state)
temp = new_state[switchIndex][permutationIndex]
new_state[switchIndex][permutationIndex] = new_state[i][j]
new_state[i][j] = temp
if checkConst(new_state): # accept only in some cases (we don't care here)
succ_list.append(('act', new_state))
permutationIndex += 1
switchIndex += 1
return succ_list