16890 unit 2 heuristic search techniques

Preview:

DESCRIPTION

 

Citation preview

Artificial Intelligence Course Code: ECE434

Suryender Kumar Sharma

Suryender.16890@lpu.co.in

Asst. Prof. D: EEE - SEE- R & A

Lovely Professional University

Heuristic Search Techniques

Review

General Purpose Problem Solving

Production System

State-Space Search

Control Strategies

Characteristics of Problems

Exhaustive Search Techniques

(BFS,DFS,DFID,BS)

Analysis of Search Methods

Travelling Salesman Problem (TSP)

Statement:

To find the shortest route of visiting all the cities once and returning back to the starting point.

Assume that there are n cities and distance between each pair of cities is given.

Factorial n-1 paths for n cities

Travelling Salesman Problem (TSP)

Start Generating complete paths, keep track of

the shortest path found so far

Stop exploring any path as soon as its partial

length becomes greater than the shortest path

found so far

TSP

C1

(C2) C3

C4

C5

11 7

12

15 20

12

10 13

17 5

n=5 No of paths (n-1)! = 4! = 24

Using problem specific knowledge to aid searching

• Without incorporating knowledge into searching, one can have no bias (i.e. a preference) on the search space.

• Without a bias, one is forced to look everywhere to find the answer. Hence, the complexity of uninformed search is intractable.

Search everywhere!!

Using problem specific knowledge to aid searching

• With knowledge, one can search the state space as if he was given “hints” when exploring a maze.

– Heuristic information in search = Hints

• Leads to dramatic speed up in efficiency.

A

B C E D

F G H I J

K L

O

M N Search only in this subtree!!

More formally, why heuristic functions work?

• In any search problem where there are at most b choices at each node and a depth of d at the goal node, a naive search algorithm would have to, in the worst case, search around O(bd) nodes before finding a solution (Exponential Time Complexity).

• Heuristics improve the efficiency of search algorithms by reducing the effective branching factor from b to (ideally) a low constant b* such that

– 1 =< b* << b

General Purpose Heuristics:

– Are useful in various problem domains

Special purpose Heuristics:

– Are domain specific

Heuristic Search Techniques

Heuristic Search Techniques

General-purpose heuristics.

Best-first search.

Branch and bound search (uniform cost search).

A* algorithm

Hill climbing.

Beam search.

General Purpose Heuristics

1. For combinatorial is nearest neighbor algorithms that

work by selecting the locally superior alternative

2. Mathematical analysis is not possible to perform

It is fun to see a program do something intelligent

than to prove it

AI Problem domain are complex, not possible to

produce analytical proof that will work

not possible to make statistical analysis of

program behavior

Heuristic Functions

• A heuristic function is a function f(n) that gives an estimation on the “cost” of getting from node n to the goal state – so that the node with the least cost among all possible choices can be selected for expansion first.

• Three approaches to defining f:

– f measures the value of the current state (its “goodness”)

– f measures the estimated cost of getting to the goal from the current state:

• f(n) = h(n) where h(n) = an estimate of the cost to get from n to a goal

– f measures the estimated cost of getting to the goal state from the current state and the cost of the existing path to it. Often, in this case, we decompose f:

• f(n) = g(n) + h(n) where g(n) = the cost to get to n (from initial state)

Approach 1: f Measures the Value of the Current State

• Usually the case when solving optimization problems

– Finding a state such that the value of the metric f is optimized

• Often, in these cases, f could be a weighted sum of a set of component values:

– N-Queens

• Example: the number of queens under attack …

Approach 2: f Measures the Cost to the Goal

A state X would be better than a state Y if the estimated cost of getting from X to the goal is lower than that of Y – because X would be closer to the goal than Y

• 8–Puzzle

h1: The number of misplaced tiles (squares with number).

h2: The sum of the distances of the tiles from their goal positions.

Approach 3: f measures the total cost of the solution path (Admissible Heuristic Functions)

• A heuristic function f(n) = g(n) + h(n) is admissible if h(n) never overestimates the cost to reach the goal.

– Admissible heuristics are “optimistic”: “the cost is not that much …”

• However, g(n) is the exact cost to reach node n from the initial state.

• Therefore, f(n) never over-estimate the true cost to reach the goal state

