Ai Assign-1
Ai Assign-1
N
Roll No.-2K21/CO/183
AI ASSIGNMENT-1
State Representation:-
. L
1 et’s denote the 4-litre jug as“x”and the 3-litre jug as“y”.
2. We can represent the state of the system as a pair(x, y), where both jugs are initially empty:
(0, 0).
Goal State:-
1. O
ur goal is to reach a state where the 4-litre jug contains2 litresof water:(2, n)(wherencan
be any value).
Production Rules:-
➢ W e’ll define a set of production rules to transform the state from the start state to the goal
state:
1. Fill the 4-litre jug: Ifx < 4, fill the 4-litre jug to its maximum capacity:(4, y).
2. Fill the 3-litre jug: Ify < 3, fill the 3-litre jug to its maximum capacity:(x, 3).
3. Pour from 4-litre jug to 3-litre jug: Ifx > 0, pour some water from the 4-litre jug into the
3-litre jug:(x - d, d).
4. Pour from 3-litre jug to 4-litre jug: Ify > 0, pour some water from the 3-litre jug into the
4-litre jug:(d, y - d).
5. Empty the 4-litre jug: Ifx > 0, empty the 4-litre jug on the ground:(0, y).
6. Empty the 3-litre jug: Ify > 0, empty the 3-litre jug on the ground:(x, 0).
7. Fill the 4-litre jug from the 3-litre jug: Ifx + y >= 4andy > 0, pour water from the 3-litre
jug into the 4-litre jug until it is full:(4, y - (4 - x)).
8. Fill the 3-litre jug from the 4-litre jug: Ifx + y >= 3andx > 0, pour water from the 4-litre
jug into the 3-litre jug until it is full:(x - (3 - y), 3).
9. Transfer all water from 3-litre jug to 4-litre jug: Ifx + y <= 4andy > 0, pour all the water
from the 3-litre jug into the 4-litre jug:(x + y, 0).
10.Transfer all water from 4-litre jug to 3-litre jug: Ifx + y <= 3andx > 0, pour all the water
from the 4-litre jug into the 3-litre jug:(0, x + y).
11.Pour 2 litres from 3-litre jug to 4-litre jug: From state(0, 2), pour 2 litres of water from the
3-litre jug into the 4-litre jug:(2, 0).
12.Empty 2 litres from 4-litre jug: From state(2, y), empty 2 litres from the 4-litre jug on the
ground:(0, y).
13.Search Algorithms:
○ To solve the water jug problem, we can use search algorithms like:
i. Breadth-First Search (BFS): Visits nodes in order of their distance from the
starting node, prioritising the nearest nodes first.
ii. Depth-First Search (DFS): Visits nodes in order of their depth, exploring
deeper before backtracking.
SOLUTION :-
ater Jug Problemwhere we need to pour exactly2 litresof water into the4-litre jugusing the
W
3-litre jug. Here’s one possible sequence of actions:
.
1 tart with both jugs empty:(0, 0).
S
2. Fill the 3-litre jug:(0, 3).
3. Pour water from the 3-litre jug into the 4-litre jug:(3, 0).
4. Fill the 3-litre jug again:(3, 3).
5. Pour water from the 3-litre jug into the 4-litre jug until the 4-litre jug is full:(4, 2).
6. Empty the 4-litre jug:(0, 2).
7. Pour the remaining 2 litres from the 3-litre jug into the 4-litre jug:(2, 0).
Now the 4-litre jug contains exactly 2 litres of water, which is our desired outcome!
QUESTION 2 :-Monkey and Banana Problem
heMonkey and Banana Problemis a classic puzzle in the field ofArtificial Intelligence. Let’s
T
delve into this intriguing scenario:
● hungry monkeyis in a room, standing near the door.
A
● The monkey is currently on the floor.
● Bananasare tantalizingly hung from the center of the ceiling.
● There’s ablock(or chair) in the room, positioned near the window.
he monkey desires those bananas, but alas, they are out of reach! How can our clever simian friend
T
obtain the coveted fruit?
Observations:
.
1 he monkey can reach the block if both are at the same level.
T
2. If the block isn’t at the center, the monkey can drag it there.
3. When both the monkey and the block are on the floor, the monkey can climb onto the block.
4. Once the monkey is on the block (with the block at the center), it can finally reach the
bananas.
We can represent this problem usingPrologpredicates. Here’s how we can solve it step by step:
he8 Queens Probleminvolves placingeight queenson an8×8 chessboardin such a way that no
T
two queens threaten each other. Specifically, no two queens should be in the same row, column, or
diagonal. This problem can be generalized to then queens problem, where we aim to place n queens
on an n×n chessboard.
Backtracking Algorithm:
➢
T he most common approach for solving the 8 Queens Problem is throughbacktracking.
➢ TheisSafefunction checks if it’s safe to place a queen on a certain row and column by
verifying that no other queens threaten it.
➢ The algorithm recursively explores different possibilities, backtracking when necessary.
) A
1 nother effective approach is usingGenetic Algorithms.
2) GA mimics natural selection, creating a population of random solutions and evaluating them
using a fitness function.
3) Over successive generations, the algorithm evolves better solutions.
Other Methods:
1. T
he 8 Queens Problem can also be tackled usinghill climbing,branch and bound, and other
optimization techniques.
I n summary, the 8 Queens Problem challenges us to find a configuration where eight queens coexist
harmoniously on a chessboard.
SOLUTION:-
Q1
Q7
Q5
Q2 Q8
Q4
Q6
Q3