0% found this document useful (0 votes)
7 views52 pages

3 Lecture AI - Example Problem Solving

The document outlines a problem-solving approach in Artificial Intelligence, focusing on various techniques and examples such as the 8-puzzle, water jug problem, and the missionaries and cannibals problem. It covers state space representation, initial and goal states, operators, and search strategies including uninformed and informed search methods. The learning objectives include understanding types of problems and AI techniques to solve them.

Uploaded by

SRISHTI AGARWAL
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views52 pages

3 Lecture AI - Example Problem Solving

The document outlines a problem-solving approach in Artificial Intelligence, focusing on various techniques and examples such as the 8-puzzle, water jug problem, and the missionaries and cannibals problem. It covers state space representation, initial and goal states, operators, and search strategies including uninformed and informed search methods. The learning objectives include understanding types of problems and AI techniques to solve them.

Uploaded by

SRISHTI AGARWAL
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 52

Problem Solving Approach in AI

Module -I

Programme: B. Sc-IT,
Course: Artificial Intelligence (CSE401)
Faculty: Dr. Seema Rawat
Index

• State Space Representation


• Problem Solving Examples
Learning Objective

To gain the knowledge about general AI approach to solve


various types of problems

3
Learning Outcomes

• Basic understanding of the types of problems

• To know the basic concepts about techniques to solve the


problems using Artificial Intelligence concepts
Examples of AI problems
• Tic-Tac toe
• Water jug problem
• 8-puzzle problem
• 8-queen problem
• Chess problem
• Missionaries and cannibals problem
• Tower of Hanoi problem
• Traveling salesman problem
• Magic square
• Language understanding problems
• Monkey and Banana Problem
• Crypt arithmatic puzzle
• Block World problem
5
8-Puzzle Problem

•In the 8-puzzle problem we have a 3×3 square board and 8 numbered
tiles. The board has one blank position.

•Tiles can be slid to adjacent blank positions. We can alternatively and


equivalently look upon this as the movement of the blank position up,
down, left or right.

•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

The start state is some (almost) random


configuration of the tiles
The goal state is as shown

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

You have a 4-gallon and a


3-gallon water jug

•You have a pump with an


unlimited amount of water

•You need to get exactly 2


gallons in 4-gallon jug
A Water Jug Problem

State representation: (x, y)


–x: Contents of four gallon
–y: Contents of three gallon

•Start state: (0, 0)


•Goal state (2, n)

Operators

–Fill 3-gallon from pump, fill 4-gallon from pump


–Fill 3-gallon from 4-gallon , fill 4-gallon from 3-gallon
–Empty 3-gallon into 4-gallon, empty 4-gallon into 3-gallon
–Dump 3-gallon down drain, dump 4-gallon down drain
State Space Search: Water Jug Problem...

1. (x, y)  (4, y) if x is less than 4, fill the 4 gallon jug


if x  4
2. (x, y)  (x, 3) fill the 3-gallon jug
if y  3
3. (x, y)  (x  d, y) pour some water out of the 4 gallon jug
if x  0

4. (x, y)  (x, y  d) pour some water out of the 3 gallon jug


if y  0
5. (x, y)
if x  0  (0, y) empty the 4-gallon jug on the ground

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...

1.Current state = (0, 0)


2.Loop until reaching the goal state (2, 0)

-Apply a rule whose left side matches the current state


-Set the new current state to be the resulting state

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.

• The 8-puzzle has 181,440 states.

• Tic-Tac-Toe has about 39 states.

• Rubikʼs Cube has about 1019 states.

• Chess has about 10120 states in a typical game.

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

Given the following configuration of


sticks, remove exactly 5 sticks in such
a way that the remaining configuration
forms exactly 3 squares.

• State: ?

• Initial State: ?

• Operators: ?

• Goal Test: ?
4-queens

•States: 4 queens in 4 columns (44 = 256 states)


•Actions: move queen in column
•Goal test: no attacks
•Evaluation: h(n) = number of attacks

• 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: ?

Goal: Place eight queens on a


chessboard such that no queen
attacks any other!
Missionaries and Cannibals
Missionaries and Cannibals

The missionaries and cannibals


wish to cross a river

They have a boat that can hold


two people

It is unsafe to have cannibals


outnumber missionaries
States

•A state can be represented by the number of missionaries and cannibals on


each side of the river

•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.

• Constraint: Missionaries can never be outnumbered by cannibals on either


side of river, or else the missionaries are killed.

• State: configuration of missionaries and cannibals and boat on each side of


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

An operation takes us from one state to another


Here are five possible operations:
–boat takes 1 missionary across river (1m)
–boat takes 1 cannibal across river (1c)
–boat takes 2 missionaries across river (2m)
–boat takes 2 cannibals across river (2c)
–boat takes 1 missionary and 1 cannibal across river (1m1c)
Solution

1. (3, 3,0)  (0,0,1) Initial state


2. (3, 1,0)  (0,2,1) two cannibal will go
3. (3,2,0)  (0,1,1) one cannibal will return
4. (3,0,0) (0,3,1) two cannibal will go
5. (3,1,0) (0,2,1) one cannibal will return
6. (1,1,0) (2,2,1) two Missionaries will go
7. (2,2,0) (1,1,1) one cannibal and one Missionaries will return
8. (0,2,0) (3,1,1) two Missionaries will go
9. (0,3,0)  (3,0,1) one cannibal will return
10. (0,1,0) (3,2,1) two cannibal will go
11. (0,2,0)  (3,1,1) one cannibal will return
12. (0,0,0) (3,3,1) two cannibal will go
29
Missionaries and Cannibals
Solution

Near side Far side


0 Initial setup: MMMCCC B -
1 Two cannibals cross over: MMMC B CC
2 One comes back: MMMCC B C
3 Two cannibals go over again: MMM B CCC
4 One comes back: MMMC B CC
5 Two missionaries cross: MC B MMCC
6 A missionary & cannibal return: MMCC B MC
7 Two missionaries cross again: CC B MMMC
8 A cannibal returns: CCC B MMM
9 Two cannibals cross: C B MMMCC
10 One returns: CC B MMMC
11 And brings over the third: - B MMMCCC
Evaluating Search Strategies
• Completeness
– Guarantees finding a solution whenever one exists

• 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

1.Uninformed search (blind search)(Exhaustive search)(Bruteforce)


Having no information about the number of steps from the current
state to the goal.

e.g- Breadth-first search , depth-first search

2.Informed search (heuristic search)


More efficient than uninformed search.

e.g- Hill climbing, best-first search, greedy search, A*


Brute Force or Uninformed Search
Strategies

• These are commonly used search procedure which explore all the alternatives
during the search process.

• They do not have any domain specific knowledge.

• 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

• The followings are example of uninformed search


–Depth First Search (DFS)
–Breadth First Search (BFS)
Search Strategies: Blind Search

• 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

• Searching processes level by level unlike depth first search which


goes deep into the tree.
• An operator is employed to generate all possible children of a
node.
DFS Vs BFS
DFS BFS

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.

Time complexity: O(bd ) Time complexity: O(bd )


where b : branching factor, d: depth where b : branching factor, d: depth
CONSTRAINT SATISFACTION

• Many problems in AI can be considered as problems of constraint


satisfaction, in which the goal state satisfies a given set of constraint.

• constraint satisfaction problems can be solved by using any of the search


strategies. The general form of the constraint satisfaction procedure is as
follows:

• Until a complete solution is found or until all paths have led to lead ends,
do

39
Example: consider the crypt arithmetic problems

Find an assignment of digits (0, ..., 9) to letters so that a given


arithmetic expression is true. examples:

FORTY Solution: 29786


+ TEN 850
+ TEN 850
SIXTY 31486
F=2, O=9, R=7, etc.
Example: consider the crypt arithmetic problem

SEND
+ MORE
----------
MONEY
----------

41
CONSTRAINTS:-

1. no two digit can be assigned to same letter.


2. only single digit number can be assign to a letter.
3. no two letters can be assigned same digit.
4. Assumption can be made at various levels such that they do not
contradict each other.
5. The problem can be decomposed into secured constraints. A
constraint satisfaction approach may be used.
6. Any of search techniques may be used.
7. Backtracking may be performed as applicable us applied search
techniques.
8. Rule of arithmetic may be followed.
42
Initial state of problem.
• D=?
• E=?
• Y=?
• N=?
• R=?
• O=?
• S=?
• M=?
• C1=?
• C2=?
• C1 ,C 2, C3 stands for the carry variables respectively.

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.

And each constraints is to be satisfied by guessing the possible digits that


the letters can be assumed that the initial guess has been already made .

45
46
47
PROBLEM REDUCTION

We already know about the divide and conquer strategy, a solution to a


problem can be obtained by decomposing it into smaller sub-problems.
Each of this sub-problem can then be solved to get its sub solution.
These sub solutions can then recombine to get a solution as a whole.
That is called is Problem Reduction. This method generates arc which
is called as AND arcs. One AND arc may point to any number of
successor nodes, all of which must be solved in order for an arc to point
to a solution. 48
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

Artificial Intelligence (2nd ed) by Elaine Rich and Kevin Knight,


McGraw Hill (1991). ISBN 0-07-100894-2

51
Thank You

52

You might also like