problem solving and search in ai heuristic search

35
Problem Solving Problem Solving and Search in AI and Search in AI Heuristic Search Heuristic Search

Post on 21-Dec-2015

220 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Problem Solving and Search in AI Heuristic Search

Problem Solving and Problem Solving and Search in AI Search in AI

Heuristic SearchHeuristic Search

Page 2: Problem Solving and Search in AI Heuristic Search

Heuristic SearchHeuristic SearchProblem with uniform cost searchProblem with uniform cost search

We are only considering the cost so far, not the expected cost of We are only considering the cost so far, not the expected cost of getting to the goal nodegetting to the goal node

But, we don’t know before hand the cost of getting to the goal from But, we don’t know before hand the cost of getting to the goal from a previous statea previous state

Solution:Solution: Need to estimate for each state the cost of getting from there to a Need to estimate for each state the cost of getting from there to a

goal stategoal state Use “Use “heuristicheuristic” information to guess which nodes to expand next” information to guess which nodes to expand next the heuristic is in the form of an evaluation function based on the heuristic is in the form of an evaluation function based on

domain-specific information related to the problem.domain-specific information related to the problem. the the evaluation functionevaluation function gives us a way to evaluate a node “locally” gives us a way to evaluate a node “locally”

based on an estimate of the cost to get from the node to a goal based on an estimate of the cost to get from the node to a goal node (the idea is to find the least cost path to a goal node).node (the idea is to find the least cost path to a goal node).

Page 3: Problem Solving and Search in AI Heuristic Search

Evaluation FunctionsEvaluation Functions

h(n) is the heuristic functionh(n) is the heuristic functiong(n): cost of the best path found so far between g(n): cost of the best path found so far between the initial node and nthe initial node and nf(n) = h(n) f(n) = h(n) greedy best-first search greedy best-first searchf(n) = g(n) + h(n) f(n) = g(n) + h(n) A* search A* search

Page 4: Problem Solving and Search in AI Heuristic Search

Best-First SearchBest-First SearchBasic Idea: always expand the node that minimizes (or maximizes) Basic Idea: always expand the node that minimizes (or maximizes) the evaluation function the evaluation function ff((nn))

Greedy strategy: Greedy strategy: ff((nn) = ) = hh((nn), where ), where hh((nn) estimates the cost of getting ) estimates the cost of getting from the node from the node nn to the goal to the goal

if we keep nodes in memory (on the queue) for backtracking, then this if we keep nodes in memory (on the queue) for backtracking, then this is called is called (Greedy)(Greedy) Best-First searchBest-First search; if no queue and we stop as soon ; if no queue and we stop as soon as as ff((nn) is worse for the children than the parent, then this is called ) is worse for the children than the parent, then this is called Hill-Hill-ClimbingClimbing..

What happens if always try at each step to move closer to the goal What happens if always try at each step to move closer to the goal node?node?

The BFS algorithm in this case willfind the longer solution path,since it will begin by moving forward and then be committedto this choice.

What about hill-climbing?

The BFS algorithm in this case willfind the longer solution path,since it will begin by moving forward and then be committedto this choice.

What about hill-climbing?

Page 5: Problem Solving and Search in AI Heuristic Search

Best-First SearchBest-First SearchThe The evaluation functionevaluation function f maps each f maps each search node n to positive real number f(n)search node n to positive real number f(n)

Traditionally, the smaller f(n), the more Traditionally, the smaller f(n), the more promising npromising n

Best-first search sorts the search queue at Best-first search sorts the search queue at each step in increasing order of feach step in increasing order of f random order is assumed among nodes with random order is assumed among nodes with

equal values of fequal values of f

Page 6: Problem Solving and Search in AI Heuristic Search

Best-First SearchBest-First SearchThe The evaluation functionevaluation function f maps each f maps each search node n to positive real number f(n)search node n to positive real number f(n)

Traditionally, the smaller f(n), the more Traditionally, the smaller f(n), the more promising npromising n

