AI Lab Tasks

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

AI lab exercises

1. Use DFS and BFS to solve a search problem and display the solution. The problem can
be the 8-puzzle problem. Students must be able to explain the choice of the data
structure for the nodes ( made up of state, parent, action, depth, path cost).
The students can start with BFS on an initial and goal states that are pre
determined. Later, The students need to display the sequence of moves to reach the
goal state from a randomly generated initial state (i.e., the goal state is fixed) . Not all
initial and goal states combinations are solvable. They should apply the test before
invoking the search function. Let them define a class with the required functions. The
auxiliary functions such as Expand through actions, child node creation, goal test,
detecting valid states (for 8-puzzle, some actions are not valid for corner and border
cases), etc.

Students should tabulate the time taken and space occupied for the executions.
Students should identify the tough input cases after running many input combinations
and then submit a list of such cases.
For the below two initial states and the goal state at the right, the second initial
state can not lead us to the goal state. This is because the number of inversions is odd
for the 2nd input state. Inversion: the values on tiles are in reverse order of their
appearance in goal state

#inversions = 10 for the 1st initial state, 11 for the second initial state
To check, you may use this code:
inv_count = 0
for i in range(0, 9):
for j in range(i + 1, 9):
if arr[j] != empty_value and arr[i] != empty_value and arr[i] > arr[j]:
inv_count += 1
2. Students are expected to implement IDS and UCS to solve a problem of his/her
choice. Two marks are devoted to the choice of the problem and its justification.
This is an open-ended task to test the student’s ability to select an innovative
problem and to find an optimal solution for the problem.
3. A* implementation for 8 puzzle problem using Manhattan distance (can be
extended to shortest path, 8 puzzle, Missionaries and Cannibals, etc with
suitable heuristic)
4. Fill the following table for 8 puzzle problem with the number of states generated,
time taken for completion.

A* IDA* RBFS Weighted A*

#misplaced tiles

Manhattan distance

Gaschnig’s heuristic

Gaschnig’s heuristic: A tile can move from square A to square B if B is blank


Use the following initial and goal states:

You might also like