使用 Google Directions API 解决 TSP
Google 还提供了一种方法来解决实际营业地点的简单 TSP, 下载 OR-工具。如果您有 Google Directions API 密钥,您可以解题, 真实营业地点的 TSP Directions API ,在网址中提供位置并获取以 JSON 格式返回的响应。 您需要自己的数据 免费的 Directions API 密钥 企业密钥用于商业用途。
例如,您可以使用下面的网址查找简短的酿酒导览 最开始是阿德莱德如果您想从 请将网址末尾的 API_KEY 替换为您的密钥。
https://maps.googleapis.com/maps/api/directions/json?origin=Adelaide,SA&destination=Adelaide,SA&waypoints=optimize:true|Barossa+Valley,SA|Clare,SA|Connawarra,SA|McLaren+Vale,SA&key=API_KEY
结果将是一个详细说明解决方案的长 JSON 响应,其中包括 Google 地图路线:
{
"routes" : [
{
"bounds" : {
"northeast" : {
"lat" : -33.8347115,
"lng" : 140.8547058
},
"southwest" : {
"lat" : -37.3511758,
"lng" : 138.4951576
}
},
"copyrights" : "Map data ©2014 Google",
"legs" : [
{
"distance" : {
"text" : "139 km",
"value" : 139119
},
"duration" : {
"text" : "1 hour 51 mins",
"value" : 6648
},
"end_address" : "Clare SA 5453, Australia",
"end_location" : {
"lat" : -33.8333395,
"lng" : 138.6117283
},
"start_address" : "Adelaide SA, Australia",
"start_location" : {
"lat" : -34.9285894,
"lng" : 138.5999429
},
"steps" : [
{
"distance" : {
"text" : "70 m",
"value" : 70
},
"duration" : {
"text" : "1 min",
"value" : 6
},
"end_location" : {
"lat" : -34.9285338,
"lng" : 138.6007031
},
"html_instructions" : "Head \u003cb\u003eeast\u003c/b\u003e on \u003cb\u003eReconciliation Plaza\u003c/b\u003e toward \u003cb\u003eVictoria Square\u003c/b\u003e",
...