为什么在寻找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

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

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