TSP algorithm: initializing population

时间:2019-02-24 03:10:14

标签: python list loops

The first element HAS to be 0 the last element HAS to be nodes-1 for each path; the issue is after path is added to the population it resets and path in population also resets... Struggling-please help. I am coding again after 10+ years, so any suggestions about structure are also appreciated.

def population(n,nodes):
    parent = range(1,nodes-1)
    population=[]   
    path=[] 
    for j in range (1,n-1):
        path.append(0)
        path=path+(random.sample(parent,nodes-2))
        path.append(nodes-1)
        population.append(path)
        path[:]=[]
     return (norm_Fit(pop_Fit_Sort(population)))

0 个答案:

没有答案