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
1 | 2 | |
---|---|---|
open list | g(s)=0 | g§=1,g(d)=3,g(e)=9 |
close list | g(s)=0 |
3 | 4 | 5 |
---|---|---|
g(d)=3,g(e)=9,g(q)=15 | g(e)=5,g(a)=6,g(c )=11,g(q)=15 | |
g(s)=0,g(p )=1 | g(s)=0,g( p)=1,g(d)=3 | g(s)=0,g(p )=1,g(d)=3,g(b)=4 |
6 | 7 | 8 |
---|---|---|
g(a)=6,g( r)=6,g(c )=11,g(h)=13,g(q)=15 | g(r )=6,g(c )=11,g(h)=13,g(q)=15 | g(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)=5 | g(s)=0,g(p )=1,g(d)=3,g(b)=4,g(e)=5,g(a)=6 | g(s)=0,g(p )=1,g(d)=3,g(b)=4,g(e)=5,g(a)=6,g( r)=6 |
9 | 10 | |
---|---|---|
g(G)=9,g(c )=11,g(h)=13,g(q)=15 | g( 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)=7 | g(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
(没有目标位置的信息)