Professional Documents
Culture Documents
In the course, we will see other, less obvious, examples which are also hidden shortest path problems Such shortest path problems are a key part of this course
Weighted Graphs
Shortest path problems use weighted graphs These are graphs in which each edge is given a number called its weight The weight of an edge is intended to be its cost, or value, or length, etc Paths then have a weight which is just the sum of the weights of the edges in the path
goal with shortest path to it and (usually) also find the shortest path itself
but there is no generally agreed exact definition sometimes taken to mean to never repeat the same work
Weighted Trees
As usual, trees are easier to understand than graphs so will start with rooted trees first
How to achieve this? Do we already have anything that that almost works in some cases? Yes. BFS does the job in some cases:
c=1
BFS would search all the c=1 nodes before it searches the c=2 node,
would correctly find goal C
not the mincost goal simple DFS is not optimal and complete
c=2
c=3
c=4
c=1
J 3
c=2
c=3 C
c=4
Search all nodes of cost c before those of cost c+1 How to implement? In BFS the effect of the depth was implicitly handled adding new nodes to the end of the queue
if fringe is empty then return found // finished the search node REMOVE-FIRST(fringe) if node is a goal
print node // if want to list all matches to the goal found true // so we remember we succeeded (if only want first goal then return true)
1. 2. 3.
4. 5.
Called a priority queue as highest priority removed first, not just by order of arrival
4.
are graphs not trees more accurately, they are weighted graphs
5
F D
6 7
E
2
C
11
G
Neighbourhood
Both problems arise because we rediscover nodes that the search has already discovere Need to consider methods to suppress nodes that have already been visited
4.
A
1 5 5
10
S
15
G
5
C
We wish to find the shortest route from node S to node G; that is, node S is the initial state and node G is the goal state. In terms of path cost, we can clearly see that the route SBG is the cheapest route. However, if we let breadth-first search loose on the problem it will find the non-optimal path SAG, assuming that A is the first node to be expanded at level 1. Press space to see a UCS of the same node set
Once nodeis with beenfrom the queue removedrevealed nodes are G)the added to the queue.queue Nodenow expand our node at queueis expand queue, node A. Press spaceto the queue. (node We AstartBremovedinitial state front andthe it the queue and is revealed node The Node is removed from the the and of the from node (node added to continue. We S has the expanded it and the revealed G)is then sorted queue is again sorted Note, we have costfoundpriority.In this case the The queue isTheon sorted on path cost.on cheaper pathnownode Ganow appears indo not queue is added. again path cost. Nodes with path cost. Note, have goal state but the queue twice, once as G10 and at the as G11. As G10 is node front the cheaper node. Press space. recognise Node A (1), node B (5), followed byatNode B isof Press space. now proceed to will be it it is not once front of the queue. the C (15). the queue, we goal state. Press space.
A
5 5
10
S
15
The goal state is achieved and the path S-B-G is returned. In relation to path cost, UCS has found the optimal route. Press space to end.
Press space to begin the search Size of Queue: 0 3 1 Nodes expanded: 0 3 2 1 Queue: Empty11, C15 G B, B, C A, G11 S 10, G, C CurrentFINISHED SEARCH action: Waiting. Backtracking Expanding Current level: n/a 2 1 0
Summary
Added costs (weights) to the edges Modified BFS to create Uniform Cost Search (UCS) that
finds optimal (minimum cost) paths to goal(s)
Expectations:
that you can run UCS by hand you can predict the order in which UCS expands nodes that you can implement UCS
Questions?