through node n.

• Theorem: A search is optimal if h(n) is admissible.

– I.e. The search using h(n) returns an optimal solution.

• Given h2(n) > h1(n) for all n, it’s always more efficient to use h2(n).

– h2 is more realistic than h1 (more informed), though both are optimistic.

Traditional informed search strategies

• Greedy Best first search

– “Always chooses the successor node with the best f value”

where f(n) = h(n)

– We choose the one that is nearest to the final state among all

possible choices

• A* search

– Best first search using an “admissible” heuristic function f

that takes into account the current cost g

– Always returns the optimal solution path

Best First Search

Informed Search Strategies

Greedy Search

eval-fn: f(n) = h(n)

Informed Search Strategies

Greedy Search

State Heuristic: h(n)

A 366

B 374

C 329

D 244

E 253

F 178

G 193

H 98

I 0

A

B

D

C

E

F

I

99

211

G

H

80

Start

Goal

97

101

75 118

111

f(n) = h (n) = straight-line distance heuristic

140

Greedy Search

State Heuristic: h(n)

A 366

B 374

C 329

D 244

E 253

F 178

G 193

H 98

I 0

A

B

D

C

E

F

I

99

211

G

H

80

Start

Goal

97

101

75 118

111

f(n) = h (n) = straight-line distance heuristic

140

Greedy Search

State Heuristic: h(n)

A 366

B 374

C 329

D 244

E 253

F 178

G 193

H 98

I 0

A

B

D

C

E

F

I

99

211

G

H

80

Start

Goal

97

101

75 118

111

f(n) = h (n) = straight-line distance heuristic

140

Greedy Search

State Heuristic: h(n)

A 366

B 374

C 329

D 244

E 253

F 178

G 193

H 98

I 0

A

B

D

C

E

F

I

99

211

G

H

80

Start

Goal

97

101

75 118

111

f(n) = h (n) = straight-line distance heuristic

140

Greedy Search

State Heuristic: h(n)

A 366

B 374

C 329

D 244

E 253

F 178

G 193

H 98

I 0

A

B

D

C

E

F

I

99

211

G

H

80

Start

Goal

97

101

75 118

111

f(n) = h (n) = straight-line distance heuristic

140

Greedy Search

State Heuristic: h(n)

A 366

B 374

C 329

D 244

E 253

F 178

G 193

H 98

I 0

A

B

D

C

E

F

I

99

211

G

H

80

Start

Goal

97

101

75 118

111

f(n) = h (n) = straight-line distance heuristic

140

Greedy Search

State Heuristic: h(n)

A 366

B 374

C 329

D 244

E 253

F 178

G 193

H 98

I 0

A

B

D

C

E

F

I

99

211

G

H

80

Start

Goal

97

101

75 118

111

f(n) = h (n) = straight-line distance heuristic

140

Greedy Search

State Heuristic: h(n)

A 366

B 374

C 329

D 244

E 253

F 178

G 193

H 98

I 0

A

B

D

C

E

F

I

99

211

G

H

80

Start

Goal

97

101

75 118

111

f(n) = h (n) = straight-line distance heuristic

140

Greedy Search

State Heuristic: h(n)

A 366

B 374

C 329

D 244

E 253

F 178

G 193

H 98

I 0

A

B

D

C

E

F

I

99

211

G

H

80

Start

Goal

97

101

75 118

111

f(n) = h (n) = straight-line distance heuristic

140

Greedy Search

State Heuristic: h(n)

A 366

B 374

C 329

D 244

E 253

F 178

G 193

H 98

I 0

A

B

D

C

E

F

I

99

211

G

H

80

Start

Goal

97

101

75 118

111

f(n) = h (n) = straight-line distance heuristic

140

Greedy Search: Tree Search

A Start

Greedy Search: Tree Search

A

B C

E

Start

75 118

140 [374] [329]

[253]

Greedy Search: Tree Search

A

B C

E

F

99

G A

80

Start

75 118

140 [374] [329]

[253]

[193]

[366]

[178]

Greedy Search: Tree Search

A

B C

E

F

I

99

211

G A

80

Start

Goal

75 118

140 [374] [329]

[253]

[193]

[366]

[178]

E [0] [253]

