算法:所有点之间的最短路径

发布于 2024-08-27 00:29:08 字数 219 浏览 7 评论 0原文

假设我有 10 分。我知道每个点之间的距离。

我需要找到穿过所有点的最短路线。

我尝试了几种算法(Dijkstra、Floyd Warshall...),它们都给出了起点和终点之间的最短路径,但它们并没有制定一条包含所有点的路线。

排列工作得很好,但它们太耗费资源了。

您可以建议我研究什么算法来解决这个问题?或者是否有记录的方法可以使用上述算法来做到这一点?

Suppose I have 10 points. I know the distance between each point.

I need to find the shortest possible route passing through all points.

I have tried a couple of algorithms (Dijkstra, Floyd Warshall,...) and they all give me the shortest path between start and end, but they don't make a route with all points on it.

Permutations work fine, but they are too resource-expensive.

What algorithms can you advise me to look into for this problem? Or is there a documented way to do this with the above-mentioned algorithms?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

电影里的梦 2024-09-03 00:29:08

查看旅行推销员问题

您可能需要研究一些启发式解决方案。他们可能无法为您提供 100% 准确的结果,但通常他们可以在合理的时间内提出足够好的解决方案(距离最佳解决方案有 2% 到 3% 的差距)。

Have a look at travelling salesman problem.

You may want to look into some of the heuristic solutions. They may not be able to give you 100% exact results, but often they can come up with good enough solutions (2 to 3 % away from optimal solutions) in a reasonable amount of time.

樱花细雨 2024-09-03 00:29:08

这显然是旅行推销员问题。特别是对于 N=10,您可以尝试 O(N!) naive 算法,或者使用 动态编程,您可以通过交换空间将其减少到O(n^2 2^n)

除此之外,由于这是一个 NP 难题,考虑到通常的注意事项,您只能希望得到近似值或启发式方法。

This is obviously Travelling Salesman problem. Specifically for N=10, you can either try the O(N!) naive algorithm, or using Dynamic Programming, you can reduce this to O(n^2 2^n), by trading space.

Beyond that, since this is an NP-hard problem, you can only hope for an approximation or heuristic, given the usual caveats.

机场等船 2024-09-03 00:29:08

正如其他人提到的,这是 TSP 的一个实例。我认为佐治亚理工学院开发的 Concord 是当前最先进的求解器。它可以在几秒钟内处理多达 10,000 个点。它还具有易于使用的 API。

As others have mentioned, this is an instance of the TSP. I think Concord, developed at Georgia Tech is the current state-of-the-art solver. It can handle upwards of 10,000 points within a few seconds. It also has an API that's easy to work with.

与往事干杯 2024-09-03 00:29:08

我认为这实际上是您正在寻找的:

Floyd Warshall

在计算机科学中,Floyd–Warshall 算法(有时称为
WFI 算法[需要澄清]、Roy–Floyd 算法或只是
Floyd 算法)是一种用于寻找最短路径的图分析算法
加权图中的路径(具有正边或负边权重)。一个
单次执行该算法将找到长度(总和
权重)所有顶点对之间的最短路径
不返回路径本身的详细信息

在“路径重建”小节中,它解释了您需要存储“路径”的数据结构(实际上您只需存储要前往的下一个节点,然后简单地重建所需的路径为需要)。

I think this is what you're looking for, actually:

Floyd Warshall

In computer science, the Floyd–Warshall algorithm (sometimes known as
the WFI Algorithm[clarification needed], Roy–Floyd algorithm or just
Floyd's algorithm) is a graph analysis algorithm for finding shortest
paths in a weighted graph (with positive or negative edge weights). A
single execution of the algorithm will find the lengths (summed
weights) of the shortest paths between all pairs of vertices though it
does not return details of the paths themselves

In the "Path reconstruction" subsection it explains the data structure you'll need to store the "paths" (actually you just store the next node to go to and then trivially reconstruct whichever path is required as needed).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文