费用模型参数

OptimizeToursRequest 消息(RESTgRPC)包含许多与 costs 相关的属性。这些费用参数共同代表请求的费用模型。费用模型涵盖了请求的许多高级优化目标,例如:

  • 优先考虑较快的 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)属性表示软性约束,即在无法满足时会产生费用的约束条件。

例如,车辆 LoadLimitRESTgRPC)约束条件具有 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 限制条件。