Best-first search sorts the search queue at Best-first search sorts the search queue at each step in increasing order of feach step in increasing order of f random order is assumed among nodes with random order is assumed among nodes with

equal values of fequal values of f

“Best” only refers to the value of f,not to the quality of the actual path.Best-first search does not generate optimal paths in general

“Best” only refers to the value of f,not to the quality of the actual path.Best-first search does not generate optimal paths in general

Page 7: Problem Solving and Search in AI Heuristic Search

Best-First Search Example (Romania)Best-First Search Example (Romania)

Suppose we don’t know the actual distances Suppose we don’t know the actual distances beforehand, but can figure out the straight line beforehand, but can figure out the straight line distances from a mapdistances from a map

Page 8: Problem Solving and Search in AI Heuristic Search

Best-First Search Example (Romania)Best-First Search Example (Romania)

Suppose we don’t know the actual Suppose we don’t know the actual distances beforehand, but can distances beforehand, but can figure out the straight line distances figure out the straight line distances from a mapfrom a map

Heuristic evaluation function:Heuristic evaluation function: h(n) = straight-line distance between h(n) = straight-line distance between nn

and Bucharestand Bucharest

h(n) is a heuristic because it is an estimate h(n) is a heuristic because it is an estimate of the actual cost of getting from n to the of the actual cost of getting from n to the goalgoal

Note that h(goal) = 0 alwaysNote that h(goal) = 0 always

Page 9: Problem Solving and Search in AI Heuristic Search

Greedy Best-First SearchGreedy Best-First Search

Arad h(n) = 366

<== Arad <==<== Arad <==

Page 10: Problem Solving and Search in AI Heuristic Search

Greedy Best-First SearchGreedy Best-First Search

Arad

Sibiu Timisoara Zerind

h(n) = 366

h(n) = 253 h(n) = 329 h(n) = 374

<== Sibiu, Timisoara, Zerind <==<== Sibiu, Timisoara, Zerind <==

Page 11: Problem Solving and Search in AI Heuristic Search

Greedy Best-First SearchGreedy Best-First Search

Arad

Sibiu Timisoara Zerind

OradeaFagarasArad Rimnicu

h(n) = 366

h(n) = 253 h(n) = 329 h(n) = 374

366 178 380193

<== Fagaras, Rimnicu, Timisoara, Zerind, Oradea <==<== Fagaras, Rimnicu, Timisoara, Zerind, Oradea <==

Page 12: Problem Solving and Search in AI Heuristic Search

Greedy Best-First SearchGreedy Best-First Search

Arad

Sibiu Timisoara Zerind

OradeaFagaras Rimnicu

h(n) = 366

h(n) = 253 h(n) = 329 h(n) = 374

178 380193

BucharestSibiu

253 h(n) = 0

<== Bucharest, Rimnicu, Timisoara, Zerind, Oradea <==<== Bucharest, Rimnicu, Timisoara, Zerind, Oradea <==

Page 13: Problem Solving and Search in AI Heuristic Search

Greedy Best-First SearchGreedy Best-First Search

Arad

Sibiu Timisoara Zerind

OradeaFagaras Rimnicu

h(n) = 366

h(n) = 253 h(n) = 329 h(n) = 374

178 380193

BucharestSibiu

253h(n) = 0 Actual cost of the solution:

Arad => Sibiu => Fagaras => Bucharestis 140 + 99 + 211 = 450

But, consider the path: Arad => Sibiu => Rimnicu => Pitesti => Bucharestwith the cost 418 – So we got a suboptimal solution

Actual cost of the solution:Arad => Sibiu => Fagaras => Bucharestis 140 + 99 + 211 = 450

But, consider the path: Arad => Sibiu => Rimnicu => Pitesti => Bucharestwith the cost 418 – So we got a suboptimal solution

Page 14: Problem Solving and Search in AI Heuristic Search

