Presentation is loading. Please wait.

Presentation is loading. Please wait.

Now would be a good time to kill your cell phone, and disconnect from the internet. For next time, print Heuristic Search.ppt slides.

Similar presentations


Presentation on theme: "Now would be a good time to kill your cell phone, and disconnect from the internet. For next time, print Heuristic Search.ppt slides."— Presentation transcript:

1 Now would be a good time to kill your cell phone, and disconnect from the internet.
For next time, print Heuristic Search.ppt slides

2 The final exam will be on the last day of class, not during finals week.
If this is inconvenient for you, and you tell me so at least a week before the final, I will be happy to offer you an equivalent exam during the official slot during finals week.

3 Last time we saw… Illegal State Repeated State Goal State
F W D C Last time we saw… Search Tree for “Farmer, Wolf, Duck, Corn” Illegal State Repeated State Goal State

4 Find a route from LAX to UCR that minimizes the mileage
A farm hand was sent to a nearby pond to fetch 8 gallons of water. He was given two pails - one 11, the other 6 gallons. How can he measure the requested amount of water? Rubiks Cube Find a route from LAX to UCR that minimizes the mileage Can you place 8 queens on a chessboard such that no piece is attacking another? Which tree shows the correct relationship between gorilla, chimp and man? When you have just 3 animals, there are only three possible trees... Species Number of trees 3 3 10 34,459,425

5 Toads And Frogs Puzzle The Toads And Frogs Puzzle is also known under the names of Hares and Tortoise and Sheep and Goats. N frogs are placed on N successive positions on the left of a string of squares; M toads occupy M rightmost squares. On the whole, there are M + N + 1 squares, so that just one square remains unoccupied. Frogs only move rightward; toads move leftward. Every move is either a Slide to the nearby square or a Jump over one position, which is allowed only if the latter is occupied by a fellow of a different kind. In any case, no two animals are allowed in the same square. The goal is to move toads into M leftmost positions and the frogs into N rightmost positions. Play online:

6 :::

7

8

9 15-Puzzle U.S. Political cartoon about finding a Republican presidential candidate in 1880 The puzzle can be shuffled into 10,461,394,944,000 different solvable positions (about 10.5 trillion) In the worst case, it can take 80 moves to solve a puzzle (the diameter is 80). The problem of finding an optimal solution is known to be NP-hard, for the general case of sliding tile puzzles.

10 ? An example of a problem with zero solutions.
In 1878, Sam Loyd offered a $1000 prize for a solution to this version of the 15 puzzle… 12 15 11 14 10 13 9 5 6 7 8 4 3 2 1 ? 12 14 11 15 10 13 9 5 6 7 8 4 3 2 1 Another example of an unsolvable puzzle. The shortest driving distance from UCR to Honolulu.

11 MSC Oscar is the largest container ship in the world (as of August 2015). It can carry 19,224 containers

12 Swap the containers marked A and B in as few moves as possible

13 Problem Solving using Search
To solve problems with search, we need two things The Problem Space The Search Algorithm As we will see today, these two things can be totally independent of each other. Lets look are problem space first.

14 Problem Solving using Search
A Problem Space consists of The current state of the world (initial state) A description of the actions we can take to transform one state of the world into another (operators). A description of the desired state of the world (goal state), this could be implicit or explicit. A solution consists of the goal state*, or a path to the goal state. * Problems were the path does not matter are known as “constraint satisfaction” problems.

15 Initial State Operators Goal State 2 1 3 4 7 6 5 8 1 2 3 4 5 6 7 8
Slide blank square left. Slide blank square right. …. Move F Move F with W …. FWDC FWDC Is it true? Distributive property Associative property ... 4 Queens Add a queen such that it does not attack other, previously placed queens. A 4 by 4 chessboard with 4 queens placed on it such that none are attacking each other

16 Initial State Operators Goal State Drive north to next intersection
Drive south to next intersection …. Your home address LAX, Terminal 1 Slide Frog Jump Frog Slide Toad Jump Toad

17 Representing the States
A state space should describe Everything that is needed to solve the problem. Nothing that is not needed to solve the problem. For the 8-puzzle 3 by 3 array 5, 6, 7 8, 4, BLANK 3, 1, 2 A vector of length nine 5,6,7,8,4, BLANK,3,1,2 A list of facts Upper_left = 5 Upper_middle = 6 Upper_right = 7 Middle_left = 8 …. In general, many possible representations are possible, choosing a good representation will make solving the problem much easier. Choose the representation that make the operators easiest to implement.

