0% found this document useful (0 votes)
9 views

Lecture+3+Problem+Solving II

The document discusses searching as a problem-solving method. It provides examples of search problems like the 8-puzzle and 8-queens problems. It describes how problems can be formulated as search problems by defining the state space, initial state, successor function, goal test, and path cost. Search algorithms generate a search tree by starting from the initial state and applying the successor function to expand nodes and find solutions. The key aspects of searching include representing the problem as a search tree, using a search strategy to choose the next node to expand, and exploring the tree until a goal or solution is found.

Uploaded by

M M
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Lecture+3+Problem+Solving II

The document discusses searching as a problem-solving method. It provides examples of search problems like the 8-puzzle and 8-queens problems. It describes how problems can be formulated as search problems by defining the state space, initial state, successor function, goal test, and path cost. Search algorithms generate a search tree by starting from the initial state and applying the successor function to expand nodes and find solutions. The key aspects of searching include representing the problem as a search tree, using a search strategy to choose the next node to expand, and exploring the tree until a goal or solution is found.

Uploaded by

M M
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 42

Solving Problems By

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

States?? Integer location of each tile


Initial state?? Any state can be initial
Actions?? {Left, Right, Up, Down}
Goal test?? Check whether goal configuration is
reached
Path cost?? Number of actions to reach goal
31-Jan-17 29
Example: 8-puzzle

8 2 1 2 3
3 4 7 4 5 6
5 1 6 7 8

Initial state Goal state

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

Size of the state space = 9!/2 = 181,440

15-puzzle  .65 x 1012


0.18 sec
6 days
24-puzzle  .5 x 1025
12 billion years

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.

A solution Not a solution

31-Jan-17 34
Example: 8-queens problem

Incremental formulation vs. complete-state formulation


• States??
• Initial state??
• Actions??
• Goal test??
• Path cost??
31-Jan-17 35
Example: 8-queens
Formulation #1:
•States: any arrangement of
0 to 8 queens on the board
• Initial state: 0 queens on the
board
• Actions: add a
queen in any square
• Goal test: 8 queens on the
board, none attacked
• Path cost: none

 648 states with 8 queens


31-Jan-17 36
Example: 8-queens
Formulation #2:
•States: any arrangement of
k = 0 to 8 queens in the k
leftmost columns with none
attacked
• Initial state: 0 queens on the
board
• Successor function: add a
queen to any square in the
leftmost empty column such
that it is not attacked
by any other queen
• Goal test: 8 queens on the
 2,057 states board
31-Jan-17 37
Real-World Problems

31-Jan-17 38
16

Example: Route finding problem


• states: each is represented by a location (e.g. An airport) and the
current time
• Initial state: specified by the problem
• Successor function: returns the states resulting from taking any
scheduled flight, leaving later than the current time plus the within
airport transit time, from the current airport to another
• goal test: are we at the destination by some pre-specified time
• Path cost:monetary cost, waiting time, flight time, customs and
immigration procedures, seat quality, time of day, type of airplane,
frequent-flyer mileage awards, etc

• Route finding algorithms are used in a variety of applications, such


as routing in computer networks, military operations planning,
airline travel planning systems

31-Jan-17 39
17

Other example problems


• Touring problems: visit every city at least once,
starting and ending at Bucharest
• Travelling salesperson problem (TSP) : each city must
be visited exactly once – find the shortest tour
• VLSI layout design: positioning millions of
components and connections on a chip to minimize
area, minimize circuit delays, minimize stray
capacitances, and maximize manufacturing yield
• Robot navigation
• Internet searching
• Automatic assembly sequencing
• Protein design

31-Jan-17 40
Example: robot assembly

States??
Initial state??
Actions??
Goal test??
Path cost??

31-Jan-17 41
Example: robot assembly

States?? Real-valued coordinates of robot joint


angles; parts of the object to be assembled.
Initial state?? Any arm position and object
configuration.
Actions?? Continuous motion of robot joints
Goal test?? Complete assembly (without robot)
Path cost?? Time to execute
31-Jan-17 42
Basic search algorithms
How do we find the solutions of previous
problems?
 Search the state space (remember complexity of
space depends on state representation)
 Here: search through explicit tree generation
 ROOT= initial state.
 Nodes and leafs generated through successor function.
 In general search generates a graph (same
state through multiple paths)

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

 ACTION: which action applied to its parent-node


to generate it
 PATH-COST: the cost, g(n), from initial state to
the node n itself
 DEPTH: number of steps along the path from the
initial state
31-Jan-17 60
31-Jan-17 61
31-Jan-17 62
Measuring problem-solving performance
The evaluation of a search strategy
 Completeness:
 is the strategy guaranteed to find a solution when
there is one?
 Optimality:
 does the strategy find the highest-quality solution
when there are several different solutions?
 Time complexity:
 how long does it take to find a solution?
 Space complexity:
 how much memory is needed to perform the search?
31-Jan-17 63
Measuring problem-solving performance
In AI, complexity is expressed in
 b, branching factor, maximum number of
successors of any node
 d, the depth of the shallowest goal node.
(number of steps along the path from the root)
 m, the maximum length of any path in the state
space
Time and Space is measured in
 number of nodes generated during the search
 maximum number of nodes stored in memory
31-Jan-17 64
Measuring problem-solving performance

For effectiveness of a search algorithm


 we can just consider the total cost
 The total cost = path cost (g)of the solution
found + search cost
 search cost = time necessary to find the solution
Tradeoff:
 (long time, optimal solution with least g)
 vs. (shorter time, solution with slightly larger
path cost g)
31-Jan-17 65
Reading Material
Russell & Norvig Chapter # 3

31-Jan-17 118

You might also like