发出包含加载费用的请求

发出包含负载费用的请求,以便优化工具考虑车辆在访问之间运送的负载。产生的费用取决于运送的 ShipmentRoute.VehicleLoad 量以及过渡的距离或时长(分别使用 cost_per_kilometercost_per_traveled_hour)。

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

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

    以下命令会向路线优化 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

请求完成后,您会收到一条响应消息。