예제 #1
0
 def insert(self, data, t_convey, total_time):
     neh_data = np.zeros([data.shape[0], 2], dtype=data.dtype)
     neh_data[:, :2] = data[:, np.array(total_time[0, :2], dtype=int) - 1]
     for k in range(2, data.shape[1]):
         temp = data[:, int(total_time[0, k] - 1)]
         neh_data = np.insert(neh_data, k, temp, axis=1)
         for i in range(k):
             if makespan_value(neh_data, t_convey) > makespan_value(
                     np.insert(neh_data, i, temp, axis=1), t_convey):
                 neh_data = np.delete(neh_data, k, axis=1)
                 neh_data = np.insert(neh_data, i, temp, axis=1)
     data_neh = neh_data[0]
     return data_neh
예제 #2
0
 def select(self, data, transfer_time, data_johnson):
     data_johnson = np.array(data_johnson, dtype=int) - 1
     data_best = data_johnson[0]
     for i in range(1, data_johnson.shape[0]):
         if makespan_value(
                 data[:, data_best],
                 transfer_time,
         ) > makespan_value(
                 data[:, data_johnson[i]],
                 transfer_time,
         ):
             data_best = data_johnson[i]
     data_best += 1
     return data_best
예제 #3
0
파일: RA.py 프로젝트: eliwchen/ISZPVRPTW
def ra(data, transfer_time, draw=0):
    """
    :param data: n行m列,第一行工序编号,其他是加工时间
    :return:
    """
    data = data[:, np.argsort(data[0])]
    new = RA()
    start_time = time.time()
    group_data = new.group_machine(data)
    ra_data = new.apply_johnson(group_data)
    end_time = time.time()
    # print("Time used: %s" % (end_time - start_time))
    # print("The minimum makespan: %s" % makespan_value(data[:, ra_data - 1]))
    if draw:
        import matplotlib.pyplot as plt
        from tool import gatt
        gatt(data[:, ra_data - 1])
        plt.show()
    return ra_data, makespan_value(data[:, ra_data - 1], transfer_time)
예제 #4
0
def neh(data, t_convey, draw=0):
    """
    :param data: n行m列,第一行工序编号,其他是加工时间
    :return:
    """
    data = data[:, np.argsort(data[0])]
    new = NEH()
    start_time = time.time()
    total_time = new.sort(data)
    data_neh = new.insert(data, t_convey, total_time)
    end_time = time.time()
    # print("Time used: %s" % (end_time - start_time))
    # print("The minimum makespan: %s" % makespan_value(data[:, data_neh - 1]))
    if draw:
        import matplotlib.pyplot as plt
        from tool import gatt
        gatt(data[:, data_neh - 1])
        plt.show()
    return data_neh, makespan_value(data[:, data_neh - 1], t_convey)
예제 #5
0
def gupta(data, transfer_time, draw=0):
    """
    :param data:3行,工序编号,机器1加工时间,机器2加工时间
    :return:
    """
    data = data[:, np.argsort(data[0])]
    new = Gupta()
    start_time = time.time()
    s = new.cals(data)
    data_gupta = new.sort(data, s)
    end_time = time.time()
    # print("Gupta// Time used: %s" % (end_time - start_time))
    # print("Gupta// The minimum makespan: %s" % makespan_value(data[:, data_gupta - 1]))
    if draw:
        import matplotlib.pyplot as plt
        from tool import gatt
        gatt(data[:, data_gupta - 1])
        plt.show()
    return data_gupta, makespan_value(data[:, data_gupta - 1], transfer_time)
예제 #6
0
def palmer(data, transfer_time, draw=0):
    """
    :param data: n行m列,第一行工序编号,其他是加工时间
    :return:
    """
    data = data[:, np.argsort(data[0])]
    new = Palmer()
    start_time = time.time()
    slope_index = new.slope_index(data)
    sort_slope = new.sort_slope(slope_index)
    palmer_data = new.palmer_data(data, sort_slope)
    end_time = time.time()
    # print("Palmer// Time used: %s" % (end_time - start_time))
    # print("Palmer// The minimum makespan: %s" % makespan_value(data[:, palmer_data - 1]))
    if draw:
        import matplotlib.pyplot as plt
        from tool import gatt
        gatt(data[:, palmer_data - 1])
        plt.show()
    return palmer_data, makespan_value(data[:, palmer_data - 1], transfer_time)