18 Operators I Single atomic actions that can transform one state into another. You must specify an exhaustive list of operators, otherwise the problem may be unsolvable. Operators consist of Precondition: Description of any conditions that must be true before using the operator. Instruction on how the operator changes the state. In general, for any given state, not all operators are possible. Examples: In FWDC, the operator Move_Farmer_Left is not possible if the farmer is already on the left bank. In this 8-puzzle, The operator Move_6_down is possible But the operator Move_7_down is not. 2 1 3 4 7 6 5 8

19 Operators II There are often many ways to specify the operators, some will be much easier to implement... Example: For the eight puzzle we could have... 2 1 3 4 7 6 5 8 Move 1 left Move 1 right Move 1 up Move 1 down Move 2 left Move 2 right Move 2 up Move 2 down Move 3 left Move 3 right Move 3 up Move 3 down Move 4 left Move Blank left Move Blank right Move Blank up Move Blank down Or

20 A complete example: The Water Jug Problem
A farm hand was sent to a nearby pond to fetch 2 gallons of water. He was given two pails - one 4, the other 3 gallons. How can he measure the requested amount of water? Two jugs of capacity 4 and 3 units. It is possible to empty a jug, fill a jug, transfer the content of a jug to the other jug until the former empties or the latter fills. Task: Produce a jug with 2 units. Abstract away unimportant details State representation (X , Y) X is the content of the 4 unit jug. Y is the content of the 3 unit jug. Define a state representation Define an initial state Initial State (0 , 0) Define an goal state(s) May be a description rather than explicit state Goal State (2 , n) Define all operators Operators Fill 3-jug from faucet (a, b)  (a, 3) Fill 4-jug from faucet (a, b)  (4, b) Fill 4-jug from 3-jug (a, b)  (a + b, 0) ...

21 Once we have defined the problem space (state representation, the initial state, the goal state and operators) are we are done? We start with the initial state and keep using the operators to expand the parent nodes till we find a goal state. …but the search space might be large… …really large… So we need some systematic way to search.

22 The length of a path to a goal is the depth d.
The average number of new nodes we create when expanding a new node is the (effective) branching factor b. The length of a path to a goal is the depth d. So visiting every the every node in the search tree to depth d will take O(bd) time. Not necessarily O(bd) space. A Generic Search Tree b b2 bd Fringe (Frontier) Set of nonterminal nodes without children I.e nodes waiting to be expanded.

23 Branching factors for some problems: I
2 1 3 4 7 6 5 8 The eight puzzle has a branching factor of 2.13, so a search tree at depth 20 has about 3.7 million nodes. (note that there only 181,400 different states). Rubik’s cube has a branching factor of There are 901,083,404,981,813,616 different states. The average depth of a solution is about 18. nine hundred one quadrillion, eighty-three trillion, four hundred four billion, nine hundred eighty-one million, eight hundred thirteen thousand, six hundred sixteen Frogs and Toads has a branching factor of about 1.5

24 Branching factors for some problems: II
The branching factor for route finding is about 4. That is to say, most intersections are four way. The branching factor for an alphametic (also known as cryptarithmetic, cryptarithm or word addition) is about ten. Find a route from LAX to UCR that minimizes the mileage

25 The Diameter of a Problem
The diameter of a problem is the depth of the longest solution, i.e. the worst case. The diameter is sometimes called God’s Number For the 3-puzzle, the diameter is 6 For the 8-puzzle the diameter is 31 For the 15-puzzle the diameter is 80 For the 24-puzzle the diameter is unknown. It is known to be at least 152 and at most 208. 2 1 3 4 7 6 5 8 1 2 3

26 The Diameter of a Problem
There exists at least one scrambled version of the 15-puzzle, that even god would need 80 moves to solve The diameter of a problem is the depth of the longest solution, i.e. the worst case. The diameter is sometimes called God’s Number For the 3-puzzle, the diameter is 6 For the 8-puzzle the diameter is 31 For the 15-puzzle the diameter is 80 For the 24-puzzle the diameter is unknown. It is known to be at least 152 and at most 208. There does not exist any scrambled version of the 15-puzzle, that god would need more than 80 moves to solve This is one (of 17) puzzles that needs 80 moves to solve it.

