Search SONG Xinying 2007.04.08. Outline Introduction Search strategies Optimization and pruning Some...
-
Upload
spencer-spencer -
Category
Documents
-
view
219 -
download
1
description
Transcript of Search SONG Xinying 2007.04.08. Outline Introduction Search strategies Optimization and pruning Some...
Search
SONG Xinying2007.04.08
Outline Introduction Search strategies Optimization and pruning Some problems
Outline Introduction Search strategies Optimization and pruning Some problems
Solving problems by search A problem:
Initial state Actions or successor function Goal test Step cost and path cost (additive)
A solution: A sequence of actions leading from the
initial state to a goal state Conversions in this PPT:
Step cost >= 0 An optimal solution is one with the minimal
path cost
General search algorithm (GSA) An implicit state tree is defined by
Initial state Successor function
Basic idea: exploring the state space Visit a state Generate all successors (expanding
states) Repeat until a goal is found
Implementation: states vs. nodes A state is a representation of
a physical configuration A node is a data structure, consisting of
state, parent node, action, path cost, depth The Expand function creates new nodes, filling in the various fields and using the SuccessorFn of the problem to create the corresponding states.
Tree search vs. Graph search Repeated states problem
Failure to detect repeated states can turn a linear problem into an exponential one!
Whether or not to detect repeated state when expanding new nodes Do not: Tree search Do: Graph search, hash table is often required
Which one to use? Differs in various problems
General tree search
General graph search
Performance evaluation Completeness
Does it always find a solution if one exists? Optimality
Does it always return an optimal solution? Time complexity
Number of nodes generated Space complexity
Maximum number of nodes in memory
Considerations about GSA Which state to visit and expand?
Search strategy is defined by the order of node expansion
How to make the tree generated small? Choose among various search
strategies Optimization and pruning
Outline Introduction Search strategies Optimization and pruning Some problems
Search strategy family Breadth first search
Bidirectional search (*) Depth first search
Depth limited search Iterative deepening search (*) Hill climbing search
Best first search Uniform cost search Gready best first search A* search (*)
Breadth first search Fringe is a FIFO queue Properties
Complete? Yes Optimal? Yes (if step cost = 1) Time? Exponential Space? Exponential
Space is a bigger problem than time ~ is indeed a special case of A* search
Bidirectional search Algorithm
Runs two simultaneous breadth first searches One forward from the initial state One backward from the goal state
Stops when the two searches meet in the middle Properties
Time: O(bd/2), compared with O(bd) of BFS Constraints
Membership check, hash table and space problem Goal state is known explicitly Actions are reversible
Depth first search Fringe is a LIFO queue, i.e., a stack Properties
Complete? No Optimal? No Time? Exponential Space? Linear!
Depth limited search Depth first search with depth limit L
Iterative Deepening search Algorithm
Iteratively employ depth limited search Depth limit L increases in each iteration
Properties Complete? Yes, the same as BFS Optimal? Yes, the same as BFS Time? Exponential, not much more than BFS Space? Linear, much better than BFS
~ is often preferred to BFS thus
Hill climbing search Algorithm
Depth first search Each time, the best successor is
generated first Properties
A kind of greedy choice Maybe just a bit better than DFS No optimality is guaranteed
Best first search Fringe is a priority queue
Assign an evaluation function f(n) to each node Select the node with the lowest f(n) to expand
In fact, ~ means “seemingly best first search” Different choices of f(n) lead to different kind of ~
Uniform cost search f(n) = g(n)
g(n): cost so far to reach the node n Properties
Complete? Yes Optimal? Yes Time? Exponential Space? Exponential
Dijkstra Algorithm, which can be better, BFS is a special case of ~ if step cost is equal ~ is a special case of A* search
Greedy best first search f(n) = h(n)
h(n) (heuristic): estimated cost from n to a goal Properties
Complete? No Optimal? No Time? Exponential Space? Exponential
~ tries to expand the node that appears to be closest to the goal ~ resembles DFS to some extent
A* search f(n) = g(n) + h(n) ~ tries to minimize the total estimated solution cost Properties
both complete and optimal, provided the heuristic function h(n) satisfies certain conditions Time and Space complexity: Exponential
~ is regarded as the best search algorithm optimally efficient for any given heuristic function. no other optimal algorithm is guaranteed to expand fewer nodes than ~
Admissible heuristics A heuristic h(n) is admissible
if for every node n, h(n) ≤ h*(n), where h*(n) is the true cost to reach the goal state from n. means never over estimating the cost to reach the goal
Theorem: If h(n) is admissible, A* using TREE-SEARCH is optimal once a goal is selected to expand, the optimal solution has been found we can return safely without no more search
Consistent heuristics A heuristic is consistent
if for every node n, every successor n' of n generated by any action a, h(n) ≤ c(n,a,n') + h(n') means f(n) is non-decreasing along any path is also admissible
Theorem: If h(n) is consistent, A* using GRAPH-SEARCH is optimal once any node n is selected to expand, the optimal path to n has been found no state is needed to expanded many times
Optimality of A* with consistent heuristics A* expands nodes in order of increasing f value Gradually adds "f-contours" of nodes
A back view BFS and Uniform cost search is a special case of A* when h(n) = 0 The zero heuristic
is consistent however, contains little useful information
We can conclude that a larger heuristic provided that it is admissible or consistent makes search more efficient
Example: 8-puzzle Two heuristics
h1(n) = number of misplaced tiles h2(n) = total Manhattan distance
h2(n) >= h1(n), h2 is better for search
Ways to obtain good heuristics – Relaxed problems A problem with fewer restrictions on the
actions is called ~ The cost of an optimal solution to a
relaxed problem is a consistent heuristic for the original problem
E.g., in 8-puzzle problem If the rules of the 8-puzzle are relaxed so
that a tile can move anywhere, then h1(n) gives the shortest solution
If the rules are relaxed so that a tile can move to any adjacent square, then h2(n) gives the shortest solution
Ways to obtain good heuristics – Subproblems The solution cost of a subproblem gives a consistent heuristic Store the exact solution costs for every possible subproblem instance E.g., in 8-puzzle problem
The subproblem involves getting tiles 1, 2, 3, 4 into their correct position
Ways to obtain good heuristics – Machine learning Learning heuristics from
experience ~ will be omitted here
Ways to obtain good heuristics – Combine multiple heuristics If we have a collection of admissible heuristics h1, h2, …, hm We can define for any node n
h(n) = max{h1(n), …, hm(n)} h(n) is
Admissible if all h1, …, hm are admissible Consistent if all h1, …, hm are consistent Better than any single heuristic hi
Memory bounded heuristic search A* search suffers from huge space demand Solutions
Iterative Deepening A* (IDA*) Recursive best first search (RBFS) Memory bounded A* (MA*) and simplified MA*
(SMA*) Discussions
All are weaker than A* because of lack of repeated state detection
RBFS* and MA* are regarded better than IDA*
Outline Introduction Search strategies Optimization and pruning Some problems
Criteria Correctness
No correct branches should be cut Sufficiency
Useless branches should be cut as many as possible
Efficiency The cost of operations of pruning
itself must be considered There is a trade-off here
Strategies overview Feasibility pruning Optimality pruning Overlap pruning Memorized search Search order organization Pre-processing Halting of pruning
Feasibility pruning Cut the illegal branches
Make sure each action do not contradict prior ones (look behind)
Make sure the current branch do lead to a feasible solution (look ahead)
Optimality pruning Gain a bound of optimal solution
Pre-calculus or estimate a feasible solution Or a feasible solution has been found
Cut the bad branches The cost so far has exceeded already (look
behind) The branches will surely lead to a worse
solution, i.e., an estimation (look ahead) A* is indeed a terrific paradigm of this
Overlap pruning Avoid doing the same search again
Detect the same subtree in state space Refuse to search again or fetch the result from memorized table Carefully do not search a path from head to tail, and then from tail to head from tree search to graph search in some problem
Memorized search A most important kind of overlap pruning
Memorize solution to each subtree Fetch the result from table The power set of state space is often required, represented by a binary number
~ is an implicit and hidden version of Dynamic Programming, so called the “state DP”
Search order organization ~ enables us to find a solution faster The same restriction performs better at nearer nodes from root Search the following elements first
having fewer legal action choices having greater impacts on latter ones
A pre-processing of sort is usually employed on the original data set
Pre-processing Serves other optimization and pruning
techniques Pre-sort the data set Pre-estimate solution range Pre-determinate some facts, e.g., feasible?
Pre-processing vs. Real-time processing More efficient Somewhat static and weak Make the trade-off
Halting of pruning Pruning itself consumes time
Maintain pruning information Calculate pruning value Compare and make decision
We should stop pruning operations when we are near the bottom of the search tree
Sometimes, ~ is crucial
Outline Introduction Search strategies Optimization and pruning Some problems
Some problems HOJ 1299 New Go Game POJ 2441 Arrange the Bulls
HOJ 1299 New Go Game Given the numbers of stone on each
row, column and diagonal line, rebuild the board. (size <= 15)
Sample Input1 3 2 3 10 2 2 2 40 0 1 3 0 2 2 1 10 0 0 2 3 2 1 2 0
Solution Pre-processing
Organize a cyclic search order Initialize a deg[], indicting stones still needed to put on each line Initialize a bla[], indicting blanks available on each line
Feasible pruning Before action = “use”, make sure each deg[i]>0, i.e., “look behind” Before action = “not use”, make sure each bla[i]>=deg[i], i.e., “look ahead”
POJ 2241 Arranging the Bulls Find how many matches are there
in a bipartite graph, covering all nodes in the left. N, M<=20 Result <= 107
Sample Result = 4
Search with pruning Sort nodes ordered by increasing
degrees Feasible pruning: in remaining graph
No nodes with 0 degrees in the left Nodes with >0 degrees in the right
should be more than those in the left Pruning Halts
When left nodes <= 6
Memorized search (state DP) State space is the power set of right nodes, i.e., 220.
int b[1<<20]; b[x20x19…x2x1], where xi = {0,1}
Solution to subtree when j nodes of right is used to match node 1 to j of left When facing such a subtree, just search and memorize it, or fetch it in future
Recommended Problems See HOJ forum,
http://acm.hit.edu.cn/forum/viewtopic.php?t=324
Summary Solving problems by search
Requires exponential time usually Should be the last choice
Pick the right search strategy according to your problem
Design your optimization and pruning techniques carefully and thoroughly
References Russell S, Norving P, Artificial Intelligence: A
Modern Approach, Pearson Eduction, 2003 马少平 , 朱小燕 . 人工智能 . 清华大学出版社 . 2004 刘汝佳 , 黄亮 . 算法艺术与信息学竞赛 . 清华大学出版社 . 2004 HIT Online Judge. http://acm.hit.edu.cn PKU Online Judge. http://acm.pku.edu.cn
The End Thank you.