Presentation is loading. Please wait.

Presentation is loading. Please wait.

UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering CSCE 580 Artificial Intelligence Dijkstra’s Algorithm: Notes to Complement.

Similar presentations


Presentation on theme: "UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering CSCE 580 Artificial Intelligence Dijkstra’s Algorithm: Notes to Complement."— Presentation transcript:

1 UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering CSCE 580 Artificial Intelligence Dijkstra’s Algorithm: Notes to Complement and Reinforce the Graduate Student Presentation Fall 2008 Marco Valtorta mgv@cse.sc.edu

2 UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Example: Romania

3 UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Single-State Problem Formulation A problem is defined by four items: 1.initial state e.g., "at Arad" 2.actions or successor function S(x) = set of action–state pairs –e.g., S(Arad) = {,, … } 3.goal test, can be –explicit, e.g., x = "at Bucharest" –implicit, e.g., Checkmate(x) 4.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 UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering 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 UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering 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 UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering 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 n 1,…,n q be the nodes in OPEN. Let n = n i 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 n p be the first node in OPEN on that path. Since path s  n p  n i is shorter than g(n), then path s  n p is shorter than path s  n i. This means that when executing step 3, g(n p ) < g(n i ), and therefore n p would be closed in step 3 instead of n i : contradiction!

7 UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering 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 UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering 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 UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering 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 UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering 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 UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering 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'.


Download ppt "UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering CSCE 580 Artificial Intelligence Dijkstra’s Algorithm: Notes to Complement."

Similar presentations


Ads by Google