27 The Diameter of a Problem
What about the Rubik cube? In 2008, Tomas Rokicki devised a computational proof that all unsolved cubes could be solved in 25 moves or fewer. This was later reduced to 23 moves. In August 2008 Rokicki announced that he has proof for 22 moves… This required approximately 50 core-years of CPU time contributed by John Welborn and Sony Pictures Imageworks. No distance 21 positions were found in this search, despite solving a total of more than twenty-five million billion cube positions. The Diameter of the Rubik Cube is 20 This assumes you count ¼ turns and ½ turns as a single move. If you only allow ¼ turns, the diameter is 26.

28 The Diameter of a Problem
For route finding, the diameter is approximately the diameter of the smallest circle that includes all the roads (in fact, this is a lower bound) For Oahu, I estimated a diameter of 41.7 miles, but the shortest route I was able to find takes 49.7 miles

29 Detecting repeated states is hard….

30 We are going to consider different techniques to search the problem space, we need to consider what criteria we will use to compare them. Completeness: Is the technique guaranteed to find an answer (if there is one). Optimality: Is the technique guaranteed to find the best answer (if there is more than one). (operators can have different costs) Time Complexity: How long does it take to find a solution. Space Complexity: How much memory does it take to find a solution.

31 General (Generic) Search Algorithm
function general-search(problem, QUEUEING-FUNCTION) nodes = MAKE-QUEUE(MAKE-NODE(problem.INITIAL-STATE)) loop do if EMPTY(nodes) then return "failure" (we have proved there is no solution!) node = REMOVE-FRONT(nodes) if problem.GOAL-TEST(node.STATE) succeeds then return node nodes = QUEUEING-FUNCTION(nodes, EXPAND(node, problem.OPERATORS)) end A nice fact about this search algorithm is that we can use a single algorithm to do many kinds of search. The only difference is in how the nodes are placed in the queue.

32 Breadth First Search Enqueue nodes in FIFO (first-in, first-out) order.
Intuition: Expand all nodes at depth i before expanding nodes at depth i + 1 Complete? Yes. Optimal? Yes. Time Complexity: O(bd) Space Complexity: O(bd), note that every node in the fringe is kept in the queue.

33 Uniform Cost Search Enqueue nodes in order of (cumulative) cost
5 2 5 2 5 2 1 7 1 7 4 5 Intuition: Expand the cheapest node. Where the cost is the path cost g(n) Complete? Yes. Optimal? Yes, if path cost is nondecreasing function of depth Time Complexity: O(bd) Space Complexity: O(bd), note that every node in the fringe keep in the queue. Note that Breadth First search can be seen as a special case of Uniform Cost Search, where the path cost is just the depth.

34 Depth First Search Enqueue nodes in LIFO (last-in, first-out) order.
Intuition: Expand node at the deepest level (breaking ties left to right) Complete? No (Yes on finite trees, with no loops). Optimal? No Time Complexity: O(bm), where m is the maximum depth. Space Complexity: O(bm), where m is the maximum depth.

35 Depth-Limited Search Enqueue nodes in LIFO (last-in, first-out) order
Depth-Limited Search Enqueue nodes in LIFO (last-in, first-out) order. But limit depth to L L is 2 in this example Intuition: Expand node at the deepest level, but limit depth to L Complete? Yes if there is a goal state at a depth less than L Optimal? No Time Complexity: O(bL), where L is the cutoff. Space Complexity: O(bL), where L is the cutoff. Picking the right value for L is a difficult, Suppose we chose 7 for FWDC, we will fail to find a solution...

36 Iterative Deepening Search I Do depth limited search starting a L = 0, keep incrementing L by 1.
Intuition: Combine the Optimality and completeness of Breadth first search, with the low space complexity of Depth first search Complete? Yes Optimal? Yes Time Complexity: O(bd), where d is the depth of the solution. Space Complexity: O(bd), where d is the depth of the solution.

37 Iterative Deepening Search II
Iterative deepening looks wasteful because we reexplore parts of the search space many times... Consider a problem with a branching factor of 10 and a solution at depth 5... If we knew the solution was a depth 5… , ,000 = 111,111 1 1+10 ,000 , ,000 = 123,456

