Exemplo n.º 1
0
def GetOUTPUTDATA(ind,
                  M_max=4,
                  c_op=c_op,
                  t_convey=t_convey,
                  t_pack=t_pack,
                  c_od=c_od,
                  lm=lm):
    """
        ind:例如[0,3,19,8,7,0,10,6,4,14,12,9,16,0,13,11,18,20,2,0,17,1,15,5,0]
        M_max:分区数
        """
    batch, batch_item = getBatch(ind)
    batch_Quantity = [len(i) for i in batch_item]
    data = getBatchPicktime(batch_item)
    batch_packingtime = [t_pack * i for i in batch_Quantity]

    ODtime = ODtimeTable(np.array(batch))  #每个客户点交付时间
    ODtime = [i[-1] * 10 for i in ODtime]  #每个批次最后一个客户点交付时间*10
    op_duetime = [(lm - i) for i in ODtime]
    """求解BSP"""
    N_max = data.shape[1]
    index = list(range(1, N_max + 1))
    #SPT
    data1 = data[1:, :].sum(axis=0)
    tup = list(zip(index, data1))
    tup.sort(key=lambda x: x[1])
    Seq_SPT = np.array([i[0] for i in tup])
    data_best_all_SPT = data[:, Seq_SPT - 1]
    TPicktime_SPT = makespan(data_best_all_SPT)[-1, :].sum()
    #LDT
    tup = list(zip(index, ODtime))
    tup.sort(key=lambda x: x[1], reverse=0)
    Seq_LDT = np.array([i[0] for i in tup])
    data_best_all_LDT = data[:, Seq_LDT - 1]
    TPicktime_LDT = makespan(data_best_all_LDT)[-1, :].sum()
    #择优
    if TPicktime_SPT <= TPicktime_LDT:
        Seq = Seq_SPT
        data_best_all = data_best_all_SPT
    else:
        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
Exemplo n.º 2
0
def calOPCost(ind,
              M_max=4,
              c_op=c_op,
              t_convey=t_convey,
              t_pack=t_pack,
              c_od=c_od,
              lm=lm):
    """
    ind:例如[0,3,19,8,7,0,10,6,4,14,12,9,16,0,13,11,18,20,2,0,17,1,15,5,0]
    M_max:分区数
    """

    batch, batch_item = getBatch(ind)
    batch_Quantity = [len(i) for i in batch_item]
    data = getBatchPicktime(batch_item)
    batch_packingtime = [t_pack * i for i in batch_Quantity]
    ODtime = ODtimeTable(np.array(batch))
    op_duetime = [lm - i[-1] * 10 for i in ODtime]
    B_max = data.shape[1]
    B = range(B_max)  #批次订单b集合
    M = range(M_max)  #分区m集合
    G = 99
    Pick_time = data[1:, :]
    """对每一个ind的BSP用Gurobi求解"""
    MODEL = Model("Order picking Schedule")

    # 创建变量
    y = MODEL.addVars(range(B_max), range(B_max), vtype=GRB.BINARY,
                      name="y")  #y_bk
    c = MODEL.addVars(range(B_max),
                      range(M_max),
                      vtype=GRB.CONTINUOUS,
                      name="c")  #c_km
    Z = MODEL.addVar(vtype=GRB.CONTINUOUS, name="Z")
    z = MODEL.addVars(range(B_max), vtype=GRB.CONTINUOUS,
                      name="z")  #各批次的违约时间z_k

    # 更新变量环境
    MODEL.update()

    # 创建目标函数CONTINUOUS
    MODEL.setObjective(
        c_op / 10 *
        (quicksum(c[k, M_max - 1]
                  for k in B) + B_max * t_convey + sum(batch_packingtime)) + Z,
        sense=GRB.MINIMIZE)

    # 创建约束条件
    MODEL.addConstrs((quicksum(y[b, k] for k in B) == 1 for b in B),
                     name="s.t.4")
    MODEL.addConstrs((quicksum(y[b, k] for b in B) == 1 for k in B),
                     name="s.t.5")
    MODEL.addConstr(
        (c[0, 0] >= quicksum(y[b, 0] * Pick_time[0][b] for b in B)),
        name="s.t.6")
    MODEL.addConstrs((c[0, m] >= quicksum(y[b, 0] * Pick_time[m][b]
                                          for b in B) + c[0, m - 1] + t_convey
                      for m in range(1, M_max)))
    MODEL.addConstrs((c[k, 0] >= quicksum(y[b, k] * Pick_time[0][b]
                                          for b in B) + c[k - 1, 0]
                      for k in range(1, B_max)))

    MODEL.addConstrs(
        (c[k, m] >= c[k - 1, m] + quicksum(y[b, k] * Pick_time[m][b]
                                           for b in B)
         for k in range(1, B_max) for m in range(1, M_max)))
    MODEL.addConstrs(
        (c[k, m] >= c[k, m - 1] + t_convey + quicksum(y[b, k] * Pick_time[m][b]
                                                      for b in B)
         for k in range(1, B_max) for m in range(1, M_max)))
    MODEL.addConstrs((c[k, m] >= 0 for k in B for m in M), name="s.t.22")

    MODEL.addConstrs((z[k] >= 0 for k in B), name="s.t.24")
    MODEL.addConstrs((z[k] >= c_od / 10 * quicksum(
        y[b, k] *
        (c[k, M_max - 1] + t_convey + batch_packingtime[b] - op_duetime[b])
        for b in B) for k in B),
                     name="s.t.25")
    MODEL.addConstr(Z == quicksum(z[k] for k in B) * c_od / 10, name="s.t.26")
    #运行参数调整
    MODEL.Params.TimeLimit = 3  #设置求解时间最长为3s
    MODEL.Params.LogToConsole = 0  #log记录不在控制台显示
    # 执行最优化
    MODEL.optimize()
    return round(MODEL.objVal, 2)
Exemplo n.º 3
0
def calOPCost(ind,
              M_max=4,
              c_op=c_op,
              t_convey=t_convey,
              t_pack=t_pack,
              c_od=c_od,
              lm=lm):
    """
    ind:例如[0,3,19,8,7,0,10,6,4,14,12,9,16,0,13,11,18,20,2,0,17,1,15,5,0]
    M_max:分区数
    """
    batch, batch_item = getBatch(ind)
    batch_Quantity = [len(i) for i in batch_item]
    data = getBatchPicktime(batch_item)
    batch_packingtime = [t_pack * i for i in batch_Quantity]  #b属于B

    ODtime = ODtimeTable(np.array(batch))
    ODtime = [i[-1] * 10 for i in ODtime]  #每个批次最后一个客户点交付时间*10
    op_duetime = [(lm - i) for i in ODtime]
    """求解BSP"""
    N_max = data.shape[1]
    index = list(range(1, N_max + 1))
    #SPT
    data1 = data[1:, :].sum(axis=0)
    tup = list(zip(index, data1))
    tup.sort(key=lambda x: x[1])
    Seq_SPT = np.array([i[0] for i in tup])
    data_best_all_SPT = data[:, Seq_SPT - 1]
    TPicktime_SPT = makespan(data_best_all_SPT)[-1, :].sum()
    #LDT
    tup = list(zip(index, op_duetime))
    tup.sort(key=lambda x: x[1])
    Seq_LDT = np.array([i[0] for i in tup])
    data_best_all_LDT = data[:, Seq_LDT - 1]
    TPicktime_LDT = makespan(data_best_all_LDT)[-1, :].sum()

    #择优
    if TPicktime_SPT <= TPicktime_LDT:
        Seq = Seq_SPT
        data_best_all = data_best_all_SPT
    else:
        Seq = Seq_LDT
        data_best_all = data_best_all_LDT
    order = np.array(data_best_all[0, :]) - 1
    """时间类"""
    #各分区订单抵达后台时间
    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(
            np.array(batch_delivery_start_time) -
            np.array([op_duetime[i] for i in order])):
        if j < 0:
            batch_over_duetime.append(0)
        else:
            batch_over_duetime.append(j)
    """成本类:将时间/10"""
    #各批次订单拣选成本
    batch_op_cost = np.array(batch_delivery_start_time) / 10 * c_op
    #各批次订单违约成本
    batch_overduetime_cost = np.array(batch_over_duetime) / 10 * c_od
    #订单总拣选成本+违约成本
    TC = batch_op_cost.sum() + batch_overduetime_cost.sum()

    return TC
Exemplo n.º 4
0
from time import time
from numpy import *
from Order_batching import getBatch
from pick_time_S_shape import getBatchPicktime
from Parameter import t_convey, c_op, c_od, c_d, delivery_cost_perMin, lm, t_pack

ind_from = 1  #0--from ortools;1--from GA ;2--gurobi
""" ind :例如[0,1,2,5,6,0,4,7,8,0,9,11,12,0]"""

if ind_from == 2:
    from CVRPDV_Gurobi import route, var_a, C_d
    ind = route
    batch, batch_item = getBatch(ind)
    last_order_perBatch = [i[-2] for i in batch]
    ODtime = [var_a[i - 1] for i in last_order_perBatch]
    C_d_Bat = 0  #待确认

elif ind_from == 0:
    from CVRPDV_ortools import vehicle_routing, batch_delivery_time, batch_route_dis
    ind = vehicle_routing
    batch, batch_item = getBatch(ind)
    ODtime = batch_delivery_time  #每个批次订单最后一个订单的交付时间
    C_d = sum(batch_route_dis) * c_d
    C_d_Bat = array(batch_route_dis) * c_d
else:
    from CVRPDV_GA import bestInd, ODtime, C_d, C_d_Bat
    ind = bestInd
    batch, batch_item = getBatch(ind)

batch_Quantity = [len(i) for i in batch_item]
data = getBatchPicktime(batch_item)