【问题标题】:Shortest path while walking x unique nodes行走 x 个唯一节点时的最短路径
【发布时间】:2013-05-03 16:58:15
【问题描述】:

我有一个图表,其中我的所有节点之间都有一个计算出的距离。

现在,我想从我的 startNode 开始,然后找到计算值最低的路径,只要路径有 X 个唯一节点。 把它想象成一张地图:我们从巴黎开始,想去 3 个城市旅行。我想找到距离巴黎总共 3 站的路径,计算值最低。

我正在考虑实施修改后的 Dijkstra 算法,这通常会给我到最终目的地的最短距离,然后我的最终目的地是所有 X_level_out 目的地,这应该给我一个类似 O(nodes^) 的运行时间等级) 。

这有意义吗? 还有其他建议吗?

【问题讨论】:

  • 没什么好说的了——修改后的 Dijkstra 应该可以正常工作。
  • 看起来应该是 BFS 的简单变体
  • “我有一个图表,其中我的所有节点之间都有一个计算出的距离。” - 这是否意味着你的图是完整的(所有节点对之间的一条边)?
  • 查看 Floyd-Warshall 算法
  • @LarsHoldgaard 您可以使用 BFS 查找所有 X 级别的节点。在遍历边缘时,只需保持最小距离,就像 Dijkstra 算法中的那样。 (Dijkstra 本身是 BFS 的概括,但您不必在这里“完整 Dijkstra”,因为路径长度或级别是固定的)。

标签: c# algorithm data-structures graph-theory dijkstra


【解决方案1】:

给定一个加权无向图 G(V,E),以及 V 的一个集合 S 子集,找到跨越 S 中节点的最小成本树。这个问题在文献中被称为施泰纳树问题。 这个问题是 NP 完全的,这意味着没有已知的 多项式 算法可以找到问题的精确解。但是,有些算法可以在指数时间内解决 Steiner 问题(O(2^N) 或 O(2^M))。

朴素或最短路径算法。

Find the Shortest path tree from one participant node to the rest of the graph. 
Prune the parts of the tree that do not lead to a participant. 

复杂度 O(N^2),CR = O(M)。

贪心或最近参与者优先算法。 (松山高桥 1980) 从参与者开始。

Find the participant that is closest to the current tree. 
Join the closest participant to the closest part of the tree. 
Repeat until you have connected all nodes. 

复杂度 O(M N^2),CR = O(1),实际上 CR

Kou、Markowsky 和 ​​Berman 算法(KMB 1981)。

1. Find the complete distance graph G' 
  (G' has V' = S , and  for each  pair of nodes (u,v) in VxV there is an edge with weight equal to the weight of the min-cost path between these nodes p_(u,v)  in G) 
2. Find a minimum spanning tree  T' in G' 
3. Translate tree T' to the  graph G: substitute every edge of T', which is an edge  of G' with the corresponding path of G. Let us call T the result of the translation. 
4. Remove any possible cycles from T. 

复杂度 O(M N^2),CR = O(1),实际上 CR

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-05-28
    • 2021-12-18
    • 1970-01-01
    • 2016-03-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多