AI Heuristic search - poojasuratia.files.wordpress.com · Tree search example 3. Tree search...

101
Dr. Pooja K Chauhan, IAI- Search methods Dr. Pooja K Chauhan, EC Dept, BITs edu campus.

Transcript of AI Heuristic search - poojasuratia.files.wordpress.com · Tree search example 3. Tree search...

Page 1: AI Heuristic search - poojasuratia.files.wordpress.com · Tree search example 3. Tree search example 4. Tree search example 5. Implementation: general tree search 6. Search strategies

Dr. Pooja K Chauhan,

IAI- Search methods

Dr. Pooja K Chauhan,

EC Dept,

BITs edu campus.

Page 2: AI Heuristic search - poojasuratia.files.wordpress.com · Tree search example 3. Tree search example 4. Tree search example 5. Implementation: general tree search 6. Search strategies

Tree search algorithms

� Basic idea:

� offline, simulated exploration of state space by generating successors of already-explored states (expanding states

2

Page 3: AI Heuristic search - poojasuratia.files.wordpress.com · Tree search example 3. Tree search example 4. Tree search example 5. Implementation: general tree search 6. Search strategies

Tree search example

3

Page 4: AI Heuristic search - poojasuratia.files.wordpress.com · Tree search example 3. Tree search example 4. Tree search example 5. Implementation: general tree search 6. Search strategies

Tree search example

4

Page 5: AI Heuristic search - poojasuratia.files.wordpress.com · Tree search example 3. Tree search example 4. Tree search example 5. Implementation: general tree search 6. Search strategies

Tree search example

5

Page 6: AI Heuristic search - poojasuratia.files.wordpress.com · Tree search example 3. Tree search example 4. Tree search example 5. Implementation: general tree search 6. Search strategies

Implementation: general tree search

6

Page 7: AI Heuristic search - poojasuratia.files.wordpress.com · Tree search example 3. Tree search example 4. Tree search example 5. Implementation: general tree search 6. Search strategies

Search strategies

� A search strategy is defined by picking the order of node expansion

� Strategies are evaluated along the following dimensions:� completeness: does it always find a solution if one exists?� time complexity: number of nodes generated� space complexity: maximum number of nodes in memory

7

� space complexity: maximum number of nodes in memory� optimality: does it always find a least-cost solution?

� Time and space complexity are measured in terms of � b: maximum number of successors of any node or branching factor.

� d: depth of the shallowest goal node.� m: maximum length of any path in state space (may be ∞)

Page 8: AI Heuristic search - poojasuratia.files.wordpress.com · Tree search example 3. Tree search example 4. Tree search example 5. Implementation: general tree search 6. Search strategies

Uninformed search strategies

� Uninformed (Blind Search) search strategies use only the information available in the problem definition:

� Breadth-first search

8

� Breadth-first search

� Uniform-cost search

�Depth-first search

� Depth-limited search

� Iterative deepening search

Page 9: AI Heuristic search - poojasuratia.files.wordpress.com · Tree search example 3. Tree search example 4. Tree search example 5. Implementation: general tree search 6. Search strategies

Breadth-first search� Expand the root node first,

� Then all the successors of the root node are expanded,

� Then their successors and so on.

� Shallowest unexpanded node is chosen for expansion.

� Implementation:

� fringe is a FIFO queue, i.e., new successors go at end

9

� fringe is a FIFO queue, i.e., new successors go at end

Page 10: AI Heuristic search - poojasuratia.files.wordpress.com · Tree search example 3. Tree search example 4. Tree search example 5. Implementation: general tree search 6. Search strategies

Breadth-first search

� Expand shallowest unexpanded node

� Implementation:� fringe is a FIFO queue, i.e., new successors go at end

10

Page 11: AI Heuristic search - poojasuratia.files.wordpress.com · Tree search example 3. Tree search example 4. Tree search example 5. Implementation: general tree search 6. Search strategies

Breadth-first search� Expand shallowest unexpanded node

� Implementation:� fringe is a FIFO queue, i.e., new successors go at end

11

Page 12: AI Heuristic search - poojasuratia.files.wordpress.com · Tree search example 3. Tree search example 4. Tree search example 5. Implementation: general tree search 6. Search strategies

Breadth-first search� Expand shallowest unexpanded node

� Implementation:� fringe is a FIFO queue, i.e., new successors go at end

12

Page 13: AI Heuristic search - poojasuratia.files.wordpress.com · Tree search example 3. Tree search example 4. Tree search example 5. Implementation: general tree search 6. Search strategies

Properties of breadth-first search

� Complete?Yes (if shallowest goal node d is finite and b is finite)

� Time? 1+b+b2+b3+… +bd = O(bd)�Goal test to nodes when selected for expansion, rather than when generated. (node at d will be

13

rather than when generated. (node at d will be expanded before goal is detected)

� Space? O(bd) (keeps every node in memory)�Optimal?Yes (if cost = 1 per step)

� Space is the bigger problem (more than time).

Page 14: AI Heuristic search - poojasuratia.files.wordpress.com · Tree search example 3. Tree search example 4. Tree search example 5. Implementation: general tree search 6. Search strategies

Uniform-cost search� Expand least-cost unexpanded node� Implementation:� fringe = queue ordered by path cost

� Equivalent to breadth-first if step costs all equal� Complete?Yes, if step cost ≥ εTime? # of nodes with g ≤ cost of optimal solution,

14

� Time? # of nodes with g ≤ cost of optimal solution, O(b(1+(C*/ ε)) where C* is the cost of the optimal solution

� Space? # of nodes with g ≤ cost of optimal solution, O(b(1+(C*/ ε))

�Optimal?Yes – nodes expanded in increasing order of g(n)

Page 15: AI Heuristic search - poojasuratia.files.wordpress.com · Tree search example 3. Tree search example 4. Tree search example 5. Implementation: general tree search 6. Search strategies

Depth-first search

� Expand deepest unexpanded node

� Implementation:

� fringe = LIFO queue, i.e. most recently generated node is chosen for expansion.

15

Page 16: AI Heuristic search - poojasuratia.files.wordpress.com · Tree search example 3. Tree search example 4. Tree search example 5. Implementation: general tree search 6. Search strategies

Depth-first search

16

Page 17: AI Heuristic search - poojasuratia.files.wordpress.com · Tree search example 3. Tree search example 4. Tree search example 5. Implementation: general tree search 6. Search strategies

Depth-first search

17

Page 18: AI Heuristic search - poojasuratia.files.wordpress.com · Tree search example 3. Tree search example 4. Tree search example 5. Implementation: general tree search 6. Search strategies

Depth-first search

18

Page 19: AI Heuristic search - poojasuratia.files.wordpress.com · Tree search example 3. Tree search example 4. Tree search example 5. Implementation: general tree search 6. Search strategies

Depth-first search

19

Page 20: AI Heuristic search - poojasuratia.files.wordpress.com · Tree search example 3. Tree search example 4. Tree search example 5. Implementation: general tree search 6. Search strategies

Depth-first search

20

Page 21: AI Heuristic search - poojasuratia.files.wordpress.com · Tree search example 3. Tree search example 4. Tree search example 5. Implementation: general tree search 6. Search strategies

Depth-first search

21

Page 22: AI Heuristic search - poojasuratia.files.wordpress.com · Tree search example 3. Tree search example 4. Tree search example 5. Implementation: general tree search 6. Search strategies

Depth-first search

22

Page 23: AI Heuristic search - poojasuratia.files.wordpress.com · Tree search example 3. Tree search example 4. Tree search example 5. Implementation: general tree search 6. Search strategies

Depth-first search

23

Page 24: AI Heuristic search - poojasuratia.files.wordpress.com · Tree search example 3. Tree search example 4. Tree search example 5. Implementation: general tree search 6. Search strategies

Depth-first search

24

Page 25: AI Heuristic search - poojasuratia.files.wordpress.com · Tree search example 3. Tree search example 4. Tree search example 5. Implementation: general tree search 6. Search strategies

Depth-first search

25

Page 26: AI Heuristic search - poojasuratia.files.wordpress.com · Tree search example 3. Tree search example 4. Tree search example 5. Implementation: general tree search 6. Search strategies

Depth-first search

26

Page 27: AI Heuristic search - poojasuratia.files.wordpress.com · Tree search example 3. Tree search example 4. Tree search example 5. Implementation: general tree search 6. Search strategies

Properties of depth-first search

� Complete? No: fails in infinite-depth spaces, spaces with loops

�Modify to avoid repeated states along path

� complete in finite spaces

� Time? O(bm): m=maximum depth of any node,

27

� Time? O(bm): m=maximum depth of any node,�Can be greater than state space, if m is much larger than d or tree is unbounded.

� but if solutions are dense, may be much faster than breadth-first

� Space? O(bm), i.e., linear space!

�Optimal? No

Page 28: AI Heuristic search - poojasuratia.files.wordpress.com · Tree search example 3. Tree search example 4. Tree search example 5. Implementation: general tree search 6. Search strategies

Backtracking Search� Variant of depth-first

� Uses less memory.

� Only one successor generated at a time rather than all successors.

� Each partially expanded node remembers which successor to generate next. O(m) memory is needed.

Page 29: AI Heuristic search - poojasuratia.files.wordpress.com · Tree search example 3. Tree search example 4. Tree search example 5. Implementation: general tree search 6. Search strategies

Depth-limited search

� Depth-first search with depth limit l,

i.e., nodes at depth l have no successor.

� Incompleteness if l<d

�Non optimal if l>d.

29

�Non optimal if l>d.

�Time complexity : O(bl)

� Space complexity: O(bl)

�With l=∞, it is a depth-first search.

Page 30: AI Heuristic search - poojasuratia.files.wordpress.com · Tree search example 3. Tree search example 4. Tree search example 5. Implementation: general tree search 6. Search strategies

Iterative deepening search or

Iterative deepening depth-first

search� Used in combination with depth-first tree search to find the best depth limit.

� Gradually increases the limit, until a goal is found.

30

� Combines the benefit of Depth-first and Breadth-First.

� Like Depth-first search: Memory requirement is modest=O(bd).

� Breadth-first: Is complete, if b is finite and optimal.

Page 31: AI Heuristic search - poojasuratia.files.wordpress.com · Tree search example 3. Tree search example 4. Tree search example 5. Implementation: general tree search 6. Search strategies

Iterative deepening search l =0

31

Page 32: AI Heuristic search - poojasuratia.files.wordpress.com · Tree search example 3. Tree search example 4. Tree search example 5. Implementation: general tree search 6. Search strategies

Iterative deepening search l =1

32

Page 33: AI Heuristic search - poojasuratia.files.wordpress.com · Tree search example 3. Tree search example 4. Tree search example 5. Implementation: general tree search 6. Search strategies

Iterative deepening search l =2

33

Page 34: AI Heuristic search - poojasuratia.files.wordpress.com · Tree search example 3. Tree search example 4. Tree search example 5. Implementation: general tree search 6. Search strategies

Iterative deepening search l =3

34

Page 35: AI Heuristic search - poojasuratia.files.wordpress.com · Tree search example 3. Tree search example 4. Tree search example 5. Implementation: general tree search 6. Search strategies

Iterative deepening search� Number of nodes generated in a depth-limited search to depth d with branching factor b:

NDLS = b0 + b1 + b2 + … + bd-2 + bd-1 + bd

� Number of nodes generated in an iterative deepening search to depth d with branching factor b:

N = d b^1 + (d-1)b^2 + … + 3bd-2 +2bd-1 + 1bd

35

NIDS = d b^1 + (d-1)b^2 + … + 3bd-2 +2bd-1 + 1bd

� For b = 10, d = 5,�NBFS = 10 + 100 + 1,000 + 10,000 + 100,000 = 111,110.

�NIDS = 50 + 400 + 3,000 + 20,000 + 100,000 = 123,450.

Page 36: AI Heuristic search - poojasuratia.files.wordpress.com · Tree search example 3. Tree search example 4. Tree search example 5. Implementation: general tree search 6. Search strategies

Properties of iterative deepening

search

� Complete?Yes

� Time? d b1 + (d-1)b2 + … + bd = O(bd)

� Space? O(bd)

�Optimal?Yes, if step cost = 1

36

�Optimal?Yes, if step cost = 1

� Iterative deepening is the preferred uninformed search method when the search space is large and the depth of the solution is not known.

Page 37: AI Heuristic search - poojasuratia.files.wordpress.com · Tree search example 3. Tree search example 4. Tree search example 5. Implementation: general tree search 6. Search strategies

Summary of algorithms

37

Page 38: AI Heuristic search - poojasuratia.files.wordpress.com · Tree search example 3. Tree search example 4. Tree search example 5. Implementation: general tree search 6. Search strategies

Informed (Heuristic) Search Strategies

� Uses Problem specific knowledge beyond the definition of the problem.

� Can find solution more efficiently.

� Best-first search is an instance of the general TREE-SEARCH or GRAPH-SEARCH algorithm.SEARCH or GRAPH-SEARCH algorithm.

� A node EVALUATION selected for expansion based on an evaluation function, f(n).

� The evaluation function is FUNCTION construed as a cost estimate, so the node with the lowest evaluation is expanded first.

Page 39: AI Heuristic search - poojasuratia.files.wordpress.com · Tree search example 3. Tree search example 4. Tree search example 5. Implementation: general tree search 6. Search strategies

� Uninformed search methods have access only to the problem definition. The basic algorithms are as follows:

� Breadth-first search expands the shallowest nodes first; it is complete, optimal for unit step costs, but has exponential space complexity.

� Uniform-cost search expands the node with lowest path cost, g(n), and is optimal for general step costs.g(n), and is optimal for general step costs.

� Depth-first search expands the deepest unexpanded node first. It is neither complete nor optimal, but has linear space complexity. Depth-limited search adds a depth bound.

� Iterative deepening search calls depth-first search with increasing depth limits until a goal is found. It is complete, optimal for unit step costs, has time complexity comparable to breadth-first search, and has linear space complexity.

Page 40: AI Heuristic search - poojasuratia.files.wordpress.com · Tree search example 3. Tree search example 4. Tree search example 5. Implementation: general tree search 6. Search strategies

Heuristic Search Techniques

� Best-first Search

�Hill climbing

�A* Search

� AO* Algorithm, � AO* Algorithm,

� IDA*,

�Recursive Best First Search.

Page 41: AI Heuristic search - poojasuratia.files.wordpress.com · Tree search example 3. Tree search example 4. Tree search example 5. Implementation: general tree search 6. Search strategies

Generated and Test

�� AlgorithmAlgorithm1.1. Generate a (potential goal) state:Generate a (potential goal) state:

–– Particular point in the problem space, orParticular point in the problem space, or–– A path from a start stateA path from a start state

2.2. Test if it is a goal stateTest if it is a goal state2.2. Test if it is a goal stateTest if it is a goal state–– Stop if positiveStop if positive–– go to step 1 otherwisego to step 1 otherwise

�� Systematic or Heuristic?Systematic or Heuristic?�� It depends on “Generate”It depends on “Generate”

4141

Page 42: AI Heuristic search - poojasuratia.files.wordpress.com · Tree search example 3. Tree search example 4. Tree search example 5. Implementation: general tree search 6. Search strategies

INFORMED (HEURISTIC) SEARCH

STRATEGIES

� One that uses problem-specific knowledge beyond the definition of the problem itself.

� can find solutions more efficiently than can an uninformed strategy.

� Best-first search is an instance of the general TREE-SEARCH � Best-first search is an instance of the general TREE-SEARCH or GRAPH-SEARCH algorithm,

� in which a node is selected for expansion based on an evaluation function, f(n).

� The evaluation function is construed as a cost estimate, so the node with the lowest evaluation is expanded first.

Page 43: AI Heuristic search - poojasuratia.files.wordpress.com · Tree search example 3. Tree search example 4. Tree search example 5. Implementation: general tree search 6. Search strategies

HEURISTIC FUNCTION

� The choice of f determines the search strategy.

�Most best-first algorithms include as a component off a heuristic function, denoted h(n):

� h(n) = estimated cost of the cheapest path from thestate at node n to a goal state.state at node n to a goal state.

� Heuristic functions are the most common form inwhich additional knowledge of the problem isimparted to the search algorithm.

� If n is a goal node, then h(n)=0.

Page 44: AI Heuristic search - poojasuratia.files.wordpress.com · Tree search example 3. Tree search example 4. Tree search example 5. Implementation: general tree search 6. Search strategies

Best First SearchBest First Search

�� Example:Example:The EightThe Eight--puzzlepuzzle

�� The task is to transform the initial puzzleThe task is to transform the initial puzzle

22 88 33

11 66 44

77 55

44

�� into the goal stateinto the goal state

11 22 33

88 44

77 66 55

�� by shifting numbers up, down, left or right.by shifting numbers up, down, left or right.

Page 45: AI Heuristic search - poojasuratia.files.wordpress.com · Tree search example 3. Tree search example 4. Tree search example 5. Implementation: general tree search 6. Search strategies

BestBest--First (First (HeuristicHeuristic) Search) Search

22 88 33

11 66 44

77 55

44

22 88 33

11 66 44

77 55

22 88 33

11 44

77 66 55

22 88 33

11 66 44

77 5555 33 55

22 88 33 22 33

11 22 33

88 44

77 66 55

22 88 33

11 44

77 66 55

22 33

11 88 44

77 66 55

22 88 33

11 44

77 66 55

33

to the goalto the goal

44

88 33

22 11 44

77 66 5533

33

22 88 33

77 11 44

66 5544

88 33

22 11 44

77 66 5533 to further unnecessary expansionsto further unnecessary expansions

Page 46: AI Heuristic search - poojasuratia.files.wordpress.com · Tree search example 3. Tree search example 4. Tree search example 5. Implementation: general tree search 6. Search strategies

Greedy bestGreedy bestGreedy bestGreedy best----first searchfirst searchfirst searchfirst search� Greedy best-first search tries to expand the node that is closest to the goal, on the grounds that this is likely to lead to a solution quickly.

� Thus, it evaluates nodes by using just the heuristic function; that is, f(n) = h(n).

� Greedy best-first tree search is also incomplete even in a finite state space, much like depth-first search.space, much like depth-first search.

� The worst-case time and space complexity for the tree version is O(b^m), where m is the maximum depth of the search space.

� With a good heuristic function, however, the complexity can be reduced substantially.

� The amount of the reduction depends on the particular problem and on the quality of the heuristic.

Page 47: AI Heuristic search - poojasuratia.files.wordpress.com · Tree search example 3. Tree search example 4. Tree search example 5. Implementation: general tree search 6. Search strategies

A* search: Minimizing the total A* search: Minimizing the total A* search: Minimizing the total A* search: Minimizing the total

estimated solution costestimated solution costestimated solution costestimated solution cost

� The most widely known form of best-first search is called A∗∗∗∗search.

� It evaluates nodes by combining:

� g(n), path cost from the start node to node n, and

h(n), the estimated cost of the cheapest path from n to the � h(n), the estimated cost of the cheapest path from n to the goal :

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

� f(n) = estimated cost of the cheapest solution through n.

� A∗ search is both complete and optimal.

� The algorithm is identical to UNIFORM-COST-SEARCH

� except that A∗ uses g + h instead of g.

Page 48: AI Heuristic search - poojasuratia.files.wordpress.com · Tree search example 3. Tree search example 4. Tree search example 5. Implementation: general tree search 6. Search strategies

Conditions for optimality:Conditions for optimality:Conditions for optimality:Conditions for optimality:� The first condition we require for optimality is that h(n ) be an admissible heuristic.

� An admissible heuristic is one that never overestimates the cost to reach the goal.

� Because g(n) is the actual cost to reach n along the current path, and f(n)=g(n) + h(n), path, and f(n)=g(n) + h(n),

� f(n) never overestimates the true cost of a solution along the current path through n.

� Admissible heuristics are by nature optimistic because they think the cost of solving

� the problem is less than it actually is.

Page 49: AI Heuristic search - poojasuratia.files.wordpress.com · Tree search example 3. Tree search example 4. Tree search example 5. Implementation: general tree search 6. Search strategies
Page 50: AI Heuristic search - poojasuratia.files.wordpress.com · Tree search example 3. Tree search example 4. Tree search example 5. Implementation: general tree search 6. Search strategies

� An obvious example of an admissible heuristic is the

� straight-line distance hSLD that we used in getting to Bucharest. Straight-line distance is

� admissible because the shortest path between any two points is a straight line, so the straight line cannot be an overestimate.

Page 51: AI Heuristic search - poojasuratia.files.wordpress.com · Tree search example 3. Tree search example 4. Tree search example 5. Implementation: general tree search 6. Search strategies

CONSISTENCY � A second, slightly stronger condition called consistency (or sometimes monotonicity) is required only for applications of A∗ to graph search.

� A heuristic h(n) is consistent if, for every node n and

� every successor n of n generated by any action a,

� the estimated cost of reaching the goal from n is no greater � the estimated cost of reaching the goal from n is no greater than the step cost of getting to n plus the estimated cost of reaching the goal from n:

� h(n) ≤ c(n, a, n’) + h(n’) .

� This is a form of the general triangle inequality, which stipulates that each side of a triangle cannot be longer than the sum of the other two sides.

� the triangle is formed by n, n’,and the goal Gn closest to n.

Page 52: AI Heuristic search - poojasuratia.files.wordpress.com · Tree search example 3. Tree search example 4. Tree search example 5. Implementation: general tree search 6. Search strategies

A properties:� The tree-search version of A∗ is optimal if h(n) is admissible,

� while the graph-search version is optimal if h(n) is consistent.

Page 53: AI Heuristic search - poojasuratia.files.wordpress.com · Tree search example 3. Tree search example 4. Tree search example 5. Implementation: general tree search 6. Search strategies

� Stages in an A∗ search for Bucharest.

� Nodes are labeled with f = g +h.

� The

� h values are the straight-line distances to Bucharest taken from Figure 3.22.

Page 54: AI Heuristic search - poojasuratia.files.wordpress.com · Tree search example 3. Tree search example 4. Tree search example 5. Implementation: general tree search 6. Search strategies
Page 55: AI Heuristic search - poojasuratia.files.wordpress.com · Tree search example 3. Tree search example 4. Tree search example 5. Implementation: general tree search 6. Search strategies
Page 56: AI Heuristic search - poojasuratia.files.wordpress.com · Tree search example 3. Tree search example 4. Tree search example 5. Implementation: general tree search 6. Search strategies

� the sequence of nodes expanded by A∗ using GRAPH-SEARCH is in nondecreasing order of f(n).

� Hence, the first goal node selected for expansion must be an optimal solution because f is the true cost for goal nodes

� (which have h=0) and all later goal nodes will be at least as � (which have h=0) and all later goal nodes will be at least as expensive.

� The fact that f-costs are nondecreasing along any path also means that we can draw contours in the state space, just like the contours in a topographic map.

Page 57: AI Heuristic search - poojasuratia.files.wordpress.com · Tree search example 3. Tree search example 4. Tree search example 5. Implementation: general tree search 6. Search strategies
Page 58: AI Heuristic search - poojasuratia.files.wordpress.com · Tree search example 3. Tree search example 4. Tree search example 5. Implementation: general tree search 6. Search strategies

Properties

� A∗ is optimally efficient for any given consistent heuristic.

� A∗ search is complete.

� The complexity of A∗ often makes it impractical to insist on finding an optimal solution.

� Drawbacks:

� Drawbacks:� Computation time.

� it keeps all generated nodes in memory , A∗ usually runs out of space long before it runs out of time.

Page 59: AI Heuristic search - poojasuratia.files.wordpress.com · Tree search example 3. Tree search example 4. Tree search example 5. Implementation: general tree search 6. Search strategies

MemoryMemoryMemoryMemory----bounded heuristic searchbounded heuristic searchbounded heuristic searchbounded heuristic search

� To reduce memory requirements for A∗,� Adapt the idea of iterative deepening to the heuristic search context,

� resulting in the iterative-deepening A∗∗∗∗ (IDA∗∗∗∗) algorithm.

∗∗∗∗ ∗∗∗∗

algorithm.

� The main difference between IDA∗ and standard iterative deepening is:

� the cutoff used is the f-cost (g+h) rather than the depth; at each iteration,

� the cutoff value is the smallest f-cost of any node that exceeded the cutoff on the previous iteration.

Page 60: AI Heuristic search - poojasuratia.files.wordpress.com · Tree search example 3. Tree search example 4. Tree search example 5. Implementation: general tree search 6. Search strategies

Recursive bestRecursive bestRecursive bestRecursive best----first search (RBFS)first search (RBFS)first search (RBFS)first search (RBFS)� Recursive best-first search (RBFS) is a simple recursive algorithm that attempts to mimic the operation of standard best-first search, but using only linear space.

� Its structure is similar to that of a recursive depth-first search, but rather than continuing indefinitely down the current path,

� it uses the f limit variable to keep track of the f-value of the best alternative path available from any ancestor of the current node.

� If the current node exceeds this limit, the recursion unwinds back to the alternative path.

� As the recursion unwinds, RBFS replaces the f-value of each node along the path

� BACKED-UP VALUE with a backed-up value—the best f-value of its children.

Page 61: AI Heuristic search - poojasuratia.files.wordpress.com · Tree search example 3. Tree search example 4. Tree search example 5. Implementation: general tree search 6. Search strategies
Page 62: AI Heuristic search - poojasuratia.files.wordpress.com · Tree search example 3. Tree search example 4. Tree search example 5. Implementation: general tree search 6. Search strategies
Page 63: AI Heuristic search - poojasuratia.files.wordpress.com · Tree search example 3. Tree search example 4. Tree search example 5. Implementation: general tree search 6. Search strategies

� RBFS is somewhat more efficient than IDA∗, but still suffers from excessive node regeneration.

�RBFS follows the path via RimnicuVilcea, then “changes its mind” and tries Fagaras, and then changes its mind back again.

changes its mind back again.

�Each mind change corresponds to an iteration of IDA∗ and could require many reexpansionsof forgotten nodes to recreate the best path and extend it one more node.

Page 64: AI Heuristic search - poojasuratia.files.wordpress.com · Tree search example 3. Tree search example 4. Tree search example 5. Implementation: general tree search 6. Search strategies

Properties

� Like A∗ tree search, RBFS is an optimal algorithm if the heuristic function h(n) is admissible.

� Its space complexity is linear in the depth of the deepest optimal solution, but

� its time complexity is rather difficult to characterize:

� it depends both on the accuracy of the heuristic function and on

� it depends both on the accuracy of the heuristic function and on how often the best path changes as nodes are expanded.

� IDA∗ and RBFS suffer from using too little memory.

� Between iterations, IDA∗ retains only a single number: the current f-cost limit.

� RBFS retains more information in memory, but it uses only linear space.

Page 65: AI Heuristic search - poojasuratia.files.wordpress.com · Tree search example 3. Tree search example 4. Tree search example 5. Implementation: general tree search 6. Search strategies

Generate-and-Test

Algorithm1. Generate a possible solution.

2. Test to see if this is actually a solution.

65

3. Quit if a solution has been found. Otherwise, return to step 1.

Page 66: AI Heuristic search - poojasuratia.files.wordpress.com · Tree search example 3. Tree search example 4. Tree search example 5. Implementation: general tree search 6. Search strategies

Generate-and-Test

�Acceptable for simple problems.

� Inefficient for problems with large space.

66

Page 67: AI Heuristic search - poojasuratia.files.wordpress.com · Tree search example 3. Tree search example 4. Tree search example 5. Implementation: general tree search 6. Search strategies

Generate-and-Test

� Exhaustive generate-and-test.

�Heuristic generate-and-test: not consider paths that seem unlikely to lead to a solution.

� Plan generate-test:

67

� Plan generate-test:− Create a list of candidates.

−Apply generate-and-test to that list.

Page 68: AI Heuristic search - poojasuratia.files.wordpress.com · Tree search example 3. Tree search example 4. Tree search example 5. Implementation: general tree search 6. Search strategies

Generate-and-Test

Example: coloured blocks“Arrange four 6-sided cubes in a row, with each side of each cube painted one of four colours, such that on all four sides of the row one block face of each colour is showing.”

68

sides of the row one block face of each colour is showing.”

Page 69: AI Heuristic search - poojasuratia.files.wordpress.com · Tree search example 3. Tree search example 4. Tree search example 5. Implementation: general tree search 6. Search strategies

Generate-and-Test

Example: coloured blocks

Heuristic: if there are more red faces than other colours then, when placing a block with several red faces, use few

69

then, when placing a block with several red faces, use few of them as possible as outside faces.

Page 70: AI Heuristic search - poojasuratia.files.wordpress.com · Tree search example 3. Tree search example 4. Tree search example 5. Implementation: general tree search 6. Search strategies

Hill Climbing

� Searching for a goal state = Climbing to the top of a hill

70

Page 71: AI Heuristic search - poojasuratia.files.wordpress.com · Tree search example 3. Tree search example 4. Tree search example 5. Implementation: general tree search 6. Search strategies

Hill ClimbingHill Climbing

�� SimpleSimple HillHill ClimbingClimbing��expandexpand thethe currentcurrent nodenode��evaluateevaluate itsits childrenchildren oneone byby oneone (using(using thetheheuristicheuristic evaluationevaluation function)function)

��choosechoose thethe FIRSTFIRST nodenode withwith aa betterbetter valuevalue

�� SteepestSteepest AscendAscend HillHill ClimbingClimbing��expandexpand thethe currentcurrent nodenode��EvaluateEvaluate allall itsits childrenchildren (by(by thethe heuristicheuristic evaluationevaluationfunction)function)

��choosechoose thethe BESTBEST nodenode withwith thethe bestbest valuevalue7171

Page 72: AI Heuristic search - poojasuratia.files.wordpress.com · Tree search example 3. Tree search example 4. Tree search example 5. Implementation: general tree search 6. Search strategies

Hill Climbing

�Generate-and-test + direction to move.

�Heuristic function to estimate how close a given state is to a goal state.

72

Page 73: AI Heuristic search - poojasuratia.files.wordpress.com · Tree search example 3. Tree search example 4. Tree search example 5. Implementation: general tree search 6. Search strategies

Simple Hill Climbing

Algorithm1. Evaluate the initial state.

2. Loop until a solution is found or there are no new operators left to be applied:

73

left to be applied:− Select and apply a new operator

− Evaluate the new state:

goal → quit

better than current state → new current state

Page 74: AI Heuristic search - poojasuratia.files.wordpress.com · Tree search example 3. Tree search example 4. Tree search example 5. Implementation: general tree search 6. Search strategies

Simple Hill Climbing� Evaluation function as a way to inject task-specific knowledgeinto the control process.

74

Page 75: AI Heuristic search - poojasuratia.files.wordpress.com · Tree search example 3. Tree search example 4. Tree search example 5. Implementation: general tree search 6. Search strategies

Simple Hill Climbing

Example: coloured blocks

Heuristic function: the sum of the number of different colours on each of the four sides (solution = 16).

75

colours on each of the four sides (solution = 16).

Page 76: AI Heuristic search - poojasuratia.files.wordpress.com · Tree search example 3. Tree search example 4. Tree search example 5. Implementation: general tree search 6. Search strategies

Hill-climbing example

a) b)

