I am pretty new to python and I am trying to swap the values of some variables in my code below:
def MutationPop(LocalBestInd,clmns,VNSdata):
import random
MutPop = []
for i in range(0,VNSdata[1]):
tmpMutPop = LocalBestInd
#generation of random numbers
RandomNums = []
while len(RandomNums) < 2:
r = random.randint(0,clmns-1)
if r not in RandomNums:
RandomNums.append(r)
RandomNums = sorted(RandomNums)
#apply swap to berths
tmpMutPop[0][RandomNums[0]] = LocalBestInd[0][RandomNums[1]]
tmpMutPop[0][RandomNums[1]] = LocalBestInd[0][RandomNums[0]]
#generation of random numbers
RandomNums = []
while len(RandomNums) < 2:
r = random.randint(0,clmns-1)
if r not in RandomNums:
RandomNums.append(r)
RandomNums = sorted(RandomNums)
#apply swap to vessels
tmpMutPop[1][RandomNums[0]] = LocalBestInd[1][RandomNums[1]]
tmpMutPop[1][RandomNums[1]] = LocalBestInd[1][RandomNums[0]]
MutPop.append(tmpMutPop)
Neighborhood = MutPop
return(Neighborhood)
my problem is that I do not want to change the variable "LocalBestInd" and want to use it as a reference to generate new "tmpMutPop"s in the loop, but the code put "LocalBestInd" equal to "tmpMutPop" every time that loop is iterated. The same problem happens for other assignments (e.g., tmpMutPop[1][RandomNums[1]] = LocalBestInd[1][RandomNums[0]]) in this code.
Would you please help me to solve this problem?
Thank you
Masoud