Beispiel #1
0
def get_vehicle_instance_dict(vehicle_infos: list, id_to_order_item: dict,
                              id_to_factory: dict):
    id_to_vehicle = {}
    for vehicle_info in vehicle_infos:
        vehicle_id = vehicle_info.get("id")
        operation_time = vehicle_info.get("operation_time")
        capacity = vehicle_info.get("capacity")
        gps_id = vehicle_info.get("gps_id")
        carrying_item_id_list = vehicle_info.get("carrying_items")
        carrying_items = [
            id_to_order_item.get(item_id) for item_id in carrying_item_id_list
            if item_id in carrying_item_id_list
        ]
        destination = vehicle_info.get("destination")
        if destination is not None:
            destination = __get_destination(destination, id_to_factory,
                                            id_to_order_item)

        logger.debug(f"Get vehicle {vehicle_id} instance from json, "
                     f"item id list = {len(carrying_item_id_list)},"
                     f"item list = {len(carrying_items)}")
        if vehicle_id not in id_to_vehicle:
            vehicle = Vehicle(vehicle_id, capacity, gps_id, operation_time,
                              carrying_items)
            vehicle.destination = destination
            id_to_vehicle[vehicle_id] = vehicle
    return id_to_vehicle
Beispiel #2
0
    def __meet_order_splitting_constraint(dispatch_result, id_to_vehicle: dict, id_to_order: dict):
        vehicle_id_to_destination = dispatch_result.vehicle_id_to_destination
        vehicle_id_to_planned_route = dispatch_result.vehicle_id_to_planned_route

        vehicle_id_to_item_list = get_item_list_of_vehicles(dispatch_result, id_to_vehicle)

        capacity = 0
        split_order_id_list = Checker.__find_split_orders_from_vehicles(vehicle_id_to_item_list)

        for vehicle_id, vehicle in id_to_vehicle.items():
            logger.debug(f"Find split orders of vehicle {vehicle_id}")

            capacity = vehicle.board_capacity
            carrying_items = copy.deepcopy(vehicle.carrying_items)
            route = []
            if vehicle_id in vehicle_id_to_destination and vehicle_id_to_destination.get(vehicle_id) is not None:
                route.append(vehicle_id_to_destination.get(vehicle_id))
            if vehicle_id in vehicle_id_to_planned_route:
                route.extend(vehicle_id_to_planned_route.get(vehicle_id))
            split_order_id_list.extend(Checker.__find_split_orders_in_vehicle_routes(route, carrying_items))

        for order_id in split_order_id_list:
            if order_id in id_to_order:
                order = id_to_order.get(order_id)
                if order.demand <= capacity:
                    logger.error(f"order {order.id} demand: {order.demand} <= {capacity}, we can not split this order.")
                    return False
        return True
Beispiel #3
0
 def __init__(self,
              order_id: str,
              components: dict,
              demand: float,
              creation_time: int,
              committed_completion_time: int,
              loading_time: int,
              unloading_time: int,
              delivery_factory_id: str,
              pickup_factory_id: str,
              delivery_state=0):
     """
     :param order_id: 订单编号
     :param components: 订单包含的物料, components of the order, e.g. {'PALLET': 1, 'HALF_PALLET': 1, 'BOX': 2}
     :param demand: 货物总量, total cargo number, unit is standard pallet
     :param creation_time: unix timestamp, unit is second
     :param committed_completion_time: unix timestamp, unit is second
     :param loading_time: unit is second
     :param unloading_time: unit is second
     :param delivery_factory_id: 送货地
     :param pickup_factory_id: 取货地
     :param delivery_state: state of the order, 0: 初始(initialization), 1: 已生成(generated), 2: 进行中(ongoing), 3: 完成(Completed)
     """
     self.id = order_id
     self.creation_time = creation_time
     self.committed_completion_time = committed_completion_time
     self.load_time = loading_time
     self.unload_time = unloading_time
     self.pickup_factory_id = pickup_factory_id
     self.delivery_factory_id = delivery_factory_id
     self.components = components
     self.demand = demand
     self.item_list = []
     self.delivery_state = int(delivery_state)
     logger.debug(
         f"{order_id}, creation time: {datetime.datetime.fromtimestamp(creation_time)}, "
         f"committed completion time: {datetime.datetime.fromtimestamp(committed_completion_time)}, "
         f"components: {self.components.get(Configs.STANDARD_PALLET_LABEL, 0)} standard pallets, "
         f"{self.components.get(Configs.SMALL_PALLET_LABEL, 0)} small pallets, "
         f"{self.components.get(Configs.BOX_LABEL, 0)} boxes, "
         f"pickup factory id: {delivery_factory_id}, delivery factory id: {pickup_factory_id}"
     )
Beispiel #4
0
    def __find_split_orders_from_vehicles(vehicle_id_to_item_list: dict):
        order_id_to_vehicle_ids = {}
        for vehicle_id, item_list in vehicle_id_to_item_list.items():
            order_id_list = []
            for item in item_list:
                order_id = item.order_id
                if order_id not in order_id_list:
                    order_id_list.append(order_id)
            logger.debug(f"Vehicle {vehicle_id} contains {len(order_id_list)} orders, {len(item_list)} order items")

            for order_id in order_id_list:
                if order_id not in order_id_to_vehicle_ids:
                    order_id_to_vehicle_ids[order_id] = []
                order_id_to_vehicle_ids[order_id].append(vehicle_id)

        split_order_ids = []
        for order_id, vehicle_ids in order_id_to_vehicle_ids.items():
            if len(vehicle_ids) > 1:
                split_order_ids.append(order_id)
        logger.debug(f"Find {len(split_order_ids)} split orders from vehicles")
        return split_order_ids
Beispiel #5
0
    def __find_split_orders_in_vehicle_routes(route, carrying_items):
        order_id_list = []
        split_order_ids = []
        while not carrying_items.is_empty():
            item = carrying_items.pop()
            order_id = item.order_id
            if order_id not in order_id_list:
                order_id_list.append(order_id)

        for node in route:
            tmp_order_id_list = []
            pickup_items = node.pickup_items
            for item in pickup_items:
                if item.order_id not in tmp_order_id_list:
                    tmp_order_id_list.append(item.order_id)
            for order_id in tmp_order_id_list:
                if order_id not in order_id_list:
                    order_id_list.append(order_id)
                else:
                    split_order_ids.append(order_id)
        logger.debug(f"find {len(split_order_ids)} split orders")
        return split_order_ids