<<

CSC384: Intro to Artificial Intelligence Search II

●Announcements: 2 Tutorials on Fri Sep 22, 10-11am & 4-5pm

Locations will be posted on the website {Arad}, {Zerind, Timisoara, },

{Zerind, Timisoara, Arad, , Fagaras, RimnicuVilcea}

{Zerind, Timisoara, Arad, Oradea, Sibiu, , RimnicuVilcea}

Solution: Arad -> Sibiu -> Fagaras -> Bucharest Cost: 140 + 99 + 211 = 450

Hojjat Ghaderi [Courtesy of Fahiem Bacchus], University of Toronto, Fall 2006 1 Hojjat Ghaderi [Courtesy of Fahiem Bacchus], University of Toronto, Fall 2006 2

{Arad} {Arad}, {Zerind, Timisoara, Sibiu}, {Zerind, Timisoara, Sibiu}, {Zerind, Timisoara, Arad, Oradea, Fagaras, RimnicuVilcea} {Zerind, Timisoara, Oradea, {Zerind, Timisoara, Arad, Oradea, Fagaras, Sibiu, Pitesti, , Arad, RimnicuVilcea} RimnicuVilcea>} {Zerind, Timisoara, Arad, Oradea, Fagaras, Sibiu, RimnicuVilcea, {Zerind, Timisoara, Oradea, Craiova,Craiova, Bucharest} Fagaras, RimnicuVilcea, Zerind, Timisoara, Sibiu} Solution: Arad -> Sibiu -> Rimnicu Vilcea -> Pitesti ->Bucharest Cost: 140 + 80 + 97 + 101 = 418 No solution found, search does not terminates because of cycles!.

Hojjat Ghaderi [Courtesy of Fahiem Bacchus], University of Toronto, Fall 2006 3 Hojjat Ghaderi [Courtesy of Fahiem Bacchus], University of Toronto, Fall 2006 4 Selection Rule. Critical Properties of Search.

●The example shows that order states are ●Completeness: will the search always find a selected from the frontier has a critical effect solution if a solution exists? on the operation of the search: ●Optimality: will the search always find the least ■ Whether or not a solution is found cost solution? (when actions have costs) ■ The cost of the solution found. ●Time complexity: what is the maximum ■ The time and space required by the search. number of nodes than can be expanded or generated? ●Space complexity: what is the maximum number of nodes that have to be stored in memory?

Hojjat Ghaderi [Courtesy of Fahiem Bacchus], University of Toronto, Fall 2006 5 Hojjat Ghaderi [Courtesy of Fahiem Bacchus], University of Toronto, Fall 2006 6

Uninformed Search Strategies Selecting vs. Sorting

●A simple equivalence we will exploit ●These are strategies that adopt a fixed rule for ■ Order the elements on the frontier. selecting the next state to be expanded. ■ Always select the first element. ●The rule does not change irrespective of the ●Any selection rule can be achieved by search problem being solved. employing an appropriate ordering of the ●These strategies do not take into account any frontier set. domain specific information about the particular search problem. ●Popular uninformed search techniques: ■ Breadth-First, Uniform-Cost, Depth-First, Depth-Limited, and Iterative-Deepening search

Hojjat Ghaderi [Courtesy of Fahiem Bacchus], University of Toronto, Fall 2006 7 Hojjat Ghaderi [Courtesy of Fahiem Bacchus], University of Toronto, Fall 2006 8 Breadth First. Breadth First Example. {0} ●Place the successors of the current state at the {1,2} end of the frontier. {2,2,3} {2,3,3,4} ●Example: {3,3,4,3,4} ■ let the states be the positive integers {0,1,2,…} ■ let each state n have as successors n+1 and n+2 {3,4,3,4,4,5} ● E.g. S(1) = {2, 3}; S(10) = {11, 12} … ■ Start state 0 ■ Goal state 5

Hojjat Ghaderi [Courtesy of Fahiem Bacchus], University of Toronto, Fall 2006 9 Hojjat Ghaderi [Courtesy of Fahiem Bacchus], University of Toronto, Fall 2006 10

Breadth First Properties Breadth First Properties

● Measuring time and space complexity. ●Completeness? ■let b be the maximum number of successors ■ The length of the path from the initial state to the of any state. expanded state must increase monotonically. ● we replace each expanded state with states on ■ let d be the number of actions in the longer paths. shortest solution. ● All shorter paths are expanded prior before any longer path. ■ Hence, eventually we must examine all paths of length d, and thus find the shortest solution.

Hojjat Ghaderi [Courtesy of Fahiem Bacchus], University of Toronto, Fall 2006 11 Hojjat Ghaderi [Courtesy of Fahiem Bacchus], University of Toronto, Fall 2006 12 Breadth First Properties Breadth First Properties