Greedy Search: Tree Search

A

B C

E

F

I

99

211

G A

80

Start

Goal

75 118

140 [374] [329]

[253]

[193]

[366]

[178]

E [0] [253]

Path cost(A-E-F-I) = 253 + 178 + 0 = 431

dist(A-E-F-I) = 140 + 99 + 211 = 450

Greedy Search: Optimal ?

State Heuristic: h(n)

A 366

B 374

C 329

D 244

E 253

F 178

G 193

H 98

I 0

A

B

D

C

E

F

I

99

211

G

H

80

Start

Goal

97

101

75 118

111

f(n) = h (n) = straight-line distance heuristic

dist(A-E-G-H-I) =140+80+97+101=418

140

Greedy Search: Complete ?

State Heuristic: h(n)

A 366

B 374

** C 250

D 244

E 253

F 178

G 193

H 98

I 0

A

B

D

C

E

F

I

99

211

G

H

80

Start

Goal

97

101

75 118

111

f(n) = h (n) = straight-line distance heuristic

140

Greedy Search: Tree Search

A Start

Greedy Search: Tree Search

A

B C

E

Start

75 118

140 [374] [250]

[253]

Greedy Search: Tree Search

A

B C

E

D

111

Start

75 118

140 [374] [250]

[253]

[244]

Greedy Search: Tree Search

A

B C

E

D

111

Start

75 118

140 [374] [250]

[253]

[244]

C [250]

Infinite Branch !

Greedy Search: Tree Search

A

B C

E

D

111

Start

75 118

140 [374] [250]

[253]

[244]

C

D

[250]

[244]

Infinite Branch !

Greedy Search: Tree Search

A

B C

E

D

111

Start

75 118

140 [374] [250]

[253]

[244]

C

D

[250]

[244]

Infinite Branch !

Greedy Search: Time and Space Complexity ?

A

B

D

C

E

F

I

99

211

G

H

80

Start

Goal

97

101

75 118

111

140

• Greedy search is not optimal.

• Greedy search is incomplete without systematic checking of repeated states.

• In the worst case, the Time and Space Complexity of Greedy Search are both O(bm)

Where b is the branching factor and m the maximum path length

Informed Search Strategies

Branch and bound search Uniform Cost Search

f(n)=g(n)

Uniform Cost Search (UCS)

2 5

1 7

4 5

[5] [2]

[9] [3]

[7] [8]

1 4

[9] [6]

[x] = g(n)

path cost of node n

Goal state

Uniform Cost Search (UCS)

2 5

[5] [2]

Uniform Cost Search (UCS)

2 5

1 7

[5] [2]

[9] [3]

Uniform Cost Search (UCS)

2 5

1 7

4 5

[5] [2]

[9] [3]

[7] [8]

Uniform Cost Search (UCS)

2 5

1 7

4 5

[5] [2]

[9] [3]

[7] [8]

1 4

[9] [6]

Uniform Cost Search (UCS)

2 5

1 7

4 5

[5] [2]

[9] [3]

[7] [8]

1 4

[9]

Goal state

path cost g(n)=[6]

Uniform Cost Search (UCS)

2 5

1 7

4 5

[5] [2]

[9] [3]

[7] [8]

1 4

[9] [6]

Uniform Cost Search (UCS)

In case of equal step costs, Breadth First search finds the optimal solution.

For any step-cost function, Uniform Cost search expands the node n with the lowest path cost.

UCS takes into account the total cost: g(n).

UCS is guided by path costs rather than depths. Nodes are ordered according to their path cost.

Uniform Cost Search (UCS)

Main idea: Expand the cheapest node. Where the cost is the path cost g(n).

Implementation:

Enqueue nodes in order of cost g(n).

QUEUING-FN:- insert in order of increasing path cost.

Enqueue new node at the appropriate position in the queue so that we dequeue the cheapest node.

Complete? Yes.

Optimal? Yes, if path cost is non decreasing function of depth

Time Complexity: O(bd)

Space Complexity: O(bd), note that every node in the fringe keep in the queue.

Branch and bound search (uniform cost search).

• Cost function g(X) is designed that gives cumulative expense to the path from start node to the current node X.

• Least cost path obtained to far is expanded at each iteration till we reach to the Goal State

