提出要求時附上載重成本,讓最佳化工具考量車輛在拜訪地點之間運送的載重。產生的費用取決於攜帶的 ShipmentRoute.VehicleLoad
數量,以及轉移的距離或時間 (分別使用 cost_per_kilometer
或 cost_per_traveled_hour
)。
包含負載費用的最低要求範例
以下是部分要求範例,其中包含載入費用。在這個例子中,單一車輛的總weightKg
負重不得超過 1000 公斤,且當weightKg
負重超過 500 公斤時,每公里會產生 1 個費用單位。
{ "model": { "vehicles": [{ "loadLimits": { "weightKg": { "maxLoad": "1000", "costPerKilometer": { "loadThreshold": "500", "costPerUnitAboveThreshold": 1 } } } }] } }
這個範例的載入費用計算方式如下:
cost = max(carried load - load threshold, 0) * distance * cost per unit above threshold
因此,如果車輛在 10 公里內運送 600 公斤的貨物,計算方式如下:weightKg
(600 - 500) * 10 * 1 = 1000 cost units
負載成本可用於模擬各種概念,例如運輸重物時車輛能源使用量增加,或車輛超載造成的磨損。
另一個包含載入費用的要求範例
以下是另一個負載成本範例,無論是否超過門檻,都會根據行駛時間收取費用:
{ "model": { "vehicles": [{ "loadLimits": { "weightLbs": { "maxLoad": "1000", "costPerTraveledHour": { "loadThreshold": "900", "costPerUnitAboveThreshold": 10, "costPerUnitBelowThreshold": 1 }, }, } }] } }
這個範例的載入費用計算方式如下:
cost = max(carried load - load threshold, 0) * time * cost per unit above threshold
+ min(carried load, load threshold) * time * cost per unit below threshold
因此,如果車輛在 5 小時內載運 weightLbs
950 的負載,計算方式如下:
max(950 - 900, 0) * 5 * 10 + min(950, 900) * 5 * 1 = 7000
在本例中,weightLbs
載入費用的 load_threshold
接近 max_load
。如果車輛載重特別重,cost_per_unit_above_threshold
會套用每行駛一小時的高成本,藉此懲罰可能增加車輛磨損或消耗過多燃料的路線。cost_per_unit_below_threshold
會為車輛運送的每單位重量增加費用,直到達到門檻為止,代表車輛負重增加時,燃料消耗量也會增加。
常見問題
以下是載入費用相關常見問題:
問題 | 解答 |
---|---|
要在哪裡指定載入費用? | 在 Vehicle.LoadLimit 中指定載入費用。 |
如何將裝載成本與出貨項目配對? | 如果貨物需求類型符合車輛的貨物限制類型 (例如重量或體積),則適用貨物成本。如載入需求和限制所述,載入類型是任意字串。 |
如何表示載入費用? | 負載成本會以轉換距離或時間表示。使用 cost_per_kilometer 指定距離費用,並使用 cost_per_traveled_hour 指定時間費用。 |
系統何時會套用載入費用? | 系統會比較車輛負重與負重成本的 load_threshold 。如果指定 cost_per_unit_above_threshold ,系統會根據車輛的負重超過 load_threshold 的比例,使用公式 max(0, load - load_threshold) 增加費用。如指定 cost_per_unit_below_threshold ,系統會根據車輛的負載量 低於 load_threshold 的比例,使用 min(load, load_threshold) 公式計算並新增費用。 |
載入費用參數的預設值為何? | load_threshold 、cost_per_unit_above_threshold 和 cost_per_unit_below_threshold 預設值皆為零。
|
負載成本的單位為何? | 載入費用會以無因次單位表示,與所有其他費用參數相同,例如 global_duration_cost_per_hour 或 Shipment.penalty_cost 。 |
回應中的載入費用位於何處? | 產生的負載費用會顯示在回應訊息的 metrics 和 route_metrics 屬性中。舉例來說,產生的 cost_per_kilometer 會顯示為 model.vehicles.load_limits.cost_per_kilometer 。 |
如要詳細瞭解負載費用,請參閱參考說明文件 (REST、gRPC)。
範例:提出 OptimizeTours
要求
您也可以使用 REST 或 gRPC 提出 OptimizeTours
要求。
提出要求前,請將下列參數替換為適合您環境的值:
- 請確認您已按照「使用 OAuth」一文所述,設定應用程式預設憑證。
將 PROJECT_NUMBER_OR_ID 設為 Cloud 專案編號或 ID。
下列指令會將
OptimizeTours
要求傳送至 Route Optimization API,並同步接收回應。curl -X POST 'https://routeoptimization.googleapis.com/v1/projects/PROJECT_NUMBER_OR_ID:optimizeTours' \ -H "Content-Type: application/json" \ -H "Authorization: Bearer $(gcloud auth application-default print-access-token)" \ --data @- << EOM { "model": { "shipments": [ { "deliveries": [ { "arrivalLocation": { "latitude": 37.789456, "longitude": -122.390192 }, "duration": "250s" } ], "penaltyCost": 100.0, "loadDemands": { "weightKg": { "amount": 50 } } }, { "deliveries": [ { "arrivalLocation": { "latitude": 37.789116, "longitude": -122.395080 }, "duration": "250s" } ], "penaltyCost": 30.0, "loadDemands": { "weightKg": { "amount": 10 } } }, { "deliveries": [ { "arrivalLocation": { "latitude": 37.795242, "longitude": -122.399347 }, "duration": "250s" } ], "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", "costPerKilometer": { "loadThreshold": "15", "costPerUnitAboveThreshold": 1 } } } } ] } } EOM
要求完成後,您會收到回覆訊息。