【发布时间】: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