An optimized route that reorders stops to minimize the distance and time required to visit all locations.
What is optimized routing?
Optimized routing, also known as the traveling salesperson problem (TRP), is the process of finding the best route to travel for a single vehicle when you need to stop at multiple destinations. Optimized routing differs from simple routing because it can reorder the sequence of stops to create the most efficient route possible, while minimizing the travel distance or travel time. Simple routing does not change the order of the stops you provide. Both simple and optimized routing take into consideration different restrictions such as speed limit, number of lanes, road conditions, and other barriers.
You can use optimized routing to:
- Find the most efficient sequence of stops to multiple destinations.
- Find the quickest and most effective path from an origin to multiple locations.
- Generate driving directions in multiple languages.
How optimized routing works
The typical workflow for creating an optimized route is to:
- Define the origin, stops, and destination.
- Define the type of travel for the route.
- Set the
find
parameter toBest Sequence true
. Unless specified, the first and last stops you provide will be kept. - Access the routing service to find the route features and directions.
How to navigate a route
Once you have a route, if you want to use your current device's location to track progress and provide navigation instructions (voice guidance) as you traverse the route, the best way to accomplish this is with the ArcGIS Maps SDKs for Native Apps.
URL requests
You can find a route and directions by making an HTTPS request to the routing service solve
operation or by using client APIs. Specify the origin, destination, and optionally, additional parameters to refine the results with directions. Some of the most common parameters are described provided below.
Request limits
Limit | Direct | Job |
---|---|---|
Maximum number of stops | 150 | 10,000 |
Maximum transaction time: | 5 minutes | 60 minutes |
Maximum number of point barriers: | 250 | 250 |
Maximum number of street features intersected by polyline barriers: | 500 | 500 |
Maximum number of street features intersected by polygon barriers: | 2,000 | 2,000 |
Maximum straight-line distance for the walking travel mode: (If the straight-line distance between any stops is greater than this limit, the analysis will fail when the walking restriction is used.) | 27 miles (43.45 kilometers) | 27 miles (43.45 kilometers) |
Force hierarchy beyond a straight-line distance of: (If the straight-line distance between any stops is greater than the limit shown here, the analysis uses hierarchy, even if the travel defines not to use hierarchy.) | 50 miles (80.46 kilometers) | 50 miles (80.46 kilometers) |
Maximum snap tolerance: (If the distance between an input point and its nearest traversable street is greater than the distance specified here, the point is excluded from the analysis.) | 12.42 miles (20 kilometers) | 12.42 miles (20 kilometers) |
Maximum number of directions features that can be returned: | No limit | 1,000,000 |
Maximum number of route edges that can be returned: | Not available | 1,000,000 |
Required parameters
Name | Description | Examples |
---|---|---|
f | The format of the data returned. | f=json f=pjson f=geojson f=html |
token | An API key or OAuth 2.0 access token. | token= |
stops | The two or more locations that need to be visited in the route. | stops=-117,34; -117.5,34.5 |
find | Specify whether the service should find the best sequence when visiting multiple destinations. Note: Set this parameter to true to generate an optimized route. | find |
Direct
Use for shorter transactions with less than 150 stops that will complete in less than 5 minutes.
https://route-api.arcgis.com/arcgis/rest/services/World/Route/NAServer/Route_World/solve?<parameters>
https://route.arcgis.com/arcgis/rest/services/World/Route/NAServer/Route_World/solve?<parameters>
Key parameters
Name (Direct) | Description | Examples |
---|---|---|
travel | The mode of transportation such as driving a car or a truck or walking. | travel JSON Object |
start | The time at which travel begins from the input stops. You can also specify a value of now , to set the depart time to the current time. | start |
return | Generate driving directions for each route. | return |
directions | The language to be used when generating driving directions. | directions |
Additional parameters: Set additional constraints for a route such as temporary slowdowns, using polygon
, or set output
to specify the type of route feature created by the service.
Job
Use for longer transactions with up to 10,000 stops that will complete in less than 60 minutes.
https://logistics.arcgis.com/arcgis/rest/services/World/Route/GPServer/FindRoutes/submitJob?<parameters>
Required parameters
Name | Description | Examples |
---|---|---|
f | The format of the data returned. | f=json f=pjson f=geojson f=html |
token | An API key or OAuth 2.0 access token. | token= |
stops | The two or more locations that need to be visited in the route. | stops=-117,34; -117.5,34.5 |
reorder | Specify whether the service should find the best sequence when visiting multiple destinations. Note:Set this parameter to true to return an optimized route. | reorder |
Key parameters
Name (Job) | Description | Examples |
---|---|---|
travel | The mode of transportation such as driving a car or a truck or walking. | travel JSON Object |
time | The time at which travel begins from the input stops. | time |
populate | Generate driving directions for each route. | populate |
directions | The language to be used when generating driving directions. | directions |
Additional parameters: Set additional constraints such as temporary slowdowns, using polygon
, route
to specify the type of route feature created by the service, or set return
if the start and end location for your route is same.
Code examples
Direct: Find an optimized route to restaurants
In this example, you find the best delivery route for ten restaurants in downtown San Diego. The default travel
is driving time by vehicle, but you can use walk or trucking travel modes as well. The start
is set as now
, which sets the route departure time as the current time and the service will use the current traffic conditions. The find
parameter is set to true
so that the service reorders the stops to generate the best route sequence.
Find an optimized route for ten stops.
APIs
const findRoutes = () => {
stopsFL.queryFeatures().then(graphics => {
const optRouteParams = new EsriRouteParams({
apiKey: appConfig._apiKey,
findBestSequence: true,
returnStops: true,
stops: graphics,
returnDirections: true,
})
EsriRoute.solve(appConfig.routeUrl, optRouteParams).then(
routeSolveDidComplete
)
})
}
REST API
curl https://route-api.arcgis.com/arcgis/rest/services/World/Route/NAServer/Route_World/solve? \
-d "f=json" \
-d "token=<ACCESS_TOKEN>" \
-d 'stops={
"spatialReference": {
"wkid": 4326
},
"features": [
{
"attributes": {
Job: Find an optimized route for a truck delivery
In this example, you use a job request to find the best route sequence for 36 stops for a delivery truck for an area around San Diego. The travel
is set to find the trucking time and the reorder
parameter is set to true
so that the service reorders the stops and creates the best sequence for the delivery route.
Find an optimized route for a truck delivery with 36 stops.
APIs
const findRoutes = () => {
showLoader(true)
stopsFL.queryFeatures().then(graphics => {
const optRouteParams = {
reorder_stops_to_find_optimal_routes: true,
stops: graphics,
travel_mode: appConfig.travelMode,
}
EsriGeoprocessor.submitJob(appConfig.routeUrl, optRouteParams).then(
results => {
const jobOptions = {
statusCallback: j => {
console.log("job status", j.jobStatus)
},
}
results.waitForJobCompletion(jobOptions).then(ji => {
Promise.all([
ji.fetchResultData("output_routes"),
ji.fetchResultData("output_stops"),
]).then(routeSolveDidComplete)
})
}
)
})
}
REST API
Unlike Direct request type which allows you to make a request and get back all the results in the response, when working with a Job request type, you need to follow a three step workflow:
- Make the
submit
request with the appropriate request parameters to get a job id.Job - Using the job id, check the job status to see if the job completed successfully.
- Use the job id to get one or more results.
curl https://logistics.arcgis.com/arcgis/rest/services/World/Route/GPServer/FindRoutes/submitJob? \
-d "f=pjson" \
-d "token=<ACCESS_TOKEN>" \
-d "stops={
"spatialReference": { "wkid": 4326, "latestWkid": 4326 },
"features": [
{
"attributes": {
"Name": "The Fish Market",
"Address": "750 North Harbor Drive, San Diego, 92101",
"ObjectId": 1,
"InspectionRequired": 1
},
"geometry": { "x": -117.17559797523053, "y": 32.712305986096304 }
},
Response (JSON)
{
"jobId": "<JOB_ID>",
"jobStatus": "esriJobSubmitted"
}