【问题标题】:In a forward search algorithm, what happens if both items are equal? [duplicate]在前向搜索算法中,如果两个项目相等会发生什么? [复制]
【发布时间】:2015-03-05 06:40:45
【问题描述】:

在前向搜索算法中,如果两个项目相等,你会怎么做?

前向搜索算法源于 Dijkstra 算法

前向搜索算法

1. Initialize the Confirmed list with an entry for myself; this entry has
a cost of 0.
2. For the node just added to the Confirmed list in the previous step,
call it node Next and select its LSP.
3. For each neighbor (Neighbor) of Next, calculate the cost (Cost) to
reach this Neighbor as the sum of the cost from myself to Next and
from Next to Neighbor.
(a) If Neighbor is currently on neither the Confirmed nor the
Tentative list, then add (Neighbor, Cost, NextHop) to the
Tentative list, where NextHop is the direction I go to reach Next.
(b) If Neighbor is currently on the Tentative list, and the Cost is less
than the currently listed cost for Neighbor, then replace the
current entry with (Neighbor, Cost, NextHop), where NextHop
is the direction I go to reach Next.
4. If the Tentative list is empty, stop. Otherwise, pick the entry from
the Tentative list with the lowest cost, move it to the Confirmed list,
and return to step 2.

在最后一步,当出现 2 个条目具有相同的最低成本时,我不确定该怎么办。我是否将两者都移至已确认列表? 还是我选择在暂定列表中停留时间最长的条目?

【问题讨论】:

    标签: algorithm network-programming computer-science dijkstra


    【解决方案1】:

    如果有两个条目具有相同的最低成本,您可以选择其中一个 - 没关系。例如,如果您的暂定列表如下所示:

    10 4 9 7 7 3 2 11 5 2
    

    并且您正在使用排序列表找到最低成本,它看起来像这样:

    2 2 3 4 5 7 7 9 10 11
    

    但无论你选择前 2 还是后 2 都没有关系。

    如果你选择了“错误”的那个,而事实证明选择的那个会导致更长的路径,那么算法会在继续进行时自行纠正。

    编辑:

    这个答案实际上与another related question 中的一个超级相似,这很可能是一个骗局。本着this meta-post 的精神,我不会删除答案,但我想我会添加更多细节,所以它不再只是相同的信息。

    显然,这里担心的是,通过选择一个节点而不是另一个节点,您会“错过”一条仍然存在的路径。但是,由于您引用的前向搜索算法是从 Dijkstra 派生的,因此它遵循相同的规则。您可能对 Dijkstra 的担忧之一是,如果我立即选择最低成本会发生什么,但实际上有一条不同的路径最终会缩短,如果不是立即缩短的话?

    例如,你可能有一个成本为 1 的节点和一个成本为 2 的节点。你选择成本为 1 的节点,但实际上,从长远来看,选择成本为 2 的节点更便宜。

    这实际上是同一个问题,只是两个节点的成本相同。但是,如果它们都具有正权重,则可以证明 Dijkstra 算法总是会找到最短路径。有证据证明here

    因此,选择任何一个最小权重的节点都可以。算法最终到达那里。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-08-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-27
      • 2011-03-14
      • 2012-02-17
      相关资源
      最近更新 更多