38 Bi-directional Search
Intuition: Start searching from both the initial state and the goal state, meet in the middle. Notes Not always possible to search backwards How do we know when the trees meet? At least one search tree must be retained in memory. Complete? Yes Optimal? Yes (if both algorithms are optimal) Time Complexity: O(bd/2), where d is the depth of the solution. Space Complexity: O(bd/2), where d is the depth of the solution.

39 A B C D E F G H I J K L M N O

40 What is the diameter of this problem?
Since (unlike Rubik's Cube or 8-puzzle) the starting state is always the same, the diameter is the solution depth.

41 Upper and Lower Bounds We can compute an upper bound and a lower bound. There are two type of operators, slides and jumps Slides move the frog/toads only one step. So let us imagine a solution that consisted only of slides… Slide 4 places Slide 4 places Slide 4 places Slide 4 places Slide 4 places Slide 4 places Six times four is 24. Therefore 24 is an upper bound to the diameter of the 3-3 Frog-Toad puzzle.

42 Upper and Lower Bounds What about jumps?
Jumps move the frog/toads two steps. So let us imagine a solution that consisted only of jumps… Jump 2 places Jump 2 places Jump 2 places Jump 2 places Jump 2 places Jump 2 places Six times two is 12. Therefore 12 is an lower bound to the diameter of the 3-3 Frog-Toad puzzle.

43 Visualizing the Upper and Lower Bounds
12 Solution must be in this region 24

44 In fact the solution dept is 15
For the N-N Frog-Toad problem, the solution depth is at (N+1)2 -1 Solution N-N Frog-Toad problem, is always a palindrome (1, 1)– SJS (2, 2)– SJSJJSJS (3, 3)– SJSJJSJJJSJJSJS 12 15 24

45 There are two solutions at depth 15
One from the move frog first path One from the move toad first path 15

46 More generally, for arbitrary problems
The number of solutions can be from zero to infinity If there are multiple solutions, they may be at different depths. If so, we prefer the cheapest one (the shallowest one, if all operators have the same cost)

47 The number of solutions can be from zero to infinity
solvable Not solvable The number of solutions can be from zero to infinity How can we have zero solutions? Solvable Not solvable Sometimes there are simple ways to detect that a problem has zero solutions (true for 15 puzzle and Rubik’s cube), but there may not be a way (or at least, not an obvious way) Siri: Give me driving directions from UCR to Honolulu Hawaii

48 The number of solutions can be from zero to infinity
How can we have zero solutions? This is a children maze puzzle that does not have a solution. I assume it was created by accident. To prove it is unsolvable, I can trace a fully closed bounding box around the target.

49

50 Can you place 8 queens on a chessboard such that no piece is attacking another?
1 8 2 We could try to solve this at least two ways Start with an empty board, the operators are to add a queen. Start with a full board, that is, 64 queens on the board. The operators are to remove a queen. Which would be better? 56

51 Converting a continuous problem to a discrete problem
The problems we considered thus far are intrinsically discrete. What happens if our problem space is continuous?

52 Curiosity was launched from Cape Canaveral on November 26, 2011, and successfully landed on Aeolis Palus in Gale Crater on Mars on August 6, 2012. The Bradbury Landing site[6] was less than 2.4 km (1.5 mi) from the center of the rover's touchdown target after a 563,000,000 km.

53 When Mars is closest to the Earth, it takes light three minutes to travel between the two planets.
Mars is usually a lot farther away than that. At its greatest distance it is 42 light minutes away

54 Path Planning Search target

55 Path Planning What is the state space?
This example is by Jean-Claude Latombe

56 Formulation #1 Cost of one horizontal/vertical step = 1
Cost of one diagonal step = 2

57 Optimal Solution? This path is the shortest in the discretized state space, but not in the original continuous space (Trade-off: The smaller the grid…The larger the grid..)

58 Formulation #2 sweep-line

59 Formulation #2

60 States

61 Operator: Visit center of adjacent region

62 Solution Path A path-smoothing post-processing step is
usually needed to shorten the path further

63 Formulation #3 Cost of one step: length of segment

64 Formulation #3 Cost of one step: length of segment Visibility graph

65 Solution Path The shortest path in this state space is also the shortest in the original continuous space

66 A description of the desired state of the world (goal state), this could be implicit or explicit.
FWDC implicit X= X or 1=1 2=2


Download ppt "Now would be a good time to kill your cell phone, and disconnect from the internet. For next time, print Heuristic Search.ppt slides."

Similar presentations


Ads by Google