AI LAB Manual Mohit Kumar
AI LAB Manual Mohit Kumar
Engineering
NATIONAL INSTITUTE OF TECHNOLOGY SRINAGAR,
HAZARATBAL(J&K)
ARTIFICIAL INTELLIGENCE
(CSL353)
Lab File
(2020 – 2024)
For
6th Semester
Submitted To : Submitted By :
Dr. Ranjeet Kumar Rout Mr. Amir Shabir
Department of CSE 2020BCSE034
B.Tech CSE(6th Sem)
Lab-01 2020BCSE034
1)Visited 2) Not Visited. So, the purpose of the algorithm is to visit all
the vertex while avoiding cycles.
BFS starts from a node, then it checks all the nodes at distance one from
the beginning node, then it checks all the nodes at distance two, and so
on. So as to recollect the nodes to be visited, BFS uses a queue.
BFS pseudocode
The pseudocode for BFS in python goes as below:
create a queue Q
mark v as visited and put v into Q
while Q is non-empty
Output:-
Lab-01 2020BCSE034
Implement the Depth First Search (DFS) Algorithm.
The only purpose of this algorithm is to visit all the vertex of the
graph avoiding cycles.
DFS pseudocode
The pseudocode for Depth-First Search in python goes as below:
DFS(G, u)
for each v ∈
u.visited = true
G.Adj[u] if v.visited
== false DFS(G,v)
For each u ∈ G
init() {
For each u ∈ G
u.visited = false
DFS(G, u)
}
Code:- 2020BCSE034
Output:-
Lab-02 2020BCSE034
Implement the n-Queen problem in python.
Output:-
Lab-03 2020BCSE034
Implement the 8-puzzle problem in python.
Definition:
“It has set off a 3x3 board having 9 block spaces out of which 8
blocks having tiles bearing number from 1 to 8. One space is left
blank. The tile adjacent to blank space can move into it. We
have to arrange the tiles in a sequence for getting the goal
state”.
1. Up
2. Down
3. Right or
4. Left
The empty space cannot move diagonally and can take only one
step at a time.
Code:- 2020BCSE034
Output:-
Lab-04 2020BCSE034
Algorithm of A* search:
Step1: Place the starting node in the OPEN list.
Step 2: Check if the OPEN list is empty or not, if the list is empty then
return failure and stops.
Step 3: Select the node from the OPEN list which has the smallest value
of evaluation function (g+h), if node n is goal node then return success
and stop, otherwise
Step 4: Expand node n and generate all of its successors, and put n into
the closed list. For each successor n', check whether n' is already in the
OPEN or CLOSED list, if not then compute evaluation function for n' and
place into Open list.
Step 5: Else if node n' is already in OPEN and CLOSED, then it should be
attached to the back pointer which reflects the lowest g(n') value.
Step 6: Return to Step 2.
Advantages:
Solution:
5. Here we have replicated the arc between the work hard and
the pass because by doing the hard work possibility of
passing an exam is more than cheating.
Procedure:
Suppose we have searched this path and we have got the Goal State,
then we will never explore the other path.
Lab-05 2020BCSE034
Starting from the left hand side (L.H.S) , the terms are S and
M. Assign a digit which could give a satisfactory result. Let’s
assign S->9 and M-
>1.
2020BCSE034
Note: When we will solve further, we will get one carry, so after applying
it, the answer will be satisfied.
Further, adding the next two terms N and R we get,
But, we have already assigned E->5. Thus, the above result does
not satisfy the values
because we are getting a different value for E. So, we need
to think more.
Again, after solving the whole problem, we will get a carryover on this
term, so our answer will be satisfied.
Map Coloring
Scheduling the tasks
Preparing Time Table
Assignment
Conflict Resolution
Sudoku
Lab-07 2020BCSE034
Example:
Suppose maximizer takes first turn which has worst-case initial value =-
infinity, and minimizer will take next turn which has worst-case initial
value = +infinity.
Step 1: At the first step the, Max player will start first move from node A
where α= -∞ and β= +∞, these value of alpha and beta passed down to
node B where again α= -∞ and β= +∞, and Node B passes the same value
to its child D.
Step 5: At node C, α=3 and β= +∞, and the same values will be passed on to
node F.
Step 7: C now returns the value of 1 to A here the best value for A is max
(3, 1)= 3.Hence the optimal value for the maximizer is 3 for this example.
– Functions, which are a subset of relations where there is only one “value”
for any given “input”
Examples:
FOL Provides :-
• Connectives – Same as in PL: not (), and (), or (), implies (), if and only if
(biconditional )
4. Find the best particle (according to the particle’s last best places).
Row 2
Passing (x1=0 and x2=1), we get;
0+1–1 = 0 2020BCSE034
From the Perceptron rule, if Wx+b >=0, then y`=1. This row
is incorrect, as the output is 0 for the AND gate.
So we want values that will make the combination of x1=0
and x2=1 to give y` a value of 0. If we change b to -1.5, we
have;
0+1–1.5 = -0.5
From the Perceptron rule, this works (for both row 1, row 2
and 3).
Row 4
Passing (x1=1 and x2=1), we get;
1+1–1.5 = 0.5
Again, from the perceptron rule, this is still valid.
Therefore, we can conclude that the model to achieve an
AND gate, using the Perceptron algorithm is;
x1+x2–1.5
OR Gate:
2020BCSE034
Row 1
From w1x1+w2x2+b, initializing w1, w2, as 1 and b as -1, we get;
x1(1)+x2(1)-1
Passing the first row of the OR logic table (x1=0, x2=0), we get;
0+0–1 = -1
From the Perceptron rule, if Wx+b<0, then y`=0. Therefore, this
row is correct.
Row 2
Passing (x1=0 and x2=1), we get;
0+1–1 = 0
From the Perceptron rule, if Wx+b >=0, then y`=1. This row
is again, correct (for both row 1, row 2 and 3).
Row 4
Passing (x1=1 and x2=1), we get;
1+1–1 = 1
Again, from the perceptron rule, this is still valid. Quite Easy!
Therefore, we can conclude that the model to achieve an
OR gate, using the Perceptron algorithm is;
x1+x2–1
2020BCSE034_AMIR SHABIR
INDEX
LAB-01):- BFS and DFS
LAB-02):- N-Queen problem
LAB-03):- 8-puzzle proble
LAB-04):- A* and AO* algorithm
LAB-05):- Crypt Arithmatic
LAB-06):- Graph Coloring
LAB-07):- Min-Max and Alpha-Beta
pruning
LAB-08):- Fuzzy Logic (First-order
Prolog)
LAB-09):- Expert system (Mamdani
fuzzy model)
LAB-10):- AND and OR Gate in
Neural Network