1 / 11

Fall 2008 Marco Valtorta mgv@cse.sc

CSCE 580 Artificial Intelligence Dijkstra’s Algorithm: Notes to Complement and Reinforce the Graduate Student Presentation. Fall 2008 Marco Valtorta mgv@cse.sc.edu. Example: Romania. Single-State Problem Formulation. A problem is defined by four items: initial state e.g., "at Arad"

trina
Download Presentation

Fall 2008 Marco Valtorta mgv@cse.sc

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CSCE 580Artificial IntelligenceDijkstra’s Algorithm: Notes to Complement and Reinforce the Graduate Student Presentation Fall 2008 Marco Valtorta mgv@cse.sc.edu

  2. Example: Romania

  3. Single-State Problem Formulation A problem is defined by four items: • initial state e.g., "at Arad" • actions or successor functionS(x) = set of action–state pairs • e.g., S(Arad) = {<Arad  Zerind, Zerind>, <Arad  Timisoara, Timisoara>, … } • goal test, can be • explicit, e.g., x = "at Bucharest" • implicit, e.g., Checkmate(x) • path cost (additive) • e.g., sum of distances, number of actions executed, etc. • c(x,a,y) is the step cost, assumed to be ≥ 0 • A solution is a sequence of actions leading from the initial state to a goal state • An optimal solution is a solution of lowest cost

  4. Uniform-Cost (Dijkstra) for Graphs Original Reference: Dijkstra, E. W. "A Note on Two Problems in Connexion with Graphs.“ Numerische Matematik, 1 (1959), 269-271 • 1. Put the start node s in OPEN. Set g(s) to 0 • 2. If OPEN is empty, exit with failure • 3. Remove from OPEN and place in CLOSED a node n for which g(n) is minimum; in case of ties, favor a goal node • 4. If n is a goal node, exit with the solution obtained by tracing back pointers from n to s • 5. Expand n, generating all of its successors. For each successor n' of n: • a. compute g'(n')=g(n)+c(n,n') • b. if n' is already on OPEN, and g'(n')<g(n'), let g(n')=g'(n’) and redirect the pointer from n' to n • c. if n' is neither on OPEN or on CLOSED, let g(n')=g'(n'), attach a pointer from n' to n, and place n' on OPEN • 6. Go to 2

  5. Properties of Dijkstra’s Algorithm • g(n) is the distance (cost) of some path from the start node to node n • f*(n) is the minimum of g(n) over all possible paths from the start node to node n • f*(k) is the distance of the goal node from the start node---assume a single goal node, k, for simplicity • A search algorithm is admissible if it returns the shortest path • 1. When node n is closed in step 3, g(n)=f*(n) • 2. When node n is closed at step 3, g(n) is at least as high as the g value of all already closed nodes and all nodes with lower g values than g(n) have already been closed • 3. Only nodes for which g(n)<f*(k) are expanded in step 5 (if there is a path from the start node to the goal node) • 4. Dijkstra's algorithm never expands the same node twice • 5. Dijkstra's algorithm expands the least number of nodes among all admissible blind, unidirectional search algorithms

  6. Property 1 of Dijkstra’s Algorithm When node n is closed in step 3, g(n)=f*(n) • The proof is by induction on the number of closed nodes. For the base case, g(s) = f*(s) = 0. • Let n1,…,nq be the nodes in OPEN. Let n = ni • Consider the path to n through nodes in CLOSED that establishes that n is to be closed in step 3 • Assume that there is a shorter path to n than the one chosen by Dijkstra’s algorithm. Let np be the first node in OPEN on that path. Since path snpni is shorter than g(n), then path snp is shorter than path sni. This means that when executing step 3, g(np) < g(ni), and therefore np would be closed in step 3 instead of ni: contradiction!

  7. Property 2 of Dijkstra’s Algorithm When node n is closed at step 3, g(n) is at least as high as the g value of all already closed nodes and all nodes with lower g values than g(n) have already been closed • This can also be proven by induction. For the induction step, note that the node that is closed at step 3 has g(n) value that is at least as high than that of all previously closed nodes---otherwise it would have been closed before! • Also note that this proof depends crucially on having non-negative edge costs

  8. Property 3 and 4 of Dijkstra’s Algorithm Only nodes for which g(n)<f*(k) are expanded in step 5 (if there is a path from the start node to the goal node) • Since nodes are expanded in non-decreasing order of shortest-path distance from the start node, only nodes for which g(n) <= f*(k) are expanded • To get the result with a strict inequality, note that ties are broken in favor of the goal node Dijkstra's algorithm never expands the same node twice • Nodes are expanded only when they are moved from OPEN to CLOSED in step 3. Since CLOSED nodes cannot be re-OPENed, no node can be expanded twice.

  9. Property 5 of Dijkstra’s Algorithm Dijkstra's algorithm expands the least number of nodes among all admissible blind, unidirectional search algorithms • Adversary argument • I claim there is an algorithm (say, B) that does not expand node m, for which g(m) < f*(k) on some graph search problem (say, G) and is admissible • Let f*(k)-g(m) = e • Consider an instance of graph search problem identical to G except for the additional edge mk of cost e/2 • Since B does not expand node m, it will not return the shortest path of length f*(k)-(e/2) • Therefore, B is not admissible

  10. Lower Bound • Assumptions and notation: • decision-tree model (count comparisons of edge costs) • blind unidirectional algorithms • n is the number of nodes and m is the number of edges in the (implicit) graph been searched • Property 5 implies Ω(m) • Ω(n log(n)) follows from a transformation of sorting to finding the shortest path spanning tree and a sequence of all the n nodes ordered in increasing distance from the start node • Overall: Ω(m + n log(n)) • The Fibonacci tree implementation of Dijkstra’s algorithm matches the lower bound and is therefore optimal • See reference in notes

  11. Bidirectional Uniform-Cost Algorithm • (Assume that there is only one goal node, k.) • 1. Put the start node s in OPEN1 and the goal node k in OPEN2. Set g(s) and h(k) to 0 • 2'. If OPEN1 is empty, exit with failure • 3'. Remove from OPEN1 and place in CLOSED1 a node n for which g(n) is minimum • 4'. If n is in CLOSED2, exit with the solution obtained by tracing backpointers from n to s and forward pointers from n to k • 5'. Expand n, generating all of its successors. For each successor n' of n: • a. compute g'(n')=g(n)+c(n,n') • b. if n' is already on OPEN1, and g'(n')<g(n'), let g(n')=g'(n) and redirect the pointer from n' to n • c. if n' is neither on OPEN1 or on CLOSED1, let g(n')=g'(n'), attach a pointer from n' to n, and place n' on OPEN1 • 2". If OPEN2 is empty, exit with failure • 3". Remove from OPEN2 and place in CLOSED2 a node n for which h(n) is minimum • 4". If n is in CLOSED1, exit with the solution obtained by tracing forwards pointers from n to k and backpointers from s to n • 5". Expand n, generating all of its predecessors. For each predecessor n' of n: • a. compute h'(n')=h(n)+c(n',n) • b. if n' is already on OPEN2, and h'(n')<h(n'), let h(n')=h'(n) and redirect the pointer from n' to n • c. if n' is neither on OPEN2 or on CLOSED2, let n(n')=n'(n'), attach a pointer from n' to n, and place n' on OPEN2 • 6. Go to 2'.

More Related