Traveling Salesman Problem (TSP)¶
The Traveling Salesman Problem (TSP) is a well-known mathematical problem in computer science and operations research. Given a set of cities and the distances between them, the TSP requires finding the shortest possible route that visits each city exactly once and returns to the starting city. This problem can be applied to the context of maps and routing, where the cities represent locations and the distances represent travel distances or travel times.
A Traveling Salesman Problem (TSP) Maps API refers to a set of functions or tools provided by VIETMAP that help developers to solve the TSP for a given set of locations. These APIs may provide algorithms or heuristics for finding approximate solutions to the TSP, as well as visualization tools for displaying the resulting routes on a map. Developers can use TSP Maps APIs to create applications that help optimize route planning and navigation, such as delivery optimization, logistics management, and more.
URL¶
https://maps.vietmap.vn/api/tsp?api-version=1.1&apikey={your-apikey}&point={point}&point={point}&point={point}&points_encoded={points_encoded}&vehicle={vehicle}&roundtrip={roundtrip}&destinations={destinations}&sources={sources}
Method¶
GET
Parameters¶
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
point | array string | yes | none | The points for which the route should be calculated. Format: [latitude,longitude]. Specify at least an origin and a destination. Via points are possible. The maximum number depends on your plan. |
points_encoded | boolean | no | true | Allows changing the encoding of location data in the response. The default is polyline encoding, which is compact but requires special client code to unpack. Set this parameter to false to switch the encoding to simple coordinate pairs like [lon,lat]. See the description of the response format for more information. |
vehicle | string | no | car | Enum: car,bike,foot,motorcycle. The vehicle profile for which the route should be calculated. |
roundtrip | boolean | no | all | Values : true (default), false. Returned route is a roundtrip (route returns to first location) |
sources | string | no | none | Values: any (default), first. Returned route start at any or first coordinate |
destinations | string | no | none | Values: any (default), last. Returned route ends at any or last coordinate |
Example¶
Input
https://maps.vietmap.vn/api/tsp?api-version=1.1&apikey={your-apikey}&point=10.79628438955497,106.70592293472612&point=10.801891047584164,106.70660958023404&point=10.801595962927763,106.6898296806408&points_encoded=true&vehicle=motorcycle&roundtrip=true
{
"license": "vietmap",
"code": "OK",
"messages": null,
"paths": [
{
"distance": 7720.5,
"weight": 1022.8,
"time": 1022800,
"transfers": 0,
"points_encoded": true,
"bbox": [
106.68973,
10.79352,
106.71098,
10.80307
],
"points": "}s{`Ac_hjSIP[r@KTuAxCOb@QVuAoAi@g@w@u@oCmC_BgBm@}@QUcB{C}@qBMYs@{B]}A_@kBSkCIo@oABFbAHtAPtAPpAbApDXv@Rj@dAzBT^dAdBqA^e@Jo@F{BLCcAAEICq@@p@AHB@DBbAzBMn@Gd@KpA_@LRZh@dAvAv@z@pI`I[t@u@vA|@h@LJDLa@jL?`AF^gBVeF~@GZuAb@sARgDr@uHfBa@PGBd@xAF\\?RGz@WnEk@~HSzCUlDH?bB?TnAJbAH|@?VBz@?j@?JGJGXGf@?n@Db@H~BjCn@?B?JAFI?}BCAcAI_CEc@?o@Fg@FYFK?K?k@C{@?WI}@KcAUoAdAAz@CP?`A?b@?z@CbAI\\E^GHAJ?VClAGbBGPA`ACLAv@CH?~BOj@C~@Al@Ar@C@kADKbDJ~@Bh@LGk@Bo@H[T[TOPGNCNA`AFlA@REVSFIFQBYGkA@{@Ig@[_AA}B@y@Hq@BO@g@EmAAWCg@Ac@BwAX_DHs@H{@DUP_@No@Be@?KEMGd@GJIDE?k@i@Q?WJGG}AqA?a@mAoAeDcDQQUUyEmEPWNc@tAyCJUZs@HQ",
"instructions": [
{
"distance": 192,
"heading": 0,
"sign": 0,
"interval": [
0,
6
],
"text": "Tiếp tục theo Đường Nguyễn Cửu Vân",
"time": 25900,
"street_name": "Đường Nguyễn Cửu Vân",
"last_heading": null
},
/// More instruction objects will response here
{
"distance": 0,
"heading": 0,
"sign": 4,
"interval": [
201,
201
],
"text": "Đích đến",
"time": 0,
"street_name": "Đường Nguyễn Cửu Vân",
"last_heading": null
}
],
"snapped_waypoints": "}s{`Ac_hjS}`@{CVphB"
}
]
}
Response description¶
Field | Type | Description |
---|---|---|
license | string | The type of license for the map data. |
code | string | A code indicating the status of the response, e.g., "OK" for success. |
messages | null | Messages associated with the response, if any. |
paths | array | An array containing route information, such as distance, time, and instructions. |
Each object in the paths
array contains the following fields:
Field | Type | Description |
---|---|---|
distance | float | The total distance of the route. |
weight | float | The weight of the route. |
time | integer | The total time required to travel the route. |
transfers | integer | The number of transfers during the route. |
points_encoded | boolean | Indicates whether the points are encoded. |
bbox | array | The bounding box of the route. |
points | string | Encoded points along the route. |
instructions | array | An array containing step-by-step instructions for navigating the route. |
snapped_waypoints | string | Snapped waypoints along the route. |
Each object in the instructions
array contains the following fields:
Field | Type | Description |
---|---|---|
distance | float | The distance of the instruction. |
heading | integer | The heading direction of the instruction. |
sign | integer | The sign indicating the action to take (e.g., turn left). |
interval | array | The time interval for the instruction. |
text | string | The textual instruction for navigating. |
time | integer | The time required to complete the instruction. |
street_name | string | The name of the street for the instruction. |
last_heading | null | The last heading direction for the instruction. |