a) shows a state of h=17 and the h-value for each possible successor.

b) A local minimum in the 8-queens state space (h=1).7676

Page 77: AI Heuristic search - poojasuratia.files.wordpress.com · Tree search example 3. Tree search example 4. Tree search example 5. Implementation: general tree search 6. Search strategies

Hill-climbing variations� Stochastic hill-climbing

� Random selection among the uphill moves.

� The selection probability can vary with the steepness of the uphill move.

� First-choice hill-climbing

� Stochastic hill climbing by generating successors randomly � Stochastic hill climbing by generating successors randomly until a better one is found.

� Random-restart hill-climbing

�� A series of Hill Climbing searches from randomly generated A series of Hill Climbing searches from randomly generated initial statesinitial states

�� SimulatedSimulatedAnnealingAnnealing

� Escape local maxima by allowing some "bad" moves butgradually decrease their frequency 7777

Page 78: AI Heuristic search - poojasuratia.files.wordpress.com · Tree search example 3. Tree search example 4. Tree search example 5. Implementation: general tree search 6. Search strategies

Steepest-Ascent Hill Climbing (Gradient

Search)

�Considers all the moves from the current state.

� Selects the best one as the next state.

78

Page 79: AI Heuristic search - poojasuratia.files.wordpress.com · Tree search example 3. Tree search example 4. Tree search example 5. Implementation: general tree search 6. Search strategies

