我已经编写了自己的函数来生成一个个体
def generate_Individual(arr1,arr2):
np.random.shuffle(arr1)
np.random.shuffle(arr2)
Candidate = tuple(zip(arr1,arr2))
return Candidate
def generate_Fitness(Individual):
sum_some = 0
for i in range (0,len(Individual)):
sum_some = sum_some + cals(Individual[i][0],Individual[i][1])
return sum_some
我正在注册到 DEAP 工具箱
import random
from deap import base
from deap import creator
from deap import tools
creator.create("FitnessMax", base.Fitness, weights=(1.0,))
creator.create("Individual", list, fitness=creator.FitnessMax)
toolbox = base.Toolbox()
toolbox.register("Individual", generate_Individual,arr1,arr2)
toolbox.register("population", tools.initRepeat, list, toolbox.Individual)
现在说我用这个代码调用了 4 个人口
pop = toolbox.population(n=4)
pop[0]
pop[3]
事实证明,尽管我在生成器函数中内置了随机性,但总体中的所有 4 个个体都是相同的
为什么会这样?