A simple TSP solver made in C++ using a greedy approach.
The algorithm works as follows:
- An arbitrary node is chosen as the current node and is marked as visited and removed from the dataset. All other nodes are considered unvisited.
- The distance to all unvisited nodes is calculated.
- The closest node is chosen as the current node and is marked as visited.
- Iteratively execute step 2 and 3 until all nodes have been visited.
- The total distance of the cycle is calculated and compared to any previous result. The lowest result is recorded.
- Iteratively execute step 1-5 until the dataset has been exhausted.
The program will output the resulting (shortest) cycle in json, however not prettified.
Change defines on rows 10 and 11 in greedy.cpp to the other dataset and corresponding ndjson file if desired.