Representation. Representation. Representation. Representation. 8 puzzle.

Save this PDF as:
 WORD  PNG  TXT  JPG

Size: px
Start display at page:

Download "Representation. Representation. Representation. Representation. 8 puzzle."

Transcription

1 You have a 3-liter jug and a 4-liter jug, and need to measure out exactly two liters of water. the jugs do not have any measurement lines you don't have any additional containers 8 puzzle. Measuring water. CPSC 444: Artificial Intelligence Spring CPSC 444: Artificial Intelligence Spring (# liters in 3-liter jug, # of liters in 4-liter jug) initial state (0,0) goal states (2,*) (*,2) and successor function fill jug fill 3-liter jug: (m,n) (3,n) [m < 3] fill 4-liter jug: (m,n) (m,4) [n < 4] empty jug empty 3-liter jug: (m,n) (0,n) [m > 0] empty 4-liter jug: (m,n) (m,0) [n > 0] pour from one jug into another, until source jug is empty or target jug is full from 3-liter to 4-liter: (m,n) (m-min(m,4-n),n+min(m,4-n)) [m > 0, n < 4] from 4-liter to 3-liter: (m,n) (m+min(3-m,n),n-min(3-m,n)) [m < 3, n > 0] number of steps permutation of tiles how the blank tile moves left, right, up, down number of moves made CPSC 444: Artificial Intelligence Spring CPSC 444: Artificial Intelligence Spring

2 Geometric analogy problems. Considerations. running time of search depends on branching factor - number of rules applicable to a given state length of solution path - shorter is better CPSC 444: Artificial Intelligence Spring CPSC 444: Artificial Intelligence Spring Search Techniques a set of statements about the shapes in a particular picture e.g. inside(a,b), left(a,b), above(a,b) allowed transformations e.g. scale(a,factor), delete(a), insertleft(a,b), insertabove(a,b), rotate(a,angle) number of transformations can also weight transformations to give priority to certain operations over others The state space forms a tree or graph. graph may be directed (some moves not reversible) or undirected (all moves reversible) uninformed (blind) search know only if a state is goal or not informed (heuristic) search can determine if one non-goal state is more promising than another adversarial search finding a good solution against an opponent who is trying to do the same CPSC 444: Artificial Intelligence Spring CPSC 444: Artificial Intelligence Spring

3 Evaluating Search Techniques Implementation Details Four properties: completeness are we guaranteed to find a solution if there is one? optimality does the algorithm find the best solution? time complexity how long does it take to find a solution? space complexity how much memory is needed to perform the search How do you determine the solution path once you've found a solution? search state includes the current problem state + the previous state and the rule applied to get to this state CPSC 444: Artificial Intelligence Spring CPSC 444: Artificial Intelligence Spring Implementation Details depth-first search (DFS) use stack for S If generate new state is implemented as a mutator, be sure to copy the current state first. breadth-first search (BFS) use queue for S CPSC 444: Artificial Intelligence Spring CPSC 444: Artificial Intelligence Spring

4 Recursive DFS solution dfs ( state, move ) { if state is the goal state return new solution containing only move } for each applicable rule generate new state if dfs(new state,rule) is successful add move to the solution found return solution return null // failure does not require an explicit stack call stack size may be limited by the runtime environment can generate new state without copying (though must then restore) CPSC 444: Artificial Intelligence Spring Time and space. b is average branching factor, m is tree depth, d is depth of solution max tree depth is length of the longest path DFS time is O(b m ), space is O(bm) time can be O(mb m ) if path is checked to avoid cycles marking states as explored instead means O(1) cycle check but O(b m ) space BFS time is O(b d ), space is O(b d ) CPSC 444: Artificial Intelligence Spring Uninformed Search DLS and IDS DFS is not optimal or complete. not guaranteed to find shortest path, unless all paths are explored and the best chosen may get stuck if there are cycles can prevent by checking current state against previous states on path may be desirable to avoid re-discovering states if there are alternate paths BFS is optimal and complete. always finds a solution always finds the shortest path may need to avoid re-discovering states if there are cycles or alternate paths Goal: DFS space requirements, with optimality and completeness. depth-limited search (DLS) DFS with a maximum depth search does not consider states deeper than that prevents infinite cycling (can omit cycle check) not optimal or complete not guaranteed to find shortest path, unless all paths are explored and the best chosen may not find a solution if the depth limit is too shallow time O(b l ), space O(bl) b = average branching factor l = depth limit of search CPSC 444: Artificial Intelligence Spring CPSC 444: Artificial Intelligence Spring

5 Uninformed Search DLS and IDS Goal: DFS space requirements, with optimality and completeness. iterative deepening (IDS) DLS with progressively-increasing depths until solution is found complete and optimal always finds a solution not trapped by cycles (no need for cycle check) finds shallowest solution time O(b d ), space O(bd) b = average branching factor d = depth of solution lots of repeated work (lower depths are searched over and over) but search time is dominated by the last level CPSC 444: Artificial Intelligence Spring