a-star

启发式搜索(heuristic search)———A*算法

烂漫一生 提交于 2020-04-29 09:36:14
在宽度优先和深度优先搜索里面,我们都是根据搜索的顺序依次进行搜索,可以称为盲目搜索,搜索效率非常低。 而启发式搜索则大大提高了搜索效率,由这两张图可以看出它们的差别: (左图类似与盲搜,右图为启发式搜索)( 图片来源 ) 很明显启发式的搜索效率远远大于盲搜。 什么是启发式搜索(heuristic search)    利用当前与问题有关的信息作为启发式信息,这些信息是能够提升查找效率以及减少查找次数的。 如何使用这些信息,我们定义了一个估价函数 h(x) 。h(x)是对当前状态x的一个估计,表示 x状态到目标状态的距离。 有: 1、h(x) >= 0 ; 2、h(x)越小表示 x 越接近目标状态; 3、如果 h(x) ==0 ,说明达到目标状态。 与问题相关的启发式信息都被计算为一定的 h(x) 的值,引入到搜索过程中。   然而,有了启发式信息还不行,还需要起始状态到 x 状态所花的代价,我们称为 g(x) 。比如在走迷宫问题、八数码问题,我们的 g(x) 就是从起点到 x 位置花的步数 ,h(x) 就是与目标状态的曼哈顿距离或者相差的数目;在最短路径中,我们的 g(x) 就是到 x 点的权值,h(x) 就是 x 点到目标结点的最短路或直线距离。   现在,从 h(x) 和 g(x) 的定义中不能看出,假如我们搜索依据为 F(x) 函数。   当 F(x) = g(x)

启发式搜索(heuristic search)———A*算法

余生长醉 提交于 2020-04-29 08:41:21
在宽度优先和深度优先搜索里面,我们都是根据搜索的顺序依次进行搜索,可以称为盲目搜索,搜索效率非常低。 而启发式搜索则大大提高了搜索效率,由这两张图可以看出它们的差别: (左图类似与盲搜,右图为启发式搜索)( 图片来源 ) 很明显启发式的搜索效率远远大于盲搜。 什么是启发式搜索(heuristic search)    利用当前与问题有关的信息作为启发式信息,这些信息是能够提升查找效率以及减少查找次数的。 如何使用这些信息,我们定义了一个估价函数 h(x) 。h(x)是对当前状态x的一个估计,表示 x状态到目标状态的距离。 有: 1、h(x) >= 0 ; 2、h(x)越小表示 x 越接近目标状态; 3、如果 h(x) ==0 ,说明达到目标状态。 与问题相关的启发式信息都被计算为一定的 h(x) 的值,引入到搜索过程中。   然而,有了启发式信息还不行,还需要起始状态到 x 状态所花的代价,我们称为 g(x) 。比如在走迷宫问题、八数码问题,我们的 g(x) 就是从起点到 x 位置花的步数 ,h(x) 就是与目标状态的曼哈顿距离或者相差的数目;在最短路径中,我们的 g(x) 就是到 x 点的权值,h(x) 就是 x 点到目标结点的最短路或直线距离。   现在,从 h(x) 和 g(x) 的定义中不能看出,假如我们搜索依据为 F(x) 函数。   当 F(x) = g(x)

Unity NavMesh 动态烘焙绘制与随机取点

混江龙づ霸主 提交于 2020-04-23 11:13:59
最初的Unity导航系统很不完善,只能静态烘焙场景图的可行走区域,而且必须在本地保存场景的NavMesh数据,难以运行时动态计算;这使得鲜有开发者愿意再尝试Unity内置的导航功能,转向了AStar寻路算法的研究。 但实际上AStar算法真的适合大多数开发情况且性能较优么? 了解过AStar算法的都知道,它是基于格子来遍历计算行走权重的,算法复杂度其实是相对较高的,受到格子密度,地图大小和路线长度的的影响较大。 AStar更适合的是策略性寻路,该算法更有利于找出最短路径的最优解,能够达到足够的精确性。 而Unity的NavMesh是用的拐角点算法,随便找一个场景烘焙一下便可得知,例如: 烘焙出来的NavMesh区域只在障碍物边缘与平面边缘存在顶点,而不会像AStar一样均匀的布满整个平面;如果是一个无任何障碍物的平面,那就只会有平面边缘的几个顶点,算法效率是相对较高的,并不会因为地图变大而有明显算法复杂度上的变化。 相反,NavMesh的缺点也正是AStar的优点,那就是难以保证寻路的最优解,更多的时候是用于AI能够更快计算出绕过障碍物朝向目标前进的路径。 对于场景不变的静态地图来说,Unity最初的NavMesh已经能够满足需求,但如果地图随机生成或障碍物的位置随时变化,此时静态NavMesh一下子就捉襟见肘了。 好在随着Unity版本的更新,关于动态烘焙的方法也已经能有效实现

