我正在尝试创建一个个性化的伴侣功能。以这样一种方式从群体中的两个个体中创造出一个新个体。下面是我的伙伴函数:
def BREED(parent1, parent2):
child = []
childP1 = []
childP2 = []
geneA = int(random.random() * len(parent1))
geneB = int(random.random() * len(parent1))
startGene = min(geneA, geneB)
endGene = max(geneA, geneB)
for i in range(startGene, endGene):
childP1.append(parent1[i])
childP2 = [item for item in parent2 if item not in childP1]
child = childP1 + childP2
#print(parent1)
parent2=array.array("i",child)
return parent1, parent2
这将返回一个错误:'array.array' object has no attribute 'fitness', because parent2 is no more an Individual Object.
如何创建新的个人
目前没有回答
相关问题 更多 >
编程相关推荐