Lecture+3+Problem+Solving II
Lecture+3+Problem+Solving II
Searching
Lecture # 04
Tuesday, January 31, 2017
Spring 2017
FAST – NUCES, Faisalabad Campus
Zain Iqbal
[email protected]
Example problems
Toy problems
those intended to illustrate or exercise
various problem-solving methods
E.g., puzzle, chess, etc.
Real-world problems
tend to be more difficult and whose
solutions people actually care about
E.g., Design, planning, etc.
31-Jan-17 24
Vacuum World
31-Jan-17 25
Example: 8-puzzle
States??
Initial state??
Actions??
Goal test??
Path cost??
31-Jan-17 28
Example: 8-puzzle
8 2 1 2 3
3 4 7 4 5 6
5 1 6 7 8
31-Jan-17 30
Example: 8-puzzle
8 2 7
3 4
8 2 5 1 6
3 4 7
5 1 6 8 2 8 2
3 4 7 3 4 7
5 1 6 5 1 6
31-Jan-17 31
Search space for Eight Puzzle
Slid
e7
Example: 8-puzzle
10 million states/sec
31-Jan-17 33
Example: 8-queens
Place 8 queens in a chessboard so that no two queens
are in the same row, column, or diagonal.
31-Jan-17 34
Example: 8-queens problem
31-Jan-17 38
16
31-Jan-17 39
17
31-Jan-17 40
Example: robot assembly
States??
Initial state??
Actions??
Goal test??
Path cost??
31-Jan-17 41
Example: robot assembly
31-Jan-17 43
Simple Tree Search Algorithm
function TREE-SEARCH(problem, strategy) return solution
or failure
Initialize search tree to the initial state of the problem
do
if no candidates for expansion then return failure
choose leaf node for expansion according to strategy
if node contains goal state then return solution
else expand the node and add resulting nodes to the
search tree
enddo
31-Jan-17 44
Search of State Space
31-Jan-17 45
Search of State Space
31-Jan-17 46
Search State Space
31-Jan-17 47
Search of State Space
31-Jan-17 48
Search of State Space
31-Jan-17 49
Search of State Space
search tree
31-Jan-17 50
3.3 Searching for solutions
Finding out a solution is done by
searching through the state space
All problems are transformed
as a search tree
generated by the initial state and
successor function
31-Jan-17 51
Search tree
Initial state
The root of the search tree is a search node
Expanding
applying successor function to the current state
thereby generating a new set of states
leaf nodes
the states having no successors
Frontier/Fringe/open-list : Set of search nodes
that have not been expanded yet.
Refer to next figure
31-Jan-17 52
Tree search example
31-Jan-17 53
Tree search example
31-Jan-17 54
Search tree
Parent Node:
In(Arad)
Child Node:
In(sibiu), In(Timisoara) , In (Zerind).
Leaf Node:
In(Arad),In(Fagaras),In(Oradea),
In(Riminicu Vilcea)
31-Jan-17 55
Tree search algorithm
function TREE-SEARCH(problem) returns a solution, or failure
initialize the frontier using the initial state of problem
loop do
if the frontier is empty then return failure
choose a leaf node and remove it from the frontier
if the node contains a goal state then return the
corresponding solution
expand the chosen node, adding the resulting nodes to
the frontier
31-Jan-17 56
Tree search algorithm (2)
31-Jan-17 57
Search tree
The essence of searching
in case the first choice is not correct
choosing one option and keep others for later
inspection
Hence we have the search strategy
which determines the choice of which state to
expand
good choice fewer work faster
Important:
state space ≠ search tree
31-Jan-17 58
Search tree
State space
has unique states {A, B}
while a search tree may have cyclic paths:
A-B-A-B-A-B- …
A good search strategy should avoid
such paths
31-Jan-17 59
Search tree
A node is having five components:
STATE: which state it is in the state space
PARENT-NODE: from which node it is generated
31-Jan-17 118