Algorithm 在正向搜索算法中,如果两个项相等,会发生什么情况?

Algorithm 在正向搜索算法中,如果两个项相等,会发生什么情况?,algorithm,network-programming,computer-science,dijkstra,Algorithm,Network Programming,Computer Science,Dijkstra,在正向搜索算法中,如果两个项相等,您会怎么做 前向搜索算法源于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. Fo

在正向搜索算法中,如果两个项相等,您会怎么做

前向搜索算法源于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.
在最后一步中,我不确定当发生具有相同最低成本的两个条目的事件时该怎么办。我是否将这两个都移到确认列表?
或者我应该选择停留在暂定列表中时间最长的条目吗?

如果有两个条目的成本相同,您可以选择其中一个—这无关紧要。例如,如果您的暂定列表如下所示:

10 4 9 7 7 3 2 11 5 2
2 2 3 4 5 7 7 9 10 11
通过使用排序列表,您可以找到最低成本,如下所示:

10 4 9 7 7 3 2 11 5 2
2 2 3 4 5 7 7 9 10 11
但是你选择前两个还是第二个都不重要

如果您选择了“错误”的一个,并且结果表明所选的一个会导致更长的路径,那么该算法将在继续时自我纠正

编辑:

这个答案实际上非常类似于一个很可能是骗局的答案。本着的精神,我不会删除答案,但我想我会添加更多的细节,这样它就不再只是相同的信息了

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

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

这里的问题其实是一样的,只是两个节点的成本相同。然而,如果它们都有正权重,你可以证明Dijkstra的算法总是能找到最短路径。这是有证据的

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