Heuristics for 8-Puzzle ProblemHeuristics for 8-Puzzle ProblemIn total, there are a possible of 9! or In total, there are a possible of 9! or 362,880 possible 362,880 possible statesstates. .

However, with a good heuristic function, it is possible to However, with a good heuristic function, it is possible to reduce this state to less than 50.reduce this state to less than 50.

Some possible heuristics for 8-Puzzle:Some possible heuristics for 8-Puzzle:

hh1(1(nn) = no. of misplaced tiles) = no. of misplaced tilesmay have many plateaus (indistinguishable states)may have many plateaus (indistinguishable states)

doesn’t captures the number of moves to get to the right placedoesn’t captures the number of moves to get to the right place

hh2(2(nn) = sum of Manhattan distances (i.e., no. of squares from ) = sum of Manhattan distances (i.e., no. of squares from desired location of each tile)desired location of each tile)

doesn’t capture the importance of sequencing tiles (putting them in the doesn’t capture the importance of sequencing tiles (putting them in the right order)right order)

Page 15: Problem Solving and Search in AI Heuristic Search

Heuristics for 8-Puzzle ProblemHeuristics for 8-Puzzle Problem

hh1(1(ss) = 7) = 7

hh2(2(ss) = 4 + 2 + 2 + 3 + 3 + ) = 4 + 2 + 2 + 3 + 3 + 0 + 2 + 2 = 180 + 2 + 2 = 18

hh1(1(ss) = 7) = 7

hh2(2(ss) = 4 + 2 + 2 + 3 + 3 + ) = 4 + 2 + 2 + 3 + 3 + 0 + 2 + 2 = 180 + 2 + 2 = 18

5 4

3

6 1 8

7 2

1 2

6

8

3

4

7 5s = start state g = goal state

Page 16: Problem Solving and Search in AI Heuristic Search

5 4

6 1 8

7 3 2

5 4

6 1 8

7 3 2

5 4 8

6 1

7 3 2

5 4

6 1 8

7 3 2

5 1 4

6 8

7 3 2

6 5 4

1 8

7 3 2

5 1 4

6 8

7 3 2

5 1 4

6 8

7 3 2

5 1 4

6 3 8

7 2

1 4

5 6 8

7 3 2

5 1 4

7 6 8

3 2

18

1917

1616

17 1515

15

1614

1 4

5 6 8

7 3 2

13

1 6 4

5 8

7 3 2

1 4

5 6 8

7 3 214 14

Part of the search tree generated by Best-First search using h2 = sum of Manhattan distances.

Part of the search tree generated by Best-First search using h2 = sum of Manhattan distances.

Page 17: Problem Solving and Search in AI Heuristic Search

1 2 3

8 4

7 6 5

Goal Node

Part of the search tree generated by Best-First search using h2 = sum of Manhattan distances.

What will happen with hill-climbing?

Part of the search tree generated by Best-First search using h2 = sum of Manhattan distances.

What will happen with hill-climbing?

5 4

6 1 8

7 3 2

18

1917

16 16

17 15 15 15

1614

13

14 14

13 13 13

12 12

13 11

Initial Node

Heuristics Search in 8-PuzzleHeuristics Search in 8-Puzzle

Page 18: Problem Solving and Search in AI Heuristic Search

A* SearchA* Search(most popular algorithm in AI)(most popular algorithm in AI)

Basic Idea: avoid expanding paths that are already expensiveBasic Idea: avoid expanding paths that are already expensive

Evaluation function: Evaluation function: ff((nn) = ) = gg((nn) + ) + hh((nn)) gg((nn) = cost so far to reach ) = cost so far to reach nn hh((nn) = estimated cost to goal from) = estimated cost to goal from n n ff((nn) = estimated total cost of path through) = estimated total cost of path through n n to reach the goalto reach the goal

AdmissibleAdmissible heuristics heuristics i.e., i.e., hh((nn) ) hh*(*(nn), for all ), for all nn, where , where hh*(*(nn) is the true cost from ) is the true cost from nn

