This is my own implementation of solving the Traveling Salesman Problem. I thought it would make a good exercise to see if I could figure out an algorithm that solves this without referring to any known solutions.
Here is what my script does:
- It creates a random board of destinations (Vector2).
- It generates a board on the screen and sets the orthographic camera accordingly as well as the size of the destinations according to how close the closest ones are.
- It goes through combinations of different ways to travel through all destinations.
- It draws the optimal route using a
Line Renderer
found on the home marker.
I also included a complete example in the TSP.unitypackage
file
I do not suggest solving it with more than 10 stops as it will get the app stuck for a bit.
This is not an optimized solution. It's just something I did for fun (and I did had fun!). It helped me figure out how to solve problems with loops that take a long time to finish. Those solutions are not part of that version though, they were implemented on another project of mine.