COMPSCI 367 23S2 Assignment 1
Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit
COMPSCI 367 23S2 Assignment 1
Lecturer: Anna Trofimova
School of Computer Science, The Univerity of Auckland
Last update 6th of August at 18:00pm, 2023
Student:
Name Surname, UPI
Submission
This interactive notebook contains the instructions to complete assignment 1; You should submit this notebook with the code and answers in one single file in .ipybnformat with name assignment1.ipybn. Write your name and UPI in the cell above (to edit the markdown text double-click the cell).
There is a maximum file size cap of 5MB, so make sure your submission does not exceed this size. The submitted notebook should contain all your source code and answers. You can add new cells and use markdown text to organise and explain your implementation/answer.
Late submission policy: for each day past the deadline, there's a 20% deduction from the maximum possible score. By the fifth day post-deadline, the highest score attainable is 0. Example: if your submission received an 80% grade, but it was turned in 2 days late, then your final score is capped at 60%.
Submit this notebook using CANVAS upload function.
The submission deadline is 18th of August at 11.59pm, 2023.
Plagiarism
This is an individual assignment. Remember that all work submitted for this assignment must be your own individual work and no codesharing or copying is allowed. You may use code from the Internet only with suitable attribution of the source in your program. Using code generation tools does not excuse you from the responsibility of ensuring the originality and authenticity of your work, and you should refrain from submitting code generated by AI as your own without
proper attribution. Do not use public code repositories as your code might be copied. Keep in mind that sharing parts of assignment solutions is a form of plagiarism. All submitted assignments will be run through plagiarism detection software to detect similarities to other submissions. It is your responsibility to
familiarise yourself with the UoA policy on academic integrity and plagiarism.
Description
This assignment consist of 5 parts with the following distribution of the mark:
part 1 is worth 5% of the total mark
part 2 is worth 25% of the total mark
part 3 is worth 35% of the total mark
part 4 is worth 25% of the total mark
part 5 is worth 15% of the total mark
For solving the problems in this assignment, please utilize the aipython package. This package offers a variety of pre-implemented classes and usage
examples. To download the mostrecent version of the package, follow this link: https://artint.info/AIPython/aipython.zip (https://artint.info/AIPython/aipython.zip)
Place this notebook in a folder next to aipyton folder (not inside it).
When working with a Jupyter notebook, you can edit the *.ipynb files either in the Jupyter interface (in your browser) or with your favorite editor (e.g. PyCharm). Whenever you save a *.ipynb file, the notebook will reload its content directly. Whenever you execute a cell, the output is displayed below that cell and remains saved within the notebook - do not clear the output.
The libraries that you can use (and need) in this assignment are the following (run the cell below to import the libraries):
In [ ]:
import sys sys.path.insert(0, "./aipython") import time import numpy as np from aipython.searchGeneric import * from aipython.searchProblem import * from aipython.cspProblem import * import random import copy import math |
Part 1 - State Space Problem & Search [5%]
This part of the assignment is based on a popular puzzle, Game of Fifteen, also known as 15-puzzle. The game consists of 15 numbered tiles on a four by four grid where one tile is missing. The objective is to rearrange the tiles by moving the empty space to order them from 1 to 15. The goal state of the puzzle is
defined as a multidimensional array of digits, where 0 represents the missing tile, as follow:
In [ ]:
goal = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 0]] |
Task 1.1 Creating a FifteenPuzzleGame class
Edit the code below to implement a search problem class representing the Game of Fifteen. The class should be an extension of Search_problem class and the heuristic function should be implemented as a Manhattan distance.
In [ ]:
class GameFifteenProblem(Search_problem): """A class that represents 15 Puzzle Game problem (with Manhattan heuristic) start - 2D array of numbers representing the initial state of the game goal - 2D array of numbers representing the goal stay of the game """ def __init__ (self, start, goal): return def start_node(self): return def is_goal(self, node): return def heuristic(self, node): return def neighbors(self, node): return |
To validate the correctness of the problem class you cab use the A* searcher algorithm (from searchGeneric.py) to find a solution.
The cost of the solution should be 7.
In [ ]:
start_test = [[1, 2, 3, 4], [9, 5, 6, 7], [10, 0, 11, 8], [13, 14, 15, 12]] puzzle = GameFifteenProblem(start_test, goal) searcher = AStarSearcher(puzzle) solution = searcher.search() print('Cost: ', solution.cost) |
Part 2 - Performance Evaluation [25%]
Task 2.1 Implement IDA*
Edit the code below to implement a class representing Iterative Deepening A* Search. The class should be an extension of Searcher class and the search should terminate when the solution is found or when the limit - the boundary for the evaluation value, cannot be updated any further.
In [ ]:
class IterativeDeepeningAStarSearcher(Searcher): """returns a searcher for a problem. Paths can be found by repeatedly calling search(). """ def __init__ (self, problem): super ().__init__ (problem) def add_to_frontier(self, path): return @visualize def search(self): return |
Task 2.2 Record Search Performance
In this task you will compare the properties of different search algorithms. You will need to run Uniform Cost Search, Greedy Search, A* Search and Iterative Deepening A* Search on each of the start states below:
In [ ]:
start6 = [[1, 2, 7, 3], [5, 6, 11, 4], [9, 10, 0, 8], [13, 14, 15, 12]] start11 = [[1, 3, 4, 0], [5, 2, 6, 7], [9, 10, 15, 8], [13, 14, 12, 11]] start25 = [[10, 11, 6, 3], [2, 1, 0, 4], [5, 8, 15, 7], [9, 13, 14, 12]] start33 = [[2, 7, 0, 4], [6, 3, 11, 12], [1, 5, 15, 14], [9, 10, 8, 13]] start41 = [[7, 11, 12, 4], [2, 5, 3, 14], [10, 0, 8, 1 |
2023-08-19