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)
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)
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)
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)
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)
Seq = Seq_LDT data_best_all = data_best_all_LDT order = np.array(data_best_all[0, :]) - 1 return Seq, data_best_all, batch_packingtime, order, op_duetime, ODtime Seq, data_best_all, batch_packingtime, order, op_duetime, ODtime = GetOUTPUTDATA( bestInd) print("Seq:", Seq) #画出甘特图 Draw_route = 1 if Draw_route == 1: plt.figure() gatt(data_best_all) plt.show() """计算各指标""" """时间类""" #拣货开始时间 op_start_time = makespan_left(data_best_all) #各分区订单抵达后台时间 batch_arrive_time = np.array([ i + t_convey for i in (makespan(data_best_all, t_convey)[-1, :]) ]) #b 属于pi,拣货顺序批次 # 批次订单开始配送时间=抵达后台时间+打包分类时间 batch_delivery_start_time = batch_arrive_time + np.array( [batch_packingtime[i] for i in order]) #批次订单违约时间 batch_over_duetime = [] for j in list(
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
elif Bsp_Method_choose == 3: from BSP_LDT import Seq, data, batch_packingtime, op_duetime, ODtime, C_d_Bat, C_d print("Best Seq:", Seq) elif Bsp_Method_choose == 4: from BSP_SSL import Seq, data, batch_packingtime, op_duetime, ODtime, C_d_Bat print("Best Seq:", Seq) data_best_all = data[:, Seq - 1] order = array(data_best_all[0, :]) - 1 """绘制甘特图""" Draw = 0 if Draw == 1: plt.figure() gatt(data_best_all, t_convey) plt.show() """计算各指标""" """时间类""" #拣货开始时间 op_start_time = makespan_left(data_best_all) #拣货完成时间 makespan_time = makespan(data_best_all) #各分区订单抵达后台时间 batch_arrive_time = array( [i + t_convey for i in (makespan(data_best_all)[-1, :])]) #批次订单开始配送时间=抵达后台时间+打包分类时间 batch_delivery_start_time = batch_arrive_time + array( [batch_packingtime[i] for i in order]) #批次订单违约时间