Given a list of addresses in Toronto, this planner can generate the most efficient (shortest) route with visting the same location twice, outputting as excel file.
"The
travelling salesman problem (TSP)
asks the following question: "Given a list of cities and the distances between each pair of cities, what is the shortest possible route that visits each city and returns to the origin city?" It is an NP-hardproblem in combinatorial optimization." -- by Wikipedia
- A list is imported by external file sources.
- A random list of addresses in Toronto with the home address as the starting and ending points:
places = [
"375 Bamburgh Cir, Scarborough, ON",
"10231 Yonge St, Richmond Hill, ON",
"1383 16th Ave, Richmond Hill, ON",
"11 Disera Dr, Thornhill, ON",
"280 West Beaver Creek Rd, Richmond Hill, ON",
"3760 Hwy 7, Unionville, ON",
"300 John St, Thornhill, ON",
"5418 Yonge St #12, North York, ON",
"8 William Kitchen Rd A, Scarborough, ON",
"7575 Keele St, Concord, ON",
"5284 Hwy 7, Markham, ON",
"4205 Keele St, North York, ON",
"3203 Dufferin St, North York, ON",
"3400 Yonge St, Toronto, ON",
"51 Gerry Fitzgerald Dr, Toronto, ON"
]
- By using ORtools from Google, the TSP question was solved to get the sub-optimal result by using distance matrix as the input.
Total distance: 98568 meters
Index:
0 -> 5 -> 10 -> 4 -> 6 -> 2 -> 1 -> 3 -> 14 -> 9 -> 11 -> 12 -> 13 -> 7 -> 8 -> 0
- A dataframe was generated in the order of delivery spots, including address, lat, lng and maps url which can be clicked on a cellphone to navigate directly:
- A map of all places are drawn on Google Maps:
- With Google Directions API, we can plot the actual routes on the map. However, due to a large number of direction requests. The screenshot is not the final result.
Lengend for the map:
1 = 375 Bamburgh Cir, Scarborough, ON
2 = 10231 Yonge St, Richmond Hill, ON
3 = 1383 16th Ave, Richmond Hill, ON
4 = 11 Disera Dr, Thornhill, ON
5 = 280 West Beaver Creek Rd, Richmond Hill, ON
6 = 3760 Hwy 7, Unionville, ON
7 = 300 John St, Thornhill, ON
8 = 5418 Yonge St #12, North York, ON
9 = 8 William Kitchen Rd A, Scarborough, ON
10 = 7575 Keele St, Concord, ON
11 = 5284 Hwy 7, Markham, ON
12 = 4205 Keele St, North York, ON
13 = 3203 Dufferin St, North York, ON
14 = 3400 Yonge St, Toronto, ON
15 = 51 Gerry Fitzgerald Dr, Toronto, ON