提出含有負載成本的請求

請提出含有載運成本的要求,讓最佳化工具考量車輛在兩次造訪之間載運的貨物。產生的費用取決於所運送的 ShipmentRoute.VehicleLoad 數量,以及轉換的距離或時間長度 (分別使用 cost_per_kilometercost_per_traveled_hour)。

含有負載費用的最低要求範例

以下是含載入成本的請求範例。在這個範例中,單一車輛最多可載運 1000 公斤的weightKg 總負載量,如果載運的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 小時內載有 950 的 weightLbs 負載,計算方式如下:

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,系統會使用公式 max(0, load - load_threshold) 計算車輛負載量超過 load_threshold 的費用,並以此為比例增加費用。如果指定 cost_per_unit_below_threshold,系統會使用 min(load, load_threshold) 公式,根據車輛在 load_threshold 以下的負載量,以比例方式加入費用。
負載成本參數的預設值為何? load_thresholdcost_per_unit_above_thresholdcost_per_unit_below_threshold 預設為零。
負載成本以哪個單位表示? 負載費用的單位與其他所有費用參數相同,例如 global_duration_cost_per_hourShipment.penalty_cost
在回應中哪裡可以找到載入成本? 產生的負載費用會顯示在回應訊息的 metricsroute_metrics 屬性中。舉例來說,產生的 cost_per_kilometer 會顯示為 model.vehicles.load_limits.cost_per_kilometer

如需負載費用的詳細說明,請參閱參考說明文件 (RESTgRPC)。

範例:提出 OptimizeTours 要求

您也可以使用 RESTgRPC 提出 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

要求完成後,您會收到回覆訊息。