ai csc361: problem solving & search 1 problem solving by searching csc361

36
AI CSC361: Problem Solving & Search 1 Problem Solving by Searching CSC361

Post on 18-Dec-2015

231 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: AI CSC361: Problem Solving & Search 1 Problem Solving by Searching CSC361

AI CSC361: Problem Solving & Search

1

Problem Solving by Searching

CSC361

Page 2: AI CSC361: Problem Solving & Search 1 Problem Solving by Searching CSC361

AI CSC361: Problem Solving & Search

2

Search Strategies: Classification

• Search Strategies can be– Uninformed Search Strategy– Informed Search Strategy

• Uninformed search strategies use only the information available in the problem definition.

• Informed search strategies use other domain specific information.

Page 3: AI CSC361: Problem Solving & Search 1 Problem Solving by Searching CSC361

AI CSC361: Problem Solving & Search

3

Informed Search Strategies

• Informed search strategies employ problem specific knowledge to make a choice of which node to select next. This knowledge is formulated in the form of a function f(x).

• Best-first search– Uniform Cost Search– Greedy best-first search– A* search

• AO*

Page 4: AI CSC361: Problem Solving & Search 1 Problem Solving by Searching CSC361

AI CSC361: Problem Solving & Search

4

Best First Search

• Idea: Select the best node to goal check and expand.

• Which is the best node? An evaluation function f(n) tell us which node is the best. The value returned by f(n) gives an estimate of the ‘desirability’ of node n. Or its closeness to the goal state.

• So the nodes in the Open List are ordered according to the values returned by f(n) and first node selected.

Page 5: AI CSC361: Problem Solving & Search 1 Problem Solving by Searching CSC361

AI CSC361: Problem Solving & Search

5

Best First Search: UCS

• Example of Best First Search:– Uniform Cost Search, Greedy Search, A*.

• UCS: its evaluation function is the total path cost incurred up to a node n.

f(n) = g(n) = cost from start state to n.• Drawback: g(n) does not direct search towards the

goal, because it considers the cost incurred in the past not the cost that will be incurred in the future.

Page 6: AI CSC361: Problem Solving & Search 1 Problem Solving by Searching CSC361

AI CSC361: Problem Solving & Search

6

Page 7: AI CSC361: Problem Solving & Search 1 Problem Solving by Searching CSC361

AI CSC361: Problem Solving & Search

7

Best First Search: Greedy Search

• Evaluation function f(n) = h(n) (a heuristic function)

• h(n) gives estimate of cost from n to goal

• e.g., hSLD(n) = straight-line distance from n to Bucharest

• Greedy search expands the node that appears to be closest to the goal

Page 8: AI CSC361: Problem Solving & Search 1 Problem Solving by Searching CSC361

AI CSC361: Problem Solving & Search

8

ARAD

366

ARAD

SIBIU TIMSOURA ZIRIND

253 329 374

Page 9: AI CSC361: Problem Solving & Search 1 Problem Solving by Searching CSC361

AI CSC361: Problem Solving & Search

9

Page 10: AI CSC361: Problem Solving & Search 1 Problem Solving by Searching CSC361

AI CSC361: Problem Solving & Search

10

Greedy Search

• Complete? No – can get stuck in loops, e.g., Iasi Neamt Iasi Neamt

• Time? O(bm), but a good heuristic can give dramatic improvement

• Space? O(bm) -- keeps all nodes in memory

• Optimal? No

Page 11: AI CSC361: Problem Solving & Search 1 Problem Solving by Searching CSC361

AI CSC361: Problem Solving & Search

11

A* Search

• Idea: Considers cost to reach node n from start state and cost to reach goal from n.

• Evaluation function f(n) = g(n) + h(n)

• g(n) = cost so far to reach n

• h(n) = estimated cost from n to goal

• f(n) = estimated total cost of path through n to goal

Page 12: AI CSC361: Problem Solving & Search 1 Problem Solving by Searching CSC361

AI CSC361: Problem Solving & Search

12

1

2

3

4

Page 13: AI CSC361: Problem Solving & Search 1 Problem Solving by Searching CSC361

