访问所有节点的最短路径

编程入门 行业动态 更新时间:2024-10-24 12:32:29
本文介绍了访问所有节点的最短路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在寻找一种对我来说非常典型的算法,但看起来常见的解决方案只有一点点不同。

在无向图,我想要访问每个节点的最短路径。节点可以重新访问,我不必返回到开始节点。

旅行推销员问题似乎增加了限制,即每个节点只能访问一次,并且路径必须返回到开始位置。

最小生成树可以是解决方案的一部分,但这样的算法只提供树,而不是最小的路径。另外,因为它们是树,因此没有循环,所以它们强制回溯到循环可能更有效的地方。

可以通过变换图来将其减少到正常的旅行推销员问题。首先,计算每对节点的最小距离。你可以使用Floyd-Warshall算法。一旦你拥有了它,只需构建一个完整的图,其中节点之间的边是从em到u到em的最小开销。然后,您可以应用普通的TSP算法,因为您不必再​​次访问节点,这已经隐藏在边缘成本中。

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 want the shortest path that visits every node. Nodes can be revisited and I do not have to return to the start node.

The Travelling Salesman Problem seems to add the restriction that each node can only be visited once and that the path has to return to where it started.

Minimal Spanning Trees may be part of a solution, but such algorithms only provide the tree, not a minimal path. Additionally, because they're trees and therefore have no loops, they force backtracking where a loop may be more efficient.

解决方案

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.

更多推荐

访问所有节点的最短路径

本文发布于:2023-11-29 23:22:12,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1647942.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:节点   最短   路径

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!