====== Lab 3 - Hashing States ====== Many environments have the property that there are several paths that lead to the same state. ===== Tasks ===== - Which of the search algorithms that we covered in class benefit from detecting repeated states? For each algorithm give a short explanation how detecting repeated states makes it better. - Which data structure is typically used for detecting repeated states and why? - Download the material below, implement a hash function for State objects that passes all the tests. - Comment on the results you get. Are the good or bad? How would they influence the efficiency and effectiveness of detecting repeated states if your hash function was used? ===== Material ===== * {{:public:t-622-arti-13-1:hashing_states.zip|java project for the lab}} 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 [[http://docs.oracle.com/javase/6/docs/api/java/lang/Object.html#hashCode%28%29|int hashCode()]] and [[http://docs.oracle.com/javase/6/docs/api/java/lang/Object.html#equals%28java.lang.Object%29|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 ===== Hand in a zip file containing: * the answers to the questions above (in a text/pdf/word file) * your source code (ideally just the whole project directory) To create the zip file you can just edit the "student" property in the build.xml and call the "zip" target using ant (execute "ant zip" in the directory containing the build.xml).