예제 #7
0
def cds(data, transfer_time, draw=0):
    """
    :param data: n行m列,第一行工序编号,其他是加工时间
    :return:
    """
    data = data[:, np.argsort(data[0])]
    new = CDS()
    start_time = time.time()
    data_group = new.group(data)
    data_johnson = new.johnson(data_group)
    data_best = new.select(data, transfer_time, data_johnson)
    end_time = time.time()
    # print("CDS// Time used: %s" % (end_time - start_time))
    # print("CDS// The minimum makespan: %s" %makespan_value(data[:, data_best - 1]))
    if draw:
        import matplotlib.pyplot as plt
        from tool import gatt
        gatt(data[:, data_best - 1])
        plt.show()
    return data_best, makespan_value(data[:, data_best - 1], transfer_time)
예제 #8
0
def ga_fsp_new(data,
               c_op,
               op_duetime,
               c_od,
               batch_packingtime,
               t_convey,
               pop_size=80,
               max_gen=300,
               Pc=0.65,
               Pm=0.35,
               draw=222):
    """
    流水车间作业调度的改进遗传算法。
    新增精英保留机制,即将每次迭代及其之前的最优个体保留下来
    轮盘赌选、部分匹配交叉混合顺序交叉
    :param data: m行n列,第1行工序编号,值加工时间
    :param pop_size: 种群大小
    :param max_gen: 最大进化代数
    :param Pc: 交叉概率
    :param Pm: 变异概率
    :param draw:甘特图、适应度图、动态适应度图
    :return:
    """
    data = data[:, np.argsort(data[0])]
    # pop_size=max(data.shape[1]*12,80)
    pop_size = 80
    # max_gen=max(data.shape[1]*40,200)
    max_gen = 800
    new = GA_FSP_NEW(data, pop_size, max_gen, Pc, Pm)
    pop = new.crtp()
    pop_trace = np.zeros([max_gen, 3])
    genetic_trace = np.zeros([max_gen, data.shape[1]], dtype=int)
    start_time = time.time()
    for g in range(max_gen):
        fitness = new.fitness(pop, c_op, op_duetime, c_od, batch_packingtime,
                              t_convey)
        pop_trace[g] = [g, np.mean(fitness), np.max(fitness)]
        genetic_trace[g] = pop[np.argmax(fitness)]

        select = new.select(pop, fitness)
        crossover = new.crossover(select)
        pop = new.mutation(crossover)
    end_time = time.time()
    best_genetic = genetic_trace[np.argmax(pop_trace[:, 2])]
    total_best = np.where(pop_trace[:, 2] == np.max(pop_trace[:, 2]))[0]
    print("GA Time used:", (end_time - start_time))
    # print("The first best generation:%s" % np.argmax(pop_trace[:, 2]))
    # print("Best generations:%s" % total_best)
    # print("Numbers of best generation:%s" % total_best.shape[0])
    print("The minimum makespan: %s" %
          makespan_value(data[:, best_genetic], t_convey))  #输出最大完成时间
    if draw != 222:
        import matplotlib.pyplot as plt
        from tool import gatt
        if int(str(draw)[0]) != 2:
            plt.figure(1)
            gatt(data[:, best_genetic], t_convey)
            plt.show()
        if int(str(draw)[1]) != 2:
            plt.figure(2)
            plt.plot(pop_trace[:, 0],
                     pop_trace[:, 2],
                     "r-",
                     label=r"$Best$ $fitness$")
            # plt.plot(pop_trace[:, 0], pop_trace[:, 1], "b-", label=r"$Pop$ $fitness$")
            plt.xlabel(r"$Generation_i$")
            plt.ylabel(r"$Fitness$")
            plt.legend()
            plt.show()
        if int(str(draw)[2]) != 2:
            plt.ioff()
            for i in range(1, max_gen):
                plt.figure(2)
                plt.plot([pop_trace[i - 1, 0], pop_trace[i, 0]],
                         [pop_trace[i - 1, 2], pop_trace[i, 2]],
                         "r-",
                         label=r"$Best$ $fitness$")
                plt.plot([pop_trace[i - 1, 0], pop_trace[i, 0]],
                         [pop_trace[i - 1, 1], pop_trace[i, 1]],
                         "b-",
                         label=r"$Pop$ $fitness$")
                plt.xlabel(r"$Generation$")
                plt.ylabel(r"$Fitness$")
                plt.pause(0.01)
            plt.show()
    best_genetic += 1
    return best_genetic