3 Lecture AI - Example Problem Solving
3 Lecture AI - Example Problem Solving
Module -I
Programme: B. Sc-IT,
Course: Artificial Intelligence (CSE401)
Faculty: Dr. Seema Rawat
Index
3
Learning Outcomes
•In the 8-puzzle problem we have a 3×3 square board and 8 numbered
tiles. The board has one blank position.
•The objective of this puzzle is to move the tiles starting from an initial
position and arrive at a given goal configuration.
Initial and Goal State
Operators are
Move empty space up
Move empty space down
Move empty space right
Move empty space left
8-puzzle problem- State Space
Learning Outcome from 8 Puzzle
• States: It describes the location of each numbered tiles and the blank
tile.
• Initial State: We can start from any state as the initial state.
• Actions: Here, actions of the blank space is defined, i.e., either left,
right, up or down
• Transition Model: It returns the resulting state as per the given state
and actions.
• Goal test: It identifies whether we have reached the correct goal-
state.
• Path cost: The path cost is the number of steps in the path where the
cost of each step is 1.
10
A Water Jug Problem
Operators
6. (x, y)
if y 0 (x, 0) empty the 3-gallon jug on the ground
1
3
Water Jug Problem...
7. (x, y) (4, y (4 x)) if x y 4, y pour water from the 3- gallon jug into the 4- gallon
jug until the 4-gallon jug is full
0
pour water from the 4- gallon jug into the 3-
8. (x, y) (x (3 y), 3) gallon jug until the 3-gallon jug is full
if x y 3, x 0
9. (x, y) (x y, 0) if x y 4, y pour all the water from the 3-gallon jug into the 4-
0 gallon jug
10. (x, y) (0, x y) if x y 3, x pour all the water from the 4-gallon jug into the 3-
gallon jug
0
pour the 2 gallons from the 3-gallon jug into the 4-
11. (0, 2) (2, 0) gallon jug
12. (2, y) (0, y) empty the 2 gallons in the 4 gallon jug on the
ground
14
State Space Search: Water Jug Problem...
Gallons in the 4-Gallon Jug Gallons in the 3-Gallon Jug Rule Applied
0 0 ?
0 3 ?
3 0
3 3
4 2
0 2
2
Interesting Facts about State.
16
Interesting Facts about State.
17
QUIZ -1 Water Jug Problem
Given a full 5-gallon jug and a full 2-gallon jug, fill the 2-gallon jug with exactly one
gallon of water.
• State: ?
• Initial State: ?
55
• Operators: ?
• Goal State: ? 2
Solution- QUIZ-1
Operator table
Name Cond. Transition Effect
• State = (x,y), where x is
the number of gallons of Empty5 – (x,y)→(0,y) Empty 5-gal.
water in the 5-gallon jug jug
and y is # of gallons in Empty2 – (x,y)→(x,0) Empty 2-gal.
the 2-gallon jug jug
2to5 x≤3 (x,2)→(x+2,0) Pour 2-gal.
• Initial State = (5,2) into 5-gal.
5to2 x≥2 (x,0)→(x-2,2) Pour 5-gal.
into 2-gal.
• Goal State = (*,1),
5to2part y<2 (1,y)→(0,y+1) Pour partial 5-
where * means any gal. into 2- gal.
amount
QUIZ -2 Remove 5 Sticks
• State: ?
• Initial State: ?
• Operators: ?
• Goal Test: ?
4-queens
• Given random initial state, we can solve n-queens for large n with high
probability
QUIZ-3 The 8-Queens Problem
State Representation: ?
Initial State: ?
Operators: ?
•State(m, c, riverbank)
m -----> no. of missionaries
c -----> no. of cannibals
Bankofriver -----> indicates whether the boat in the left bank or right bank
0 -----> left bank, 1 -----> right bank
•Initial state (3,3,0)
•Goal state: (0,0,0)
Missionaries and Cannibals
• Goal: Move all the missionaries and cannibals across the river.
• Initial State: 3 missionaries, 3 cannibals and the boat are on the near bank
• Operators: Move boat containing some set of occupants across the river (in
either direction) to the other side.
Operations
• Time complexity
– How long (worst or average case) does it take to find a solution?
Usually measured in terms of the number of nodes expanded
• Space complexity
– How much space is used by the algorithm? Usually measured in
terms of the maximum size of the “nodes” list during the search
• Optimality/Admissibility
– If a solution is found, is it guaranteed to be an optimal one? That is, is it
the one with minimum cost?
Search Strategies
• These are commonly used search procedure which explore all the alternatives
during the search process.
• They need the initial state, the goal state and a set of legal operators.
• The strategy gives the order in which the search space is searched
• Breadth-first search
Expand all the nodes of
one level first.
• Depth-first search
Expand one of the nodes at
the deepest level.
Breadth First Search
It require less memory because only the It require more memory because all the tree
nodes on the current path are stored. that has so far been generated must be
stored.
It is one in which by luck solution can be While in BFS all parts of the tree must be
found without examining much of the search examined to level n before any nodes on
space at all. level n+1 can be examined.
It does not give optimal solution. It gives optimal solution.
DFS may find a long path to a solution in one BFS guarantees to find a solution if it exists.
part of the tree, when a shorter path exists in Furthermore if there are multiple solutions,
some other, unexplored part of the tree. then a minimal solution will be found.
• Until a complete solution is found or until all paths have led to lead ends,
do
39
Example: consider the crypt arithmetic problems
SEND
+ MORE
----------
MONEY
----------
41
CONSTRAINTS:-
Goal State: the digits to the letters must be assigned in such a manner so that the sum is
43
satisfied.
44
The same process can be repeated further. The problem has to be
composed into various constraints.
45
46
47
PROBLEM REDUCTION
49
References
[1] https://www.merriam-webster.com/
[2] https://www.wikipedia.org/
[3] Stuart Russell, Peter Norvig, Artificial Intelligence: A Modern
Approach, 4th Edition, 2020, Pearson
[4 ] https://www.sas.com
[5] https://www.tutorialspoint.com/artificial_intelligence
[6] https://www.mcs.anl.gov
50
Bibliography
51
Thank You
52