Search Space - Suraj @ LUMS

SEARCH METHODS
•
State space search
•
Heuristic search
c
M M Awais (LUMS)
1
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)
2
BASIC METHODS
Initial State
(Through all
possible actions)
Target State
Background
Material required is “GRAPH THEORY”
c
M M Awais (LUMS)
3
TYPICAL EXAMPLES OF
SEARCH PROBLEMS
•
Toy Problem (The 8 puzzle)
•
Route Finding
•
Traveling Save Person
•
Robot Navigation
•
Assembly Sequencing
c
M M Awais (LUMS)
4
Eight Puzzle Problem
c
M M Awais (LUMS)
5
Route Finding Problem
c
M M Awais (LUMS)
6
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)
7
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)
8
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)
9
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)
10
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,
c
M M Awais (LUMS)
Leaf Node
11
Graphs VS Trees
• Compare the searches in the two (which is
efficient)
d
a
a
c
b
c
d
b
c
M M Awais (LUMS)
e
f
g
12
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)
13
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)
14
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)
15
Types: Breadth First/Depth First
c
M M Awais (LUMS)
16
Example: Map Problem-1
c
M M Awais (LUMS)
17
Example: Map Problem -2
c
M M Awais (LUMS)
18
Breath First
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
c
M M Awais (LUMS)
19
c
M M Awais (LUMS)
20
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)
21
Depth First
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
c
M M Awais (LUMS)
22
Example
c
M M Awais (LUMS)
23
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]
c
M M Awais (LUMS)
24