U NIVERSITÄTK OBLENZ -L ANDAU

Introduction to Artificial Intelligence Informed Search Bernhard Beckert

  U

  NIVERSITÄT

  K

  OBLENZ

  ANDAU Winter Term 2004/2005

  • -L

  Best-first search

  ∗

  A search Heuristics

  function T -S ( problem, fringe) returns a solution or failure

  ← fringe I (M -N (I -S [problem]),fringe)

  loop do if fringe is empty then return failure

  EMOVE

  IRST ← node R -F (fringe)

  if G -T [problem] applied to S (node) succeeds then return node else

  XPAND ← fringe I -A (E (node, problem), fringe)

  end

  Strategy

  Defines the order of node expansion

  Idea

  Use an evaluation function for each node (estimate of “desirability”) Expand most desirable unexpanded node

  Implementation fringe is a queue sorted in decreasing order of desirability Special cases

  Greedy search

  ∗

  A search

  Oradea Straight−line distance to Bucharest

  71 Neamt Arad 366

  Bucharest Zerind 87 151

  Craiova

  75 Iasi Dobreta 160 Arad 242

  Eforie 161

  140

  92 Fagaras Sibiu Fagaras 178

  99 Giurgiu

  77 118 Vaslui 151 Hirsova

  80 Iasi Rimnicu Vilcea 226 Timisoara

  Lugoj 244

  Mehadia 241

  142 211 111 Neamt Pitesti

  234 Lugoj

  97 Oradea 380

  70

  98 Pitesti Hirsova

  98

  85 146 101 Rimnicu Vilcea Mehadia Urziceni

  193 Sibiu

  86 253

  75 138 Bucharest Timisoara

  329 Dobreta 120 Urziceni

  80 Craiova

  

90

Vaslui

Giurgiu

Eforie 199 Zerind

  374

  Heuristic

  Evaluation function

  h estimate of cost from n to goal (n) =

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

  Example

h SLD straight-line distance from n to Bucharest

  (n) = Note

  Unlike uniform-cost search the node evaluation function has nothing to do with the nodes explored so far

  Arad 366

  Zerind Arad Sibiu

  Timisoara 253 329 374 Rimnicu Vilcea Zerind Arad

  Sibiu Arad Fagaras Oradea Timisoara 329 374

  366 176 380 193

  Rimnicu Vilcea Zerind Arad

  Sibiu Arad Fagaras Oradea Timisoara

  Sibiu Bucharest 329 374 366 380 193

  253

  Complete Time Space Optimal

  Complete No

  Can get stuck in loops Example: Iasi to Oradea Iasi

  →

  Neamt

  →

  Iasi

  →

  Neamt

  → · · ·

  Complete in finite space with repeated-state checking

  Time Space Optimal

  Complete No

  Can get stuck in loops Example: Iasi to Oradea

  → → → → · · ·

  Iasi Neamt Iasi Neamt Complete in finite space with repeated-state checking m

  Time O (b )

  Space Optimal

  Complete No

  Can get stuck in loops Example: Iasi to Oradea

  → → → → · · ·

  Iasi Neamt Iasi Neamt Complete in finite space with repeated-state checking m

  Time O (b ) m

  Space O (b )

  Optimal

  Complete No

  Can get stuck in loops Example: Iasi to Oradea

  → → → → · · ·

  Iasi Neamt Iasi Neamt Complete in finite space with repeated-state checking m

  Time O (b ) m

  Space O (b )

  Optimal No

  Complete No

  Can get stuck in loops Example: Iasi to Oradea Iasi

  →

  Neamt

  →

  Iasi

  →

  Neamt

  → · · ·

  Complete in finite space with repeated-state checking

  Time O (b m )

  Space O (b m )

  Optimal No Note

  Worst-case time same as depth-first search, Worst-case space same as breadth-first But a good heuristic can give dramatic improvement

  Idea

  Avoid expanding paths that are already expensive

  Evaluation function f g

  

(n) = (n) + h(n)

  where

  g cost so far to reach n (n) = h estimated cost to goal from n

  (n) = f n

  estimated total cost of path through to goal

  (n) =

  Admissibility of heuristic h is admissible if

  (n) ∗

h n

  for all

  (n) ≤ h (n) ∗

  where h is the true cost from n to goal

  (n)

  Admissibility of heuristic h is admissible if

  (n) ∗

h n

  for all

  (n) ≤ h (n) ∗

  where h is the true cost from n to goal

  (n) Also required

h for all n

  (n) ≥ 0

  In particular: h for goal G

  (G) = 0

  Admissibility of heuristic h is admissible if

  (n) ∗

h n

  for all

  (n) ≤ h (n) ∗

  where h is the true cost from n to goal

  (n) Also required

h for all n

  (n) ≥ 0

  In particular: h for goal G

  (G) = 0 Example

  Straight-line distance never overestimates the actual road distance

  Theorem

  A search with admissible heuristic is optimal

  Arad 366=0+366

  Zerind Arad Sibiu

  Timisoara 447=118+329 449=75+374 393=140+253

  Zerind Arad Sibiu Arad

  Timisoara Rimnicu Vilcea

  Fagaras Oradea 447=118+329 449=75+374 646=280+366 413=220+193 415=239+176 671=291+380

  Zerind Arad Sibiu Arad

  Timisoara Fagaras Oradea 447=118+329 449=75+374 646=280+366 415=239+176

  Rimnicu Vilcea Craiova Pitesti Sibiu 526=366+160

  553=300+253 417=317+100 671=291+380

  Zerind Arad Sibiu Arad

  Timisoara Sibiu Bucharest

  Rimnicu Vilcea Fagaras Oradea Craiova Pitesti Sibiu

  447=118+329 449=75+374 646=280+366 591=338+253 450=450+0 526=366+160 553=300+253

  417=317+100 671=291+380

  Zerind Arad Sibiu Arad

  Timisoara Sibiu Bucharest

  Rimnicu Vilcea Fagaras Oradea

  Craiova Pitesti Sibiu Bucharest Craiova Rimnicu Vilcea

  418=418+0 447=118+329 449=75+374 646=280+366 591=338+253 450=450+0 526=366+160

  553=300+253 615=455+160 607=414+193 671=291+380

  f

  A

  ∗

  gradually adds “

  f

  • -contours” of nodes

  O Z A T L M D C R

