Module 2 Chapter 3
Module 2 Chapter 3
Irbed
20 km 25 km
ajlun
33km 35 km Mafraq
45 km 15 km 20 km
Jarash
45 km 75 km
Zarqa
Salat 40 km15 km
15 km Azraq
25 km amman
55 km 250 km
Madaba
150 km
150 km
200 km
Karak
180 km
Aqaba
From the Example
1. Formulate Goal
- Be In Amman
2. Formulate Problem
- States : Cities
- actions : Drive Between Cities
3. Find Solution
{Aj → Ja → Am} }
8. State Set Space : {Ajlun → Jarash → Amman}
Example: Romania
On holiday in Romania; currently in Arad.
Flight leaves tomorrow from Bucharest
Formulate goal:
⚫ be in Bucharest
Formulate problem:
⚫ states: various cities
⚫ actions: drive between cities
Find solution:
⚫ sequence of cities, e.g., Arad, Sibiu, Fagaras,
Bucharest
Example: Romania
Single-state problem formulation
A problem is defined by four items:
initial state e.g., "at Arad"
1. actions or successor function S(x) = set of action–state pairs
⚫ e.g., S(Arad) = {<Arad → Zerind, Zerind>, … }
Real-world problems
⚫ tend to be more difficult and whose
solutions people actually care about
⚫ E.g., Design, planning, etc.
Toy problem (1)
Example: vacuum world
Number of states: 8
Initial state: Any
Number of actions: 4
⚫ left, right, suck,
noOp
Goal: clean up all dirt
⚫ Goal states: {7, 8}
Path Cost:
⚫ Each step costs 1
Toy problem (1)
Vacuum world
⚫ States: 8 = (2*2^2) or n*2^n
⚫ What is the first n about?
⚫ Initial states: any
⚫ Actions: Left, Right, Suck
⚫ Transition model – Shown in next slide
⚫ Goal test: Clean or not
⚫ Path cost: Each step costs 1
25
The 8-puzzle
The 8-puzzle
States:
⚫a state description specifies the location of each of
the eight tiles and blank in one of the nine squares
No. of States – 9!/2 = 181,440 reachable (Worst Case)
Initial State:
⚫ Any state in state space
Actions
⚫ the blank moves Left, Right, Up, or Down
Goal test:
⚫ current state matches the goal configuration
Path cost:
⚫ each step costs 1, so the path cost is just the length
of the path
The 8-queens
There are two ways to formulate the
problem
All of them have the common followings:
⚫ Goal test: 8 queens on board, not attacking
to each other
⚫ Path cost: zero
The 8-queens
(1) Incremental formulation
⚫ Initial State: No queens on board
⚫ Action: Each action adds a queen to the state
33
3.3 Searching for solutions
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
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
Fringe: Set of search nodes that have not been
expanded yet.
Refer to next figure
Tree search example
Tree search example
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
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
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
Bidirectional search
Breadth-first search
The root node is expanded first (FIFO)
All the nodes generated by the root
node are then expanded
And then their successors and so on
Breadth-first search
S
A D
B D A E
C E E B B F
11
D F B F C E A C G
14 17 15 15 13
G C G F
19 19 17 G 25
Breadth-first search (Analysis)
Breadth-first search
⚫ Complete – find the solution eventually
⚫ Optimal, if step cost is 1
The disadvantage
⚫ if the branching factor of a node is large,
⚫ the space complexity and the time complexity
are enormous
Properties of breadth-first search
Complete? Yes (if b is finite)
A D
B D A E
C E E B B F
11
D F B F C E A C G
14 17 15 15 13
G C G F
19 19 17 G 25
Depth-first search (Analysis)
Not complete
⚫ because a path may be infinite or looping
⚫ then the path will never fail and go back try
another option
Not optimal
⚫ it doesn't guarantee the best solution
It overcomes
⚫ the time and space complexities
Properties of depth-first search
Complete? No: fails in infinite-depth spaces,
spaces with loops
→ complete in finite spaces
Optimal? No