为什么在寻找A*算法的启发式函数时,我们要返回四个角落中的最大距离?

我在尝试解决cs188人工智能项目-1中的搜索问题。在cornersHeuristic()函数中,我们需要返回一个启发式函数,以便在遍历角落时使用。我们希望使用最短路径,因此我们使用A*搜索算法。为了更好地理解代码,这里是代码的总结:我们有角落的位置以(x,y)格式表示,我们角色的当前位置同样以(x, y)格式表示。返回的启发式函数是位置到所有角落的距离中的最大距离。但这里的逻辑是什么?我们不应该返回到最近角落的最小距离吗?为什么我们要返回这些距离中的最大值,这如何帮助找到最短路径?代码如下:对代码的一些解释:corner1, corner2, corner3, corner4和location变量都是元组,存储x和y值。例如(1, 1), (4, 5)

def cornersHeuristic(state, problem):    A heuristic for the CornersProblem that you defined.      state:   The current search state               (a data structure you chose in your search problem)      problem: The CornersProblem instance for this layout.    This function should always return a number that is a lower bound on the    shortest path from the state to a goal of the problem; i.e.  it should be    admissible (as well as consistent).    corners = problem.corners # These are the corner coordinates    walls = problem.walls # These are the walls of the maze, as a Grid (game.py)    location, corner1, corner2, corner3, corner4 = state    corners = [corner1, corner2, corner3, corner4]    heuristic = 0    for x in corners[1]:        heuristic = max(heuristic,(abs(location[0]-x[0]) + abs(location[1] - x[1])))    return max_r

回答:

启发式函数是对实际距离的一个下界。你希望这个下界尽可能大,同时仍然保证是一个界。

所以你说的min确实可以工作。但max更好,因为它是一个更大的下界。

我们可以保证它仍然是一个下界,因为问题陈述是我们需要访问所有角落。完成这个任务所需的路径长度总是至少是访问最远角落的成本。如果问题是访问任何一个角落,那么我们就需要使用min

Related Posts

L1-L2正则化的不同系数

我想对网络的权重同时应用L1和L2正则化。然而,我找不…

使用scikit-learn的无监督方法将列表分类成不同组别,有没有办法?

我有一系列实例,每个实例都有一份列表,代表它所遵循的不…

f1_score metric in lightgbm

我想使用自定义指标f1_score来训练一个lgb模型…

通过相关系数矩阵进行特征选择

我在测试不同的算法时,如逻辑回归、高斯朴素贝叶斯、随机…

可以将机器学习库用于流式输入和输出吗?

已关闭。此问题需要更加聚焦。目前不接受回答。 想要改进…

在TensorFlow中,queue.dequeue_up_to()方法的用途是什么?

我对这个方法感到非常困惑,特别是当我发现这个令人费解的…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注