●Time Complexity? ●Space Complexity? ■ O(bd+1): If goal node is last node at level d, all of the successors of the other nodes will be on the frontier when the goal node is expanded b(bd –1)

● Optimality? ■ Will find shortest length solution ●least cost solution? No! ■ 1 + b + b2 + b3 + … + bd-1 + bd + b(bd –1) = O(bd+1)

Hojjat Ghaderi [Courtesy of Fahiem Bacchus], University of Toronto, Fall 2006 13 Hojjat Ghaderi [Courtesy of Fahiem Bacchus], University of Toronto, Fall 2006 14

Breadth First Properties Uniform Cost Search.

●Space complexity is a real problem. ●Keep the frontier sorted in increasing cost of ■ E.g., let b = 10, and say 1000 nodes can be the path to a node. expanded per second and each node requires 100 ●Always expand the least cost node. bytes of storage: ●Identical to Breadth first if each transition has Depth Nodes Time Memory the same cost. 1 1 1 millisec. 100 bytes 6 106 18 mins. 111 MB ●Example: 8 108 31 hrs. 11 GB ■ let the states be the positive integers {0,1,2,…} ■ let each state n have as successors n+1 and n+2 ●Run out of space long before we run out of ■ Say that the n+1 action has cost 2, while the n+2 time in most applications. action has cost 3.

Hojjat Ghaderi [Courtesy of Fahiem Bacchus], University of Toronto, Fall 2006 15 Hojjat Ghaderi [Courtesy of Fahiem Bacchus], University of Toronto, Fall 2006 16 Uniform-Cost Search Example Uniform-Cost Search (cost are shown in [ ], frontier sorted in increasing cost ) {0} ●Completeness? ■ If each transition has costs ≥ ε > 0. {1[2],2[3]} ■ The previous argument used for breadth first search {2[3],2[4],3[5]} holds: the cost of the expanded state must increase monotonically. {2[4],3[5],3[5],4[6]} {3[5],3[5],4[6],3[6],4[7]} …

Hojjat Ghaderi [Courtesy of Fahiem Bacchus], University of Toronto, Fall 2006 17 Hojjat Ghaderi [Courtesy of Fahiem Bacchus], University of Toronto, Fall 2006 18

Uniform-Cost Search Uniform-Cost Search

● Time and Space Complexity? ●Optimality? C*/ε ■O(b ) where C* is the cost of the optimal solution. ■ Finds optimal solution if each transition has cost ≥ ε ●Difficulty is that there may be many long paths > 0. with cost ≤ C*; Uniform-cost search must ● Explores paths in the search space in increasing explore them all. order of cost. So must find minimum cost path to a goal before finding any higher costs paths.

Hojjat Ghaderi [Courtesy of Fahiem Bacchus], University of Toronto, Fall 2006 19 Hojjat Ghaderi [Courtesy of Fahiem Bacchus], University of Toronto, Fall 2006 20 Uniform-Cost Search. Proof of Uniform-Cost Search. Proof of Optimality. Optimality.

● Claim: Let c(n) be the cost of the path to node n. If 2. Claim: When n is expanded every path with cost strictly less than c(n) has already been expanded (i.e., every node on it has n2 is expanded after n1 then been expanded). c(n1) ≤ c(n2). Proof: ● Let be a path with cost less than c(n). Let ni be the last node on this path that has been expanded: Proof: there are 2 cases: a. n2 was on the frontier when n1 was expanded, in which case c(n2) ≥ c(n1) else n1 would not have been ● So, ni+1 must still be on the frontier. Also c(ni+1) < c(n) since selected for expansion. the cost of the entire path to nk is < c(n).

● But then uniform-cost would have expanded ni+1 not n. b. n2 was added to the frontier when n1 was expanded, in which case c(n2) ≥ c(n1) since the path ● So every node on this path must already be expanded, i.e., this to n2 extends the path to n1. path has already been expanded. QED

Hojjat Ghaderi [Courtesy of Fahiem Bacchus], University of Toronto, Fall 2006 21 Hojjat Ghaderi [Courtesy of Fahiem Bacchus], University of Toronto, Fall 2006 22

Uniform-Cost Search. Proof of Depth First Search Optimality.

3. Claim: The first time uniform-cost expands a state, it ●Place the successors of the current state at has found the minimal cost path to it (it might later find other paths to the same state). the front of the frontier.

Proof: ● No cheaper path exists, else that path would have been expanded before. ● No cheaper path will be discovered later, as all those paths must be at least as expensive. ● So, when a goal state is expanded the path to it must be optimal.

