# Route Optimization

The Route Optimization API solves [traveling salesman](https://en.wikipedia.org/wiki/Travelling_salesman_problem) and [vehicle routing problems](https://en.wikipedia.org/wiki/Vehicle_routing_problem): given a set of stops to visit and a set of vehicles to visit them with, it returns an assignment of stops to vehicles and an order to visit them in, minimizing an objective you choose (total time, number of vehicles used, longest single route, etc.) while respecting constraints you specify (time windows, vehicle capacities, driver skills, and many more).

This page describes the conceptual model. The endpoint reference pages linked at the bottom describe the request and response schema in detail. If you prefer to learn by example, jump to the [API Explorer](https://explorer.graphhopper.com/?endpoint=vrp) or the [Getting Started tutorial](https://www.graphhopper.com/blog/2019/05/17/getting-started-with-the-optimization-api-traveling-salesman-problem/).



## Solve a route optimization problem

 - [POST /vrp](https://docs.graphhopper.com/openapi/route-optimization/solvevrp.md): Start by reading the introduction to the Route Optimization API.

To solve a new vehicle routing problem, make a HTTP POST to this URL


https://graphhopper.com/api/1/vrp?key=


It returns the solution to this problem in the JSON response.

Please note that this endpoint is well suited for solving smaller problems.
Larger vehicle routing problems that take longer than 10 seconds to solve cannot be processed using this endpoint.
To solve them, please use the batch mode URL instead.

## Submit a route optimization job

 - [POST /vrp/optimize](https://docs.graphhopper.com/openapi/route-optimization/asyncvrp.md): 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=


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/?key=


We recommend querying the solution every 500ms until it returns 'status=finished'.

Note: Since the workflow is more complex and you lose some time fetching the solution, you should prefer
the synchronous endpoint when possible. Use the batch mode only for long-running problems.

## Retrieve solution of a route optimization job

 - [GET /vrp/solution/{jobId}](https://docs.graphhopper.com/openapi/route-optimization/getsolution.md): Take the job id and fetch the solution for the vehicle routing problem from this URL:


https://graphhopper.com/api/1/vrp/solution/?key=


You get the job id by sending a vehicle routing problem to the batch mode URL.