Steepest-Ascent Hill Climbing (Gradient

Search)

Algorithm1. Evaluate the initial state.

2. Loop until a solution is found or a complete iteration produces no change to current state:

79

produces no change to current state:− SUCC = a state such that any possible successor of the current state will be better than SUCC (the worst state).

− For each operator that applies to the current state, evaluate the new state:

goal → quit

better than SUCC → set SUCC to this state

− SUCC is better than the current state → set the current state to SUCC.

Page 80: AI Heuristic search - poojasuratia.files.wordpress.com · Tree search example 3. Tree search example 4. Tree search example 5. Implementation: general tree search 6. Search strategies

Hill Climbing: DisadvantagesLocal maximumA state that is better than all of its neighbours, but not better than some other states far away.

80

Page 81: AI Heuristic search - poojasuratia.files.wordpress.com · Tree search example 3. Tree search example 4. Tree search example 5. Implementation: general tree search 6. Search strategies

Hill Climbing: DisadvantagesPlateauA flat area of the search space in which all neighbouring states have the same value.

81

Page 82: AI Heuristic search - poojasuratia.files.wordpress.com · Tree search example 3. Tree search example 4. Tree search example 5. Implementation: general tree search 6. Search strategies

Hill Climbing: DisadvantagesRidgeThe orientation of the high region, compared to the set of available moves, makes it impossible to climb up. However, two moves executed serially may increase the height.

