User Tools

Site Tools


public:t-622-arti-16-1:lab_2_-_hashing_states

Lab 2 - Hashing States

Note: For this lab, you can work together in teams of up to 4 students. However, this is not a necessity. The assignment is small enough to do it alone in which case you may get more experience. You can use Piazza to find team members and discuss problems.

You will need a Java Development Kit (JDK) and a Java IDE (any text editor should do as well).

Tasks

Many environments have the property that there are several paths that lead to the same state.

  1. Which of the search algorithms that we covered in class (breadth-first, depth-first and uniform-cost search) benefit from detecting repeated states? For each algorithm give a short explanation how detecting repeated states can make it better.
  2. Which data structure is typically used for detecting repeated states and why?
  3. Download the material below, implement a hash function for State objects that passes all the tests.
  4. Report and comment on the results you get. How many hash collisions and bucket index collisions do you get? Is this good or bad? (If the results are bad try to improve your hash function. If you only get very few collisions, increase the number of states that are generated in Main.java to 10000 or 100000 and see what happens.)
  5. Why is it important to have few hash collisions if hashing is used to detect repeated states?

Material

The Java project for the lab can be found on Skel. See, instructions below on how to get it.

The project contains a State class that could be thought of implementing a state of some robot. The state consists of a position, an orientation and a boolean holding the information of whether or not the robot is turned on. The project also contains code to test how good the hashCode() method of the State class is. To run the tests simply run the Main class or use “ant run” on the terminal.

Hints

  • You need to implement the methods int hashCode() and boolean equals(Object o) in classes State and Position appropriately.
  • For two states s1 and s2 that you'd consider the same, s1.equals(s2) must return true and false otherwise.
  • For any two objects o1 and o2, if o1.equals(o2) then o1.hashCode() == o2.hashCode() must be true!
  • Objects that are not equal are allowed have the same hash code. However, if that happens too often then hash maps become very inefficient.

Handing In

Connect to skel.ru.is using your favorite ssh client and unpack the assignment into your home directory by running the following commands:

[student14@skel ~]$ tar xvf /labs/arti16/lab2/lab2.tar
[student14@skel ~]$ cd arti16/lab2
[student14@skel hw1]$ ls
answers build.xml dist Makefile questions src

You can copy the code to your own machine for development by using any SCP or SFTP client (e.g., WinSCP). However, you need to copy it back to skel before handing in.

To answer the questions run make answers while being in the directory containing Makefile. Single answers will be put into files called answers/answerX.Y.txt, which you can also edit.

Finally, to hand in your answers run make handin while being in the directory containing Makefile. This should produce a file ``/labs/art16/.handin/lab2/student14/handin.tar.gz''. You can check if it exists using the ls command.

/var/www/cadia.ru.is/wiki/data/pages/public/t-622-arti-16-1/lab_2_-_hashing_states.txt · Last modified: 2024/04/29 13:33 by 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki