예제 #1
0
def find_the_nearest_empty_car_for_one(query, driver_list, regl_Hexg_grids,
                                       t_cur):
    ## 在订单的接载点所在格子寻找空车
    g_o = query.pickup_location
    # 接应点所在格子内的所有司机,并从这些司机中找出在pickup_latest_time之前到这个格子的空车司机
    for driver_tuple in regl_Hexg_grids[query.pickup_location -
                                        num_of_intersections -
                                        1].driver_will_coming:
        if driver_tuple[1] <= query.latest_pickup_time and driver_list[
                driver_tuple[0]].num_of_occupied_position == 0:
            # 进行路径规划
            driver_list[driver_tuple[0]].cur_schedule.append(
                [query.pickup_location, query.latest_pickup_time, 0])
            driver_list[driver_tuple[0]].cur_schedule.append(
                [query.delivery_location, query.latest_delivery_time, 1])
            # 计算司机没有共享的总行驶距离
            driver_list[driver_tuple[0]].total_distance_no_sharing += D[
                query.pickup_location - 1][query.delivery_location - 1]
            # 路径规划
            # 乘客加len(merged_order)
            driver_list[driver_tuple[0]].add_passenger(1)
            ## test ##
            if query.condition == 1:
                print("错误3")
            ## test ##
            # 司机所接订单总数加一
            driver_list[driver_tuple[0]].number_of_order += 1
            # 原来路径的第一个点
            # 判断路径是否非空
            if driver_list[driver_tuple[0]].route:
                first_location_origin_route = driver_list[
                    driver_tuple[0]].route[0]
            else:
                first_location_origin_route = None
            # 从格子的driver_will_coming中删除剩下路径
            for node in driver_list[driver_tuple[0]].route:
                regl_Hexg_grids[nodes_belong_to_which_grid[int(node)] -
                                1].driver_will_coming = [
                                    driver_tuple
                                    for driver_tuple in regl_Hexg_grids[
                                        nodes_belong_to_which_grid[int(node)] -
                                        1].driver_will_coming
                                    if driver_tuple[0] != driver_list[
                                        driver_tuple[0]].driver_id
                                ]
            # Recalculate route after schedule change
            driver_list[driver_tuple[0]].route = []
            driver_list[driver_tuple[0]].route.extend(
                (str(driver_list[driver_tuple[0]].cur_location) + obtainPath(
                    driver_list[driver_tuple[0]].cur_location - 1,
                    driver_list[driver_tuple[0]].cur_schedule[0][0] - 1) +
                 str(driver_list[driver_tuple[0]].cur_schedule[0][0])).split())
            for i in range(len(driver_list[driver_tuple[0]].cur_schedule) - 1):
                driver_list[driver_tuple[0]].route.extend(
                    (obtainPath(
                        driver_list[driver_tuple[0]].cur_schedule[i][0] - 1,
                        driver_list[driver_tuple[0]].cur_schedule[i + 1][0] -
                        1) +
                     str(driver_list[driver_tuple[0]].cur_schedule[i + 1][0])
                     ).split())
            del driver_list[driver_tuple[0]].route[0]
            # 遍历司机的路径列表
            for node_will_pass in driver_list[driver_tuple[0]].route:
                node_will_pass = int(node_will_pass)
                regl_Hexg_grids[
                    nodes_belong_to_which_grid[node_will_pass] -
                    1].driver_will_coming.append([
                        driver_list[driver_tuple[0]].driver_id,
                        t_cur + datetime.timedelta(
                            seconds=T[driver_list[driver_tuple[0]].cur_location
                                      - 1][node_will_pass - 1])
                    ])
            # 如果调整之后的路径第一个点和原始路径第一个点相同
            if driver_list[
                    driver_tuple[0]].route[0] == first_location_origin_route:
                driver_list[driver_tuple[0]].assist_t = driver_list[
                    driver_tuple[0]].assist_t
            else:
                driver_list[driver_tuple[0]].assist_t = -abs(
                    driver_list[driver_tuple[0]].assist_t)
            # 成功返回True
            return True
    ## 将能在latest_pickup_time之前到达query.pickup_location所在格子的所有格子保存入一个列表中
    l_o = []
    for g_i in Gt[g_o - num_of_intersections - 1]:
        if t_cur + datetime.timedelta(
                seconds=T[g_o - 1][int(g_i) + num_of_intersections -
                                   1]) <= query.latest_pickup_time:
            l_o.append(g_i)
        else:
            break
    ## 遍历列表l_o从中找到一个
    for g_i in l_o:
        # 将格子中的司机取出来
        for driver_tuple in regl_Hexg_grids[int(g_i) - 1].driver_will_coming:
            if driver_tuple[1] <= query.latest_pickup_time and driver_list[
                    driver_tuple[0]].num_of_occupied_position == 0:
                # 进行路径规划
                driver_list[driver_tuple[0]].cur_schedule.append(
                    [query.pickup_location, query.latest_pickup_time, 0])
                driver_list[driver_tuple[0]].cur_schedule.append(
                    [query.delivery_location, query.latest_delivery_time, 1])
                # 计算司机没有共享运行的总距离
                driver_list[driver_tuple[0]].total_distance_no_sharing += D[
                    query.pickup_location - 1][query.delivery_location - 1]
                # 路径规划
                # 乘客加len(merged_order)
                driver_list[driver_tuple[0]].add_passenger(1)
                ## test ##
                if query.condition == 1:
                    print("错误4")
                ## test ##
                # 司机所接订单总数加一
                driver_list[driver_tuple[0]].number_of_order += 1
                # 原来路径的第一个点
                # 判断路径是否为空
                if driver_list[driver_tuple[0]].route:
                    first_location_origin_route = driver_list[
                        driver_tuple[0]].route[0]
                else:
                    first_location_origin_route = None
                # 从格子的driver_will_coming中删除剩下路径
                for node in driver_list[driver_tuple[0]].route:
                    regl_Hexg_grids[
                        nodes_belong_to_which_grid[int(node)] -
                        1].driver_will_coming = [
                            driver_tuple for driver_tuple in regl_Hexg_grids[
                                nodes_belong_to_which_grid[int(node)] -
                                1].driver_will_coming if driver_tuple[0] !=
                            driver_list[driver_tuple[0]].driver_id
                        ]
                # Recalculate route after schedule change
                driver_list[driver_tuple[0]].route = []
                driver_list[driver_tuple[0]].route.extend(
                    (str(driver_list[driver_tuple[0]].cur_location) +
                     obtainPath(
                         driver_list[driver_tuple[0]].cur_location - 1,
                         driver_list[driver_tuple[0]].cur_schedule[0][0] - 1) +
                     str(driver_list[driver_tuple[0]].cur_schedule[0][0])
                     ).split())
                for i in range(
                        len(driver_list[driver_tuple[0]].cur_schedule) - 1):
                    driver_list[driver_tuple[0]].route.extend((obtainPath(
                        driver_list[driver_tuple[0]].cur_schedule[i][0] - 1,
                        driver_list[driver_tuple[0]].cur_schedule[i + 1][0] -
                        1) + str(driver_list[driver_tuple[0]].cur_schedule[
                            i + 1][0])).split())
                del driver_list[driver_tuple[0]].route[0]
                # 遍历司机的路径列表
                for node_will_pass in driver_list[driver_tuple[0]].route:
                    node_will_pass = int(node_will_pass)
                    regl_Hexg_grids[
                        nodes_belong_to_which_grid[node_will_pass] -
                        1].driver_will_coming.append([
                            driver_list[driver_tuple[0]].driver_id,
                            t_cur + datetime.timedelta(seconds=T[
                                driver_list[driver_tuple[0]].cur_location -
                                1][node_will_pass - 1])
                        ])
                # 如果调整之后的路径第一个点和原始路径第一个点相同
                if driver_list[driver_tuple[0]].route[
                        0] == first_location_origin_route:
                    driver_list[driver_tuple[0]].assist_t = driver_list[
                        driver_tuple[0]].assist_t
                else:
                    driver_list[driver_tuple[0]].assist_t = -abs(
                        driver_list[driver_tuple[0]].assist_t)
                # 成功返回True
                return True
    return False
예제 #2
0
def find_the_nearest_empty_car_for_many(regl_Hexg_grids, merged_order,
                                        driver_list, t_cur):
    # 找出latest_pickup_time最小的订单
    merged_order.sort(key=lambda query: query.latest_pickup_time)
    # 为合单的每一个订单的接载点初始化一个保存格子的字典集合
    L_os = dict()
    for i in range(len(merged_order)):
        L_os[i] = []
    # 寻找距离所有订单所在格子最近的格子
    for i in range(len(merged_order)):
        for g_i in Gt[merged_order[i].pickup_location - num_of_intersections -
                      1]:
            if t_cur + datetime.timedelta(
                    seconds=T[merged_order[i].pickup_location -
                              1][int(g_i) + num_of_intersections -
                                 1]) <= merged_order[i].latest_pickup_time:
                L_os[i].append(g_i)
            else:
                break
    # 求多个list的交集
    # 初始化交集列表
    S_intersection = [grid for grid in L_os[0] if grid in L_os[1]]
    ## test ##
    # print("司机列表",S_intersection)
    ## test ##
    for i in range(2, len(merged_order)):
        S_intersection = [grid for grid in S_intersection if grid in L_os[i]]
    ## test ##
    # print("司机列表", S_intersection)
    ## test ##
    ## 判断集合是否为空
    if not S_intersection:
        return False
    else:
        # 集合不为空,从集合中选出格子,然后从格子中找出空车司机
        for grid in S_intersection:
            ## test ##
            # print("格子",grid)
            ## test ##
            # 将浮点数转换为整数
            grid = int(grid)
            for driver_tuple in regl_Hexg_grids[grid - 1].driver_will_coming:
                ## test ##
                # print("将要到的司机",regl_Hexg_grids[grid-1].driver_will_coming)
                ## test ##
                if driver_list[driver_tuple[
                        0]].num_of_occupied_position == 0 and driver_tuple[
                            1] < merged_order[0].latest_pickup_time:
                    ## 找到空车司机
                    #进行路径规划
                    merged_order.sort(
                        key=cmp_to_key(lambda query_1, query_2: D[
                            grid + num_of_intersections - 1][
                                query_1.pickup_location - 1] - D[
                                    grid + num_of_intersections - 1][
                                        query_2.pickup_location - 1]))
                    # 将订单中的接应点加入到司机安排中
                    for query in merged_order:
                        driver_list[driver_tuple[0]].cur_schedule.append([
                            query.pickup_location, query.latest_pickup_time, 0
                        ])
                    ## 将订单根据接应点进行排序
                    merged_order.sort(
                        key=cmp_to_key(lambda query_1, query_2: D[
                            grid + num_of_intersections - 1][
                                query_1.delivery_location - 1] - D[
                                    grid + num_of_intersections - 1][
                                        query_2.delivery_location - 1]))
                    # 将订单中的传送点加入到司机安排中
                    for query in merged_order:
                        driver_list[driver_tuple[0]].cur_schedule.append([
                            query.delivery_location,
                            query.latest_delivery_time, 1
                        ])
                    # 计算没有共享运行的总距离
                    for query in merged_order:
                        driver_list[
                            driver_tuple[0]].total_distance_no_sharing += D[
                                query.pickup_location -
                                1][query.delivery_location - 1]
                    # 路径规划
                    # 乘客加len(merged_order)
                    driver_list[driver_tuple[0]].add_passenger(
                        len(merged_order))
                    # 司机所接订单总数增加
                    driver_list[driver_tuple[0]].number_of_order += len(
                        merged_order)
                    ## test ##
                    for query in merged_order:
                        if query.condition == 1:
                            print("错误1")
                    ## test ##
                    # 原来路径的第一个点
                    if driver_list[driver_tuple[0]].route:
                        first_location_origin_route = driver_list[
                            driver_tuple[0]].route[0]
                    else:
                        first_location_origin_route = None
                    # 从格子的driver_will_coming中删除剩下路径
                    for node in driver_list[driver_tuple[0]].route:
                        regl_Hexg_grids[
                            nodes_belong_to_which_grid[int(node)] -
                            1].driver_will_coming = [
                                driver_tuple
                                for driver_tuple in regl_Hexg_grids[
                                    nodes_belong_to_which_grid[int(node)] -
                                    1].driver_will_coming if driver_tuple[0] !=
                                driver_list[driver_tuple[0]].driver_id
                            ]
                    # Recalculate route after schedule change
                    driver_list[driver_tuple[0]].route = []
                    driver_list[driver_tuple[0]].route.extend(
                        (str(driver_list[driver_tuple[0]].cur_location) +
                         obtainPath(
                             driver_list[driver_tuple[0]].cur_location - 1,
                             driver_list[driver_tuple[0]].cur_schedule[0][0] -
                             1) +
                         str(driver_list[driver_tuple[0]].cur_schedule[0][0])
                         ).split())
                    for i in range(
                            len(driver_list[driver_tuple[0]].cur_schedule) -
                            1):
                        driver_list[driver_tuple[0]].route.extend((obtainPath(
                            driver_list[driver_tuple[0]].cur_schedule[i][0] -
                            1,
                            driver_list[driver_tuple[0]].cur_schedule[i + 1][0]
                            - 1) + str(driver_list[driver_tuple[0]].
                                       cur_schedule[i + 1][0])).split())
                    del driver_list[driver_tuple[0]].route[0]
                    # 遍历司机的路径列表
                    for node_will_pass in driver_list[driver_tuple[0]].route:
                        node_will_pass = int(node_will_pass)
                        regl_Hexg_grids[
                            nodes_belong_to_which_grid[node_will_pass] -
                            1].driver_will_coming.append([
                                driver_list[driver_tuple[0]].driver_id,
                                t_cur + datetime.timedelta(seconds=T[
                                    driver_list[driver_tuple[0]].cur_location -
                                    1][node_will_pass - 1])
                            ])
                    # 如果调整之后的路径第一个点和原始路径第一个点相同
                    if driver_list[driver_tuple[0]].route[
                            0] == first_location_origin_route:
                        driver_list[driver_tuple[0]].assist_t = driver_list[
                            driver_tuple[0]].assist_t
                    else:
                        driver_list[driver_tuple[0]].assist_t = -abs(
                            driver_list[driver_tuple[0]].assist_t)
                    #返回True
                    return True
    return False
예제 #3
0
def recommendation(driver_list, pickup_clusters, t_cur, regl_Hexg_grids,
                   amplification_factor):
    ## 预测模型参数
    a = 1
    b = 3 / 4
    c = 2 / 4
    d = 1 / 4
    ## 给空车司机推荐路径
    for driver in driver_list:
        # 车上乘客为0,且路径为空
        if driver.num_of_occupied_position == 0 and not driver.route:
            ## 初始化变量
            ## 寻找到距离司机最近的区域
            nearest_cluster_id = regl_Hexg_grids[
                nodes_belong_to_which_grid[driver.cur_location] -
                1].pickup_cluster[0]
            ## 到达最近区域所需要的时间
            t_go = T[driver.cur_location -
                     1][num_of_intersections + num_of_grids +
                        nearest_cluster_id - 1]
            ## 司机到达最近区域所在的时间段
            time_slot = int(((t_cur - Timeframe.starttime).seconds + t_go) /
                            60 / Cluster.dt) + 1
            # 如果时间段超过6,就等于6
            if time_slot > 10:
                time_slot = 10
            # 第time_slot段时间的开始时间
            starttime_temp = Timeframe.starttime + datetime.timedelta(
                seconds=(time_slot - 1) * 60 * Cluster.dt)
            ## 统计当前时间以及在当前时间过后的t_go时间内,会有多少个空车司机、一个乘客司机、两个乘客司机、三个乘客司机
            # 空车司机
            empty_car = set()
            # 一个乘客司机
            one_passenger_car = set()
            # 两个乘客司机数
            two_passenger_car = set()
            # 三个乘客司机数
            three_passenger_car = set()
            ## 统计区域内所有格子的空车司机、一个乘客司机。。
            for grid in pickup_clusters[nearest_cluster_id - 1].grids_included:
                for driver_tuple in regl_Hexg_grids[grid -
                                                    1].driver_will_coming:
                    # 司机到达该点时间之前
                    if driver_tuple[1] < t_cur + datetime.timedelta(
                            seconds=t_go) and driver_tuple[1] >= starttime_temp:
                        # 空车司机
                        if driver_list[
                                driver_tuple[0]].num_of_occupied_position == 0:
                            empty_car.add(driver_tuple[0])
                        elif driver_list[
                                driver_tuple[0]].num_of_occupied_position == 1:
                            one_passenger_car.add(driver_tuple[0])
                        elif driver_list[
                                driver_tuple[0]].num_of_occupied_position == 2:
                            two_passenger_car.add(driver_tuple[0])
                        elif driver_list[
                                driver_tuple[0]].num_of_occupied_position == 3:
                            three_passenger_car.add(driver_tuple[0])
                    elif driver_tuple[1] > t_cur + datetime.timedelta(
                            seconds=t_go):
                        break
            ## 计算在starttime_temp到当前时间之后t_go时间内司机带走多少乘客
            num_of_passengers_taken_away = floor(a * len(empty_car) +
                                                 b * len(one_passenger_car) +
                                                 c * len(two_passenger_car) +
                                                 d * len(three_passenger_car))
            ## 计算在starttime_temp到(当前时间+t_go)有多少个单位时间
            num_unit_time = ceil((t_go + (starttime_temp - t_cur).seconds) /
                                 Timeframe.windowsize.seconds)
            # 该区域顾客到达速率
            V_arrival = pickup_clusters[
                nearest_cluster_id - 1].avg_of_each_duration[time_slot - 1] / (
                    Cluster.dt * 60) * Timeframe.windowsize.seconds
            # 对区域顾客到达速率进行放大
            V_arrival = V_arrival * amplification_factor
            ## 到达num_of_passengers_taken_away+1个司机的概率
            P_max = exp(-V_arrival * num_unit_time) * pow(
                V_arrival * num_unit_time, num_of_passengers_taken_away +
                1) / factorial(num_of_passengers_taken_away + 1)
            ## 最大化概率的区域
            cluster_id_max = nearest_cluster_id
            for cluster_id in Gt_c[nearest_cluster_id - 1]:
                ## 到达最近区域所需要的时间
                t_go = T[driver.cur_location -
                         1][num_of_intersections + num_of_grids +
                            int(cluster_id) - 1]
                ## 司机到达最近区域所在的时间段
                time_slot = int(
                    ((t_cur - Timeframe.starttime).seconds + t_go) / 60 /
                    Cluster.dt) + 1
                # 列表访问越界处理
                if time_slot > 10:
                    time_slot = 10
                # 第time_slot段时间的开始时间
                starttime_temp = Timeframe.starttime + datetime.timedelta(
                    seconds=(time_slot - 1) * 60 * Cluster.dt)
                ## 统计当前时间以及在当前时间过后的t_go时间内,会有多少个空车司机、一个乘客司机、两个乘客司机、三个乘客司机
                # 空车司机
                empty_car = set()
                # 一个乘客司机
                one_passenger_car = set()
                # 两个乘客司机数
                two_passenger_car = set()
                # 三个乘客司机数
                three_passenger_car = set()
                ## 统计区域内所有格子的空车司机、一个乘客司机。。
                for grid in pickup_clusters[int(cluster_id) -
                                            1].grids_included:
                    for driver_tuple in regl_Hexg_grids[grid -
                                                        1].driver_will_coming:
                        # 司机到达该点时间之前
                        if driver_tuple[1] < t_cur + datetime.timedelta(
                                seconds=t_go
                        ) and driver_tuple[1] >= starttime_temp:
                            # 空车司机
                            if driver_list[driver_tuple[
                                    0]].num_of_occupied_position == 0:
                                empty_car.add(driver_tuple[0])
                            elif driver_list[driver_tuple[
                                    0]].num_of_occupied_position == 1:
                                one_passenger_car.add(driver_tuple[0])
                            elif driver_list[driver_tuple[
                                    0]].num_of_occupied_position == 2:
                                two_passenger_car.add(driver_tuple[0])
                            elif driver_list[driver_tuple[
                                    0]].num_of_occupied_position == 3:
                                three_passenger_car.add(driver_tuple[0])
                        elif driver_tuple[1] > t_cur + datetime.timedelta(
                                seconds=t_go):
                            break
                ## 计算在当前时间到当前时间之后t_go时间内司机带走多少乘客
                num_of_passengers_taken_away = floor(
                    a * len(empty_car) + b * len(one_passenger_car) +
                    c * len(two_passenger_car) + d * len(three_passenger_car))
                ## 计算在starttime到(当前时间+t_go)有多少个单位时间
                num_unit_time = ceil(
                    (t_go + (starttime_temp - t_cur).seconds) /
                    Timeframe.windowsize.seconds)
                # 该区域顾客到达速率
                V_arrival = pickup_clusters[int(
                    cluster_id) - 1].avg_of_each_duration[time_slot - 1] / (
                        Cluster.dt * 60) * Timeframe.windowsize.seconds
                # 对区域顾客到达速率进行放大
                V_arrival = V_arrival * amplification_factor
                ## 到达num_of_passengers_taken_away+1个司机的概率
                P_temp = exp(-V_arrival * num_unit_time) * pow(
                    V_arrival * num_unit_time, num_of_passengers_taken_away +
                    1) / factorial(num_of_passengers_taken_away + 1)
                ## 最大化概率的区域
                if P_temp > P_max:
                    P_max = P_temp
                    cluster_id_max = cluster_id
            ## 更改该司机的路径
            # 空车司机要去的区域锚点
            next_station = num_of_intersections + num_of_grids + int(
                cluster_id_max)
            # 路径更改
            driver.route.extend(
                (str(driver.cur_location) +
                 obtainPath(driver.cur_location - 1, next_station - 1) +
                 str(next_station)).split())
            del driver.route[0]
            # 遍历司机的路径列表
            for node_will_pass in driver.route:
                node_will_pass = int(node_will_pass)
                regl_Hexg_grids[nodes_belong_to_which_grid[node_will_pass] -
                                1].driver_will_coming.append([
                                    driver.driver_id,
                                    t_cur + datetime.timedelta(
                                        seconds=T[driver.cur_location -
                                                  1][node_will_pass - 1])
                                ])