AI CSC361: Problem Solving & Search

13

5

6

Page 14: AI CSC361: Problem Solving & Search 1 Problem Solving by Searching CSC361

AI CSC361: Problem Solving & Search

14

A* Search

• Complete? Yes

• Time? O(bd) .. Exponential

• Space? Keeps all nodes in memory

• Optimal? Yes provided that h(n) is admissible and consistent.

Page 15: AI CSC361: Problem Solving & Search 1 Problem Solving by Searching CSC361

AI CSC361: Problem Solving & Search

15

Admissible Heuristic

• A heuristic h(n) is admissible if for every node n,h(n) ≤ h*(n), where h*(n) is the true cost to reach the goal state from n.

• An admissible heuristic never overestimates the cost to reach the goal, i.e., it is optimistic

• Example: hSLD(n) (never overestimates the actual road distance)

• Theorem: If h(n) is admissible, A* using TREE-SEARCH is optimal

Page 16: AI CSC361: Problem Solving & Search 1 Problem Solving by Searching CSC361

AI CSC361: Problem Solving & Search

16

Admissible Heuristic

For the 8-puzzle:

• h1(n) = No. of misplaced tiles h1(S)= 8

• h2(n) = sum of distances of tiles from their goal position h2(S) = 3+1+2+2+2+3+3+2 = 18

Page 17: AI CSC361: Problem Solving & Search 1 Problem Solving by Searching CSC361

AI CSC361: Problem Solving & Search

17

Consistent Heuristic