Hojjat Ghaderi [Courtesy of Fahiem Bacchus], University of Toronto, Fall 2006 23 Hojjat Ghaderi [Courtesy of Fahiem Bacchus], University of Toronto, Fall 2006 24 Depth First Search Example Depth First Properties (applied to the example of Breadth First Search) {0} ●Completeness? No! ■ Infinite paths? Cause incompleteness! {1,2} {2,3,2}

{3,4,3,2} ■ Prune paths with duplicate states? We get {4,5,4,3,2} completeness if state space is finite {5,6 4,5,4,3,2}

… ●Optimality? No!

Hojjat Ghaderi [Courtesy of Fahiem Bacchus], University of Toronto, Fall 2006 25 Hojjat Ghaderi [Courtesy of Fahiem Bacchus], University of Toronto, Fall 2006 26

Depth First Properties Depth First Backtrack Points

●Time Complexity? ●At each step, all nodes in the frontier (except ■ O(bm) where m is the length of the longest path in the head) are backtrack points (see example on the state space. page 25, and draw the tree for state-space to see this)

■ Very bad if m is much larger than d, but if there are many solution paths it can be much faster than breadth first.

Hojjat Ghaderi [Courtesy of Fahiem Bacchus], University of Toronto, Fall 2006 27 Hojjat Ghaderi [Courtesy of Fahiem Bacchus], University of Toronto, Fall 2006 28 Depth First Properties Depth Limited Search

● Space Complexity? ● Breadth first has computational, especially, space ■O(bm), linear space! problems. Depth first can run off down a very long (or infinite) path. ●Only explore a single path at a time. ● Depth limited search. ●The frontier only contains the deepest states on ■ Perform depth first search but only to a pre-specified depth the current path along with the backtrack points. limit L. ■ No node on a path that is more than L steps from the initial state is placed on the Frontier. ■ We “truncate” the search by looking only at paths of length L or less. ● Now infinite length paths are not a problem. ● But will only find a solution if a solution of length ≤ L exists.

Hojjat Ghaderi [Courtesy of Fahiem Bacchus], University of Toronto, Fall 2006 29 Hojjat Ghaderi [Courtesy of Fahiem Bacchus], University of Toronto, Fall 2006 30

Depth Limited Search Iterative Deepening Search.

DLS(Frontier, Sucessors, Goal?) ●Take the idea of depth limited search one step If Frontier is empty return failure further. ●Starting at depth limit L = 0, we iteratively Curr = select state from Frontier increase the depth limit, performing a depth If(Goal?(Curr)) return Curr. limited search for each depth limit. If Depth(Curr) < L ●Stop if no solution is found, or if the depth Frontier’ = (Frontier – {Curr}) U Successors(state) limited search failed without cutting off any Else nodes because of the depth limit. Frontier’ = Frontier – {Curr} CutOffOccured = TRUE. return DLS(Frontier’, Successors, Goal?) Hojjat Ghaderi [Courtesy of Fahiem Bacchus], University of Toronto, Fall 2006 31 Hojjat Ghaderi [Courtesy of Fahiem Bacchus], University of Toronto, Fall 2006 32 Iterative Deepening Search Example Iterative Deepening Search Properties

●Completeness? ■ Yes, if solution of length d exists, will the search will find it when L = d. ●Time Complexity?

Hojjat Ghaderi [Courtesy of Fahiem Bacchus], University of Toronto, Fall 2006 33 Hojjat Ghaderi [Courtesy of Fahiem Bacchus], University of Toronto, Fall 2006 34

Iterative Deepening Search Properties Iterative Deepening Search Properties

● Time Complexity ● Space Complexity ■(d+1)b0 + db1 + (d-1)b2 + … + bd = O(bd) ■ O(bd) Still linear! ● ■E.g. b=4, d=10 Optimal? 0 1 2 9 = ■ Will find shortest length solution which is optimal if costs are ●(11)*4 + 10*4 + 9*4 + … + 2*4 815,555 uniform. 10 ●4 = 1,048,576 ■ If costs are not uniform, we can use a “cost” bound instead. ●Most nodes lie on bottom layer. ● Only expand paths of cost less than the cost bound. ●In fact IDS can be more efficient than breadth ● Keep track of the minimum cost unexpanded path in each depth first iteration, increase the cost bound to this on the first search: nodes at limit are not expanded. BFS next iteration. must expand all nodes until it expand a goal ● This can be very expensive. Need as many iterations of the node. search as there are distinct path costs.

Hojjat Ghaderi [Courtesy of Fahiem Bacchus], University of Toronto, Fall 2006 35 Hojjat Ghaderi [Courtesy of Fahiem Bacchus], University of Toronto, Fall 2006 36 Iterative Deepening Search Properties ● Consider space with three paths of length 3, but each action having a distinct cost.

Hojjat Ghaderi [Courtesy of Fahiem Bacchus], University of Toronto, Fall 2006 37