Ex: straight-line distance never overestimates the actual road distanceEx: straight-line distance never overestimates the actual road distanceEx: Ex: h1h1 and and h2h2 is 8-puzzle never overestimate the actual no. of moves is 8-puzzle never overestimate the actual no. of moves

A* search is optimal (finds lowest cost solution)A* search is optimal (finds lowest cost solution) if if hh((nn) is admissible) is admissiblehowever, the number of nodes expanded depends on how good the however, the number of nodes expanded depends on how good the heuristic is heuristic is best case: best case: hh((nn) = ) = hh*(*(nn) for all ) for all nn A* will find the best solution with no A* will find the best solution with no searchsearch

if if hh((nn)) > h* > h*((nn)) for somefor some n n, then A*, then A*might still work, but might not find any solution at allmight still work, but might not find any solution at all

Page 19: Problem Solving and Search in AI Heuristic Search

A* SearchA* SearchArad

Sibiu Timisoara Zerind

OradeaFagarasArad Rimnicu

f(n) = 366

h(n) = 374f(n) = 449

PitestiCraiova

75

h(n) = 329f(n) = 447

118140

h(n) = 253f(n) = 393

140 15199 80

f(n) = 646 f(n) = 417 f(n) = 661

f(n) = 413

Sibiu

146 97 80

f(n) = 526 f(n) = 415 f(n) = 553

Page 20: Problem Solving and Search in AI Heuristic Search

A* SearchA* SearchSibiu

OradeaFagarasArad Rimnicu

PitestiCraiova

h(n) = 253f(n) = 393

140 15199 80

f(n) = 646 f(n) = 417 f(n) = 661

f(n) = 413

Sibiu

146 97 80

f(n) = 526

f(n) = 415

f(n) = 553

CraiovaRimnicu Bucharest

97138

101

f(n) = 607 f(n) = 615 f(n) = 418

...

Page 21: Problem Solving and Search in AI Heuristic Search

A* SearchA* SearchSibiu

OradeaFagarasArad Rimnicu

PitestiCraiova

h(n) = 253f(n) = 393

140151

99 80

f(n) = 646

f(n) = 417

f(n) = 526

f(n) = 413

Sibiu

146 97 80

f(n) = 526

f(n) = 415

f(n) = 553

CraiovaRimnicu Bucharest

97138

101

f(n) = 607 f(n) = 615 f(n) = 418

BucharestSibiu

99 211

f(n) = 591 f(n) = 450

...

Page 22: Problem Solving and Search in AI Heuristic Search

A* SearchA* SearchSibiu

OradeaFagarasArad Rimnicu

PitestiCraiova

h(n) = 253f(n) = 393

140151

99 80

f(n) = 646

f(n) = 417

f(n) = 526

f(n) = 413

Sibiu

146 97 80

f(n) = 526

f(n) = 415

f(n) = 553

CraiovaRimnicu Bucharest

97138

101

f(n) = 607 f(n) = 615f(n) = 418

BucharestSibiu

99 211

f(n) = 591 f(n) = 450

...

Page 23: Problem Solving and Search in AI Heuristic Search

A* search for an instance of 8-puzzle with h1 (sum of misplaced tiles).

g(n) assumes each move has a cost of 1.

Here we assume repeated state checking.

f(n) = g(n) + h(n)

Page 24: Problem Solving and Search in AI Heuristic Search

A* search for an instance of 8-puzzle with h1 (sum of misplaced tiles).

g(n) assumes each move has a cost of 1.

Here we assume repeated state checking.

f(n) = g(n) + h(n)Order of

expansion

Page 25: Problem Solving and Search in AI Heuristic Search

A* search for an instance of 8-puzzle with h1 (sum of misplaced tiles).

g(n) assumes each move has a cost of 1.

Here we assume repeated state checking.

f(n) = g(n) + h(n)

Page 26: Problem Solving and Search in AI Heuristic Search

