A Go implementation of the Nearest Neighbor algorithm is presented with the charting of the path and supporting report output. A circular set of Nodes shows the implementation is reasonably accurate for the algorithm. The project is hosted publicly on gitlab as noted in reference 6.
This project is an approximate solution to the Traveling Salesman problem using a nearest neighbor(NN) algorithm. A very detailed analysis and discussion of this relatively famous Computer Science problem is covered in reference (4). This solution is believed to be within about 25% longer than the exact solution as noted by Wikipedia(4). This project is an exercise in implementing the NN algorithm in Go and possibly some improvements to the basic NN algorithm.
Notes about this project:
The starting node does not affect the total distance traveled for any one set of Nodes. The reason is that the same set of edges gets selected since no change to the relative position of the nodes to one another affects the shortest distance to the next node for that node.
Once the algorithm was working the first question that comes to mind is how to prove it is working as designed. The first solution was to compute 26 nodes in the form of a 27 edge polygon, close enough to a circle to compare the Salesman’s route distance to a circle composed of the 27 edges. The circumference of the circle was computed and rounded to 314 while the salesman’s route was computed as 313.18.
#search #computer-science #data-science