当前位置: 首页>>代码示例>>Python>>正文


Python tools.cxTwoPoint方法代码示例

本文整理汇总了Python中deap.tools.cxTwoPoint方法的典型用法代码示例。如果您正苦于以下问题:Python tools.cxTwoPoint方法的具体用法?Python tools.cxTwoPoint怎么用?Python tools.cxTwoPoint使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在deap.tools的用法示例。


在下文中一共展示了tools.cxTwoPoint方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: create_toolbox

# 需要导入模块: from deap import tools [as 别名]
# 或者: from deap.tools import cxTwoPoint [as 别名]
def create_toolbox(num_bits):
    creator.create("FitnessMax", base.Fitness, weights=(1.0,))
    creator.create("Individual", list, fitness=creator.FitnessMax)

    # Initialize the toolbox
    toolbox = base.Toolbox()

    # Generate attributes 
    toolbox.register("attr_bool", random.randint, 0, 1)

    # Initialize structures
    toolbox.register("individual", tools.initRepeat, creator.Individual, 
        toolbox.attr_bool, num_bits)

    # Define the population to be a list of individuals
    toolbox.register("population", tools.initRepeat, list, toolbox.individual)

    # Register the evaluation operator 
    toolbox.register("evaluate", eval_func)

    # Register the crossover operator
    toolbox.register("mate", tools.cxTwoPoint)

    # Register a mutation operator
    toolbox.register("mutate", tools.mutFlipBit, indpb=0.05)

    # Operator for selecting individuals for breeding
    toolbox.register("select", tools.selTournament, tournsize=3)
    
    return toolbox 
开发者ID:PacktPublishing,项目名称:Artificial-Intelligence-with-Python,代码行数:32,代码来源:bit_counter.py

示例2: getToolbox

# 需要导入模块: from deap import tools [as 别名]
# 或者: from deap.tools import cxTwoPoint [as 别名]
def getToolbox(Strategy, genconf, Attributes):
    toolbox = base.Toolbox()
    creator = Creator.init(base.Fitness, {'Strategy': Strategy})
    toolbox.register("newind", initInd, creator.Individual, Attributes)
    toolbox.register("population", tools.initRepeat, list, toolbox.newind)
    toolbox.register("mate", tools.cxTwoPoint)
    toolbox.register("mutate", tools.mutUniformInt, low=10, up=10, indpb=0.2)
    toolbox.register("constructPhenotype", constructPhenotype, Attributes)
    return toolbox 
开发者ID:Gab0,项目名称:japonicus,代码行数:11,代码来源:oldschool.py

示例3: runOptGenetic

# 需要导入模块: from deap import tools [as 别名]
# 或者: from deap.tools import cxTwoPoint [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 
开发者ID:fneum,项目名称:ev_chargingcoordination2017,代码行数:58,代码来源:run.py


注:本文中的deap.tools.cxTwoPoint方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。