本文整理汇总了Python中deap.tools.mutGaussian方法的典型用法代码示例。如果您正苦于以下问题:Python tools.mutGaussian方法的具体用法?Python tools.mutGaussian怎么用?Python tools.mutGaussian使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类deap.tools
的用法示例。
在下文中一共展示了tools.mutGaussian方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: runOptGenetic
# 需要导入模块: from deap import tools [as 别名]
# 或者: from deap.tools import mutGaussian [as 别名]
def runOptGenetic():
'''
@return:
@rtype:
'''
# COULDDO parametrisation
creator.create("FitnessMin", base.Fitness, weights=(-1.0,))
creator.create("Individual", list, fitness=creator.FitnessMin)
IND_SIZE = num_slots * num_evs
POP_SIZE = 30
toolbox = base.Toolbox()
toolbox.register("attr_float", rd.random) # COULDDO heuristic init
toolbox.register("individual", tools.initRepeat, creator.Individual, toolbox.attr_float, n=IND_SIZE)
toolbox.register("population", tools.initRepeat, list, toolbox.individual, n=POP_SIZE)
toolbox.register("evaluate", evaluate)
toolbox.decorate("evaluate", tools.DeltaPenalty(feasible, 0.0, distance))
toolbox.register("mate", tools.cxTwoPoint)
toolbox.register("mutate", tools.mutGaussian, mu=0, sigma=0.5, indpb=0.5)
toolbox.register("select", tools.selTournament, tournsize=3)
stats = tools.Statistics(key=lambda ind: ind.fitness.values)
stats.register("avg", np.mean)
stats.register("std", np.std)
stats.register("min", np.min)
stats.register("max", np.max)
hof = tools.HallOfFame(1)
population = toolbox.population()
# if no of-the-shelf algorithm used...
# fits = toolbox.map(toolbox.evaluate, population)
# for fit, ind in zip(fits, population):
# ind.fitness.values = fit
population, logbook = algorithms.eaSimple(population, toolbox, cxpb=0.5, mutpb=0.3, ngen=5, stats=stats, verbose=True, halloffame=hof)
sorted_pop = sorted(population, key=lambda ind: ind.fitness)
ev_schedules = np.asarray(best).reshape((num_evs, num_slots))
schedules = np.zeros((num_households, num_slots)).tolist()
for i in range(num_evs):
schedules[evs[i].position] = ev_schedules[i].tolist()
evs[i].schedule = schedules[evs[i].position]
return schedules
# *****************************************************************************************************
# * Metaheuristics Side Functions
# *****************************************************************************************************
# UNUSED