Use uniform-cost search on unequal edges
Keep the names of states and actions distinct. · 170 words
Uniform-cost search (UCS) finds a least-total-cost path when edge costs differ. Its priority is g(n), the cost of the best known route from the start S to node n; lower g means earlier expansion. For example, let S-A cost 2, S-B cost 1, B-C cost 2, A-C cost 5, and C-G cost 3. UCS expands S, then B at cost 1, then A at cost 2, and then C at cost 3. Reaching G gives cost 6, so the returned route is S-B-C-G.
Try another small road map. The edges are S-X = 4, S-Y = 1, Y-X = 1, X-G = 5, and Y-G = 7. The open list stores frontier nodes ordered by their accumulated cost. UCS expands S, Y with g(Y) = 1, and X with g(X) = 2. Expanding X inserts G with g(G) = 7. The route through Y already offers G at cost 8, so the cheaper goal route S-Y-X-G is retained. This shows why UCS compares full path costs rather than counting edges.
Check your recall
In the first road map, which route does UCS return, and what is its total cost?
Check your answer
UCS returns S-B-C-G. Its total cost is 1 + 2 + 3 = 6.
Sources and credits
Original KeyTouch lesson. Background reading · UC Berkeley · Introduction to Artificial Intelligence.