費用模式參數

OptimizeToursRequest 訊息 (RESTgRPC) 包含與成本相關的多個屬性。這些費用參數加總起來,代表要求的費用模式。成本模型會擷取要求的許多高層級最佳化目標,例如:

  • 優先採用較短的 Vehicle 路線,或是逆向其他航線的路線
  • 決定是否應將 Shipment 提交成本視為 Shipment 完成作業的價值
  • 只在符合成本效益的情況下,才在時間範圍內提供取貨和交付服務

查看包含費用的要求範例

{
  "model": {
    "globalStartTime": "2023-01-13T16:00:00-08:00",
    "globalEndTime": "2023-01-14T16:00:00-08:00",
    "shipments": [
      {
        "deliveries": [
          {
            "arrivalLocation": {
              "latitude": 37.789456,
              "longitude": -122.390192
            },
            "duration": "250s"
          }
        ],
        "pickups": [
          {
            "arrivalLocation": {
              "latitude": 37.794465,
              "longitude": -122.394839
            },
            "duration": "150s"
          }
        ],
        "penaltyCost": 100.0
      },
      {
        "deliveries": [
          {
            "arrivalLocation": {
              "latitude": 37.789116,
              "longitude": -122.395080
            },
            "duration": "250s"
          }
        ],
        "pickups": [
          {
            "arrivalLocation": {
              "latitude": 37.794465,
              "longitude": -122.394839
            },
            "duration": "150s"
          }
        ],
        "penaltyCost": 5.0
      },
      {
        "deliveries": [
          {
            "arrivalLocation": {
              "latitude": 37.795242,
              "longitude": -122.399347
            },
            "duration": "250s"
          }
        ],
        "pickups": [
          {
            "arrivalLocation": {
              "latitude": 37.794465,
              "longitude": -122.394839
            },
            "duration": "150s"
          }
        ],
        "penaltyCost": 50.0
      }
    ],
    "vehicles": [
      {
        "endLocation": {
          "latitude": 37.794465,
          "longitude": -122.394839
        },
        "startLocation": {
          "latitude": 37.794465,
          "longitude": -122.394839
        },
        "costPerHour": 40.0,
        "costPerKilometer": 10.0
      }
    ]
  }
}
    

Vehicle 費用屬性

Vehicle 訊息 (RESTgRPC) 有幾個費用屬性:

  • Vehicle.cost_per_hour:代表每小時的車輛營運成本,包括運輸、等待、拜訪和休息時間。
  • Vehicle.cost_per_kilometer:代表車輛行駛每公里的費用。
  • Vehicle.cost_per_traveled_hour:代表只在大眾運輸的情況下駕駛車輛的費用,不含等待、造訪和休息時間。

這些成本參數可讓最佳化工具權衡時間與行駛距離。最佳化路徑產生的費用會以 metrics.costs 的形式顯示在回應訊息中:

隨著 costPerHour 增加,最佳化工具會嘗試找出較快的路徑,但可能不是最短路徑。在本範例中,最快的路徑剛好是最短路徑,因此變更成本參數幾乎沒有效果。

Shipment 費用屬性

Shipment 訊息 (RESTgRPC) 也包含多個費用參數:

  • Shipment.penalty_cost 代表略過運送作業所產生的費用。
  • Shipment.VisitRequest.cost 代表特定取貨或送貨的費用,主要用於在單一貨件中,為多個取貨或送貨選項提供成本取捨。

Shipment 成本參數使用與 Vehicle 成本參數相同的無維度單位。如果完成 Shipment 所產生的費用超過罰款費用,Shipment 就不會納入任何 Vehicle 的路線,而是會顯示在回應訊息的 skipped_shipments 清單中。

ShipmentModel 費用屬性

ShipmentModel 訊息 (RESTgRPC) 包含單一費用屬性 globalDurationCostPerHour。這筆費用的計算方式是根據所有車輛完成 ShipmentRoute 所需的總時間。提高 globalDurationCostPerHour 的值,可優先完成所有出貨作業。

路線最佳化回應費用屬性

OptimizeToursResponse 訊息 (RESTgRPC) 具有費用屬性,代表完成 ShipmentRoute 時產生的費用。metrics.costsmetrics.totalCost 屬性代表回應中所有路徑產生的費用單位數量。每個 routes 項目都有 routeCostsrouteTotalCosts 屬性,代表該特定路線的費用。

查看包含費用的示例申請回覆

{
  "routes": [
    {
      "vehicleStartTime": "2023-01-14T00:00:00Z",
      "vehicleEndTime": "2023-01-14T00:28:22Z",
      "visits": [
        {
          "isPickup": true,
          "startTime": "2023-01-14T00:00:00Z",
          "detour": "0s"
        },
        {
          "shipmentIndex": 2,
          "isPickup": true,
          "startTime": "2023-01-14T00:02:30Z",
          "detour": "150s"
        },
        {
          "startTime": "2023-01-14T00:08:55Z",
          "detour": "150s"
        },
        {
          "shipmentIndex": 2,
          "startTime": "2023-01-14T00:21:21Z",
          "detour": "572s"
        }
      ],
      "transitions": [
        {
          "travelDuration": "0s",
          "waitDuration": "0s",
          "totalDuration": "0s",
          "startTime": "2023-01-14T00:00:00Z"
        },
        {
          "travelDuration": "0s",
          "waitDuration": "0s",
          "totalDuration": "0s",
          "startTime": "2023-01-14T00:02:30Z"
        },
        {
          "travelDuration": "235s",
          "travelDistanceMeters": 795,
          "waitDuration": "0s",
          "totalDuration": "235s",
          "startTime": "2023-01-14T00:05:00Z"
        },
        {
          "travelDuration": "496s",
          "travelDistanceMeters": 1893,
          "waitDuration": "0s",
          "totalDuration": "496s",
          "startTime": "2023-01-14T00:13:05Z"
        },
        {
          "travelDuration": "171s",
          "travelDistanceMeters": 665,
          "waitDuration": "0s",
          "totalDuration": "171s",
          "startTime": "2023-01-14T00:25:31Z"
        }
      ],
      "metrics": {
        "performedShipmentCount": 2,
        "travelDuration": "902s",
        "waitDuration": "0s",
        "delayDuration": "0s",
        "breakDuration": "0s",
        "visitDuration": "800s",
        "totalDuration": "1702s",
        "travelDistanceMeters": 3353
      },
      "routeCosts": {
        "model.vehicles.cost_per_kilometer": 33.53,
        "model.vehicles.cost_per_hour": 18.911111111111111
      },
      "routeTotalCost": 52.441111111111113
    }
  ],
  "skippedShipments": [
    {
      "index": 1
    }
  ],
  "metrics": {
    "aggregatedRouteMetrics": {
      "performedShipmentCount": 2,
      "travelDuration": "902s",
      "waitDuration": "0s",
      "delayDuration": "0s",
      "breakDuration": "0s",
      "visitDuration": "800s",
      "totalDuration": "1702s",
      "travelDistanceMeters": 3353
    },
    "usedVehicleCount": 1,
    "earliestVehicleStartTime": "2023-01-14T00:00:00Z",
    "latestVehicleEndTime": "2023-01-14T00:28:22Z",
    "totalCost": 57.441111111111113,
    "costs": {
      "model.vehicles.cost_per_kilometer": 33.53,
      "model.vehicles.cost_per_hour": 18.911111111111111,
      "model.shipments.penalty_cost": 5
    }
  }
}
    

在範例回應中,頂層 metrics.costs 如下:

{
  "metrics": {
    ...
    "costs": {
      "model.vehicles.cost_per_hour": 18.911111111111111,
      "model.vehicles.cost_per_kilometer": 33.53,
      "model.shipments.penalty_cost": 5
    }
  }
}

model.shipments.penalty_cost 值代表因跳過出貨而產生的成本。skippedShipments 屬性會列出略過哪些出貨。

在本例中,系統只會略過範例要求中的 model.shipments[1]model.shipments[1] 的罰款費用為 5 個單位,與範例回應中的總 model.shipments.penalty_cost 鍵相符。相較於 Vehicle 的 40.0 costPerHour 和 10.0 costPerKilometer,出貨的 penaltyCost 較低,因此跳過出貨比完成出貨更符合成本效益。

進階主題:成本和軟性限制

幾個 OptimizeToursRequest 訊息 (RESTgRPC) 屬性代表軟性限制條件,也就是無法滿足的限制條件所產生的成本。

舉例來說,車輛 LoadLimit (RESTgRPC) 限制有 softMaxLoadcostPerUnitAboveSoftMax 屬性。綜合以上因素,這些資源會產生費用與超過 softMaxLoad 的載入單元成正比,因此只有在合理考量到費用的合理的情況下,才會超過限制。

同樣地,TimeWindow 限制 (RESTgRPC) 具有 soft_start_timesoft_end_time 屬性,以及相應的 cost_per_hour_before_soft_start_timecost_per_hour_after_soft_end_time 屬性,這些屬性是根據受限事件發生在 TimeWindow 的提前或延遲發生。

與所有成本模型參數一樣,軟限制成本會以與其他成本參數相同的無量綱單位表示。

如要進一步瞭解 LoadLimit 限制,請參閱「負載需求和限制」一文。TimeWindow 限制條件已在「接送和送達時間限制」一文中詳細說明。