AI Lab Course Handout Spring 2024
AI Lab Course Handout Spring 2024
Deemed to be University
BHUBANESWAR-751024
Course
Handout
1. Course code : CS 39002
2. Course Title : Artificial Intelligence Laboratory (AI Lab.)
3. LTP Structure :
L T P Total Credit
2 0 0 2 1
4. Course Faculty :
Name : Jayeeta Chakrborty, Ph.D.
Email ID : [email protected]
Faculty Room : F102(c), First Floor, Block-C, Campus-14
6. Course Objective:
⚫ To provide skills for designing and analyzing AI based algorithms.
⚫ To enable students to work on various AI tools.
⚫ To provide skills to work towards solution of real life problems
General Instructions:
Install Python and use the python IDE or Jupyter Notebook to implement the
assignments given for AI Lab. or,
Use Google Colab to implement the assignments given for the AI Lab. Students must
use their KIIT mail ID to create Google Colab Notebooks. Naming convention can be
"RollNo_AssignmentNo.ipynb."
Tasks:
⚫ Use BFS to find the shortest path.
⚫ Use DFS to explore all possible paths and report one valid path (not necessarily
the shortest).
⚫ Compare the number of nodes explored by BFS and DFS.
Problem Statement: Represent a city map as a graph where intersections are nodes
and roads are edges. Find the shortest path between two locations.
Tasks:
⚫ Implement Bi-directional BFS to minimize the number of nodes explored.
⚫ Compare the performance of Bi-directional BFS with standard BFS and DFS.
⚫ Visualize the search process (e.g., using a library like networkx in Python).
Problem Statement: The treasure is hidden in a grid, and each cell has a heuristic
value representing its "closeness" to the treasure. Implement Best-First Search to
locate the treasure.
Tasks:
⚫ Use Manhattan distance as a heuristic.
⚫ Implement the algorithm to always move to the most promising cell first
(minimum heuristic value).
⚫ Analyze how heuristic choice affects performance.
Problem Statement: Given a weighted graph (e.g., a transportation network with travel
costs), find the minimum-cost path between two nodes.
Tasks:
⚫ Represent the graph as an adjacency list.
⚫ Implement Uniform Cost Search to find the optimal path.
⚫ Compare it with BFS for unweighted graphs.
Assignment 5: A Search for a Puzzle Solver*
Problem Statement: The 8-puzzle involves sliding tiles to achieve a goal state. Use A*
to solve it.
Tasks:
Define heuristic functions:
⚫ H1: Number of misplaced tiles.
⚫ H2: Sum of Manhattan distances of all tiles from their goal positions.
⚫ Implement A* with both heuristics.
⚫ Compare the performance of the two heuristics in terms of the number of nodes
explored and solution depth.
Objective: Use A* Search to find an optimal path for a robot navigating a 2D grid.
Problem Statement: A robot must move from a start point to a goal in a grid while
avoiding obstacles.
Tasks:
Implement A* with:
⚫ The Manhattan distance heuristic applies to grids without any diagonal movement.
⚫ The Euclidean distance heuristic is applicable to grids that allow diagonal
movement.
⚫ Use a plotting library to visualize the found path.
⚫ Compare A* with BFS and Uniform Cost Search.
Tasks:
⚫ Use BFS and DFS for exploring game states.
⚫ Implement A* Search with a heuristic function to improve efficiency.
⚫ Compare search strategies for different game board configurations.
Objective: Solve a problem where multiple goals exist using search algorithms.
Problem Statement: A robot in a grid needs to collect items (goals) before reaching an
exit. Each goal has a different priority or cost.
Tasks:
⚫ Use BFS/DFS for simpler scenarios (unweighted goals).
⚫ Implement A* or Uniform Cost Search for weighted scenarios.
⚫ Analyze the trade-offs between path length and goal priority.
Tasks:
⚫ Represent tasks and dependencies as a directed graph.
⚫ Use A* Search when the heuristic estimates the remaining tasks' duration.
⚫ Compare results with a greedy algorithm.
Problem Statement: Given a domain (e.g., pathfinding, puzzle solving), evaluate BFS,
DFS, Bi-directional BFS, Uniform Cost Search, Best-First Search, and A* Search.
Tasks:
Analyze:
⚫ Efficiency: Nodes explored, time taken.
⚫ Optimality: Whether the solution is optimal.
⚫ Create visualizations to compare algorithms
Develop a competitive version of the Water-Jugs problem where two players take
turns making moves. Implement the Minimax algorithm to determine the optimal
strategy for the AI player. Extend the solution by incorporating alpha-beta pruning for
improved efficiency.
Problem Setup:
You are given two jugs of capacities A liters and B liters, and a target volume T liters.
Two players alternately make moves, with the objective of the game being to reach
exactly T liters in any jug. The first player to achieve this win. If no valid moves are
left, the game ends in a draw.
Rules for Valid Moves:
Game Design:
Minimax Implementation:
1. Use the Minimax algorithm to evaluate all possible moves for both
players.
2. Define a utility function:
⚫ Positive scores for states closer to the target volume TTT for the
AI player.
⚫ Negative scores for states closer to the target for the opponent.
⚫ Zero for states with no valid moves left.
Player Interaction:
1. Test the AI’s performance against a human opponent and analyze its
strategies.
2. Compare execution times for the Minimax algorithm with and without
alpha-beta pruning.
Deliverables:
⚫ Minimax algorithm.
⚫ Alpha-beta pruning.
Design a competitive version of the 4-Queens problem where two players alternately
place queens on a 4x4 chessboard. Implement the Minimax algorithm to strategize
queen placements and incorporate alpha-beta pruning for efficient decision-making.
Problem Setup:
The game involves two players (AI and Human) alternately placing queens on a 4x4
chessboard. The goal is to place queens such that no two queens threaten each other.
The player unable to make a valid move loses the game.
1. A queen can be placed in any cell of the chessboard, provided it is not attacked
by any previously placed queen.
2. A queen attacks cells in the same row, column, and diagonals.
3. Players take turns placing one queen at a time.
4. The game ends when no valid moves are left or all 4 queens are placed.
Game Design:
Minimax Implementation:
1. Use the Minimax algorithm to evaluate all possible moves for both
players.
2. Define a utility function:
1. Positive scores for AI-favorable positions.
2. Negative scores for opponent-favorable positions.
3. Zero for neutral or draw positions.
Player Interaction:
Deliverables:
Assignment 15: Solving the Tower of Hanoi Problem Using Adversarial Search
Transform the traditional Tower of Hanoi puzzle into a competitive two-player game.
Implement adversarial search strategies using the Minimax algorithm to solve the
problem. Enhance efficiency by incorporating alpha-beta pruning.
Problem Setup:
The Tower of Hanoi involves three rods and a set of N disks of decreasing size
stacked on the first rod. The goal is to move all the disks to the last rod following
these rules:
The player who moves the largest disk to the target rod wins. If no valid moves are
left and the game hasn't ended, it is considered a draw.
Game Design:
1. Represent the rods and disks using lists (e.g., rods = [[3, 2, 1], [], []]
for N=3N=3N=3).
2. Create a function to validate moves and update the rods.
Adversarial Search:
Alpha-Beta Pruning:
1. Integrate alpha-beta pruning to optimize the search process by pruning
unnecessary branches.
Player Interaction:
End Condition:
2. The winner is determined based on the size of the largest disk moved
to the target rod by each player.
Deliverables:
Implement and compare heuristic search strategies for solving the 8-Puzzle problem.
Specifically, develop solutions using the A* algorithm and Greedy Best-First Search
(GBFS), leveraging heuristics like the Manhattan Distance or the number of
misplaced tiles.
Problem Setup:
The 8-Puzzle is a sliding puzzle consisting of a 3x3 grid with numbered tiles (1-8)
and a blank space. The goal is to arrange the tiles in a specified order (usually
numerical) by sliding tiles into the blank space, starting from a given configuration.
Heuristic Functions:
Search Algorithms:
1. A*: Combines the cost to reach a state (g(n)) with the heuristic
estimate to the goal h(n).
2. Greedy Best-First Search (GBFS): Considers only the heuristic value
(h(n)) for each state.
Implementation Requirements:
Performance Evaluation:
Deliverables:
Marks Distributions$:
References: