負載成本

載重成本是在 `ShipmentModel` 下的 `Vehicle` 的 `loadLimits` 屬性中定義。

載貨成本是指車輛在取貨和送貨之間載貨時產生的成本或罰款。你可以根據costPerKilometer的旅行距離、costPerTraveledHour的旅行時間,或同時使用兩者來設定這些費用。

設定載入費用,以支援下列目標:

  • 將燃料成本納入考量,這項成本會隨著貨物重量增加。
  • 避免讓重型車輛長途行駛。
  • 考量重物造成的車輛磨損。

屬性

在 Vehicle 的 loadLimits 屬性中指定負載成本。 與所有其他費用參數一樣,載入費用會使用無因次相對費用單位。

您可以使用下列屬性定義裝載成本:

屬性 類型 說明
costPerKilometer 物件 包含 LoadCost 物件型別,可根據行駛里程計算交通費用。
costPerTraveledHour 物件 包含 LoadCost 物件型別,可根據旅行時數計算旅行費用,不含等待、拜訪和休息時間。

LoadCost

LoadCost 訊息類型會定義運送特定貨物的旅行費用。您可以設定負載閾值,然後指定低於和高於該閾值的每單位負載的不同費率。

LoadCost 物件包含下列設定參數:

參數 類型 說明
loadThreshold 字串 (64 位元整數格式) 費用計算費率變更的負載量。預設值為 0。
costPerUnitAboveThreshold 數字 高於 loadThreshold 的每單位負載所適用的費用。預設值為 0。
costPerUnitBelowThreshold 數字 套用至每個負載單位的費用低於或等於 loadThreshold。預設值為 0。

將貨物成本與出貨項目配對

當車輛運送的貨物符合路線上的出貨loadDemands類型時,系統會套用裝載成本。負載類型是任意字串,例如重量或體積。如要進一步瞭解如何設定負載類型,請參閱「負載類型」。

範例

本節將說明三種範例:

程式碼範例

以下範例說明如何使用所有可用的設定參數,建構載入費用。這個範例使用 costPerKilometer,但您可以將其替換為 costPerTraveledHour,根據旅行時間而非距離計算費用。

{
  "model": {
    "vehicles": [{
      "loadLimits": {
        "LOAD_TYPE": {
          "maxLoad": "MAX_LOAD",
          "costPerKilometer": {
            "loadThreshold": "LOAD_THRESHOLD",
            "costPerUnitAboveThreshold": COST_ABOVE,
            "costPerUnitBelowThreshold": COST_BELOW
          }
        }
      }
    }]
  }
}

範例情境

本節說明如何盡量減少燃料消耗量,而燃料消耗量與距離和貨物重量成正比。車輛載重越大,耗油量就越高,因此建議先配送較重的包裹。

如要設定這項行為,可以設定要求,對載重物長途行駛的車輛進行處罰。在本範例中,請在要求中使用下列屬性值:

父項 屬性 類型 值 情境
loadLimits 負載類型 字串 weightKg 定義要追蹤的容量類型。這個範例使用 weightKg 代表貨物重量 (以公斤為單位)。
loadLimits maxLoad 字串 100 車輛可載運的貨物重量上限。
costPerKilometer loadThreshold 字串 15 設定基準負載門檻。如果貨物重量超過 15 公斤,將依重量收取燃料費罰款。
costPerKilometer costPerUnitAboveThreshold 數字 1 做為燃料費用係數。每超過 15 公斤的貨物,每行駛一公里就會產生 1 個費用單位。
loadDemands amount 字串 出貨批次 1:50
出貨批次 2:10
出貨批次 3:80
指出三批貨物各自的重量。

在這個情境中,您設定的值會產生下列影響:

  • 最佳化工具會安排路線,優先遞送最重的包裹。求解器會在路線開頭安排 80 公斤和 50 公斤的配送作業,盡量減少重物載運時的行駛距離。
  • 最佳化工具會安排路線,盡量縮短載運重物時的行駛距離。如要瞭解這些設定對路線的影響,可以將 costPerUnitAboveThreshold 從 1 增加到 5。提高重量懲罰,可促使最佳化工具更加努力,盡量減少載重貨物行駛的距離,這可能會重新安排卸貨順序,或將貨物分裝到多部車輛。

要求範例

以下範例顯示基本 optimizeTours 要求的結構,其中納入範例情境中的載入費用值:

{
  "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
            }
          }
        }
      }
    ]
  }
}

計算公式

最佳化工具會使用下列公式計算負載成本。

完整門檻計算

如果同時指定 costPerUnitAboveThreshold 和 costPerUnitBelowThreshold,系統會針對高於和低於 loadThreshold 的負載量分別計算運送費用。公式如下:

cost = max(carried_load - load_threshold, 0) * distance_or_time * cost_per_unit_above_threshold
       + min(carried_load, load_threshold) * distance_or_time * cost_per_unit_below_threshold

舉例來說,使用要求範例中的值,其中 costPerUnitBelowThreshold 的值為 2,如果車輛載重 50 公斤行駛 10 公里,計算方式如下:

max(50 - 15, 0) * 10 * 1 + min(50, 15) * 10 * 2 = 650 cost units

高於門檻的計算方式

如果只指定 costPerUnitAboveThreshold,計算方式會是完整門檻公式的特例。由於低於門檻的費用為零,完整公式的後半部會評估為零。公式如下:

cost = max(carried_load - load_threshold, 0) * distance_or_time * cost_per_unit_above_threshold

舉例來說,使用要求範例中的值,其中 loadThreshold 為 15,costPerUnitAboveThreshold 為 1,如果車輛載重 50 公斤行駛 10 公里,計算方式如下:

max(50 - 15, 0) * 10 * 1 = 350 cost units

低於門檻的計算方式

同樣地,如果您只指定 costPerUnitBelowThreshold,則計算方式是完整門檻公式的另一種特殊情況,其中高於門檻的費用為零。公式如下:

cost = min(carried_load, load_threshold) * distance_or_time * cost_per_unit_below_threshold