A* search for an instance of 8-puzzle with h1 (sum of misplaced tiles).

g(n) assumes each move has a cost of 1.

Here we assume repeated state checking.

f(n) = g(n) + h(n)

Page 27: Problem Solving and Search in AI Heuristic Search

A* search for an instance of 8-puzzle with h1 (sum of misplaced tiles).

g(n) assumes each move has a cost of 1.

Here we assume repeated state checking.

f(n) = g(n) + h(n)

Page 28: Problem Solving and Search in AI Heuristic Search

A* search for an instance of 8-puzzle with h1 (sum of misplaced tiles).

g(n) assumes each move has a cost of 1.

Here we assume repeated state checking.

f(n) = g(n) + h(n)

Page 29: Problem Solving and Search in AI Heuristic Search

A* search for an instance of 8-puzzle with h1 (sum of misplaced tiles).

g(n) assumes each move has a cost of 1.

Here we assume repeated state checking.

f(n) = g(n) + h(n)

Page 30: Problem Solving and Search in AI Heuristic Search

A* search for an instance of 8-puzzle with h1 (sum of misplaced tiles).

g(n) assumes each move has a cost of 1.

Here we assume repeated state checking.

f(n) = g(n) + h(n)

Note: at level 2 there are two nodes listed with f(n) = 5. Depending on which node is we put in front of the queue, the algorithm will either expand 6 or 7 nodes. Here we have assumed the worse case, and thus the tree shows that 6 nodes were expanded

7

Page 31: Problem Solving and Search in AI Heuristic Search

Efficiency of A*Efficiency of A*

Comparison of search costs and effective branching factors for the Iterative Deepening search and A* algorithms with h1 and h2 for 8-puzzle. d is the average depth of the search tree. Data are averaged over 100 instances of the problem, for various solution lengths.

Page 32: Problem Solving and Search in AI Heuristic Search

When to Use Search Techniques?When to Use Search Techniques?

The search space is small, andThe search space is small, and No other technique is available, orNo other technique is available, or Developing a more efficient technique is not Developing a more efficient technique is not

worth the effort worth the effort

The search space is large, andThe search space is large, and No other available technique is available, andNo other available technique is available, and There exist “good” heuristicsThere exist “good” heuristics

Page 33: Problem Solving and Search in AI Heuristic Search

Heuristics in Tic-Tac-Toe?Heuristics in Tic-Tac-Toe?(you are X)(you are X)

Which is a better move? Why?

?

?

?

?

Is there a heuristic we can use to evaluate these configurations?

Page 34: Problem Solving and Search in AI Heuristic Search

Heuristics in Tic-Tac-Toe?Heuristics in Tic-Tac-Toe?(you are X)(you are X)

Which is a better move? Why?

?

?

?

Page 35: Problem Solving and Search in AI Heuristic Search

ExerciseExerciseConsider the problem of solving a cross-word puzzleConsider the problem of solving a cross-word puzzle

initial state is an empty board with some possible blocked cellsinitial state is an empty board with some possible blocked cells a goal state is board configuration filled in with legal English words:a goal state is board configuration filled in with legal English words:

How can this problem be viewed as a search problem? What are the operators? How can this problem be viewed as a search problem? What are the operators? How can we measure path costs? Etc.How can we measure path costs? Etc.

Assuming we have dictionary of 100,000 words, what would be a good Assuming we have dictionary of 100,000 words, what would be a good (uninformed) search strategy to use? Why?(uninformed) search strategy to use? Why?

What might be some good heuristics to use for this problem?What might be some good heuristics to use for this problem? How effective might hill-climbing strategies work in solving this problem? How How effective might hill-climbing strategies work in solving this problem? How

can we handle the local minima problem? Propose a solution and discuss its can we handle the local minima problem? Propose a solution and discuss its effectiveness.effectiveness.

1 2

3

4

T O N A L

O F

A F

S E L E C T

T C

I T E M