python中的奇怪任务

时间:2018-05-04 12:39:58

标签: python

我正在尝试在python中开发一个变异(遗传算法)运算符。我的人口是一个元组数组 - (数组(解),浮点数(目标函数))。 在这种情况下考虑解决方案的大小是1,这是我的测试代码:

position = 4
ind1 = population[position]
p1 = ()
p1 = ind1[0]
point = 0)
new_point = 4
print "bla", population
population[position][0][point] = new_point
print "pop", population
if(flag == 1):
    ind1 = (p1,dist(p1))
    population[position] = ind1
else:
    ind1 = (p1,heuristic_dist(p1))
    population[position] = ind1

这是最初的人口:

bla [([11],0.0015072271967127016),([8],0.0573155547768569),([8],0.0573155547768569),([4],0.0573155547768569),([2],0.0573155547768569),([4], 0.0573155547768569),([2],0.0573155547768569),([2],0.0573155547768569),([4],0.0573155547768569),([4],0.0573155547768569),([8],0.0573155547768569),([4],0.0573155547768569) ]

我希望只替换位置4中的元组,而是替换包含值[2]的所有元组,如下所示:

pop [([11],0.0015072271967127016),([8],0.0573155547768569),([8],0.0573155547768569),([4],0.0573155547768569),([4],0.0573155547768569),([4], 0.0573155547768569),([4],0.0573155547768569),([4],0.0573155547768569),([4],0.0573155547768569),([4],0.0573155547768569),([8],0.0573155547768569),([4],0.0573155547768569) ]

为什么呢?任何人都可以帮我这个吗?

0 个答案:

没有答案