informed search algorithms - · pdf filelocal search algorithms • in many optimization...
TRANSCRIPT
![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](https://reader034.vdocument.in/reader034/viewer/2022051720/5a78e2077f8b9aa17b8e083b/html5/thumbnails/1.jpg)
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](https://reader034.vdocument.in/reader034/viewer/2022051720/5a78e2077f8b9aa17b8e083b/html5/thumbnails/2.jpg)
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](https://reader034.vdocument.in/reader034/viewer/2022051720/5a78e2077f8b9aa17b8e083b/html5/thumbnails/3.jpg)
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](https://reader034.vdocument.in/reader034/viewer/2022051720/5a78e2077f8b9aa17b8e083b/html5/thumbnails/4.jpg)
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](https://reader034.vdocument.in/reader034/viewer/2022051720/5a78e2077f8b9aa17b8e083b/html5/thumbnails/5.jpg)
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](https://reader034.vdocument.in/reader034/viewer/2022051720/5a78e2077f8b9aa17b8e083b/html5/thumbnails/6.jpg)
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](https://reader034.vdocument.in/reader034/viewer/2022051720/5a78e2077f8b9aa17b8e083b/html5/thumbnails/7.jpg)
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](https://reader034.vdocument.in/reader034/viewer/2022051720/5a78e2077f8b9aa17b8e083b/html5/thumbnails/8.jpg)
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](https://reader034.vdocument.in/reader034/viewer/2022051720/5a78e2077f8b9aa17b8e083b/html5/thumbnails/9.jpg)
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](https://reader034.vdocument.in/reader034/viewer/2022051720/5a78e2077f8b9aa17b8e083b/html5/thumbnails/10.jpg)
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](https://reader034.vdocument.in/reader034/viewer/2022051720/5a78e2077f8b9aa17b8e083b/html5/thumbnails/11.jpg)
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](https://reader034.vdocument.in/reader034/viewer/2022051720/5a78e2077f8b9aa17b8e083b/html5/thumbnails/12.jpg)
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](https://reader034.vdocument.in/reader034/viewer/2022051720/5a78e2077f8b9aa17b8e083b/html5/thumbnails/13.jpg)
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](https://reader034.vdocument.in/reader034/viewer/2022051720/5a78e2077f8b9aa17b8e083b/html5/thumbnails/14.jpg)
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](https://reader034.vdocument.in/reader034/viewer/2022051720/5a78e2077f8b9aa17b8e083b/html5/thumbnails/15.jpg)
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](https://reader034.vdocument.in/reader034/viewer/2022051720/5a78e2077f8b9aa17b8e083b/html5/thumbnails/16.jpg)
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](https://reader034.vdocument.in/reader034/viewer/2022051720/5a78e2077f8b9aa17b8e083b/html5/thumbnails/17.jpg)
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](https://reader034.vdocument.in/reader034/viewer/2022051720/5a78e2077f8b9aa17b8e083b/html5/thumbnails/18.jpg)
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](https://reader034.vdocument.in/reader034/viewer/2022051720/5a78e2077f8b9aa17b8e083b/html5/thumbnails/19.jpg)
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](https://reader034.vdocument.in/reader034/viewer/2022051720/5a78e2077f8b9aa17b8e083b/html5/thumbnails/20.jpg)
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](https://reader034.vdocument.in/reader034/viewer/2022051720/5a78e2077f8b9aa17b8e083b/html5/thumbnails/21.jpg)
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](https://reader034.vdocument.in/reader034/viewer/2022051720/5a78e2077f8b9aa17b8e083b/html5/thumbnails/22.jpg)
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](https://reader034.vdocument.in/reader034/viewer/2022051720/5a78e2077f8b9aa17b8e083b/html5/thumbnails/23.jpg)
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](https://reader034.vdocument.in/reader034/viewer/2022051720/5a78e2077f8b9aa17b8e083b/html5/thumbnails/24.jpg)
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](https://reader034.vdocument.in/reader034/viewer/2022051720/5a78e2077f8b9aa17b8e083b/html5/thumbnails/25.jpg)
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](https://reader034.vdocument.in/reader034/viewer/2022051720/5a78e2077f8b9aa17b8e083b/html5/thumbnails/26.jpg)
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](https://reader034.vdocument.in/reader034/viewer/2022051720/5a78e2077f8b9aa17b8e083b/html5/thumbnails/27.jpg)
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](https://reader034.vdocument.in/reader034/viewer/2022051720/5a78e2077f8b9aa17b8e083b/html5/thumbnails/28.jpg)
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](https://reader034.vdocument.in/reader034/viewer/2022051720/5a78e2077f8b9aa17b8e083b/html5/thumbnails/29.jpg)
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](https://reader034.vdocument.in/reader034/viewer/2022051720/5a78e2077f8b9aa17b8e083b/html5/thumbnails/30.jpg)
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](https://reader034.vdocument.in/reader034/viewer/2022051720/5a78e2077f8b9aa17b8e083b/html5/thumbnails/31.jpg)
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](https://reader034.vdocument.in/reader034/viewer/2022051720/5a78e2077f8b9aa17b8e083b/html5/thumbnails/32.jpg)
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](https://reader034.vdocument.in/reader034/viewer/2022051720/5a78e2077f8b9aa17b8e083b/html5/thumbnails/33.jpg)
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](https://reader034.vdocument.in/reader034/viewer/2022051720/5a78e2077f8b9aa17b8e083b/html5/thumbnails/34.jpg)
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](https://reader034.vdocument.in/reader034/viewer/2022051720/5a78e2077f8b9aa17b8e083b/html5/thumbnails/35.jpg)
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](https://reader034.vdocument.in/reader034/viewer/2022051720/5a78e2077f8b9aa17b8e083b/html5/thumbnails/36.jpg)
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](https://reader034.vdocument.in/reader034/viewer/2022051720/5a78e2077f8b9aa17b8e083b/html5/thumbnails/37.jpg)
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](https://reader034.vdocument.in/reader034/viewer/2022051720/5a78e2077f8b9aa17b8e083b/html5/thumbnails/38.jpg)
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](https://reader034.vdocument.in/reader034/viewer/2022051720/5a78e2077f8b9aa17b8e083b/html5/thumbnails/39.jpg)
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](https://reader034.vdocument.in/reader034/viewer/2022051720/5a78e2077f8b9aa17b8e083b/html5/thumbnails/40.jpg)
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](https://reader034.vdocument.in/reader034/viewer/2022051720/5a78e2077f8b9aa17b8e083b/html5/thumbnails/41.jpg)
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](https://reader034.vdocument.in/reader034/viewer/2022051720/5a78e2077f8b9aa17b8e083b/html5/thumbnails/42.jpg)
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](https://reader034.vdocument.in/reader034/viewer/2022051720/5a78e2077f8b9aa17b8e083b/html5/thumbnails/43.jpg)
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](https://reader034.vdocument.in/reader034/viewer/2022051720/5a78e2077f8b9aa17b8e083b/html5/thumbnails/44.jpg)
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](https://reader034.vdocument.in/reader034/viewer/2022051720/5a78e2077f8b9aa17b8e083b/html5/thumbnails/45.jpg)
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](https://reader034.vdocument.in/reader034/viewer/2022051720/5a78e2077f8b9aa17b8e083b/html5/thumbnails/46.jpg)
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](https://reader034.vdocument.in/reader034/viewer/2022051720/5a78e2077f8b9aa17b8e083b/html5/thumbnails/47.jpg)
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