Shortest path to visit all nodes

后端 未结 1 1973
悲哀的现实
悲哀的现实 2021-01-11 15:16

I\'m looking for an algorithm that seems very typical to me, but it seems that the common solutions are all just a little bit different.

In an undirected graph, I wa

1条回答
  •  北海茫月
    2021-01-11 16:21

    You can reduce it to the normal Travelling Salesman Problem by transforming the graph.

    First, compute the minimum distance for every pair of nodes. You can use Floyd-Warshall algorithm for that. Once you have it, just construct the complete graph where the edge between nodes u and v is the minimum cost from u to v.

    Then, you can apply a normal TSP algorithm as you don't have to revisit nodes anymore, that's already hidden in the costs of the edges.

    0 讨论(0)
提交回复
热议问题