0% found this document useful (0 votes)
101 views12 pages

IoT Lab Manual Aktu

The document is a lab report for the Internet of Things Lab at GL Bajaj Institute of Technology and Management for the session 2024-25. It includes a list of experiments focusing on Prolog and LISP programming, covering topics such as temperature conversion, the Monkey Banana problem, medical diagnosis, and various algorithm implementations. Each experiment outlines objectives, theoretical background, program examples, and execution steps.

Uploaded by

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

IoT Lab Manual Aktu

The document is a lab report for the Internet of Things Lab at GL Bajaj Institute of Technology and Management for the session 2024-25. It includes a list of experiments focusing on Prolog and LISP programming, covering topics such as temperature conversion, the Monkey Banana problem, medical diagnosis, and various algorithm implementations. Each experiment outlines objectives, theoretical background, program examples, and execution steps.

Uploaded by

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

GL BAJAJ INSTITUTE OF

TECHNOLOGY AND MANAGEMENT

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING (AI)

SESSION 2024-25

LAB REPORT

INTERNET OF THINGS LAB (KCS-751 )

SEMESTER :VII

Submitted To: Submitted By:


Dr. Pawan Kumar Mall Name:
Roll No:
Section:
lOMoARcPSD|458 417 36

GL BAJAJ Approved by AICTE, Govt. of India & Affiliated to Dr. APJ


Abdul Kalam Technical University, Lucknow, U.P., India
Department of Computer Sc. & Engineering (AI)
Institute of Technology & Management
Greater Noida

LIST OF EXPERIMENTS

SL.NO. PROGRAM Date of Signature


Submission
1 Study of Prolog 02/09/2024

2 16/09/2024
Write simple fact for the statements using
PROLOG.
3 Write predicates One converts centigrade 07/10/2024
temperatures to Fahrenheit, the other checks if a
temperature is below freezing.

4 Write a program to solve the Monkey Banana 14/10/2024


problem.

5 WAP in turbo prolog for medical diagnosis and 28/10/2024


Show the advantage and disadvantage of green
and red cuts.

6 WAP to implement factorial, Fibonacci of a given 04/11/2024


number.

7 Write a program to solve 4-Queen problem. 11/11/2024

8 Write a program to solve traveling sales man 18/11/2024


problem.

9 Write a program to solve water jug problem 25/11/2024


using LISP.

10 Write a Lisp program to solve best first search 02/12/2024


traversal.
lOMoARcPSD|458 417 36

GL BAJAJ Approved by AICTE, Govt. of India & Affiliated to Dr. APJ


Abdul Kalam Technical University, Lucknow, U.P., India
Department of Computer Sc. & Engineering (AI)
Institute of Technology & Management
Greater Noida

Experiment 1: Study of Prolog


1. Objective
Understand the basics of Prolog programming, including syntax for facts, rules, and
queries.
2. Theory
Prolog is a logic programming language that relies on facts, rules, and queries to solve
problems. It is declarative and widely used in AI and computational linguistics.
3. Program
No specific program; focus on understanding syntax.
4. Detailed Explanation
Prolog programs are constructed with:
Facts: Represent known truths.
Rules: Define relationships between facts.
Queries: Extract information or verify statements based on the knowledge base.
5. Execution Steps
Write facts and rules in a .pl file.
Run the Prolog interpreter (e.g., SWI-Prolog).
Load the file and execute queries.
lOMoARcPSD|458 417 36

GL BAJAJ Approved by AICTE, Govt. of India & Affiliated to Dr. APJ


Abdul Kalam Technical University, Lucknow, U.P., India
Department of Computer Sc. & Engineering (AI)
Institute of Technology & Management
Greater Noida

Experiment 2: Writing Simple Facts in Prolog


1. Objective
Create a Prolog database with simple facts and demonstrate how to query it.
2. Theory
Facts in Prolog define relationships between objects. Queries test these relationships or
find values that satisfy them.
3. Program
% Facts
parent(john, mary).
parent(mary, susan).
parent(john, tom).

% Query examples:
% ?- parent(john, mary).
% ?- parent(mary, X).
4. Detailed Explanation
I. parent(john, mary). indicates John is a parent of Mary.
II. Queries like ?- parent(mary, X). search for all values of X that satisfy the
relationship.
5. Execution Steps
I. Save the program as facts.pl.
II. Load it into Prolog: [facts].
III. Run queries interactively.
lOMoARcPSD|458 417 36

GL BAJAJ Approved by AICTE, Govt. of India & Affiliated to Dr. APJ


