Menu

📰
0

Travelling Sales Person [TSP] solver

Computer Science for Computer Scientists·/u/Humble_Homework_3894·about 1 month ago
#3o1P18Ye
#reddit#quot#city#loop#shortest#next
Reading 0:00
15s threshold

Start from any city and go to the next city with the shortest distance, from there go to the next city with the shortest distance, repeat; until a loop is formed intersecting all cities—this is the base loop. ​Now, starting again from the initial city, go to the next city using the second shortest distance [if, before traversing a distance, you realize it will make the path longer than the base loop, then go to the next city using the next shortest distance; if you run out of paths, go back to the previous city and repeat; and if it is shorter, treat it as the new base loop and proceed], from there go to the next city using the second shortest distance, repeat; until another loop is formed intersecting all cities. ​Repeat this process until you find the shortest base loop, and then output that as the result.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.

Read More