Optimized routing

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:

  1. Define the origin, stops, and destination.
  2. Define the type of travel for the route.
  3. Set the findBestSequence parameter to true. Unless specified, the first and last stops you provide will be kept.
  4. 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.

Required parameters

NameDescriptionExamples
fThe format of the data returned.f=json f=pjson f=geojson f=html
tokenAn API key or OAuth 2.0 access token. Learn how to get an access token in Security and authentication.token=<YOUR_API_KEY>
token=<ACCESS_TOKEN>
stopsThe two or more locations that need to be visited in the route.stops=-117,34; -117.5,34.5
findBestSequenceSpecify whether the service should find the best sequence when visiting multiple destinations. Note: Set this parameter to true to generate an optimized route.findBestSequence=true

Direct

Use for shorter transactions with less than 150 stops that will complete in less than 5 minutes.

Use dark colors for code blocksCopy
1
https://route-api.arcgis.com/arcgis/rest/services/World/Route/NAServer/Route_World/solve?<parameters>
Use dark colors for code blocksCopy
1
https://route.arcgis.com/arcgis/rest/services/World/Route/NAServer/Route_World/solve?<parameters>

Key parameters

Name (Direct)DescriptionExamples
travelModeThe mode of transportation such as driving a car or a truck or walking.travelMode=JSON Object
startTimeThe 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.startTime=now
returnDirectionsGenerate driving directions for each route.returnDirections=true
directionsLanguageThe language to be used when generating driving directions.directionsLanguage=es

Additional parameters: Set additional constraints for a route such as temporary slowdowns, using polygonBarriers, or set outputLines 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.

Use dark colors for code blocksCopy
1
https://logistics.arcgis.com/arcgis/rest/services/World/Route/GPServer/FindRoutes/submitJob?<parameters>

Required parameters

NameDescriptionExamples
fThe format of the data returned.f=json f=pjson f=geojson f=html
tokenAn API key or OAuth 2.0 access token. Learn how to get an access token in Security and authentication.token=<YOUR_API_KEY>
token=<ACCESS_TOKEN>
stopsThe two or more locations that need to be visited in the route.stops=-117,34; -117.5,34.5
reorder_stops_to_find_optimal_routesSpecify whether the service should find the best sequence when visiting multiple destinations. Note:Set this parameter to true to return an optimized route.reorder_stops_to_find_optimal_routes=true

Key parameters

Name (Job)DescriptionExamples
travel_modeThe mode of transportation such as driving a car or a truck or walking.travel_mode=JSON Object
time_of_dayThe time at which travel begins from the input stops.time_of_day=1608022800000
populate_directionsGenerate driving directions for each route.populate_directions=true
directions_languageThe language to be used when generating driving directions.directions_language=es

Additional parameters: Set additional constraints such as temporary slowdowns, using polygon_barriers, route_shape to specify the type of route feature created by the service, or set return_to_start 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 travelMode is driving time by vehicle, but you can use walk or trucking travel modes as well. The startTime is set as now, which sets the route departure time as the current time and the service will use the current traffic conditions. The findBestSequence 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

ArcGIS Maps SDK for JavaScriptArcGIS Maps SDK for JavaScriptArcGIS Maps SDK for .NETArcGIS Maps SDK for SwiftArcGIS Maps SDK for KotlinArcGIS Maps SDK for JavaArcGIS Maps SDK for Qt (C++)ArcGIS Maps SDK for Qt (QML)ArcGIS API for PythonArcGIS REST JSEsri LeafletMapLibre GL JSOpenLayersCesiumJS
Expand
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
        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

cURLcURLHTTP
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
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_mode is set to find the trucking time and the reorder_stops_to_find_optimal_routes 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

ArcGIS Maps SDK for JavaScriptArcGIS Maps SDK for JavaScriptArcGIS API for PythonArcGIS REST JS
Expand
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
        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:

  1. Make the submitJob request with the appropriate request parameters to get a job id.
  2. Using the job id, check the job status to see if the job completed successfully.
  3. Use the job id to get one or more results.
cURLcURLHTTP
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
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)
Use dark colors for code blocksCopy
1
2
3
4
{
  "jobId": "<JOB_ID>",
  "jobStatus": "esriJobSubmitted"
}

Tutorials

Services

Routing service

Get turn-by-turn directions and solve advanced routing problems.

API support

RoutingOptimized RoutingFleet routingClosest facility routingService areasLocation-allocationTravel cost matrix
ArcGIS Maps SDK for JavaScript111
ArcGIS Maps SDK for .NET111
ArcGIS Maps SDK for Kotlin111
ArcGIS Maps SDK for Swift111
ArcGIS Maps SDK for Java111
ArcGIS Maps SDK for Qt111
ArcGIS API for Python
ArcGIS REST JS
Esri Leaflet2222222
MapLibre GL JS2222222
OpenLayers2222222
Full supportPartial supportNo support
  • 1. Access with geoprocessing task.
  • 2. Access via ArcGIS REST JS.

Tools

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.