82

the height.

Page 83: AI Heuristic search - poojasuratia.files.wordpress.com · Tree search example 3. Tree search example 4. Tree search example 5. Implementation: general tree search 6. Search strategies

Hill Climbing: Disadvantages

Ways Out

� Backtrack to some earlier node and try going in a different direction.

�Make a big jump to try to get in a new section.

83

�Make a big jump to try to get in a new section.

�Moving in several directions at once.

Page 84: AI Heuristic search - poojasuratia.files.wordpress.com · Tree search example 3. Tree search example 4. Tree search example 5. Implementation: general tree search 6. Search strategies

Hill Climbing: Disadvantages�Hill climbing is a local method: Decides what to do next by looking only at the “immediate” consequences of its choices.

�Global information might be encoded in heuristic functions.

84

Page 85: AI Heuristic search - poojasuratia.files.wordpress.com · Tree search example 3. Tree search example 4. Tree search example 5. Implementation: general tree search 6. Search strategies

Hill Climbing: Disadvantages

CD

BC

Start GoalA D

85

BC

AB

Blocks World

Page 86: AI Heuristic search - poojasuratia.files.wordpress.com · Tree search example 3. Tree search example 4. Tree search example 5. Implementation: general tree search 6. Search strategies

Hill Climbing: Disadvantages

