路径问题的算法或方法,n <= 12 时有 n 个点的最短路径

发布于 2024-10-20 01:41:08 字数 319 浏览 1 评论 0 原文

我在 2d 平面上有 n 个点,其中 n <= 12,并且我需要可用的最短路径的距离,包括所有点,从其中任何一个点开始,但不形成闭合电路,

我一直在尝试弗洛伊德元帅、旅行推销员问题等算法均未成功。

这个问题对我的老师来说很容易,所以我不认为它需要阿罗拉近似,但我不知道解决这个问题的最佳方法是什么,但也许一些动态算法和类似的

for i = 0 to n
    for j = 0 to n
    if path_distance(i,j) < mininum
        set minimum

帮助?

i have n points on a 2d plane, with n <= 12, and i need the distance of the shortest path available including all points, starting on any of them, but not making a closed circuit

i've been trying floyd-marshal, travel salesman problem and other algorithms without success.

the problem is considered EASY for my teacher so i don't think it would require arora approximations or so, but i dont know whats the best approach to solve this, but maybe some dynamic algorithm and something like

for i = 0 to n
    for j = 0 to n
    if path_distance(i,j) < mininum
        set minimum

any help?

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

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

发布评论

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

评论(3

白色秋天 2024-10-27 01:41:08

如果您知道只有 12 个点并且想要找到访问每个节点一次的最短路径,那么您始终可以通过尝试节点的所有可能排列并计算沿该路径的路径长度来暴力破解解决方案排列。这根本无法很好地扩展,但如果节点数量有固定的上限,那么它应该是合理的。

If you know that you only have twelve points and want to find the shortest path that visits every node exactly once, then you can always just brute-force the solution by trying all possible permutations of the nodes and computing the length of the path along that permutation. This doesn't scale well at all, but if you have a fixed upper bound on the number of nodes then it should be reasonable.

甲如呢乙后呢 2024-10-27 01:41:08

当且仅当n <= 12时,我推荐分支定界算法,这是暴力算法的改进版本。

If and only if n <= 12, I 'd recommend the Branch and Bound algorithm, which is an improved version of the brute force algorithm.

何必那么矫情 2024-10-27 01:41:08

我只会提供一个提示,因为这是家庭作业:

在分解此类问题时,递归非常有用。

您可以编写一个函数,该函数获取迄今为止的路线列表、迄今为止的最佳/最小距离以及未访问节点的列表。对于每个未访问的节点,它会尝试将其添加到迄今为止的路线中,如果该路线仍然短于迄今为止的最佳/最小距离,那么它将使用新路线和未访问节点列表来调用自身。

I'll only provide a hint since this is homework:

Recursion is very useful when breaking down these kinds of problems.

You could write a function that takes a list of the route so far, the best/minimum distance so far, and a list of unvisited nodes. For-each unvisited node it would try adding it to the route so far and if that route was still shorter than the best/minimum distance so far then it would call itself with the new route and list of unvisited nodes.

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