• A heuristic is consistent if for every node n, every successor n' of n generated by any action a, h(n) ≤ c(n,a,n') + h(n')

• If h is consistent, we have f(n') = g(n') + h(n') = g(n) + c(n,a,n') + h(n') ≥ g(n) + h(n) = f(n) f(n) is non-decreasing along any path• Theorem: If h(n) is consistent, A* using GRAPH-SEARCH is optimal

Page 18: AI CSC361: Problem Solving & Search 1 Problem Solving by Searching CSC361

AI CSC361: Problem Solving & Search

18

Dominance

• If h2(n) ≥ h1(n) for all n (both admissible) then h2 dominates h1

• h2 is better for search• Typical search costs (average number of nodes

expanded):• d=12 IDS = 3,644,035 nodes

A*(h1) = 227 nodes A*(h2) = 73 nodes

• d=24 IDS = too many nodesA*(h1) = 39,135 nodes A*(h2) = 1,641 nodes

Page 19: AI CSC361: Problem Solving & Search 1 Problem Solving by Searching CSC361

AI CSC361: Problem Solving & Search

19

AND-OR Search Graphs

• OR Graphs: The state-space graphs dealt with previously were OR graphs; from any state one-of the applicable actions is chosen to reach the goal.

STATE 1OR Node

Page 20: AI CSC361: Problem Solving & Search 1 Problem Solving by Searching CSC361

AI CSC361: Problem Solving & Search

20

AND-OR Search Graphs

• AND-OR Graphs: In AND-OR graphs, from a state not one but all the paths may have to be pursued to reach the goal state.

STATE 1AND Node

Page 21: AI CSC361: Problem Solving & Search 1 Problem Solving by Searching CSC361

AI CSC361: Problem Solving & Search

21

AND-OR Search Graphs

• How do AND-OR graphs arise?– AND-OR graphs arise when it is advantageous

to decompose a state into its components which are independent of each other.

• Example: Integration (See the handout)

• Example: Rewriting problem – found in syntax analysis.

Page 22: AI CSC361: Problem Solving & Search 1 Problem Solving by Searching CSC361

AI CSC361: Problem Solving & Search

22

AND-OR Search Graphs

• Example: Rewriting Problem:– Start State: (C, B, Z)– Operators/actions: R1: C (D, L)

R2: C (B, M)

R3: B (M, M)

R4: Z (B, B, M)– Goal State: any state consisting only of M’s

Page 23: AI CSC361: Problem Solving & Search 1 Problem Solving by Searching CSC361

AI CSC361: Problem Solving & Search

23

AO*

• How are AND-OR graphs searched with a best-first strategy?– A* algorithm is not suitable– Should we choose C to expand next?No, because total cost along Cwould be 3+4+1+1=9;Along B, 5+1=6B is the best choice.

A

B C D

h = 5 h = 3 h = 4

1 1 1

Page 24: AI CSC361: Problem Solving & Search 1 Problem Solving by Searching CSC361

AI CSC361: Problem Solving & Search

24

AO* Algorithm

General search for AND-OR graphs:

1. Initialize: {D1,..,Dn} decompose initial state into independent components Di, if possible.

2. Loop until {Di} is Empty

3. Select: Select current path D* from {Di} according to some strategy and a node in D*.

4. Goal Check: Do all leaves in the current path D* satisfy goal_test()? If Yes, return solution.

Page 25: AI CSC361: Problem Solving & Search 1 Problem Solving by Searching CSC361

AI CSC361: Problem Solving & Search

25

AO* Algorithm

5. Expand: Expand node selected from D*. Decompose each state generated and add the components to {Di}.

6. End.

Page 26: AI CSC361: Problem Solving & Search 1 Problem Solving by Searching CSC361

AI CSC361: Problem Solving & Search

26

Local Search Algorithms

Page 27: AI CSC361: Problem Solving & Search 1 Problem Solving by Searching CSC361

AI CSC361: Problem Solving & Search

27

Local Search Algorithms

• What type of problems can these algorithms be used to solve?– Many problems (e.g. 8-queens, VLSI layout, ..)

have the property that the state description of a goal itself contains all the information needed for a solution – the path by which the solution is reached is does not matter.

• These algorithms keep a single state and try to improve it.

Page 28: AI CSC361: Problem Solving & Search 1 Problem Solving by Searching CSC361

AI CSC361: Problem Solving & Search

28

Local Search Algorithms

• Put n queens on an n × n board with no two queens on the same row, column, or diagonal

Page 29: AI CSC361: Problem Solving & Search 1 Problem Solving by Searching CSC361

AI CSC361: Problem Solving & Search

29

Local Search Algorithms

• Generate-and-Test (the basic algorithm)– Hill-Climbing

• Simple-Hill-Climbing

• Steepest-Ascent-Hill-Climbing

– Simulated Annealing– Genetic Algorthms

Page 30: AI CSC361: Problem Solving & Search 1 Problem Solving by Searching CSC361

AI CSC361: Problem Solving & Search

30

Generate-and-Test Algorithm

1. Generate a possible solution state. (Randomly or by improving the current state)

2. Test if it is a solution state by comparing with the goal state.

3. If the solution state has been found quit else go to step 1.

Page 31: AI CSC361: Problem Solving & Search 1 Problem Solving by Searching CSC361

AI CSC361: Problem Solving & Search

31

Hill-Climbing Algorithm

• "Like climbing Everest in thick fog with amnesia“

Page 32: AI CSC361: Problem Solving & Search 1 Problem Solving by Searching CSC361

AI CSC361: Problem Solving & Search

32

Hill-Climbing Algorithm

• Problem: Algorithm depends on initial state, can get stuck in local maxima.

Page 33: AI CSC361: Problem Solving & Search 1 Problem Solving by Searching CSC361

AI CSC361: Problem Solving & Search

33

Hill-Climbing: 8-Queens

• h (n) = number of pairs of queens that are attacking each other, either directly or indirectly

• h (n) = 17 for this state

Page 34: AI CSC361: Problem Solving & Search 1 Problem Solving by Searching CSC361

AI CSC361: Problem Solving & Search

34

Hill-Climbing: 8-Queens

• h (n) = 1 for this state

Page 35: AI CSC361: Problem Solving & Search 1 Problem Solving by Searching CSC361

AI CSC361: Problem Solving & Search

35

Hill-Climbing

• Problems with Hill-Climbing:– Local Maxima– Plateaus– Ridges

Page 36: AI CSC361: Problem Solving & Search 1 Problem Solving by Searching CSC361

AI CSC361: Problem Solving & Search

36

Summary

• Informed search algorithms

• Local search algorithms