Summary

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.

Introduction

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

Notes about this project:

  1. It is apparent from a casual inspection of the output chart that the algorithm, while quick to execute, is less than ideal in terms of accuracy. Many test runs revealed this and has prompted some ideas for further testing.
  2. It might be possible to improve the accuracy by using a look ahead feature to consider two nodes rather than a single node in the NN algorithm.
  3. Another improvement might be to implement a circle such that nodes are selected by comparison to their distance from some point on the circle circumference.
  4. Code reorganization and chart improvements are anticipated.

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

A Nearest Neighbor solution in Go to the Traveling Salesman Problem
1.40 GEEK