F

P G B U H E

  V I N 380 400

  420 S

  

Start

n G

  G 2 Suppose a suboptimal goal G has been generated

  f

  since h

  (G ) = g(G ) (G ) = 0

  2

  2

  2 > g since G suboptimal (G)

  2 ∗ = g(n) + h (n) ≥ g since h is admissible

  (n) + h(n) f

  = (n) ∗

  G

  Thus, A never selects for expansion

  2

  Complete Time Space Optimal

  Complete Yes

  (unless there are infinitely many nodes n with f )

  (n) ≤ f (G) Time Space Optimal

  Complete Yes

  (unless there are infinitely many nodes n with f )

  (n) ≤ f (G) Time Exponential in

  [relative error in h × length of solution]

  Space Optimal

  Complete Yes

  (unless there are infinitely many nodes n with f

  (n) ≤ f (G)

  )

  Time Exponential in

  [relative error in h × length of solution]

  Space Same as time Optimal

  Complete Yes

  (unless there are infinitely many nodes n with f )

  (n) ≤ f (G) Time Exponential in

  [relative error in h × length of solution]

  Space Same as time Optimal Yes

  Complete Yes

  (unless there are infinitely many nodes n with f )

  (n) ≤ f (G) Time Exponential in

  [relative error in h × length of solution]

  Space Same as time Optimal Yes Note

  ∗

  A expands all nodes with f

  (n) < C

  ∗

  A expands some nodes with f

  (n) = C

  ∗

  A expands no nodes with f

  (n) > C

  5

  7

  2

  4

  1

  2

  3

  5

  6

  4

  5

  6

  8

  3

  1

  7

  8 Start State Goal State

  Addmissible heuristics h = number of misplaced tiles

  (n)

  1 h = total ˘ Manhattan distance

  (n)

  2

  (i.e., no. of squares from desired location of each tile)

  5

  7

  2

  4

  1

  2

  3

  5

  6

  4

  5

  6

  8

  3

  1

  7

  8 Start State Goal State

  Addmissible heuristics h = number of misplaced tiles

  (n)

  1 h = total ˘ Manhattan distance

  (n)

  2

  (i.e., no. of squares from desired location of each tile)

  In the example h =

  (S)

  1 h

  =

  (S)

  2

  5

  7

  2

  4

  1

  2

  3

  5

  6

  4

  5

  6

  8

  3

  1

  7

  8 Start State Goal State

  Addmissible heuristics h = number of misplaced tiles

  (n)

  1 h = total ˘ Manhattan distance

  (n)

  2

  (i.e., no. of squares from desired location of each tile)

  In the example h =

  6

  (S)

  1 h

  =

  (S)

  2

  5

  7

  2

  4

  1

  2

  3

  5

  6

  4

  5

  6

  8

  3

  1

  7

  8 Start State Goal State

  Addmissible heuristics h = number of misplaced tiles

  (n)

  1 h = total ˘ Manhattan distance

  (n)

  2

  (i.e., no. of squares from desired location of each tile)

  In the example h =

  6

  (S)

  1 h

  = 2 + 0 + 3 + 1 + 0 + 1 + 3 + 4 = 14

  (S)

  2

  Definition h , h two admissible heuristics

  1

  2 h dominates h if

  2

  1

h for all n

  (n) ≥ h (n)

  2

  1

  Definition h , h two admissible heuristics

  1

  2 h dominates h if

  2

  1

h for all n

  (n) ≥ h (n)

  2

  2

  1

  2

  1

  Typical search costs d

  IDS too many nodes A

  d : depth of first solution

  1,641 nodes

  2 )

  ∗ (h

  39,135 nodes A

  1 )

  ∗ (h

  d = 24

  = 14

  113 nodes

  2 )

  ∗ (h

  539 nodes A

  1 )

  ∗ (h

  IDS 3,473,941 nodes A

  IDS: iterative deepening search

  Finding good admissible heuristics is an art! Deriving admissible heuristics

  Admissible heuristics can be derived from the exact solution cost of a relaxed version of the problem

  Finding good admissible heuristics is an art! Deriving admissible heuristics

  Admissible heuristics can be derived from the exact solution cost of a relaxed version of the problem

  Example

  If the rules of the 8-puzzle are relaxed so that a tile can move anywhere,

  h

  then we get heuristic

  then we get heuristic h

  2

  Finding good admissible heuristics is an art! Deriving admissible heuristics

  Admissible heuristics can be derived from the exact solution cost of a relaxed version of the problem

  Example

  If the rules of the 8-puzzle are relaxed so that a tile can move anywhere,

  h

  then we get heuristic

  1 If the rules are relaxed so that a tile can move to any adjacent square,

  then we get heuristic h

  2 Key point

  The optimal solution cost of a relaxed problem is not greater than the optimal solution cost of the real problem