1. Route Optimization
GraphHopper Directions API
  • Routing
    • Calculate a route
      GET
    • Calculate a route
      POST
  • Isochrones
    • Compute an isochrone
      GET
  • Matrices
    • Compute a matrix
      POST
    • Compute a matrix
      GET
    • Submit a matrix computation job
      POST
    • Retrieve result of a matrix computation job
      GET
  • Map Matching
    • Map-match a GPX file
      POST
  • Geocoding
    • Geocoding Endpoint
      GET
  • Route Optimization
    • Solve a route optimization problem
      POST
    • Submit a route optimization job
      POST
    • Retrieve solution of a route optimization job
      GET
  • Clustering
    • Solve a clustering problem
      POST
    • Submit a clustering job
      POST
    • Retrieve solution of a clustering job
      GET
  • Custom Profiles
    • Create a custom routing profile
      POST
    • List your custom routing profiles
      GET
    • Submit a profile creation job
      POST
    • Retrieve result of a profile creation job
      GET
    • Delete a custom routing profile
      DELETE
  • 数据模型
    • Schemas
      • ClusterResponse
      • Cluster
      • ClusterRequest
      • ClusterConfiguration
      • Clusters
      • ClusterCustomer
      • ClusterCustomerAddress
      • ClusterConfigurationRouting
      • ClusterConfigurationClustering
      • GeocodingResponse
      • GeocodingLocation
      • GeocodingPoint
      • MatrixRequest
      • SymmetricalMatrixRequest
      • MatrixResponse
      • RouteRequest
      • CustomModel
      • CustomModelForProfile
      • ProfileRequest
      • ProfileResponse
      • ProfileGetResponse
      • RouteResponse
      • EncodedLineString
      • BBox
      • FeatureCollection
      • RouteResponsePath
      • ResponseInfo
      • IsochroneResponse
      • IsochroneResponsePolygon
      • LineString
      • Polygon
      • GHError
      • JobId
      • BadRequest
      • ErrorMessage
      • InternalErrorMessage
      • Request
      • Vehicle
      • VehicleProfileId
      • Shift
      • Algorithm
      • Address
      • ResponseAddress
      • SnappedWaypoint
      • DriveTimeBreak
      • TimeWindowBreak
      • VehicleType
      • Service
      • Shipment
      • Pickup
      • Stop
      • TimeWindow
      • PreferredVehicle
      • Configuration
      • Optimization
      • Routing
      • Objective
      • CostMatrix
      • GroupRelation
      • JobRelation
      • Response
      • Solution
      • Detail
      • Route
      • RoutePoint
      • Activity
  1. Route Optimization

Submit a route optimization job

POST
/vrp/optimize
To solve a vehicle routing problem, perform the following steps:
1.) Make a HTTP POST to this URL
https://graphhopper.com/api/1/vrp/optimize?key=<your_key>
It returns a job id (job_id).
2.) Take the job id and fetch the solution for the vehicle routing problem from this URL:
https://graphhopper.com/api/1/vrp/solution/<job_id>?key=<your_key>
We recommend to query the solution every 500ms until it returns 'status=finished'.
Note: Since the workflow is a bit more cumbersome and since you lose some time in fetching the solution, you should always prefer
the synchronous endpoint. You should use the batch mode only for long running problems.

请求参数

Authorization
API Key
在 query 添加参数
key
示例:
key: ********************
or
Body 参数application/json必填

示例
{
    "vehicles": [
        {
            "vehicle_id": "vehicle-1",
            "type_id": "cargo-bike",
            "start_address": {
                "location_id": "berlin",
                "lon": 13.406,
                "lat": 52.537
            },
            "earliest_start": 1554804329,
            "latest_end": 1554808329,
            "max_jobs": 3
        },
        {
            "vehicle_id": "vehicle-2",
            "type_id": "cargo-bike",
            "start_address": {
                "location_id": "berlin",
                "lon": 13.406,
                "lat": 52.537
            },
            "earliest_start": 1554804329,
            "latest_end": 1554808329,
            "max_jobs": 3,
            "skills": [
                "physical strength"
            ]
        }
    ],
    "vehicle_types": [
        {
            "type_id": "cargo-bike",
            "capacity": [
                10
            ],
            "profile": "bike"
        }
    ],
    "services": [
        {
            "id": "s-1",
            "name": "visit-Joe",
            "address": {
                "location_id": "13.375854_52.537338",
                "lon": 13.375854,
                "lat": 52.537338
            },
            "size": [
                1
            ],
            "time_windows": [
                {
                    "earliest": 1554805329,
                    "latest": 1554806329
                }
            ]
        },
        {
            "id": "s-2",
            "name": "serve-Peter",
            "address": {
                "location_id": "13.393364_52.525851",
                "lon": 13.393364,
                "lat": 52.525851
            },
            "size": [
                1
            ]
        },
        {
            "id": "s-3",
            "name": "visit-Michael",
            "address": {
                "location_id": "13.416882_52.523543",
                "lon": 13.416882,
                "lat": 52.523543
            },
            "size": [
                1
            ]
        },
        {
            "id": "s-4",
            "name": "do nothing",
            "address": {
                "location_id": "13.395767_52.514038",
                "lon": 13.395767,
                "lat": 52.514038
            },
            "size": [
                1
            ]
        }
    ],
    "shipments": [
        {
            "id": "7fe77504-7df8-4497-843c-02d70b6490ce",
            "name": "pickup and deliver pizza to Peter",
            "priority": 1,
            "pickup": {
                "address": {
                    "location_id": "13.387613_52.529961",
                    "lon": 13.387613,
                    "lat": 52.529961
                }
            },
            "delivery": {
                "address": {
                    "location_id": "13.380575_52.513614",
                    "lon": 13.380575,
                    "lat": 52.513614
                }
            },
            "size": [
                1
            ],
            "required_skills": [
                "physical strength"
            ]
        }
    ],
    "objectives": [
        {
            "type": "min",
            "value": "vehicles"
        },
        {
            "type": "min",
            "value": "completion_time"
        }
    ],
    "configuration": {
        "routing": {
            "calc_points": true,
            "snap_preventions": [
                "motorway",
                "trunk",
                "tunnel",
                "bridge",
                "ferry"
            ]
        }
    }
}

