Skip to content

Traveling Salesman Problem (TSP)

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
Response
{
    "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
                },
                {
                    "distance": 869.9,
                    "heading": 0,
                    "sign": 2,
                    "interval": [
                        6,
                        21
                    ],
                    "text": "Rẽ phải vào Đường Điện Biên Phủ",
                    "time": 108800,
                    "street_name": "Đường Điện Biên Phủ",
                    "last_heading": null
                },
                {
                    "distance": 555.1,
                    "heading": 0,
                    "sign": -8,
                    "interval": [
                        21,
                        32
                    ],
                    "text": " vào Đường Điện Biên Phủ",
                    "time": 76000,
                    "street_name": "Đường Điện Biên Phủ",
                    "last_heading": null
                },
                {
                    "distance": 167,
                    "heading": 0,
                    "sign": 2,
                    "interval": [
                        32,
                        36
                    ],
                    "text": "Rẽ phải",
                    "time": 22400,
                    "street_name": "",
                    "last_heading": null
                },
                {
                    "distance": 74.2,
                    "heading": 0,
                    "sign": 2,
                    "interval": [
                        36,
                        40
                    ],
                    "text": "Rẽ phải",
                    "time": 8900,
                    "street_name": "",
                    "last_heading": null
                },
                {
                    "distance": 0,
                    "heading": 0,
                    "sign": 5,
                    "interval": [
                        40,
                        40
                    ],
                    "text": "Qua điểm",
                    "time": 0,
                    "street_name": "",
                    "last_heading": null
                },
                {
                    "distance": 74.2,
                    "heading": 0,
                    "sign": 0,
                    "interval": [
                        40,
                        44
                    ],
                    "text": "Tiếp tục",
                    "time": 14500,
                    "street_name": "",
                    "last_heading": null
                },
                {
                    "distance": 167,
                    "heading": 0,
                    "sign": -2,
                    "interval": [
                        44,
                        48
                    ],
                    "text": "Rẽ trái",
                    "time": 21100,
                    "street_name": "",
                    "last_heading": null
                },
                {
                    "distance": 405.4,
                    "heading": 0,
                    "sign": 2,
                    "interval": [
                        48,
                        53
                    ],
                    "text": "Rẽ phải vào Đường Điện Biên Phủ",
                    "time": 49500,
                    "street_name": "Đường Điện Biên Phủ",
                    "last_heading": null
                },
                {
                    "distance": 90.2,
                    "heading": 0,
                    "sign": 2,
                    "interval": [
                        53,
                        55
                    ],
                    "text": "Rẽ phải vào Hẻm 153 Điện Biên Phủ",
                    "time": 15900,
                    "street_name": "Hẻm 153 Điện Biên Phủ",
                    "last_heading": null
                },
                {
                    "distance": 348.5,
                    "heading": 0,
                    "sign": -2,
                    "interval": [
                        55,
                        61
                    ],
                    "text": "Rẽ trái",
                    "time": 46200,
                    "street_name": "",
                    "last_heading": null
                },
                {
                    "distance": 59,
                    "heading": 0,
                    "sign": 2,
                    "interval": [
                        61,
                        62
                    ],
                    "text": "Rẽ phải vào Cầu Ráp",
                    "time": 14200,
                    "street_name": "Cầu Ráp",
                    "last_heading": null
                },
                {
                    "distance": 132.6,
                    "heading": 0,
                    "sign": 0,
                    "interval": [
                        62,
                        63
                    ],
                    "text": "Tiếp tục theo Đường Nguyễn Xuân Ôn",
                    "time": 17200,
                    "street_name": "Đường Nguyễn Xuân Ôn",
                    "last_heading": null
                },
                {
                    "distance": 15.2,
                    "heading": 0,
                    "sign": 0,
                    "interval": [
                        63,
                        64
                    ],
                    "text": "Tiếp tục theo Đường Nguyễn Xuân Ôn",
                    "time": 2000,
                    "street_name": "Đường Nguyễn Xuân Ôn",
                    "last_heading": null
                },
                {
                    "distance": 52.7,
                    "heading": 0,
                    "sign": 0,
                    "interval": [
                        64,
                        65
                    ],
                    "text": "Tiếp tục theo Đường Nguyễn Xuân Ôn",
                    "time": 6300,
                    "street_name": "Đường Nguyễn Xuân Ôn",
                    "last_heading": null
                },
                {
                    "distance": 347.4,
                    "heading": 0,
                    "sign": 0,
                    "interval": [
                        65,
                        69
                    ],
                    "text": "Tiếp tục theo Đường Bùi Hữu Nghĩa",
                    "time": 41700,
                    "street_name": "Đường Bùi Hữu Nghĩa",
                    "last_heading": null
                },
                {
                    "distance": 592.2,
                    "heading": 0,
                    "sign": -2,
                    "interval": [
                        69,
                        78
                    ],
                    "text": "Rẽ trái vào Đường Phan Đăng Lưu",
                    "time": 82100,
                    "street_name": "Đường Phan Đăng Lưu",
                    "last_heading": null
                },
                {
                    "distance": 60.2,
                    "heading": 0,
                    "sign": -2,
                    "interval": [
                        78,
                        80
                    ],
                    "text": "Rẽ trái vào Đường Vạn Kiếp",
                    "time": 8100,
                    "street_name": "Đường Vạn Kiếp",
                    "last_heading": null
                },
                {
                    "distance": 355.3,
                    "heading": 0,
                    "sign": 2,
                    "interval": [
                        80,
                        93
                    ],
                    "text": "Rẽ phải vào Đường Trần Kế Xương",
                    "time": 48000,
                    "street_name": "Đường Trần Kế Xương",
                    "last_heading": null
                },
                {
                    "distance": 107.7,
                    "heading": 0,
                    "sign": -2,
                    "interval": [
                        93,
                        95
                    ],
                    "text": "Rẽ trái vào Hẻm 67 Trần Kế Xương",
                    "time": 17300,
                    "street_name": "Hẻm 67 Trần Kế Xương",
                    "last_heading": null
                },
                {
                    "distance": 0,
                    "heading": 0,
                    "sign": 5,
                    "interval": [
                        95,
                        95
                    ],
                    "text": "Qua điểm vào Hẻm 67 Trần Kế Xương",
                    "time": 0,
                    "street_name": "Hẻm 67 Trần Kế Xương",
                    "last_heading": null
                },
                {
                    "distance": 11,
                    "heading": 0,
                    "sign": 0,
                    "interval": [
                        95,
                        97
                    ],
                    "text": "Tiếp tục theo Hẻm 67 Trần Kế Xương",
                    "time": 3800,
                    "street_name": "Hẻm 67 Trần Kế Xương",
                    "last_heading": null
                },
                {
                    "distance": 75.4,
                    "heading": 0,
                    "sign": 2,
                    "interval": [
                        97,
                        99
                    ],
                    "text": "Rẽ phải vào Hẻm 61 Trần Kế Xương",
                    "time": 10800,
                    "street_name": "Hẻm 61 Trần Kế Xương",
                    "last_heading": null
                },
                {
                    "distance": 392.4,
                    "heading": 0,
                    "sign": 2,
                    "interval": [
                        99,
                        113
                    ],
                    "text": "Rẽ phải vào Đường Trần Kế Xương",
                    "time": 50600,
                    "street_name": "Đường Trần Kế Xương",
                    "last_heading": null
                },
                {
                    "distance": 649.7,
                    "heading": 0,
                    "sign": 2,
                    "interval": [
                        113,
                        137
                    ],
                    "text": "Rẽ phải vào Đường Vạn Kiếp",
                    "time": 82500,
                    "street_name": "Đường Vạn Kiếp",
                    "last_heading": null
                },
                {
                    "distance": 48.1,
                    "heading": 0,
                    "sign": -2,
                    "interval": [
                        137,
                        139
                    ],
                    "text": "Rẽ trái",
                    "time": 6500,
                    "street_name": "",
                    "last_heading": null
                },
                {
                    "distance": 151.7,
                    "heading": 0,
                    "sign": 2,
                    "interval": [
                        139,
                        142
                    ],
                    "text": "Rẽ phải",
                    "time": 25200,
                    "street_name": "",
                    "last_heading": null
                },
                {
                    "distance": 958.5,
                    "heading": 0,
                    "sign": -2,
                    "interval": [
                        142,
                        180
                    ],
                    "text": "Rẽ trái vào Đường Trường Sa",
                    "time": 122800,
                    "street_name": "Đường Trường Sa",
                    "last_heading": null
                },
                {
                    "distance": 96.6,
                    "heading": 0,
                    "sign": 0,
                    "interval": [
                        180,
                        187
                    ],
                    "text": "Tiếp tục theo Đường Trường Sa",
                    "time": 12300,
                    "street_name": "Đường Trường Sa",
                    "last_heading": null
                },
                {
                    "distance": 75.3,
                    "heading": 0,
                    "sign": 2,
                    "interval": [
                        187,
                        189
                    ],
                    "text": "Rẽ phải vào Đường Điện Biên Phủ",
                    "time": 9200,
                    "street_name": "Đường Điện Biên Phủ",
                    "last_heading": null
                },
                {
                    "distance": 404.1,
                    "heading": 0,
                    "sign": 0,
                    "interval": [
                        189,
                        195
                    ],
                    "text": "Tiếp tục theo Đường Điện Biên Phủ",
                    "time": 49900,
                    "street_name": "Đường Điện Biên Phủ",
                    "last_heading": null
                },
                {
                    "distance": 192,
                    "heading": 0,
                    "sign": 2,
                    "interval": [
                        195,
                        201
                    ],
                    "text": "Rẽ phải vào Đường Nguyễn Cửu Vân",
                    "time": 23100,
                    "street_name": "Đường Nguyễn Cửu Vân",
                    "last_heading": null
                },
                {
                    "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"
        }
    ]
}