Example #1
0
        init_p = MiscPhases.SimpleInitPhase(EPs.num_of_generations)
        number_of_bins = int(np.sqrt(EPs.pop_size))

        out_file_path = RPs.out_path + 'out' + str(
            number_of_bins) + 'bins' + str(i).zfill(3) + '.txt'
        record_p = MiscPhases.MaintainRecordBestsPhase(
            EPs.get_fitness,
            out_file_path=out_file_path,
            debug_output=BoardGen.DEBUG_OUTPUT)

        EPs.save_solutions_p.restart()

        # cyc = Evolution.Cycle(
        #     [EPs.elite_e_p, select_p, EPs.mut_p, EPs.elite_m_p, EPs.eval_p, record_p, save_solutions_p])
        cyc = Evolution.Cycle([
            select_p, EPs.mut_p, EPs.gmut_p, EPs.eval_p, record_p,
            EPs.save_solutions_p, EPs.distorter_p
        ])
        # print([i for i in cyc])
        ebody = Evolution.EpochBasicBody(cyc, EPs.init_p.check_gen_limit)
        init_cyc = Evolution.Cycle([
            EPs.pop_init_p, EPs.init_p, EPs.eval_p, record_p,
            EPs.save_solutions_p
        ])
        epo = Evolution.Epoch(ebody, init_cycle=init_cyc)
        evo = Evolution.Evolution(epo)

        if i == 0:
            # with open(RPs.experiment_big_fit_out_file_name, 'w') as fit_f:
            #     fit_f.write("Sim#, Best_fitness\n")
            RC.write_experiment_preamble(init_cyc, cyc, None)
Example #2
0
    calc_fitness = RuleInd.RuleIndividual.calculate_fitness
    get_fitness = RuleInd.RuleIndividual.get_fitness

    init_p = MiscPhases.SimpleInitPhase(num_of_generations)
    elite_e_p = Selection.SimpleExtractElitePhase(get_fitness, elite_size=5)
    elite_m_p = Selection.SimpleMergeElitePhase()
    select_p = Selection.TournamentSelectionPhase(get_fitness, tour_size=4)
    mut_p = MutationPhase(probability=0.2)
    eval_p = FitnessEvaluationPhase(fitness_calc_function=calc_fitness,
                                    fitness_getter_function=get_fitness)
    record_p = MiscPhases.MaintainBestsPhase(get_fitness)

    # cyc = Evolution.Cycle([select_p, eval_p, record_p])
    # cyc = Evolution.Cycle([select_p, mut_p, eval_p, record_p])
    cyc = Evolution.Cycle(
        [elite_e_p, select_p, mut_p, elite_m_p, eval_p, record_p])
    ebody = Evolution.EpochBasicBody(cyc, init_p.check_gen_limit)
    epo = Evolution.Epoch(ebody,
                          init_cycle=Evolution.Cycle(
                              [init_p, eval_p, record_p]))
    evo = Evolution.Evolution(epo)

    _t0 = t.time()
    evo.run(pop)
    _t1 = t.time()

    print("\nRuntime: %.3f" % (_t1 - _t0))
    print("Best ever individual")
    print(record_p.best_ever_ind.rule_to_string())
    print(record_p.best_ever_ind.scores)
    print("Fitness: %.5f" % record_p.best_ever_ind.fitness)