Beispiel #1
0
def run3(problem):
    ga = GA.GA_BASIC(problem)
    start = time.process_time()
    ga.run()
    end = time.process_time()
    run_time = end - start
    print("*********  GA_BASIC runtime:   *********")
    print(run_time)
    y1 = ga.memo_opt[0:-1]
    x1 = np.arange(1, len(y1) + 1)
    l1 = plt.plot(x1, y1, 'r--', label='GA_BASIC')
    plt.plot(x1, y1, 'r-')
    plt.title('The Convergence Curve of GA')
    plt.xlabel('Iteration')
    plt.ylabel('Best Objective')
    plt.legend()
    plt.show()
    print("**************** GA_BASIC ****************")
    print([a for a in ga.opt_chromo])
    print("********* GA_BASIC Block lasts:   *********")
    for i in ga.memo_FV[tuple(ga.opt_chromo)].block_lasts:
        print(i)
    print("*********  GA_BASIC end times:   *********")
    for i in ga.memo_FV[tuple(ga.opt_chromo)].end_times:
        print(i)
    print("*********  GA_BASEIC eti_penalty:   *********")
    print("overall penalty of GA_BASIC:",
          ga.memo_FV[tuple(ga.opt_chromo)].eti_penalty)
Beispiel #2
0
def run5(p):
    ga_basic = GA.GA_BASIC(p)
    start = time.process_time()
    ga_basic.run()
    end = time.process_time()
    run_time = end - start
    b_ratio = ga_basic.memo_FV[tuple(ga_basic.opt_chromo)].b_ratio
    f = open('basicGA_results.txt', 'a')
    f.write(
        str(p.n) + "\t" + str(p.b) + "\t" + str(p.rho) + "\t" + str(run_time) +
        "\t" + str(b_ratio) + "\n")
    f.close()
Beispiel #3
0
def run5(p):
    ga = GA.GA_BASIC(p)
    start = time.process_time()
    ga.run()
    end = time.process_time()
    run_time = end - start
    f = open('GA_My_DP_0717.txt', 'a')
    f.write(
        str(p.n) + "\t" + str(p.b) + "\t" + str(p.rho) + "\t" + str(run_time) +
        "\t" + str(ga.memo_opt[ga.max_iter]) + "\t" +
        str(ga.memo_opt[ga.max_iter - 5]) + "\t" +
        str(ga.memo_opt[ga.max_iter - 10]) + "\n")
    f.close()