""" pop是种群,种群中的每个个体的形式是,(makespan, 染色体)""" pop = [(ComputeStartTimes(g, I)[-1], g) for g in InitPopulation(ps, I)] 2 for it in xrange(1, mit+1):""" mit是迭代次数""" 3 # Random ordering of the population 4 shuffle(pop)"""把pop中各个个体的顺序打乱 """ 5 hpop = len(pop) / 2""" hpop是种群的一半""" 6 for i in xrange(hpop):""" 遍历种群的前半部分份""" 7 if random() < pc:"""若[0,1]之间的随机数 < pc """ 8 # Create two new elements 9 ch1 = Crossover(pop[i][1], pop[hpop + i][1], I)""" 通过交叉生成下一代""" 10 ch2 = Crossover(pop[hpop + i][1], pop[i][1], I)""" 通过交叉生成下一代""" 11 if random() < pm:"""若[0,1]之间的随机数 < pm """ 12 ch1 = Mutation(ch1)""" 对ch1进行变异""" 13 if random() < pm:"""若[0,1]之间的随机数 < pm """ 14 ch2 = Mutation(ch2)"""对ch2进行变异""" 15 pop.append((ComputeStartTimes(ch1, I)[-1], ch1))""" 将进化后的染色体放回种群""" 16 pop.append((ComputeStartTimes(ch2, I)[-1], ch2)) 17 # Sort individuals in increasing timespan order and 18 # select only the best ones for the next iteration 19 pop.sort()""" 将pop中的染色体按makespan排序""" 20 pop = pop[:ps]""" 提取pop中的前ps个染色体""" 21 return pop[0]"""返回makespan最大的染色体 """
时间: 2024-12-27 04:21:53