示例#1
0
        next_ind_order = individual_order

        # エリート戦略
        elite = fitness.index(max(fitness))
        # 世代ごとの一番高い適応度とエリート番地
        print(str(i + 1) + "世代目:" + str(maxinds_fit[i]) + "\tエリート番地:" + str(elite))

        f.write(str(i + 1) + "," + str(max(fitness)) + "\n")

        next_ind_path[0] = individual_path[elite]
        next_ind_order[0] = individual_order[elite]

        for j in range(1 , 100):
            sel_num = rl.selection(fitness)

            newinds = []
            newinds = co.crossover(individual_order[sel_num[0]] , individual_order[sel_num[1]])

            next_ind_order[j] = newinds
            next_ind_path[j] = cv.convertOTP(next_ind_order[j])

        individual_order = next_ind_order
        individual_path = next_ind_path

        print(np.array(individual_path).reshape(inds , len_dat))
        print()

    f.close()

    #kame.path(individual_path , dat , fitness , len_dat)
示例#2
0
        next_path = np.array([0 for col in range(inds) for row in range(len_dat)]).reshape(inds, len_dat)
        next_order = np.array([0 for col in range(inds) for row in range(len_dat)]).reshape(inds, len_dat)

        # 順番に選択
        for j in range(inds):
            j_path = individual_path[j]
            j_order = individual_order[j]

            # ランダム3つ
            select_path, select_order = sri.select(inds, individual_path, individual_order, j, len_dat)

            # 差分変異親
            mutant_order = np.array(cm.mutant(select_order, S_factor))

            # 交叉して子(Trial)の生成
            trial_order = co.crossover(j_order, mutant_order)
            trial_path = cv.convertOTP(trial_order)

            # 親と子で競争
            fitness[j], next_path[j], next_order[j] = ev.evaluation(dat, j_path, j_order, trial_path, trial_order)

        individual_path = next_path
        individual_order = next_order

        print(str(i + 1) + "世代目:" + str(max(fitness)) + "\n" + str(individual_path[fitness.index(max(fitness))]))

        f.write(str(i + 1) + "," + str(max(fitness)) + "\n")

    f.close()
    print(individual_path[fitness.index(max(fitness))])