• There can be incomplete paths as the shortest one is always extended one level further.

• Can create as many new incomplete paths

Algorithm: Branch and Bound Input: START and GOAL states Local variables: OPEN, CLOSED, NODE, SUCCs, FOUND; OUTPUT: Yes Or No Method: • Initially store the root node with g(root)=0 in a open list and CLOSED= and FOUND= false; • While(OPEN≠ and FOUND= false) do { • Remove the top element from OPEN and call it NODE; • If NODE= GOAL Node then FOUND= true else • { • Put NODE in closed list: • Find SUCC’s of NODE. If any and compute their ‘g’ values and store them in OPEN list • Sort all the nodes in the open list based on their cost function values: } } /* end of while*/ If FOUND= true then return Yes else return No • Stop

A* Search

eval-fn: f(n)=g(n)+h(n)

Informed Search Strategies

A* (A Star)

• Greedy Search minimizes a heuristic h(n) which is an estimated cost from a node n to the goal state. However, although greedy search can considerably cut the search time (efficient), it is neither optimal nor complete.

• Uniform Cost Search minimizes the cost g(n) from the initial state to n. UCS is optimal and complete but not efficient.

• New Strategy: Combine Greedy Search and UCS to get an efficient algorithm which is complete and optimal.

A* (A Star)

• A* uses a heuristic function which combines g(n) and h(n): f(n) = g(n) + h(n)

• g(n) is the exact cost to reach node n from the initial state. Cost so far up to node n.

• h(n) is an estimation of the remaining cost to reach the goal.

A* (A Star)

n

g(n)

h(n)

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

A* Search

State Heuristic: h(n)

A 366

B 374

C 329

D 244

E 253

F 178

G 193

H 98

I 0

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

g(n): is the exact cost to reach node n from the initial state.

A

B

D

C

E

F

I

99

211

G

H

80

Start

Goal

97

101

75 118

111

140

A* Search: Tree Search

A Start

A* Search: Tree Search

A

B C E

Start

75 118 140

[393] [449] [447]

A* Search: Tree Search

A

B C E

F

99

G

80

Start

75 118 140

[393] [449] [447]

[417] [413]

A* Search: Tree Search

A

B C E

F

99

G

80

Start

75 118 140

[393] [449] [447]

[417] [413]

H

97

[415]

A* Search: Tree Search

A

B C E

F

I

99

G

H

80

Start

97

101

75 118 140

[393] [449] [447]

[417] [413]

[415]

Goal [418]

A* Search: Tree Search

A

B C E

F

I

99

G

H

80

Start

97

101

75 118 140

[393] [449] [447]

[417] [413]

[415]

Goal [418]

I [450]

A* Search: Tree Search

A

B C E

F

I

99

G

H

80

Start

97

101

75 118 140

[393] [449] [447]

[417] [413]

[415]

Goal [418]

I [450]

A* Search: Tree Search

A

B C E

F

I

99

G

H

80

Start

97

101

75 118 140

[393] [449] [447]

[417] [413]

[415]

Goal [418]

I [450]

h() overestimates the cost to reach the goal state

A* with h() not Admissible

A* Search: h not admissible !

State Heuristic: h(n)

A 366

B 374

C 329

D 244

E 253

F 178

G 193

H 138

I 0

A

B

D

C

E

F

I

99

211

G

H

80

Start

Goal

97

101

75 118

111

f(n) = g(n) + h (n) – (H-I) Overestimated

g(n): is the exact cost to reach node n from the initial state.

140

A* Search: Tree Search

A Start

A* Search: Tree Search

A

B C E

Start

75 118 140

[393] [449] [447]

A* Search: Tree Search

A

B C E

F

99

G

80

Start

75 118 140

[393] [449] [447]

[417] [413]

A* Search: Tree Search

A

B C E

F

99

G

80

Start

75 118 140

[393] [449] [447]

[417] [413]

H

97

[455]

A* Search: Tree Search

A

B C E

F

99

G

H

80

Start

97

75 118 140

[393] [449] [447]

[417] [413]

[455] Goal I [450]

A* Search: Tree Search

A

B C E

F

99

G

H

80

Start

97

75 118 140

[393] [449] [447]

[417] [413]

