Dijkstra算法

Dijkstra算法是一种用于寻找图中两点间最短路径的算法,它通过优先队列存储待展开节点,并始终保持到起点的最低累积成本。在每次迭代中,算法会标记并更新最近发现的节点,直到目标节点被找到。尽管Dijkstra算法能保证找到最优解,但它无法预知目标位置信息,只能按当前累积成本顺序探索所有可能的路径。
摘要由CSDN通过智能技术生成

Dijkstra

2.2.1 Dijkstra(priority queue)

1)Strategy: expand/visit the node with cheapest accumulated cost g(n)

• g(n): The current best estimates of the accumulated cost from the start state to node “n”
(从开始状态到节点“n”的累积成本的当前最佳估计)
• Update the accumulated costs g(m) for all unexpanded neighbors “m” of node “n”
(更新节点“n”的所有未展开邻居“m”的累计代价g(m))
• A node that has been expanded/visited is guaranteed to have the smallest cost from the start state
(已展开/访问的节点保证从开始状态起具有最小的开销)

2)Dijkstra’s Algorithm

• Maintain a priority queue to store all the nodes to be expanded
• The priority queue is initialized with the start state XS
• Assign g(XS)=0, and g(n)=infinite for all other nodes in the graph
• Loop
	*• If the queue is empty, return FALSE; break;*
	*• Remove the node “n” with the lowest g(n) from the priority queue (=open list 相反的是已经扩展的close list)*
	*• Mark node “n” as expanded*
	*• If the node “n” is the goal state, return TRUE; break;*
	*• For all unexpanded neighbors “m” of node “n”*
		*• If g(m) = infinite*
			*• g(m)= g(n) + Cnm*
			*• Push node “m” into the queue*
		*• If g(m) > g(n) + Cnm*
			*• g(m)= g(n) + Cnm*
	*• end*
• End Loop

在这里插入图片描述

12
open listg(s)=0g§=1,g(d)=3,g(e)=9
close listg(s)=0
345
g(d)=3,g(e)=9,g(q)=15g(e)=9,g(b)=4,g(e)=5,g(c )=11,g(q)=15g(e)=5,g(a)=6,g(c )=11,g(q)=15
g(s)=0,g(p )=1g(s)=0,g( p)=1,g(d)=3g(s)=0,g(p )=1,g(d)=3,g(b)=4
678
g(a)=6,g( r)=6,g(c )=11,g(h)=13,g(q)=15g(r )=6,g(c )=11,g(h)=13,g(q)=15g(f)=7,g( c)=11,g(h)=13,g(q)=15
g(s)=0,g(p )=1,g(d)=3,g(b)=4,g(e)=5g(s)=0,g(p )=1,g(d)=3,g(b)=4,g(e)=5,g(a)=6g(s)=0,g(p )=1,g(d)=3,g(b)=4,g(e)=5,g(a)=6,g( r)=6
910
g(G)=9,g(c )=11,g(h)=13,g(q)=15g( c)=11,g(h)=13,g(q)=15
g(s)=0,g(p )=1,g(d)=3,g(b)=4,g(e)=5,g(a)=6,g( r)=6,g(f)=7g(s)=0,g(p )=1,g(d)=3,g(b)=4,g(e)=5,g(a)=6,g(r )=6,g(f)=7,g(G)=9找到终点,结束

3)Pros and Cons of Dijkstra’s Algorithm

3)Pros and Cons of Dijkstra’s Algorithm

The good:
• Complete and optimal
The bad:
• Can only see the cost accumulated so far (i.e. the uniform cost), thus exploring next state in every “direction”
(只能看到到目前为止累积的成本(即统一成本),然后从各个“方向”探索下一个状态)
• No information about goal location
(没有目标位置的信息)

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值