代写 algorithm game prolog Go COMP3411/9414 Artificial Intelligence Term 1, 2019

COMP3411/9414 Artificial Intelligence Term 1, 2019
Assignment 2 – Heuristics and Search
Due: Tuesday 9 April, 11:59pm Marks: 12% of final assessment
Question 1: Search Algorithms for the 15-Puzzle (2 marks)
In this question you will construct a table showing the number of states expanded when the 15-puzzle is solved, from various starting positions, using four different searches:
(i) Uniform Cost Search (with Dijkstra’s Algorithm)
(ii) Iterative Deepening Search
(iii) A∗Search (using the Manhattan Distance heuristic)
(iv) Iterative Deepening A∗Search
Go to the Course Web Site, Week 3 Prolog Code: Path Search, scroll to the Activity at the bottom of the page and click on “prolog search.zip”. Unzip the file and change directory to prolog search, e.g.
unzip prolog_search.zip
cd prolog_search
Start prolog and load puzzle15.pl and ucsdijkstra.pl by typing [puzzle15].
[ucsdijkstra].
Then invoke the search for the specified start10 position by typing start10(S), solve(S,P,G,N), showsol(P).
When the answer comes back, just hit Enter/Return. This version of UCS uses Dijkstra’s algorithm which is memory efficient, but is designed to return only one answer. Note that the length of the path is returned as G, and the total number of states expanded during the search is returned as N.
(a) Draw up a table with four rows and five columns. Label the rows as UCS, IDS, A∗ and IDA∗, and the columns as start10, start20, start27, start35 and start43. Run each of the following algorithms on each of the 5 start states:
(i) [ucsdijkstra] (ii) [ideepsearch]
(iii) [astar] (iv) [idastar]
1

In each case, record in your table the number of nodes generated dur- ing the search. If the algorithm runs out of memory, just write “Mem” in your table. If the code runs for five minutes without producing out- put, terminate the process by typing Control-C and then “a”, and write “Time” in your table.
(b) Briefly discuss the time and space efficiency of these four algorithms.
Question 2: Deceptive Starting States (1.5 marks) Consider the two starting states start49 and start51.
(a) Print state start49 and calculate its heuristic value by typing
start49(S), showpos(S), h(S,H).
Do the same for start51 and copy the result into your solutions.
(b) Use [idastar] to search, starting from start51, and report the number of nodes that are expanded.
(c) When [idastar] is used to search from start49, the number of nodes expanded is 178880187. Briefly explain why the search from start49 expands so many more nodes than the search from start51, even though the true path length is very similar.
Question 3: Heuristic Path Search (2 marks)
In this question you will be exploring an Iterative Deepening version of the Heuristic Path Search algorithm discussed in the Week 4 Tutorial. Draw up a table in the following format:
start49
start60
start64
IDA∗
49
178880187
60
321252368
64
1209086782
1.2 1.4
Greedy
The top row of the table has been filled in for you (to save you from running some rather long computations).
(a) Run[greedy]forstart49,start60andstart64,andrecordthevalues returned for G and N in the last row of your table (using the Manhattan Distance heuristic defined in puzzle15.pl).
2

(b) Nowcopyidastar.pltoanewfileheuristic.plandmodifythecodeof this new file so that it uses an Iterative Deepening version of the Heuristic Path Search algorithm discussed in the Week 4 Tutorial Exercise, with w = 1.2 .
In your submitted document, briefly show the section of code that was changed, and the replacement code.
(c) Run [heuristic] on start49, start60 and start64 and record the values of G and N in your table. Now modify your code so that the value of w is 1.4 instead of 1.2 ; in each case, run the algorithm on the same three start states and record the values of G and N in your table.
(d) Briefly discuss the tradeoff between speed and quality of solution for these four algorithms.
Question 4: Maze Search Heuristics (2.5 marks)
Consider the problem of an agent moving around in a 2-dimensional maze, trying to get from its current position (x,y) to the Goal position (xG,yG) in as few moves as possible, avoiding obstacles along the way.
3

(a) Assume that at each time step, the agent can move one unit either up, down, left or right, to the centre of an adjacent grid square:
One admissible heuristic for this problem is the Straight-Line-Distance heuristic:
hSLD(x,y,xG,yG)=􏰁(x−xG)2 +(y−yG)2
However, this is not the best heuristic.
Give the name of another admissible heuristic which dominates the Straight- Line-Distance heuristic, and write the formula for it in the format:
h(x,y,xG,yG) = …
(b) Now assume that at each time step, the agent can take one step either up, down, left, right or diagonally. When it moves diagonally, it travels to the centre of a diagonally neighboring grid square, but a diagonal step is still considered to have the same “cost” (i.e. one “move”) as a horizontal or vertical step (like a King move in Chess).
(i) Assuming that the cost of a path is the total number of (horizontal, vertical or diagonal) moves to reach the goal, is the Straight-Line- Distance heuristic still admissible? Explain why.
(ii) Is your heuristic from part (a) still admissible? Explain why.
(iii) Try to devise the best admissible heuristic you can for this problem, and write a formula for it in the format:
h(x,y,xG,yG) = …
4

Question 5: Game Trees and Pruning (4 marks)
(a) Consider a game tree of depth 4, where each internal node has exactly two children (shown below). Fill in the leaves of this game tree with all of the values from 0 to 15, in such a way that the alpha-beta algorithm prunes as many nodes as possible. Hint: make sure that, at each branch of the tree, all the leaves in the left subtree are preferable to all the leaves in the right subtree (for the player whose turn it is to move).
MAX
MIN
MAX
MIN
(b) Trace through the alpha-beta search algorithm on your tree, showing clearly which nodes are evaluated and which ones are pruned.
(c) Now consider another game tree of depth 4, but where each internal node has exactly three children. Assume that the leaves have been assigned in such a way that the alpha-beta algorithm prunes as many nodes as possible. Draw the shape of the pruned tree. How many of the original 81 leaves will be evaluated?
Hint: If you look closely at the pruned tree from part (b) you will see a pattern. Some nodes explore all of their children; other nodes explore only their leftmost child and prune the other children. The path down the extreme left side of the tree is called the line of best play or Principal Variation (PV). Nodes along this path are called PV-nodes. PV-nodes explore all of their children. If we follow a path starting from a PV-node but proceeding through non-PV nodes, we see an alternation between nodes which explore all of their children, and those which explore only one child. By reproducing this pattern for the tree in part (c), you should be able to draw the shape of the pruned tree (without actually assigning values to the leaves or tracing through the alpha-beta algorithm).
(d) What is the time complexity of alpha-beta search, if the best move is always examined first (at every branch of the tree)? Explain why.
5

Submission
This assignment must be submitted electronically. COMP9414 students should submit by typing
give cs9414 hw2 …
COMP3411 students should submit by typing give cs3411 hw2 …
The give script will accept *.pdf *.txt *.doc *.rtf If you prefer some other format, let me know.
Late submissions will incur a penalty of 15% per day, applied to the maximum mark.
Group submissions will not be allowed. By all means, discuss the assignment with your fellow students. But you must write (or type) your answers indi- vidually. Do not copy anyone else’s assignment, or send your assignment to any other student.
Good luck!
6