예제 #4
0
def insertion_feasibility_check(query, driver, m, n, t_cur, regl_Hexg_grids):
    # 计算司机当前位置到达订单接载点位置所需要的时间
    t_i = 0
    # 如果m=1,那么司机直接从当前位置到达订单的接载点
    if m == 1:
        t_i = t_i + T[driver.cur_location - 1][query.pickup_location - 1]
    #如果m!=1,那么司机先经过schedule中前m-1个地点
    else:
        t_i = t_i + T[driver.cur_location - 1][driver.cur_schedule[0][0] - 1]
        for i in range(m - 2):
            t_i = t_i + T[driver.cur_schedule[i][0] -
                          1][driver.cur_schedule[i + 1][0] - 1]
        t_i = t_i + T[driver.cur_schedule[m - 2][0] -
                      1][query.pickup_location - 1]
    # 判断到达订单接载点的时间有没有超过最晚接载时间
    if t_cur + datetime.timedelta(seconds=t_i +
                                  driver.assist_t) > query.latest_pickup_time:
        return False

    # 插入订单接载点之后,在schedule中,判断订单接载点之后的地点是否超过最晚接载时间
    t_i = t_i + T[query.pickup_location - 1][driver.cur_schedule[m - 1][0] - 1]
    if t_cur + datetime.timedelta(
            seconds=t_i + driver.assist_t) > driver.cur_schedule[m - 1][1]:
        return False
    for i in range(m, len(driver.cur_schedule)):
        t_i = t_i + T[driver.cur_schedule[i - 1][0] -
                      1][driver.cur_schedule[i][0] - 1]
        if t_cur + datetime.timedelta(
                seconds=t_i + driver.assist_t) > driver.cur_schedule[i][1]:
            return False
    # 将订单接载点插入schedule中
    driver.cur_schedule.insert(
        m - 1, [query.pickup_location, query.latest_pickup_time, 0])

    # 计算从当前位置到达订单传送点所需的时间
    t_j = 0
    t_j = t_j + T[driver.cur_location - 1][driver.cur_schedule[0][0] - 1]
    for j in range(n + 1 - 2):
        t_j = t_j + T[driver.cur_schedule[j][0] -
                      1][driver.cur_schedule[j + 1][0] - 1]
    t_j = t_j + T[driver.cur_schedule[n + 1 - 2][0] -
                  1][query.delivery_location - 1]
    # 判断到达订单传送点的时间是否超过最晚传送时间
    if t_cur + datetime.timedelta(
            seconds=t_j + driver.assist_t) > query.latest_delivery_time:
        # 如果是,则删除插入schedule的接载点记录
        del driver.cur_schedule[m - 1]
        return False
    elif n == len(driver.cur_schedule):
        # 在schedule末尾插入订单传送点
        driver.cur_schedule.insert(
            n + 1 - 1,
            [query.delivery_location, query.latest_delivery_time, 1])
        # 计算司机没有共享运行的总距离
        driver.total_distance_no_sharing += D[query.pickup_location -
                                              1][query.delivery_location - 1]
        # 车上乘客加1
        driver.add_passenger(1)
        # 原来路径的第一个点
        first_location_origin_route = driver.route[0]
        # 从格子的driver_will_coming中删除剩下路径
        for node in driver.route:
            regl_Hexg_grids[nodes_belong_to_which_grid[int(node)] -
                            1].driver_will_coming = [
                                driver_tuple
                                for driver_tuple in regl_Hexg_grids[
                                    nodes_belong_to_which_grid[int(node)] -
                                    1].driver_will_coming
                                if driver_tuple[0] != driver.driver_id
                            ]
        # 重新计算路径
        driver.route = []
        driver.route.extend((str(driver.cur_location) + obtainPath(
            driver.cur_location - 1, driver.cur_schedule[0][0] - 1) +
                             str(driver.cur_schedule[0][0])).split())
        for i in range(len(driver.cur_schedule) - 1):
            driver.route.extend(
                (obtainPath(driver.cur_schedule[i][0] - 1,
                            driver.cur_schedule[i + 1][0] - 1) +
                 str(driver.cur_schedule[i + 1][0])).split())
        # 删除当前位置
        del driver.route[0]
        # 遍历司机的路径列表
        for node_will_pass in driver.route:
            node_will_pass = int(node_will_pass)
            regl_Hexg_grids[nodes_belong_to_which_grid[node_will_pass] -
                            1].driver_will_coming.append([
                                driver.driver_id, t_cur + datetime.timedelta(
                                    seconds=T[driver.cur_location -
                                              1][node_will_pass - 1])
                            ])
        # 如果调整之后的路径第一个点和原始路径第一个点相同
        if driver.route[0] == first_location_origin_route:
            driver.assist_t = driver.assist_t
        else:
            driver.assist_t = -abs(driver.assist_t)
        return True

    # 如果订单传送点插入位置不是在schedule最后,需要判断订单传送点插入位置之后的所有地点到达时是否超过最晚到达时间
    t_j = t_j + T[query.delivery_location -
                  1][driver.cur_schedule[n + 1 - 1][0] - 1]
    if t_cur + datetime.timedelta(
            seconds=t_j + driver.assist_t) > driver.cur_schedule[n + 1 - 1][1]:
        # 如果超时
        del driver.cur_schedule[m - 1]
        return False
    for j in range(n + 1, len(driver.cur_schedule)):
        t_j = t_j + T[driver.cur_schedule[j - 1][0] -
                      1][driver.cur_schedule[j][0] - 1]
        if t_cur + datetime.timedelta(
                seconds=t_j + driver.assist_t) > driver.cur_schedule[j][1]:
            del driver.cur_schedule[m - 1]
            return False
    # 将订单传送点插入schedule
    driver.cur_schedule.insert(
        n + 1 - 1, [query.delivery_location, query.latest_delivery_time, 1])
    # 计算司机没有共享运行的总距离
    driver.total_distance_no_sharing += D[query.pickup_location -
                                          1][query.delivery_location - 1]
    # 乘客加一
    driver.add_passenger(1)
    first_location_origin_route = driver.route[0]
    # 重新计算路径
    # 从格子的driver_will_coming中删除剩下路径
    for node in driver.route:
        regl_Hexg_grids[nodes_belong_to_which_grid[int(node)] -
                        1].driver_will_coming = [
                            driver_tuple for driver_tuple in regl_Hexg_grids[
                                nodes_belong_to_which_grid[int(node)] -
                                1].driver_will_coming
                            if driver_tuple[0] != driver.driver_id
                        ]
    driver.route = []
    driver.route.extend(
        (str(driver.cur_location) +
         obtainPath(driver.cur_location - 1, driver.cur_schedule[0][0] - 1) +
         str(driver.cur_schedule[0][0])).split())
    for i in range(len(driver.cur_schedule) - 1):
        driver.route.extend((obtainPath(driver.cur_schedule[i][0] - 1,
                                        driver.cur_schedule[i + 1][0] - 1) +
                             str(driver.cur_schedule[i + 1][0])).split())
    # 删除路径第一个点
    del driver.route[0]
    # 遍历司机的路径列表
    for node_will_pass in driver.route:
        node_will_pass = int(node_will_pass)
        regl_Hexg_grids[nodes_belong_to_which_grid[node_will_pass] -
                        1].driver_will_coming.append([
                            driver.driver_id, t_cur + datetime.timedelta(
                                seconds=T[driver.cur_location -
                                          1][node_will_pass - 1])
                        ])
    # 如果改变路径前后,下一个点相同,那么assist_t不变,否则变为-abs(driver.assist_t)
    if driver.route[0] == first_location_origin_route:
        driver.assist_t = driver.assist_t
    else:
        driver.assist_t = -abs(driver.assist_t)

    return True