Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/algorithm/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Algorithm 在线DFS(人工智能)中的问题_Algorithm_Artificial Intelligence_Graph Algorithm - Fatal编程技术网

Algorithm 在线DFS(人工智能)中的问题

Algorithm 在线DFS(人工智能)中的问题,algorithm,artificial-intelligence,graph-algorithm,Algorithm,Artificial Intelligence,Graph Algorithm,我认为在线深度搜索算法存在一些问题,因为我没有看到任何递归调用。 这是peter Norvig的代码。 请帮助我理解这是正确的还是错误的 function ONLINE -DFS-AGENT (s′) returns an action inputs: s′, a percept that identifies the current state persistent: result , a table indexed by state and action, initial

我认为在线深度搜索算法存在一些问题,因为我没有看到任何递归调用。 这是peter Norvig的代码。
请帮助我理解这是正确的还是错误的

function ONLINE -DFS-AGENT (s′) returns an action

    inputs: s′, a percept that identifies the current state

    persistent: result , a table indexed by state and action, initially empty
    untried, a table that lists, for each state, the actions not yet tried
    unbacktracked , a table that lists, for each state, the backtracks not yet tried

    s, a: the previous state and action, initially null

    if GOAL-TEST(s') then 
        return stop
    if s ′ is a new state (not in untried ) then 
        untried[s′] ← ACTIONS(s′)
    if s is not null then
        result[s, a] ← s′
        add s to the front of unbacktracked[s′]
    if untried[s′] is empty then
        if unbacktracked[s′] is empty then return stop
        else a ← an action b such that result [s′, b] = POP(unbacktracked [s′])
    else 
        a ← POP (untried [s′])
    s ← s′
    return a

您几乎不需要递归,它只是方便而已

使用一个或多个堆栈是DFS的替代方案。具体而言,上面的堆栈代码涉及:

  • 两个堆栈表:
    untried
    unbacktracked
  • 设置整个堆栈:
    untried[s']← 行动‘
  • 将元素推送到堆栈:
    将s添加到unbacktracked[s′]的前面
  • 弹出一个元素:
    [s′,b]=POP(unbacktracked[s′])
  • 弹出一个元素:
    a← POP(未试验过的[s')
使用显式堆栈而不是递归的原因如下:

  • 更容易停止
  • 动态内存在许多系统上的限制小于堆栈内存,因此您可以处理较大的图形

但是,代码并不清楚-它使用了POP和“将s添加到前端”,我认为这是一个推送。

我现在没有这本书,但是递归调用不是实现递归的唯一方法。还可以将当前级别i的信息存储在堆栈中,向下移动到递归级别i+1,计算级别i+1的结果,然后弹出级别i的信息以计算级别i的结果。这段代码中的递归是通过堆栈实现的。递归调用只能通过一个用布尔逻辑表示的堆栈来实现。命令是push和pop,用于与堆栈交互。因为推送操作在源代码中缺失,所以无法工作。这是我在干运行此程序时的想法。我不知道它是怎么工作的?但如果可能的话,我需要有人给我解释这一点。但当堆栈不为空时,并没有什么比这更好的了。它只需检查条件并执行一些push和pop操作,然后返回a。它将被反复调用(等),直到它返回stop(由于目标测试或因为两个堆栈都为空)。感谢您的帮助。