加载费用

载荷成本在 `ShipmentModel` 下的 `Vehicle` 的 `loadLimits` 属性中定义。

载重成本用于指定车辆在取货和送货之间因载重而产生的成本或罚款。您可以使用 costPerKilometer 根据出行距离或使用 costPerTraveledHour 根据出行时长来配置这些费用,也可以同时使用这两种方式。

配置负载费用以支持以下目标:

  • 考虑因货物重量而增加的燃油费用。
  • 避免让重载车辆长距离行驶。
  • 考虑重型货物对车辆造成的磨损。

属性

在 Vehicle 的 loadLimits 属性中指定负载费用。 与其他所有费用形参一样,负载费用使用无量纲的相对费用单位。

您可以使用以下属性定义负载费用:

属性 类型 说明
costPerKilometer 对象 包含 LoadCost 对象类型,用于根据行驶的公里数计算差旅费用。
costPerTraveledHour 对象 包含 LoadCost 对象类型,用于根据出行时间(不包括等待时间、拜访时间和休息时间)计算出行费用。

LoadCost

LoadCost 消息类型用于定义运输特定负载的出行费用。您可以设置一个负载阈值,然后指定低于和高于该阈值的每单位负载的不同费用率。

LoadCost 对象包含以下配置参数:

参数 类型 说明
loadThreshold 字符串(int64 格式) 费用计算速率发生变化的负载级别。默认值为 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 用作燃油费用系数。每行驶 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