Ví dụ này cho thấy cách sử dụng loadDemands và loadLimits để quản lý các hạn chế về sức chứa của xe trong yêu cầu Route Optimization API.
Để biết thông tin tổng quan đầy đủ về khái niệm, hãy xem tài liệu Các khái niệm chính về nhu cầu và giới hạn tải.
Ví dụ về yêu cầu
Ví dụ sau đây minh hoạ một tình huống trong đó một chiếc xe duy nhất có giới hạn tải phải giao 3 lô hàng có trọng lượng khác nhau.
Yêu cầu ví dụ này chứa các thông số liên quan đến tải sau đây:
shipments[0]với nhu cầu tảiamountlà 50weightKg.shipments[1]có nhu cầu tảiamountlà 10weightKg.shipments[2]với nhu cầu tảiamountlà 80weightKg.vehicles[0]với giới hạn tảimaxLoadlà 100weightKg.
Xem ví dụ về yêu cầu có nhu cầu và giới hạn tải
{ "populatePolylines": false, "populateTransitionPolylines": false, "model": { "globalStartTime": "2023-01-13T16:00:00Z", "globalEndTime": "2023-01-14T16:00:00Z", "shipments": [ { "deliveries": [ { "arrivalLocation": { "latitude": 37.789456, "longitude": -122.390192 }, "duration": "250s" } ], "pickups": [ { "arrivalLocation": { "latitude": 37.794465, "longitude": -122.394839 }, "duration": "150s" } ], "penaltyCost": 100.0, "loadDemands": { "weightKg": { "amount": "50" } } }, { "deliveries": [ { "arrivalLocation": { "latitude": 37.789116, "longitude": -122.395080 }, "duration": "250s" } ], "pickups": [ { "arrivalLocation": { "latitude": 37.794465, "longitude": -122.394839 }, "duration": "150s" } ], "penaltyCost": 15.0, "loadDemands": { "weightKg": { "amount": "10" } } }, { "deliveries": [ { "arrivalLocation": { "latitude": 37.795242, "longitude": -122.399347 }, "duration": "250s" } ], "pickups": [ { "arrivalLocation": { "latitude": 37.794465, "longitude": -122.394839 }, "duration": "150s" } ], "penaltyCost": 50.0, "loadDemands": { "weightKg": { "amount": "80" } } } ], "vehicles": [ { "endLocation": { "latitude": 37.794465, "longitude": -122.394839 }, "startLocation": { "latitude": 37.794465, "longitude": -122.394839 }, "costPerHour": 40.0, "costPerKilometer": 10.0, "loadLimits": { "weightKg": { "maxLoad": "100" } } } ] } }
Ví dụ về phản hồi
Phản hồi cho thấy tuyến đường được tối ưu hoá cho xe. Vì tổng trọng lượng của tất cả các lô hàng vượt quá sức chứa của xe, nên trình tối ưu hoá sẽ tạo một chuỗi các lượt lấy hàng và giao hàng để đảm bảo không vi phạm loadLimits.
Xem phản hồi cho yêu cầu có nhu cầu và giới hạn tải
{ "routes": [ { "vehicleStartTime": "2023-01-13T16:00:00Z", "vehicleEndTime": "2023-01-13T16:43:27Z", "visits": [ { "isPickup": true, "startTime": "2023-01-13T16:00:00Z", "detour": "0s", "loadDemands": { "weightKg": { "amount": "50" } } }, { "shipmentIndex": 1, "isPickup": true, "startTime": "2023-01-13T16:02:30Z", "detour": "150s", "loadDemands": { "weightKg": { "amount": "10" } } }, { "startTime": "2023-01-13T16:08:55Z", "detour": "150s", "loadDemands": { "weightKg": { "amount": "-50" } } }, { "shipmentIndex": 1, "startTime": "2023-01-13T16:16:37Z", "detour": "343s", "loadDemands": { "weightKg": { "amount": "-10" } } }, { "shipmentIndex": 2, "isPickup": true, "startTime": "2023-01-13T16:27:07Z", "detour": "1627s", "loadDemands": { "weightKg": { "amount": "80" } } }, { "shipmentIndex": 2, "startTime": "2023-01-13T16:36:26Z", "detour": "0s", "loadDemands": { "weightKg": { "amount": "-80" } } } ], "transitions": [ { "travelDuration": "0s", "waitDuration": "0s", "totalDuration": "0s", "startTime": "2023-01-13T16:00:00Z", "vehicleLoads": { "weightKg": {} } }, { "travelDuration": "0s", "waitDuration": "0s", "totalDuration": "0s", "startTime": "2023-01-13T16:02:30Z", "vehicleLoads": { "weightKg": { "amount": "50" } } }, { "travelDuration": "235s", "travelDistanceMeters": 795, "waitDuration": "0s", "totalDuration": "235s", "startTime": "2023-01-13T16:05:00Z", "vehicleLoads": { "weightKg": { "amount": "60" } } }, { "travelDuration": "212s", "travelDistanceMeters": 791, "waitDuration": "0s", "totalDuration": "212s", "startTime": "2023-01-13T16:13:05Z", "vehicleLoads": { "weightKg": { "amount": "10" } } }, { "travelDuration": "380s", "travelDistanceMeters": 1190, "waitDuration": "0s", "totalDuration": "380s", "startTime": "2023-01-13T16:20:47Z", "vehicleLoads": { "weightKg": {} } }, { "travelDuration": "409s", "travelDistanceMeters": 1371, "waitDuration": "0s", "totalDuration": "409s", "startTime": "2023-01-13T16:29:37Z", "vehicleLoads": { "weightKg": { "amount": "80" } } }, { "travelDuration": "171s", "travelDistanceMeters": 665, "waitDuration": "0s", "totalDuration": "171s", "startTime": "2023-01-13T16:40:36Z", "vehicleLoads": { "weightKg": {} } } ], "metrics": { "performedShipmentCount": 3, "travelDuration": "1407s", "waitDuration": "0s", "delayDuration": "0s", "breakDuration": "0s", "visitDuration": "1200s", "totalDuration": "2607s", "travelDistanceMeters": 4812, "maxLoads": { "weightKg": { "amount": "80" } } }, "routeCosts": { "model.vehicles.cost_per_kilometer": 48.12, "model.vehicles.cost_per_hour": 28.966666666666665 }, "routeTotalCost": 77.086666666666659 } ], "metrics": { "aggregatedRouteMetrics": { "performedShipmentCount": 3, "travelDuration": "1407s", "waitDuration": "0s", "delayDuration": "0s", "breakDuration": "0s", "visitDuration": "1200s", "totalDuration": "2607s", "travelDistanceMeters": 4812, "maxLoads": { "weightKg": { "amount": "80" } } }, "usedVehicleCount": 1, "earliestVehicleStartTime": "2023-01-13T16:00:00Z", "latestVehicleEndTime": "2023-01-13T16:43:27Z", "totalCost": 77.086666666666659, "costs": { "model.vehicles.cost_per_hour": 28.966666666666665, "model.vehicles.cost_per_kilometer": 48.12 } } }
Vì tổng loadDemands của 3 lô hàng (50 + 10 + 80 = 140) vượt quá loadLimits của xe (100), nên xe không thể nhận tất cả các lô hàng cùng một lúc. Trình tối ưu hoá chỉ xem xét những tuyến đường mà shipment[0] và shipment[2] không cùng nằm trong xe, vì những lô hàng này là những lô hàng vượt quá giới hạn tải trọng của xe khi kết hợp trọng lượng của chúng.
Tuyến đường có visits sau đây để không vượt quá giới hạn tải trọng của xe:
- Đã đến lấy
shipment[0] - Đã đến lấy
shipment[1] shipment[0]đã được gửishipment[1]đã được gửi- Đã đến lấy
shipment[2] shipment[2]đã được gửi
Tải trọng của xe thay đổi trong suốt tuyến đường, bạn có thể quan sát điều này trong mảng transitions. Ví dụ: transitions[2] cho thấy chiếc xe đang chở 60 weightKg sau khi nhận 2 lô hàng đầu tiên (50 + 10).
Thuộc tính maxLoads trong metrics cho thấy tải trọng tối đa được chở tại bất kỳ thời điểm nào trên tuyến đường là 80 weightKg, xác nhận rằng giải pháp đã nằm trong giới hạn 100 weightKg của xe.
Giới hạn tải mềm
Ví dụ sau đây cho thấy cách sử dụng giới hạn tải mềm để tối ưu hoá một tuyến đường có nhiều xe. Giải pháp này chia các lô hàng giữa hai xe để tránh bị phạt chi phí do vượt quá giới hạn tải mềm của xe.
Ví dụ về yêu cầu
Yêu cầu này hiện bao gồm 3 lô hàng chỉ giao và 2 xe có cùng loadLimits và softMaxLoad.
Các tham số chính cho ví dụ này là:
- Tổng
- 60 + 30).
loadDemandscủa 3 lô hàng là 140weightKg(50- Có 2 chiếc xe có
softMaxLoadlà "100"weightKgvàcostPerUnitAboveSoftMaxlà 5.0.
Xem ví dụ về yêu cầu có giới hạn tải mềm
{ "populatePolylines": false, "populateTransitionPolylines": false, "model": { "globalStartTime": "2023-01-13T16:00:00Z", "globalEndTime": "2023-01-14T16:00:00Z", "shipments": [ { "deliveries": [ { "arrivalLocation": { "latitude": 37.789456, "longitude": -122.390192 }, "duration": "250s" } ], "loadDemands": { "weightKg": { "amount": "50" } } }, { "deliveries": [ { "arrivalLocation": { "latitude": 37.789116, "longitude": -122.395080 }, "duration": "250s" } ], "loadDemands": { "weightKg": { "amount": "60" } } }, { "deliveries": [ { "arrivalLocation": { "latitude": 37.795242, "longitude": -122.399347 }, "duration": "250s" } ], "loadDemands": { "weightKg": { "amount": "30" } } } ], "vehicles": [ { "endLocation": { "latitude": 37.794465, "longitude": -122.394839 }, "startLocation": { "latitude": 37.794465, "longitude": -122.394839 }, "costPerHour": 40.0, "costPerKilometer": 10.0, "loadLimits": { "weightKg": { "maxLoad": "150", "softMaxLoad": "100", "costPerUnitAboveSoftMax": 5.0 } } }, { "endLocation": { "latitude": 37.794465, "longitude": -122.394839 }, "startLocation": { "latitude": 37.794465, "longitude": -122.394839 }, "costPerHour": 40.0, "costPerKilometer": 10.0, "loadLimits": { "weightKg": { "maxLoad": "150", "softMaxLoad": "100", "costPerUnitAboveSoftMax": 5.0 } } } ] } }
Ví dụ về phản hồi
Giờ đây, phản hồi chứa 2 tuyến đường, mỗi tuyến đường cho một xe. Trình tối ưu hoá xác định rằng việc sử dụng cả hai xe sẽ tiết kiệm chi phí hơn so với việc sử dụng một xe và chịu mức phạt giới hạn mềm.
Xem phản hồi cho yêu cầu có giới hạn tải mềm
{ "routes": [ { "vehicleStartTime": "2023-01-13T16:00:00Z", "vehicleEndTime": "2023-01-13T16:13:31Z", "visits": [ { "startTime": "2023-01-13T16:03:53Z", "detour": "0s", "loadDemands": { "weightKg": { "amount": "-50" } } } ], "transitions": [ { "travelDuration": "233s", "travelDistanceMeters": 794, "waitDuration": "0s", "totalDuration": "233s", "startTime": "2023-01-13T16:00:00Z", "vehicleLoads": { "weightKg": { "amount": "50" } } }, { "travelDuration": "328s", "travelDistanceMeters": 1188, "waitDuration": "0s", "totalDuration": "328s", "startTime": "2023-01-13T16:08:03Z", "vehicleLoads": { "weightKg": {} } } ], "metrics": { "performedShipmentCount": 1, "travelDuration": "561s", "visitDuration": "250s", "totalDuration": "811s", "travelDistanceMeters": 1982, "maxLoads": { "weightKg": { "amount": "50" } } }, "routeCosts": { "model.vehicles.cost_per_kilometer": 19.82, "model.vehicles.cost_per_hour": 9.01 }, "routeTotalCost": 28.83 }, { "vehicleIndex": 1, "vehicleStartTime": "2023-01-13T16:00:00Z", "vehicleEndTime": "2023-01-13T16:21:43Z", "visits": [ { "shipmentIndex": 1, "startTime": "2023-01-13T16:05:54Z", "detour": "0s", "loadDemands": { "weightKg": { "amount": "-60" } } }, { "shipmentIndex": 2, "startTime": "2023-01-13T16:13:52Z", "detour": "473s", "loadDemands": { "weightKg": { "amount": "-30" } } } ], "transitions": [ { "travelDuration": "354s", "travelDistanceMeters": 1196, "waitDuration": "0s", "totalDuration": "354s", "startTime": "2023-01-13T16:00:00Z", "vehicleLoads": { "weightKg": { "amount": "90" } } }, { "travelDuration": "228s", "travelDistanceMeters": 808, "waitDuration": "0s", "totalDuration": "228s", "startTime": "2023-01-13T16:10:04Z", "vehicleLoads": { "weightKg": { "amount": "30" } } }, { "travelDuration": "221s", "travelDistanceMeters": 655, "waitDuration": "0s", "totalDuration": "221s", "startTime": "2023-01-13T16:18:02Z", "vehicleLoads": { "weightKg": {} } } ], "metrics": { "performedShipmentCount": 2, "travelDuration": "803s", "visitDuration": "500s", "totalDuration": "1303s", "travelDistanceMeters": 2659, "maxLoads": { "weightKg": { "amount": "90" } } }, "routeCosts": { "model.vehicles.cost_per_kilometer": 26.59, "model.vehicles.cost_per_hour": 14.48 }, "routeTotalCost": 41.07 } ], "metrics": { "aggregatedRouteMetrics": { "performedShipmentCount": 3, "travelDuration": "1364s", "visitDuration": "750s", "totalDuration": "2114s", "travelDistanceMeters": 4641, "maxLoads": { "weightKg": { "amount": "90" } } }, "usedVehicleCount": 2, "earliestVehicleStartTime": "2023-01-13T16:00:00Z", "latestVehicleEndTime": "2023-01-13T16:21:43Z", "totalCost": 69.90, "costs": { "model.vehicles.cost_per_kilometer": 46.41, "model.vehicles.cost_per_hour": 23.49 } } }
Các trường sau đây cho biết cách trình tối ưu hoá chia các lô hàng trên 2 xe để giữ tải trọng dưới hạn mức mềm là 100 weightKg.
- Tuyến đường đầu tiên (
vehicleIndex: 0) xử lý lô hàng 50weightKg.maxLoadscủa chiến dịch là "50", thấp hơn giới hạn mềm. - Tuyến đường thứ hai (
vehicleIndex: 1) xử lý 60 và 30 lô hàngweightKg.maxLoadscủa chỉ số này là "90", cũng thấp hơn giới hạn mềm. - Vì không có xe nào vi phạm giới hạn mềm, nên
routeCostscho cả hai tuyến đường đều không bị phạtcostPerUnitAboveSoftMax.