CD

BC

Start GoalA D0 4

86

BC

AB

Blocks World

Local heuristic: +1 for each block that is resting on the thing it is supposed to be resting on. −1 for each block that is resting on a wrong thing.

Page 87: AI Heuristic search - poojasuratia.files.wordpress.com · Tree search example 3. Tree search example 4. Tree search example 5. Implementation: general tree search 6. Search strategies

Hill Climbing: Disadvantages

CD

CDA0 2

87

BC

BC

A

Page 88: AI Heuristic search - poojasuratia.files.wordpress.com · Tree search example 3. Tree search example 4. Tree search example 5. Implementation: general tree search 6. Search strategies

Hill Climbing: Disadvantages

BCD

A

2

88

BCDA

BC D

A BC

DA

00

0

B A

Page 89: AI Heuristic search - poojasuratia.files.wordpress.com · Tree search example 3. Tree search example 4. Tree search example 5. Implementation: general tree search 6. Search strategies

Hill Climbing: Disadvantages

CD

BC

Start GoalA D−6 6

89

BC

AB

Blocks World

Global heuristic: For each block that has the correct support structure: +1 to

every block in the support structure. For each block that has a wrong support structure: −1 to

every block in the support structure.

Page 90: AI Heuristic search - poojasuratia.files.wordpress.com · Tree search example 3. Tree search example 4. Tree search example 5. Implementation: general tree search 6. Search strategies

