You are on page 1of 3

Class 17CTT – Term I/2019-2020

Course: CS420 – Artificial Intelligence

Lab 01 – Uninformed Search

You are given a graph and a pair of source and destination nodes. Write a program to find
the (optimal) path from source to destination using the following search strategies
a. Breath-first search (BFS)
b. Depth-first search (DFS): avoid infinite loops by checking new states against those
on the path from the root to the current node
c. Uniform-cost search (UCS)
d. Iterative-deepening search (IDS)
Run those algorithms on a set of at least 5 different graphs. Make a comparison of their
performances following the orders of expanded nodes and the paths returned.
Hint: Graphs of large diversity (e.g., the proximity of source and destination, dense/sparse
graph, etc.) are useful for your analysis.

1. Specifications
• Input: the given graph is represented by its adjacency matrix, which is stored in the file
input.txt. The input file format is described as follows:
- The first line contains an integer N indicating the number of nodes in the graph.
- The second line stores three integers separated by white spaces. They represent
the indices of source and destination, and the search strategy (whose possible
values are 0 = BFS, 1 = DFS, 2 = UCS and 3 = IDS), respectively.
- The N next lines represent the N  N adjacency matrix. Each line contains N
integers separated by white spaces. [i, j] = A > 0 (A is an integer) if there is a link
of weight A from node i to node j, and [i, j] = 0 otherwise.
• Output: the result is stored in the file output.txt, whose format is described as follows:
- If there exists a path from the source to the destination
▪ The first line contains the order of expanded nodes
▪ The second line show nodes in the path return by the strategy.
- Otherwise:
▪ The first line contains the order of expanded nodes
▪ The second line show a notification of search failure
- Nodes are represented using their indices (from zero) and they are separated by
white spaces.
1
• The main function must perform the following basic actions
- Read the input data from the input file and store it in appropriate data
structures.
- Call the function BFS (or DFS, UCS, IDS), which implements the Breadth-first
search (or Depth-first search, Uniform-cost, Iterative-deepening), to find a path
from source to destination.
- Show the outputs.
• When there are many candidate nodes with equal possibilities, the algorithms must
visit them following their ascending index ordering.
• Use relative paths for the input and output files and do not change their names.

An example of the input graph and its corresponding files input.txt and output.txt
Graph input.txt output.txt Note
5 014 Find a path from node 0
030 043 to node 3 using BFS
02001
00506
00030
01000
00010

Another example with the same input graph yet a different pair of source – destination and
a different search strategy.
Graph input.txt output.txt Note
5 3124 Find a path from node 3
301 No path is found. to node 0 using DFS
02001
00506
00030
01000
00010

2. Grading
No. Specifications Scores
1 Implement search strategies (5% each) 20%
2 Correct orders of expanded nodes (5% each) 20%
3 Correct paths (5% each) 20%
4 Follow the lab specifications well 10%
5 A comprehensive comparison of uninformed search algorithms 30%
Total 100%

2
3. Notice
• This is an INDIVIDUAL assignment.
• Your program should be programmed in C++ or Python. Write down your report on a
PDF File.
• You are allowed to use data structure functions/libraries (e.g. queue, stack), yet you
must implement the uninformed search algorithms by yourself.

You might also like