发出包含加载费用的请求

发出包含载客费用的请求,以便优化器考虑车辆在两次访问之间的载客量。所产生的费用取决于所传输的 ShipmentRoute.VehicleLoad 量以及转换的距离或时长(分别使用 cost_per_kilometercost_per_traveled_hour)。

包含加载费用的最小请求示例

以下是包含加载费用的请求的部分示例。在此示例中,单辆车辆的总 weightKg 载荷不得超过 1,000 千克,如果载运的 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

因此,如果车辆的 weightLbs 载荷为 950,且行驶 5 小时,则计算方式如下:

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。

    以下命令会向路线优化 API 发送 OptimizeTours 请求,并同步接收响应。

    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

请求完成后,您会收到一条回复消息。