Hill Climbing: Disadvantages

BCD

A

−3

90

BCDA

BC D

A BC

DA

−6−2

−1

B A

Page 91: AI Heuristic search - poojasuratia.files.wordpress.com · Tree search example 3. Tree search example 4. Tree search example 5. Implementation: general tree search 6. Search strategies

Hill Climbing: Conclusion�Can be very inefficient in a large, rough problem space.

�Global heuristic may have to pay for computational complexity.

91

�Often useful when combined with other methods, getting it started right in the right general neighbourhood.

Page 92: AI Heuristic search - poojasuratia.files.wordpress.com · Tree search example 3. Tree search example 4. Tree search example 5. Implementation: general tree search 6. Search strategies

Problem Reduction

Goal: Acquire TV set

Goal: Steal TV set Goal: Earn some money Goal: Buy TV set

92

AND-OR Graphs

Goal: Steal TV set Goal: Earn some money Goal: Buy TV set

Algorithm AO* (Martelli & Montanari 1973, Nilsson 1980)

Page 93: AI Heuristic search - poojasuratia.files.wordpress.com · Tree search example 3. Tree search example 4. Tree search example 5. Implementation: general tree search 6. Search strategies

Problem Reduction: AO*

ADCB

43 5

A5

69

93

FE44

ADCB

4310

99

FE44

ADCB

46 10

1112

HG75

Page 94: AI Heuristic search - poojasuratia.files.wordpress.com · Tree search example 3. Tree search example 4. Tree search example 5. Implementation: general tree search 6. Search strategies

Problem Reduction: AO*

A

CB 10

11

13

ED F

A

CB 15

14

13

ED F

94

G 5

ED 65 F 3

G 10

ED 65 F 3

H 9Necessary backward propagation

Page 95: AI Heuristic search - poojasuratia.files.wordpress.com · Tree search example 3. Tree search example 4. Tree search example 5. Implementation: general tree search 6. Search strategies

Constraint Satisfaction�Many AI problems can be viewed as problems of constraint satisfaction.

Cryptarithmetic puzzle:

95

SENDMORE

MONEY +

Page 96: AI Heuristic search - poojasuratia.files.wordpress.com · Tree search example 3. Tree search example 4. Tree search example 5. Implementation: general tree search 6. Search strategies

Constraint Satisfaction�As compared with a straightforard search procedure, viewing a problem as one of constraint satisfaction can reduce substantially the amount of search.

96

Page 97: AI Heuristic search - poojasuratia.files.wordpress.com · Tree search example 3. Tree search example 4. Tree search example 5. Implementation: general tree search 6. Search strategies

Constraint Satisfaction�Operates in a space of constraint sets.

� Initial state contains the original constraints given in the problem.

97

�A goal state is any state that has been constrained “enough”.

Page 98: AI Heuristic search - poojasuratia.files.wordpress.com · Tree search example 3. Tree search example 4. Tree search example 5. Implementation: general tree search 6. Search strategies

Constraint SatisfactionTwo-step process:

1. Constraints are discovered and propagated as far as possible.

2. If there is still not a solution, then search begins, adding new constraints.

98

new constraints.

Page 99: AI Heuristic search - poojasuratia.files.wordpress.com · Tree search example 3. Tree search example 4. Tree search example 5. Implementation: general tree search 6. Search strategies

M = 1S = 8 or 9O = 0N = E + 1C2 = 1N + R > 8E ≠ 9

N = 3

E = 2

Initial state:• No two letters have the same value.

• The sum of the digits must be as shown.

SENDMORE

MONEY+

99

N = 3R = 8 or 92 + D = Y or 2 + D = 10 + Y

2 + D = YN + R = 10 + ER = 9S =8

2 + D = 10 + YD = 8 + YD = 8 or 9

Y = 0 Y = 1

C1 = 0 C1 = 1

D = 8 D = 9

Page 100: AI Heuristic search - poojasuratia.files.wordpress.com · Tree search example 3. Tree search example 4. Tree search example 5. Implementation: general tree search 6. Search strategies

Constraint SatisfactionTwo kinds of rules:

1. Rules that define valid constraint propagation.

2. Rules that suggest guesses when necessary.

100

Page 101: AI Heuristic search - poojasuratia.files.wordpress.com · Tree search example 3. Tree search example 4. Tree search example 5. Implementation: general tree search 6. Search strategies

ENDEND