我正在尝试创建个性化的配合功能。这样可以从总体上的两个个人创建一个新的个人。这是我的配合功能:
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.
如何创建新的个人?