def main(multicore, NGEN, POP, refmap, MUTPB, mu_mean, mu_sigma, verb, grid, graph): creator.create("FitnessMax", base.Fitness, weights=(1.0, )) creator.create("Individual", list, fitness=creator.FitnessMax) toolbox = base.Toolbox() toolbox.register("attr_trans", random.uniform, TRANS_MIN, TRANS_MAX) toolbox.register("attr_rot", random.uniform, ROT_MIN, ROT_MAX) toolbox.register( "individual", tools.initCycle, creator.Individual, (toolbox.attr_trans, toolbox.attr_trans, toolbox.attr_rot), n=1) toolbox.register("population", tools.initRepeat, list, toolbox.individual) if grid: pop = initPop(POP, refmap, creator.Individual) else: pop = toolbox.population(n=POP) toolbox.register("select", tools.selNSGA2) toolbox.register("mate", tools.cxOnePoint) toolbox.register("evaluate", evaluate) if multicore: pool = multiprocessing.Pool() toolbox.register("map", pool.map) hof = tools.HallOfFame(5) stats = tools.Statistics(lambda ind: ind.fitness.values) stats.register("max", np.max) stats.register("min", np.min) stats.register("avg", np.mean) stats.register("std", np.std) random.seed() record, log = eaMuPlusLambdaZeno(pop, toolbox, mu=int(POP * elite), lambda_=int(POP * (1 - elite)), cxpb=CXPB, mutpb=MUTPB, ngen=NGEN, mu_mean=mu_mean, mu_sigma=mu_sigma, stats=stats, halloffame=hof, verbose=args.v, graph=graph) expr = tools.selBest(pop, 1)[0] if verb: print "Best individual:", expr print "Fitness:", evaluate_solution(expr[0], expr[1], expr[2], errorscan.posx, errorscan.posy, errorscan.rot) best_result = evaluate_solution(expr[0], expr[1], expr[2], errorscan.posx, errorscan.posy, errorscan.rot) return best_result, record, log, expr
def main(multicore, NGEN, POP, scan, map, CXPB, MUTPB, verb, graph): creator.create("FitnessMax", base.Fitness, weights=(1.0, )) creator.create("Individual", list, fitness=creator.FitnessMax) toolbox = base.Toolbox() toolbox.register("attr_trans", random.uniform, TRANS_MIN, TRANS_MAX) toolbox.register("attr_rot", random.uniform, ROT_MIN, ROT_MAX) toolbox.register( "individual", tools.initCycle, creator.Individual, (toolbox.attr_trans, toolbox.attr_trans, toolbox.attr_rot), n=1) toolbox.register("population", tools.initRepeat, list, toolbox.individual) toolbox.register("mutate", tools.mutGaussian, sigma=0.125 / 4, mu=0, indpb=MUTPB) toolbox.register("select", tools.selTournament, tournsize=3) toolbox.register("mate", tools.cxOnePoint) toolbox.register("evaluate", evaluate) if multicore: pool = multiprocessing.Pool() toolbox.register("map", pool.map) pop = toolbox.population(n=POP) hof = tools.HallOfFame(5) stats = tools.Statistics(lambda ind: ind.fitness.values) stats.register("max", np.max) stats.register("min", np.min) stats.register("avg", np.mean) stats.register("std", np.std) random.seed() record, log = eaSimple(pop, toolbox, cxpb=CXPB, mutpb=MUTPB, ngen=NGEN, stats=stats, halloffame=hof, verbose=args.v, graph=args.graph) expr = tools.selBest(pop, 1)[0] if verb: print "Best individual:", expr print "Fitness:", evaluate_solution(expr[0], expr[1], expr[2], errorscan.posx, errorscan.posy, errorscan.rot) best_result = evaluate_solution(expr[0], expr[1], expr[2], errorscan.posx, errorscan.posy, errorscan.rot) return best_result, record, log, expr