请求示例代码

Shell
JavaScript
Java
Swift
Go
PHP
Python
HTTP
C
C#
Objective-C
Ruby
OCaml
Dart
R
请求示例请求示例
Shell
JavaScript
Java
Swift
curl --location '/vrp/optimize?key=%3Capi-key%3E' \
--header 'Content-Type: application/json' \
--data '{
    "vehicles": [
        {
            "vehicle_id": "vehicle-1",
            "type_id": "cargo-bike",
            "start_address": {
                "location_id": "berlin",
                "lon": 13.406,
                "lat": 52.537
            },
            "earliest_start": 1554804329,
            "latest_end": 1554808329,
            "max_jobs": 3
        },
        {
            "vehicle_id": "vehicle-2",
            "type_id": "cargo-bike",
            "start_address": {
                "location_id": "berlin",
                "lon": 13.406,
                "lat": 52.537
            },
            "earliest_start": 1554804329,
            "latest_end": 1554808329,
            "max_jobs": 3,
            "skills": [
                "physical strength"
            ]
        }
    ],
    "vehicle_types": [
        {
            "type_id": "cargo-bike",
            "capacity": [
                10
            ],
            "profile": "bike"
        }
    ],
    "services": [
        {
            "id": "s-1",
            "name": "visit-Joe",
            "address": {
                "location_id": "13.375854_52.537338",
                "lon": 13.375854,
                "lat": 52.537338
            },
            "size": [
                1
            ],
            "time_windows": [
                {
                    "earliest": 1554805329,
                    "latest": 1554806329
                }
            ]
        },
        {
            "id": "s-2",
            "name": "serve-Peter",
            "address": {
                "location_id": "13.393364_52.525851",
                "lon": 13.393364,
                "lat": 52.525851
            },
            "size": [
                1
            ]
        },
        {
            "id": "s-3",
            "name": "visit-Michael",
            "address": {
                "location_id": "13.416882_52.523543",
                "lon": 13.416882,
                "lat": 52.523543
            },
            "size": [
                1
            ]
        },
        {
            "id": "s-4",
            "name": "do nothing",
            "address": {
                "location_id": "13.395767_52.514038",
                "lon": 13.395767,
                "lat": 52.514038
            },
            "size": [
                1
            ]
        }
    ],
    "shipments": [
        {
            "id": "7fe77504-7df8-4497-843c-02d70b6490ce",
            "name": "pickup and deliver pizza to Peter",
            "priority": 1,
            "pickup": {
                "address": {
                    "location_id": "13.387613_52.529961",
                    "lon": 13.387613,
                    "lat": 52.529961
                }
            },
            "delivery": {
                "address": {
                    "location_id": "13.380575_52.513614",
                    "lon": 13.380575,
                    "lat": 52.513614
                }
            },
            "size": [
                1
            ],
            "required_skills": [
                "physical strength"
            ]
        }
    ],
    "objectives": [
        {
            "type": "min",
            "value": "vehicles"
        },
        {
            "type": "min",
            "value": "completion_time"
        }
    ],
    "configuration": {
        "routing": {
            "calc_points": true,
            "snap_preventions": [
                "motorway",
                "trunk",
                "tunnel",
                "bridge",
                "ferry"
            ]
        }
    }
}'

返回响应

🟢200成功
application/json
A jobId you can use to retrieve your solution from the server - see solution endpoint.
Headers

Bodyapplication/json

示例
{
    "job_id": "44886560-b584-4da5-b245-768151dacd8f"
}
🟠400请求有误
🔴500服务器错误
修改于 2025-11-25 06:18:54
上一页
Solve a route optimization problem
下一页
Retrieve solution of a route optimization job
Built with