I am basically needing to create a local search technique using the cost function. I need to create a new function that randomly swaps the original solution in the latin square, then calculates the cost and if it is better than the original solution, swap the two. This needs to be done until either the cost function is 0 or enough iterations are done. Any help at all would be massively appreciated. Thanks!!
def cost(sol):
nolist1 = [i for i in range(0,dim)]
costcol = []
missno = []
for i in range(0,dim):
nolist1 = [i for i in range(0,dim)]
for j in range(0,dim):
for k in range(0,len(nolist1)):
if sol[j][i] not in nolist1:
continue
elif sol[j][i] == nolist1[k]:
nolist1.remove(sol[j][i])
missno.append(nolist1)
costcol.append(len(missno[i]))
totalcost = sum(costcol)
return(totalcost,costcol,missno)
cost = cost(sol)