[455] Goal I [450]

D [473]

A* Search: Tree Search

A

B C E

F

99

G

H

80

Start

97

75 118 140

[393] [449] [447]

[417] [413]

[455] Goal I [450]

D [473]

A* Search: Tree Search

A

B C E

F

99

G

H

80

Start

97

75 118 140

[393] [449] [447]

[417] [413]

[455] Goal I [450]

D [473]

A* Search: Tree Search

A

B C E

F

99

G

H

80

Start

97

75 118 140

[393] [449] [447]

[417] [413]

[455] Goal I [450]

D [473]

A* not optimal !!!

A* Search: Analysis

A

B

D

C

E

F

I

99

211

G

H

80

Start

Goal

97

101

75 118

111

140

•A* is complete except if there is an infinity of nodes with f < f(G).

•A* is optimal if heuristic h is admissible.

•Time complexity depends on the quality of heuristic but is still exponential.

•For space complexity, A* keeps all nodes in memory. A* has worst case O(bd) space complexity, but an iterative deepening version is possible (IDA*).

A* Algorithm 1. Search queue Q is empty.

2. Place the start state s in Q with f value h(s).

3. If Q is empty, return failure.

4. Take node n from Q with lowest f value.

(Keep Q sorted by f values and pick the first element).

5. If n is a goal node, stop and return solution.

6. Generate successors of node n.

7. For each successor n’ of n do:

a) Compute f(n’) = g(n) + cost(n,n’) + h(n’).

b) If n’ is new (never generated before), add n’ to Q.

c) If node n’ is already in Q with a higher f value, replace it with current f(n’) and place it in sorted order in Q.

End for

8. Go back to step 3.

Iterative Deepening A*

Informed Search Strategies

Iterative Deepening A*:IDA*

• Use f(N) = g(N) + h(N) with admissible and consistent h

• Each iteration is depth-first with cutoff on the value of f of expanded nodes

Consistent Heuristic

• The admissible heuristic h is consistent (or satisfies the monotone restriction) if for every node N and every successor N’ of N: h(N) c(N,N’) + h(N’) (triangular inequality)

• A consistent heuristic is admissible.

N

N’ h(N)

h(N’)

c(N,N’)

IDA* Algorithm

• In the first iteration, we determine a “f-cost limit” – cut-off value f(n0) = g(n0) + h(n0) = h(n0), where n0 is the start node.

• We expand nodes using the depth-first algorithm and backtrack whenever f(n) for an expanded node n exceeds the cut-off value.

• If this search does not succeed, determine the lowest f-value among the nodes that were visited but not expanded.

• Use this f-value as the new limit value – cut-off value and do another depth-first search.

• Repeat this procedure until a goal node is found.

Hill Climbing

