簡體   English   中英

了解FRINGE搜索偽代碼

[英]Understanding FRINGE Search pseudocode

我無法解釋 FRIGE 搜索算法的偽代碼中的一行。 該行是以下代碼中的#3:

init(start, goal)
fringe F = s
cache C[start] = (0, null)
flimit = h(start)
found = false

while (found == false) AND (F not empty)
    fmin = ∞
    for node in F, from left to right
        (g, parent) = C[node]
        f = g + h(node)
        if f > flimit
            fmin = min(f, fmin)
            continue
        if node == goal
            found = true
            break
        for child in children(node), from right to left
            g_child = g + cost(node, child)
            if C[child] != null
                (g_cached, parent) = C[child]
                if g_child >= g_cached
                    continue
            if child in F
                remove child from F
            insert child in F past node
            C[child] = (g_child, node)
        remove node from F
    flimit = fmin

if reachedgoal == true
    reverse_path(goal)

偽代碼取自這篇維基文章: https : //en.wikipedia.org/wiki/Fringe_search

我無法弄清楚該語法在說什么。 謝謝你的幫助!

稍微檢查一下代碼發現一個 C 條目包含 (g, link_to_parent)。 在哪里

  • 'g' 是該節點處 g(x) 的值。 g(x) 是從第一個節點到當前節點的搜索路徑的成本

  • 'link_to_parent' 是讓你回到父母身邊的東西。 一種
    可能是指針或索引值,甚至可能是
    父母。 它究竟是什么取決於您的實現。
    偽代碼使用“null”來表示沒有父級。

所以第 3 行是說開始節點不需要任何成本,而且它沒有父節點。

C 本身是節點到對 (g,parent_link) 的映射。

C(緩存)的實現方式由您決定,但您需要保留 C 的索引與節點同義的邏輯,並且該節點的內容是 (g, way_to_indicate_parent)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM