Informed search algorithms - · PDF fileLocal search algorithms • In many optimization...

47
Informed search algorithms

Transcript of Informed search algorithms - · PDF fileLocal search algorithms • In many optimization...

Page 1: Informed search algorithms -  · PDF fileLocal search algorithms • In many optimization problems, the path to the goal is irrelevant; the goal state itself is the solution

Informed search algorithms

Page 2: Informed search algorithms -  · PDF fileLocal search algorithms • In many optimization problems, the path to the goal is irrelevant; the goal state itself is the solution

Outline

• Best-first search

• Greedy best-first search

• A* search

• Heuristics

• Local search algorithms

• Hill-climbing search

Page 3: Informed search algorithms -  · PDF fileLocal search algorithms • In many optimization problems, the path to the goal is irrelevant; the goal state itself is the solution

Best-first search

• Idea: use an evaluation function f(n) for each node – estimate of "desirability« -istenme derecesi-

Expand most desirable unexpanded node

• Implementation:

Order the nodes in fringe in decreasing order of desirability

• Special cases: – greedy best-first search

– A* search

Page 4: Informed search algorithms -  · PDF fileLocal search algorithms • In many optimization problems, the path to the goal is irrelevant; the goal state itself is the solution

Romania with step costs in km

Page 5: Informed search algorithms -  · PDF fileLocal search algorithms • In many optimization problems, the path to the goal is irrelevant; the goal state itself is the solution

Greedy best-first search

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

• = estimate of cost from n to goal

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

to Bucharest

• Greedy best-first search expands the node

that appears to be closest to goal

Page 6: Informed search algorithms -  · PDF fileLocal search algorithms • In many optimization problems, the path to the goal is irrelevant; the goal state itself is the solution

Greedy best-first search

example

Page 7: Informed search algorithms -  · PDF fileLocal search algorithms • In many optimization problems, the path to the goal is irrelevant; the goal state itself is the solution

Greedy best-first search

example

Page 8: Informed search algorithms -  · PDF fileLocal search algorithms • In many optimization problems, the path to the goal is irrelevant; the goal state itself is the solution

Greedy best-first search

example

Page 9: Informed search algorithms -  · PDF fileLocal search algorithms • In many optimization problems, the path to the goal is irrelevant; the goal state itself is the solution

Greedy best-first search

example

Page 10: Informed search algorithms -  · PDF fileLocal search algorithms • In many optimization problems, the path to the goal is irrelevant; the goal state itself is the solution

Properties of greedy best-first

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

Neamt Iasi Neamt

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

dramatic improvement

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

• Optimal? No

Page 11: Informed search algorithms -  · PDF fileLocal search algorithms • In many optimization problems, the path to the goal is irrelevant; the goal state itself is the solution

A* search

• Idea: avoid expanding paths that are already

expensive

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

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

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

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

goal

Page 12: Informed search algorithms -  · PDF fileLocal search algorithms • In many optimization problems, the path to the goal is irrelevant; the goal state itself is the solution

A* search example

Page 13: Informed search algorithms -  · PDF fileLocal search algorithms • In many optimization problems, the path to the goal is irrelevant; the goal state itself is the solution

A* search example

Page 14: Informed search algorithms -  · PDF fileLocal search algorithms • In many optimization problems, the path to the goal is irrelevant; the goal state itself is the solution

A* search example

Page 15: Informed search algorithms -  · PDF fileLocal search algorithms • In many optimization problems, the path to the goal is irrelevant; the goal state itself is the solution

A* search example

Page 16: Informed search algorithms -  · PDF fileLocal search algorithms • In many optimization problems, the path to the goal is irrelevant; the goal state itself is the solution

A* search example

Page 17: Informed search algorithms -  · PDF fileLocal search algorithms • In many optimization problems, the path to the goal is irrelevant; the goal state itself is the solution

A* search example

Page 18: Informed search algorithms -  · PDF fileLocal search algorithms • In many optimization problems, the path to the goal is irrelevant; the goal state itself is the solution

Admissible heuristics

• A heuristic h(n) is admissible – kabul edilebilir - if for every node n,

h(n) ≤ h*(n), where h*(n) is the true cost to reach the goal state from

n.

• An admissible heuristic never overestimates – fazla tahmin etmez -

the cost to reach the goal, i.e., it is optimistic

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

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

Page 19: Informed search algorithms -  · PDF fileLocal search algorithms • In many optimization problems, the path to the goal is irrelevant; the goal state itself is the solution

Properties of A*

• Complete? Yes (unless there are infinitely many nodes

with f ≤ f(G) )

• Time? Exponential

• Space? Keeps all nodes in memory

• Optimal? Yes

Page 20: Informed search algorithms -  · PDF fileLocal search algorithms • In many optimization problems, the path to the goal is irrelevant; the goal state itself is the solution

Admissible heuristics

E.g., for the 8-puzzle:

• h1(n) = number of misplaced tiles

• h2(n) = total Manhattan distance

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

• h1(S) = ?

• h2(S) = ?

Page 21: Informed search algorithms -  · PDF fileLocal search algorithms • In many optimization problems, the path to the goal is irrelevant; the goal state itself is the solution

Admissible heuristics

E.g., for the 8-puzzle:

• h1(n) = number of misplaced tiles

• h2(n) = total Manhattan distance

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

• h1(S) = ? 8

• h2(S) = ? 3+1+2+2+2+3+3+2 = 18

Page 22: Informed search algorithms -  · PDF fileLocal search algorithms • In many optimization problems, the path to the goal is irrelevant; the goal state itself is the solution

Relaxed problems

• A problem with fewer restrictions on the actions is called a relaxed problem

• The cost of an optimal solution to a relaxed problem is an admissible heuristic for the original problem

Page 23: Informed search algorithms -  · PDF fileLocal search algorithms • In many optimization problems, the path to the goal is irrelevant; the goal state itself is the solution

Local search algorithms

• In many optimization problems, the path to the goal is irrelevant; the goal state itself is the solution

• State space = set of "complete" configurations

• Find configuration satisfying constraints, e.g., n-queens

• In such cases, we can use local search algorithms

• keep a single "current" state, try to improve it

Page 24: Informed search algorithms -  · PDF fileLocal search algorithms • In many optimization problems, the path to the goal is irrelevant; the goal state itself is the solution

Example: n-queens

• Put n queens on an n × n board with no

two queens on the same row, column, or

diagonal

Page 25: Informed search algorithms -  · PDF fileLocal search algorithms • In many optimization problems, the path to the goal is irrelevant; the goal state itself is the solution

Hill-climbing search

• "Like climbing Everest in thick fog with

amnesia"

Page 26: Informed search algorithms -  · PDF fileLocal search algorithms • In many optimization problems, the path to the goal is irrelevant; the goal state itself is the solution

Hill-climbing search

• Problem: depending on initial state, can

get stuck in local maxima

Page 27: Informed search algorithms -  · PDF fileLocal search algorithms • In many optimization problems, the path to the goal is irrelevant; the goal state itself is the solution

Hill-climbing search: 8-queens problem

• h = number of pairs of queens that are attacking each other, either directly

or indirectly

• h = 17 for the above state

Page 28: Informed search algorithms -  · PDF fileLocal search algorithms • In many optimization problems, the path to the goal is irrelevant; the goal state itself is the solution

Hill-climbing search: 8-queens problem

• A local minimum with h = 1

Page 29: Informed search algorithms -  · PDF fileLocal search algorithms • In many optimization problems, the path to the goal is irrelevant; the goal state itself is the solution

Constraint Satisfaction

Problems

Page 30: Informed search algorithms -  · PDF fileLocal search algorithms • In many optimization problems, the path to the goal is irrelevant; the goal state itself is the solution

Outline

• Constraint Satisfaction Problems (CSP)

• Backtracking search for CSPs

Page 31: Informed search algorithms -  · PDF fileLocal search algorithms • In many optimization problems, the path to the goal is irrelevant; the goal state itself is the solution

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

• Allows useful general-purpose algorithms with more power than standard search algorithms

Page 32: Informed search algorithms -  · PDF fileLocal search algorithms • In many optimization problems, the path to the goal is irrelevant; the goal state itself is the solution

Example: Map-Coloring

• Variables WA, NT, Q, NSW, V, SA, T

• Domains Di = {red,green,blue}

• Constraints: adjacent regions must have different colors

• e.g., WA ≠ NT, or (WA,NT) in {(red,green),(red,blue),(green,red), (green,blue),(blue,red),(blue,green)}

Page 33: Informed search algorithms -  · PDF fileLocal search algorithms • In many optimization problems, the path to the goal is irrelevant; the goal state itself is the solution

Example: Map-Coloring

• Solutions are complete and consistent

assignments, e.g., WA = red, NT = green,Q =

red,NSW = green,V = red,SA = blue,T = green

Page 34: Informed search algorithms -  · PDF fileLocal search algorithms • In many optimization problems, the path to the goal is irrelevant; the goal state itself is the solution

Constraint graph

• Constraint graph: nodes are variables, arcs are constraints

Page 35: Informed search algorithms -  · PDF fileLocal search algorithms • In many optimization problems, the path to the goal is irrelevant; the goal state itself is the solution

Real-world CSPs

• Assignment problems – e.g., who teaches what class

• Timetabling problems

• – e.g., which class is offered when and where?

• Transportation scheduling

• Factory scheduling

• Notice that many real-world problems involve real-valued variables

Page 36: Informed search algorithms -  · PDF fileLocal search algorithms • In many optimization problems, the path to the goal is irrelevant; the goal state itself is the solution

Standard search formulation (incremental)

Let's start with the straightforward approach, then fix it

States are defined by the values assigned so far

• Initial state: the empty assignment { }

• Successor function: assign a value to an unassigned variable that does not conflict with current assignment fail if no legal assignments

• Goal test: the current assignment is complete

1. This is the same for all CSPs

2. Every solution appears at depth n with n variables use depth-first search

3. Path is irrelevant, so can also use complete-state formulation

Page 37: Informed search algorithms -  · PDF fileLocal search algorithms • In many optimization problems, the path to the goal is irrelevant; the goal state itself is the solution

Backtracking search

• Variable assignments are commutative - değişmeli}, i.e.,

[ WA = red then NT = green ] same as [ NT = green then WA = red ]

• It repeatedly chooses an unassigned variable and then tries all values in the domain of that variable in turn, trying to find a solution.

• Backtracking search is the basic uninformed algorithm for CSPs

Page 38: Informed search algorithms -  · PDF fileLocal search algorithms • In many optimization problems, the path to the goal is irrelevant; the goal state itself is the solution

Backtracking search

Page 39: Informed search algorithms -  · PDF fileLocal search algorithms • In many optimization problems, the path to the goal is irrelevant; the goal state itself is the solution

Backtracking example

Page 40: Informed search algorithms -  · PDF fileLocal search algorithms • In many optimization problems, the path to the goal is irrelevant; the goal state itself is the solution

Backtracking example

Page 41: Informed search algorithms -  · PDF fileLocal search algorithms • In many optimization problems, the path to the goal is irrelevant; the goal state itself is the solution

Backtracking example

Page 42: Informed search algorithms -  · PDF fileLocal search algorithms • In many optimization problems, the path to the goal is irrelevant; the goal state itself is the solution

Backtracking example

Page 43: Informed search algorithms -  · PDF fileLocal search algorithms • In many optimization problems, the path to the goal is irrelevant; the goal state itself is the solution

Improving backtracking efficiency

• General-purpose methods can give huge

gains in speed:

– Which variable should be assigned next?

– In what order should its values be tried?

– Can we detect inevitable failure early?

Page 44: Informed search algorithms -  · PDF fileLocal search algorithms • In many optimization problems, the path to the goal is irrelevant; the goal state itself is the solution

Most constrained variable

• Most constrained variable:

choose the variable with the fewest legal values

• a.k.a. minimum remaining values (MRV)

heuristic

Page 45: Informed search algorithms -  · PDF fileLocal search algorithms • In many optimization problems, the path to the goal is irrelevant; the goal state itself is the solution

Most constraining variable

• Most constraining variable:

• choose the variable with the most

constraints on remaining variables

Page 46: Informed search algorithms -  · PDF fileLocal search algorithms • In many optimization problems, the path to the goal is irrelevant; the goal state itself is the solution

Least constraining value

• Given a variable, choose the least constraining value:

– the one that rules out the fewest values in the remaining

variables

• Combining these heuristics makes 1000 queens feasible

Page 47: Informed search algorithms -  · PDF fileLocal search algorithms • In many optimization problems, the path to the goal is irrelevant; the goal state itself is the solution

Summary

• CSPs are a special kind of problem:

– states defined by values of a fixed set of variables

– goal test defined by constraints on variable values

• Backtracking = depth-first search with one variable assigned per node

• Variable ordering and value selection heuristics help significantly