Input: START and GOAL states Local variables: OPEN, CLOSED, NODE, SUCCs, FOUND; OUTPUT: Yes Or No Method: • Initially store the root node in a open list (maintained as stack) FOUND= false; • While(OPEN≠ and FOUND= false) do { • Remove the top element from OPEN and call it NODE; • If NODE= GOAL Node then FOUND= true else { • Find SUCC’s of NODE If any: • Sort SUCC’s by estimated cost from NODE to goal state and add them to the front of OPEN list: } /* end of while*/ If FOUND= true then return Yes else return No • Stop

Hill Climbing: Disadvantages

• Fail to find a solution

• Either Algo may terminate not by finding a goal state but by getting to a state from which no better state can be generated.

• This happen if program reached

– Local maximum,

– Plateau,

– Ridge.

86

87

Hill Climbing: Disadvantages

Local maximum

A state that is better than all of its neighbours, but not better than some other states far away.

88

Hill Climbing: Disadvantages

Plateau

A flat area of the search space in which all neighbouring states have the same value.

• requiring random walk

89

Hill Climbing: Disadvantages

Ridge

Special kind of local maximum.

The orientation of the high region, compared to the set of available moves, makes it impossible to climb up.

Many moves executed serially may increase the height.

90

Hill Climbing: Disadvantages

Ways Out

• Backtrack to some earlier node and try going in a different direction. (good way in dealing with local maxima)

• Make a big jump to try to get in a new section. (good way in dealing with plateaus)

• Moving in several directions at once. (good strategy for dealing with ridges)

91

Hill Climbing: Disadvantages

• Hill climbing is a local method:

Decides what to do next by looking only at the “immediate” consequences of its choices rather than by exhaustively exploring all the consequences.

• Global information might be encoded in heuristic functions.

Beam search Input: START and GOAL states Local variables: OPEN, NODE, SUCC’s, W_OPEN, FOUND; OUTPUT: Yes Or No Method: • NODE= Root_node: FOUND= false: If NODE= GOAL Node then FOUND= true else Find SUCC’s of NODE If any: with estimated cost and store in OPEN list. While(FOUND=False and not able to proceed further) do { • Sort OPEN list: • Select top W elements from OPEN list and put it in W_OPEN list and empty open list: • For each node from W_OPEN list { • If NODE=Goal State then found = true else find SUCC’s of NODE if any with its estimated cost and store in open list } } /* end of while*/ • If FOUND= true then return Yes else return No • Stop

Continue till goal state is found or not able to proceed further

Beam search

Constraint Satisfaction Problems (CSPs)

• Standard search problem:

– state is a "black box“ – any data structure that supports successor function, heuristic function, and goal test

• CSP:

– state is defined by variables Xi with values from domain Di

– goal test is a set of constraints specifying allowable combinations of values for subsets of variables

Constraint Satisfaction

• Constraint Satisfaction problems in AI have goal of discovering some problem state that satisfies a given set of constraints.

• Design tasks can be viewed as constraint satisfaction problems in which a design must be created within fixed limits on time, cost, and materials.

Constraint satisfaction

• Constraint satisfaction is a search procedure that operates in a space of constraint sets. The initial state contains the constraints that are originally given in the problem description. A goal state is any state that has been constrained “enough” where “enough”must be defined for each problem. For example, in cryptarithmetic, enough means that each letter has been assigned a unique numeric value.

• Constraint Satisfaction is a two step process:

– First constraints are discovered and propagated as far as possible throughout the system.

– Then if there still not a solution, search begins. A guess about something is made and added as a new constraint.

97

Constraint Satisfaction: Example

• Cryptarithmetic Problem: SEND

+MORE

-----------

MONEY

Initial State:

• No two letters have the same value

• The sums of the digits must be as shown in the problem

Goal State:

• All letters have been assigned a digit in such a way that all the initial constraints are satisfied.

Cryptasithmetic Problem: Constraint Satisfaction

• The solution process proceeds in cycles. At each cycle, two significant things are done:

1. Constraints are propagated by using rules that correspond to the properties of arithmetic.

2. A value is guessed for some letter whose value is not yet determined.

A few Heuristics can help to select the best guess to try first:

• If there is a letter that has only two possible values and other with six possible values, there is a better chance of guessing right on the first than on the second.

• Another useful Heuristic is that if there is a letter that participates in many constraints then it is a good idea to prefer it to a letter that participates in a few.

Solving a Cryptarithmetic Problem Initial state

M=1

S= 8 or 9

O = 0 or 1 => O =0

N= E or E+1 -> N= E+1

C2 = 1

N+R >8

E≠ 9

N=3

R= 8 or 9

2+D = Y or 2+D = 10 +Y

2+D =Y

N+R = 10+E

R =9

S =8

2+D = 10 +Y

D = 8+Y

D = 8 or 9

Y= 0 ; Conflict Y =1 ; Conflict

E=2

C1= 0 C1= 1

D=8 D=9

SEND

+MORE

-------------

MONEY

Constraint Satisfaction

Two-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.

Constraint Satisfaction

Two kinds of rules:

1. Rules that define valid constraint propagation.

2. Rules that suggest guesses when necessary.

When to Use Search Techniques

• The search space is small, and

– There are no other available techniques, or

– It is not worth the effort to develop a more efficient technique

• The search space is large, and

– There is no other available techniques, and

– There exist “good” heuristics

Conclusions

• Frustration with uninformed search led to the idea of using domain specific knowledge in a search so that one can intelligently explore only the relevant part of the search space that has a good chance of containing the goal state. These new techniques are called informed (heuristic) search strategies.

• Even though heuristics improve the performance of informed search algorithms, they are still time consuming especially for large size instances.

Recommended