c m m awais (lums)1 search methods state space search heuristic search
Post on 22-Dec-2015
220 views
TRANSCRIPT
c M M Awais (LUMS) 2
SEARCH
Introduction:-
• If the general idea and action is known
• The actions that lead to solution is not known
• search methods can be applied
examples:-
• Systematical steps that lead to prove certain theorems
• Sequence of steps that solve a puzzle
c M M Awais (LUMS) 3
BASIC METHODS
(Through all possible actions)
Initial State
Target State
Background
Material required is “GRAPH THEORY”
c M M Awais (LUMS) 4
TYPICAL EXAMPLES OF
SEARCH PROBLEMS
• Toy Problem (The 8 puzzle)
• Route Finding
• Traveling Save Person
• Robot Navigation
• Assembly Sequencing
c M M Awais (LUMS) 7
Suppose Initial State is Library
Goal State is University
Possible Route ?
Problem is simple so all possible paths can be searched systematically to reach the goal
Library via Hospital via newsagent
to
University
What happens if search space is complex ?
c M M Awais (LUMS) 8
ANALYSIS OF SEARCH STRATEGIES
Completeness: is the strategy guaranteed to find a solution where there is one?
Time Complexity: How long does it take to find a solution?
Space Complexity: How much memory does it need to perform the search?
Optimality: Does the strategy find the highest quality solution when there are several different solutions?
c M M Awais (LUMS) 9
Exhaustive Search
One can systematically check every state that is reachable from initial state to end out if it is a goal state.
Search Space
The set of all states is the search space
• For simple/small search space exhaustive search is applicable [BRUTE FORCE or BLIND SEARCH]
• For complex search space HEURISTIC SEARCH is used
c M M Awais (LUMS) 10
GRAPHS AND TREES
Graphs:-
• Consist of a set of nodes with links between them
• links can be directed / undirected
• Path is the sequence of nodes connected nodes via links.
Acyclic graphs = (Paths linking a node
with itself are absent)
Trees???
c M M Awais (LUMS) 11
Tree:-
A tree is a special kind of graph with only one path to each node, usually represented with a special root node at
the top
Relationship between nodes
• Parent
• Children
• Sibling
Ancestor Node, Descendant Node, Leaf Node
c M M Awais (LUMS) 12
Graphs VS Trees
• Compare the searches in the two (which is efficient)
a
b
c
d a
b c
de f g
c M M Awais (LUMS) 13
Type of searches
• What is the value of profit if sales,employees, expenses etc., are given?.
• For a given profit what level of sales,employees, expenses etc., are required
c M M Awais (LUMS) 14
STRATEGIES FOR STATE SPACE SEARCH
DATA DRIVEN SEARCH
(Forward Chaining)
• Start with some given facts
• Set of legal moves are given
• Search proceeds by applying rules to facts to generate new facts
• Process continues unless goal is reached
c M M Awais (LUMS) 15
Goal - Driven Search (Backward Chaining)
• Take the goal
• Find what conditions or rules can produce or generate the goal
• Apply the conditions to generate subgoals
• Continue until the goal is reached
c M M Awais (LUMS) 19
1. Start with queue = [initial - state] and found = FALSE
2. While queue not empty and not found do:
(a) Remove the first node n from queue
(b) if N is a goal state then found = TRUE
(c ) Find all the successor nodes of X, and put them on the end of the queue
Breath First
c M M Awais (LUMS) 21
1. Open = [A]; closed = []
2. Open = [B,C,D]; closed = [A]
3. Open = [C,D,E,F]; closed = [A,B]
4. Open = [D,E,F,G,H]; closed = [C,B,A]
5. Open = [E,F,G,H,I,J]; closed = [D,C,B,A]
6. Open = [F,G,H,I,J,K,L]; closed = [E,D,C,B,A]
7. Open = [G,H,I,J,K,L,M]; closed = [F,E,D,C,B,A]
8. Open = [H,I,J,K,L,M,N]; closed = [G,F,E,D,C,B,A]
9. And so on until either U is found or open = []
c M M Awais (LUMS) 22
1. Start with agenda = [initial - state] and found = FALSE
2. While agenda not empty and not found do:
(a) Remove the first node N from agenda
(b) if N is not in visited then
(I) Add N to visited
(II) if N is a goal state then found = TRUE
(III) Put N’s successors on the front of the stack
Depth First
c M M Awais (LUMS) 24
1. Open = [A]; closed = []
2. Open = [B,C,D]; closed = [A]
3. Open = [E,F, C,D]; closed = [B,A]
4. Open = [K,L,F,C,D]; closed = [E,B,A]
5. Open = [S,L,F,C,D]; closed = [K,E,B,A]
6. Open = [L,F,C,D]; closed = [S,K,E,B,A]
7. Open = [T,F,C,D]; closed = [L,S,K,E,B,A]
8. Open = [F,C,D]; closed = [T,L,S,K,E,B,A]
9. Open = [M,C,D]as L is already on closed;
closed = [F,T,L,S,K,E,B,A]
10. Open = [C,D]; closed = [M,F,T,L,S,K,E,B,A]
11. Open = [G.H.D]; closed = [C,M,F,T,L,S,K,E,B,A]