Java Python COMP3702 Artificial Intelligence
Semester 2, 2024
Tutorial 3
Before you begin, please note:
• Tutorial exercises are provided to help you understand the materials discussed in class, and to improve your skills in solving AI problems.
• Tutorial exercises will not be graded. However, you are highly encouraged to do them for your own learning. Moreover, we hope you get the satisfaction from solving these problems.
• The skills you acquire in completing the tutorial exercises will help you complete the assignments.
• You’ll get the best learning outcome when you try to solve these exercises on your own first (before your tutorial session), and use your tutorial session to ask about the difficulties you face when trying to solve this set of exercises.
• The following data structures may be useful: heapq, queue (Queue, LifoQueue, PriorityQueue).
Exercises
Exercise 3.1. Consider the path planning problem on a 9 × 9 grid world in the figure below. The goal is to move from the star to the ag in as few steps as possible. Crosses indicate obstacles, and attempting to traverse either an obstacle or a boundary wall is an invalid move, and does not move your agent (it should have no cost or efect).
a) Develop a state graph representation for this search problem, and implement a get successors() method for finding the next legal states to this problem, i.e. for generating successor nodes (vertices).
b) Implement BFS for this problem (using a FIFO queue) using your get successors() function.
c) Implement iterative-deepening DFS (IDDFS) for this problem using a length-limited LIFO queue, and reusing get successors().
d) Compare the performance of BFS and IDDFS in terms of:
i) The number of nodes visited/reached
ii) The number of nodes explored/expanded when the search terminates
iii) The number of nodes on the frontier when the search terminates
iv) The cost of the solution path
v) The run time of the algorithm, e.g.
from timeit import default_timer
as timer start = timer()
# . . . Run the code you want to time
end = timer()
COMP3702 Artificial Intelligence Semester 2, 2024 Tutorial 3Python
print(end - start) # Time in seconds, e.g . 150 .38091952400282
Discuss your findings.
Exercise 3.2. Now consider the path planning problem with costly moves on a 9 × 9 grid world in the figure below, where costs of arriving at a state are indicated on the board and the goal is to move from the star to the flag:
a) Run BFS for this problem, reusing your answer from Exercise 3.1 (N.B. it should not use the costs on the grid).
b) Implement UCS for this problem using a priority queue.
c) Compare the performance of BFS and UCS in terms of:
i) The number of nodes visited/reached
ii) The number of nodes explored/expanded when the search terminates
iii) The number of nodes on the frontier when the search terminates
iv) The cost of the solution path
v) The run time of the algorithm
Discuss how and why these results difer from those for Exercise 3.1.
d) Now derive an admissible heuristic for this path planning problem.
e) Using your heuristic, implement A* search for solving this path planning problem.
f) Compare the performance of UCS and A* search in terms of:
i) The number of nodes visited/reached
ii) The number of nodes explored/expanded when the search terminates
iii) The number of nodes on the frontier when the search terminates
iv) The cost of the solution path
v) The run time of the algorithm Explain these results.
Exercise 3.3. Implement A* for solving the 8-puzzle problem, assuming the goal of the 8-puzzle agent is to find the solution in as few steps as possible.
a) Discuss the heuristics you could use with your classmates.
b) Reuse the container in the program you created in the last tutorial, by modifying it to a priority queue. Along with this, revise the program, so as to use the cost from initial to the current node and the heuristics to identify which node to expand next.
c) Implement the heuristic as part of your A* search algorithm.
Exercise 3.4. Let h1 be an admissible heuristic, where the lowest value is 0.1 and the highest value is 2.0. Suppose that for any state s:
• h2 (s) = h1 (s) + 5,
• h3 (s) = 2h1 (s),
• h4 (s) = cos(h1 (s) * π), and
• h5 (s) = h1 (s) * |cos(h1 (s) * π)|