Abdul Kalam Technical University, Lucknow, U.P., India
Department of Computer Sc. & Engineering (AI)
Institute of Technology & Management
Greater Noida

Experiment 3: Predicates for Temperature Conversion and Freezing Check


1. Objective
Create predicates to convert temperatures from Centigrade to Fahrenheit and check if a
temperature is below freezing.
2. Theory
Prolog predicates are logic-based rules that describe relationships or compute values.
3. Program
% Convert Centigrade to Fahrenheit
to_fahrenheit(C, F) :- F is C * 9 / 5 + 32.

% Check if temperature is below freezing


below_freezing(C) :- C < 0.

% Query examples:
% ?- to_fahrenheit(0, F).
% ?- below_freezing(-5).
4. Detailed Explanation
I. to_fahrenheit/2 computes the Fahrenheit equivalent of a given Centigrade value.
II. below_freezing/1 checks if a temperature is below 0°C.
5. Execution Steps
I. Save the program as temperature.pl.
II. Load it into Prolog and run the provided queries.
lOMoARcPSD|458 417 36

GL BAJAJ Approved by AICTE, Govt. of India & Affiliated to Dr. APJ


Abdul Kalam Technical University, Lucknow, U.P., India
Department of Computer Sc. & Engineering (AI)
Institute of Technology & Management
Greater Noida

Experiment 4: Monkey Banana Problem

1. Objective
Solve the Monkey Banana Problem using state-space representation in Prolog.
2. Theory
The Monkey Banana Problem is a classic AI problem where a monkey needs to perform
a series of actions to obtain a banana.
3. Program
% Actions: monkey moves, climbs, or grabs banana
state(at(monkey, ground), has(banana, no)).
action(grab, state(at(monkey, top), has(banana, no)), state(at(monkey, top), has(banana,
yes))).

% Solve the problem by querying actions:


% ?- action(grab, state(at(monkey, top), has(banana, no)), FinalState).
4. Detailed Explanation
I. The initial state defines the monkey’s position and whether it has the banana.
II. Actions represent transitions between states.
5. Execution Steps
I. Save the program as monkey_banana.pl.
II. Load it and query state transitions to solve the problem.
lOMoARcPSD|458 417 36

GL BAJAJ Approved by AICTE, Govt. of India & Affiliated to Dr. APJ


Abdul Kalam Technical University, Lucknow, U.P., India
Department of Computer Sc. & Engineering (AI)
Institute of Technology & Management
Greater Noida

Experiment 5: Medical Diagnosis in Turbo Prolog

1. Objective
Create a knowledge base for diagnosing diseases based on symptoms.
2. Theory
Turbo Prolog allows creating decision-making systems by defining symptoms and
diagnoses as rules and facts.
3. Program
% Facts
symptom(john, fever).
symptom(john, cough).

diagnosis(X, flu) :- symptom(X, fever), symptom(X, cough).

% Query example:
% ?- diagnosis(john, flu).
4. Detailed Explanation
I. Each symptom/2 fact associates a person with a symptom.
II. diagnosis/2 uses logical conjunction to infer a disease.
5. Execution Steps
I. Save the program as diagnosis.pl.
II. Run it in Turbo Prolog to diagnose based on input symptoms.
lOMoARcPSD|458 417 36

GL BAJAJ Approved by AICTE, Govt. of India & Affiliated to Dr. APJ


Abdul Kalam Technical University, Lucknow, U.P., India
Department of Computer Sc. & Engineering (AI)
Institute of Technology & Management
Greater Noida

Experiment 6: Factorial and Fibonacci Programs in Prolog

1. Objective
Implement programs to calculate factorial and Fibonacci series values.
2. Theory
Recursive definitions in Prolog simplify computation for mathematical sequences.
3. Factorial Program
factorial(0, 1).
factorial(N, F) :- N > 0, N1 is N - 1, factorial(N1, F1), F is N * F1.

% Query example:
% ?- factorial(5, F).
3. Fibonacci Program
fibonacci(0, 0).
fibonacci(1, 1).
fibonacci(N, F) :- N > 1, N1 is N - 1, N2 is N - 2, fibonacci(N1, F1), fibonacci(N2, F2), F
is F1 + F2.

% Query example:
% ?- fibonacci(6, F).
4. Detailed Explanation
I. Factorial uses recursive multiplication.
II. Fibonacci sums the previous two values in the series.
5. Execution Steps
I. Save the programs as factorial.pl and fibonacci.pl
II. Load and query them in Prolog.
lOMoARcPSD|458 417 36

GL BAJAJ Approved by AICTE, Govt. of India & Affiliated to Dr. APJ


Abdul Kalam Technical University, Lucknow, U.P., India
Department of Computer Sc. & Engineering (AI)
Institute of Technology & Management
Greater Noida

Experiment 7: . 4-Queen Problem

1. Objective
Solve the 4-Queen problem using backtracking in Prolog.
2. Theory
The N-Queen problem involves placing N queens on an N×N chessboard such that no
two queens threaten each other.
3. Program
nqueen(N, Qs) :- length(Qs, N), place_queens(Qs), safe_queens(Qs).

place_queens([]).
place_queens([Q|Qs]) :- place_queens(Qs), member(Q, [1,2,3,4]).

safe_queens([]).
safe_queens([Q|Qs]) :- safe(Q, Qs, 1), safe_queens(Qs).

safe(_, [], _).


safe(Q, [Q1|Qs], D) :- Q =\= Q1, abs(Q - Q1) =\= D, D1 is D + 1, safe(Q, Qs, D1).

% Query example:
% ?- nqueen(4, Qs).
4. Detailed Explanation
I. place_queens/1 generates permutations for queen positions.
II. safe_queens/1 ensures no two queens threaten each other.
5. Execution Steps
I. Save the program as nqueen.pl.
II. Query it with different values for N.
lOMoARcPSD|458 417 36

GL BAJAJ Approved by AICTE, Govt. of India & Affiliated to Dr. APJ


Abdul Kalam Technical University, Lucknow, U.P., India
Department of Computer Sc. & Engineering (AI)
Institute of Technology & Management
Greater Noida

Experiment 8: Traveling Salesman Problem

1. Objective
Solve the Traveling Salesman Problem using Prolog.
2. Theory
The TSP aims to find the shortest possible route visiting each city exactly once and
returning to the origin.
3. Program
tsp(Start, Path, Cost) :- findall([P, C], path(Start, P, C), AllPaths), shortest(AllPaths, Path,
Cost).

path(Start, [Start|P], Cost) :- travel(Start, P, Cost).

% Query example:
% ?- tsp(a, Path, Cost).
4. Detailed Explanation
I. path/3 generates all possible routes.
II. shortest/3 finds the route with the minimum cost.
5. Execution Steps
I. Save the program as tsp.pl.
II. Load and execute queries for various starting cities.
lOMoARcPSD|458 417 36

GL BAJAJ Approved by AICTE, Govt. of India & Affiliated to Dr. APJ


Abdul Kalam Technical University, Lucknow, U.P., India
Department of Computer Sc. & Engineering (AI)
Institute of Technology & Management
Greater Noida

Experiment 9: . Water Jug Problem in LISP


1. Objective
Solve the water jug problem using LISP.
2. Theory
The Water Jug Problem explores state transitions to achieve a goal measurement using
two jugs of fixed capacities.
3. Program
(defun water-jug (x y goal)
(cond ((or (= x goal) (= y goal)) (list x y))
((< x 4) (water-jug 4 y goal))
((< y 3) (water-jug x 3 goal))
((> x 0) (water-jug 0 y goal))
((> y 0) (water-jug x 0 goal))
(t 'unsolvable)))

% Query example:
% (water-jug 0 0 2)
4. Detailed Explanation
I. Each recursive call represents a state transition.
II. Termination occurs when the goal measurement is achieved.
5. Execution Steps
III. Save the program as water_jug.lisp.
I. Load and execute it in a LISP interpreter.
lOMoARcPSD|458 417 36

GL BAJAJ Approved by AICTE, Govt. of India & Affiliated to Dr. APJ


Abdul Kalam Technical University, Lucknow, U.P., India
Department of Computer Sc. & Engineering (AI)
Institute of Technology & Management
Greater Noida

Experiment 10: Best-First Search Traversal in LISP

1. Objective
Implement best-first search for graph traversal.
2. Theory
Best-First Search uses heuristics to explore the most promising paths in a graph.
3. Program
(defun best-first-search (start goal graph)
(if (equal start goal)
(list start)
(let ((neighbors (cdr (assoc start graph))))
(append (list start)
(best-first-search (car neighbors) goal graph)))))

% Example Graph:
% (best-first-search 'a 'd '((a b c) (b d) (c e))).
4. Detailed Explanation
I. The function evaluates neighbors based on a heuristic.
II. The path with the least estimated cost is explored first.
5. Execution Steps
I. Save the program as best_first_search.lisp.
II. Load and execute it in a LISP interpreter.

You might also like