How to solve 15-puzzle paradigm in Prolog with Manhattan & Hamming Heuristics

半腔热情 提交于 2020-04-11 05:32:29
问题 I have this implementation of the 15-puzzle game, using Prolog (Swipl). I have already implemented the A* search using Manhattan heuristic, but now I need to add hamming heuristic. Do yo know how to implement it? :- op(400,yfx,'@'). resolver(Estado,MovimientosSolucion) :- evaluar(Estado,0,F), buscarSolucion([Estado@0@F@[]],S), reverse(S,MovimientosSolucion). evaluar(Estado,Profundidad,F) :- evaluarCoste(Estado,Coste), F is Profundidad + Coste. buscarSolucion([Estado@_@_@MovimientosSolucion|_]

How to solve 15-puzzle paradigm in Prolog with Manhattan & Hamming Heuristics

六月ゝ 毕业季﹏ 提交于 2020-04-11 05:32:08
问题 I have this implementation of the 15-puzzle game, using Prolog (Swipl). I have already implemented the A* search using Manhattan heuristic, but now I need to add hamming heuristic. Do yo know how to implement it? :- op(400,yfx,'@'). resolver(Estado,MovimientosSolucion) :- evaluar(Estado,0,F), buscarSolucion([Estado@0@F@[]],S), reverse(S,MovimientosSolucion). evaluar(Estado,Profundidad,F) :- evaluarCoste(Estado,Coste), F is Profundidad + Coste. buscarSolucion([Estado@_@_@MovimientosSolucion|_]

Pathfinding through four dimensional data

北城以北 提交于 2020-04-11 05:23:06
问题 The problem is finding an optimal route for a plane through four dimensional winds (winds at differing heights and that change as you travel (predicative wind model)). I've used the traditional A* search algorithm and hacked it to get it to work in 3 dimensions and with wind vectors. It works in a lot the cases but is extremely slow (im dealing with huge amounts of data nodes) and doesnt work for some edge cases. I feel like I've got it working "well" but its feels very hacked together. Is

A_Star 算法

浪尽此生 提交于 2020-03-27 09:46:57
3 月,跳不动了?>>> 摘录A*算法的erlang实现 原作者出自: https://stevegilham.blogspot.com/2008/10/first-refactoring-of-star-in-erlang.html -module(a_star). -export([main/0]). astar(Start,Goal) -> Closedset = sets:new(), % The set of nodes already evaluated. Openset = sets:add_element(Start,sets:new()), %The set of tentative nodes to be evaluated Fscore = dict:append(Start, h_score(Start), dict:new()), Gscore = dict:append(Start, 0, dict:new()), % Distance from start along optimal path. CameFrom = dict:append(Start, none, dict:new()), astar_step(Goal, Closedset, Openset, Fscore, Gscore, CameFrom). astar_step(Goal,

A星寻路的启发式加盐和扩展

寵の児 提交于 2020-02-27 01:55:43
原汁原味的astar是启发式搜索,随着启发式的算法改变,搜索结果和使用场景也会不一样。 启发式函数可以有很多加盐的东西,比如权重,3d距离,道路材质(摩擦力等),个性偏好等。 加盐的目的是为了适应更多的应用场景,不过原始的astar是二维平面的,对于具有多重高度图的三维那么用起来就不太方便了。 进行三维空间的扩展的话,原理和二维一样的,只不过方向可以扩展为3x3x3的立方体组合,这种立方体借助了体素的思想,复杂一点的可以基于网格mesh 来源: oschina 链接: https://my.oschina.net/kkkkkkkkkkkkk/blog/3156452

Why does the A-star algorithm need g(n)?

穿精又带淫゛_ 提交于 2020-02-05 06:47:45
问题 Dijkstra's algorithm is f(n) = g(n) and A* is f(n) = g(n) + h(n) . g(n) is the cost of the path from the start node to n. h(n) is a heuristic function that estimates the cost of the cheapest path from n to the goal. Is g(n) needed? Can't it find the shortest path without g(n)? Why does A* need g(n)? 回答1: We need g(n) Consider the case when h(n) is 0 for all nodes on some given path to the goal (which is a perfectly valid, i.e. admissible, heuristic) and non-zero for all other nodes. If we

Does A* need to know the optimal solution cost while utilizing an admissible heuristic?

删除回忆录丶 提交于 2020-01-25 20:27:07
问题 I've read through a few stackoverflows on this topic, as well as the wikipedia on A* but I'm still a little confused. I think this post almost explained it completely to me: A* heuristic, overestimation/underestimation? My only confusion left is, how does the A* know the optimal solution? It seems like with an admissible heuristic, you can throw out paths that exceed the known optimal solution, because the heuristic is guaranteed to be less than or equal. But how would A* know the optimal