My lazy take on Travelling Salesman Problem in Golang
Been considering giving Golang a chance , as it appeared to feature the best of both worlds , (in this case , my 2 favorite languages ) Python and Java. And I tried combining some simple loops and printing with some ready-made Permutation function for solving a simplified version of the TSP.
Assumptions and limitations made for simplicity’s sake :
- 4x4 Matrix for modelling the vertices and edges of the graph
- 0-index is the first city , Where our journey starts and ends
- the graph is complete , many Hamiltonian Tours exist
I traversed all the permutations of every village except the one where we start(every route) and calculate the sum of every distance (weight of edge) and check if it’s the shortest distance or equal to one we found already and save the route and shortest distance . And I proudly declare that I know this approach to be called Exhaustive search.
I’ve spent so few time on this language but feels like it really delivers about all the claim of simplicity. Even after an hour of meddling around , the variable declaration or initialization , clause structuring , String operations all feel intuitive.
I personally enjoy challenging myself with understanding the motives behind the main trade-offs which this language is built on (or any trade-off anywhere!). I was so intrigued to see the fiery discussion about the lack of some really-seriously-trivially common language features being kept out of Golang , and I’m looking forward to have a proper idea about the reasons one day.