UMBC CMSC 471.02 Spring 2023 |
• home • about • schedule • hw • exams • notes • code • colab • github • resources • discord • webex • news • |
HW2: Solving search problems with algorithm Aout 2/16, due 3/2click to accept your repositoryThis assignment will give you experience in developing heuristics for Algorithm A*. 1 The DOGCAT GameDOGCAT is a simple word game that I learned from Jeff Shrager, who was the TA when I first taught an AI course in 1980. We used it for a Lisp programming assignment. You are given two words with the same number of letters (we will be using three and four letter words) in each, e.g. DOG and CAT. Your goal is to transform the first word into the second by replacing one letter at a time with any other letter as long as the result is a proper English word. For example, we could change DOG to FOG but not to GOG (not a proper English word) or to GOD (two letters were changed). Thus, one way of getting from DOG to CAT might be:
There are many ways to make most translations. Here is another way:
Some examples are very hard to do. Try changing WHY to ASK. The game can be generalized to words of other lengths and we can also make the problem more interesting by defining other properties of the transformation we want to optimize. For this assignment, we'll work with words of three or four characters. We will define three cost measures:
2. What to doStart by accepting your GitHub Classroom repository. This will contain the starter file dc.py that you will need to complete as well as the AIMA Python required files search.py and utils.py files. Then study the aima search.py file. You should look at the Problem class and its methods, in particular, and the search algorithms. Write a generic version of a DC class that solves instances of the dog_cat problem given an initial and final word using the aima code for astar_search. We've created a stub file for dc.py, which is the only file you need to complete. To complete this stub, you must finish the DC class by completing the init, actions, result, goal_test, h and repr methods. You will probably need to write some auxiliary functions as well. Your heuristic h function must be admissible, that is, always returning an estimate that is less than or equal to the true value. It should not be the trivial estimate of 0, of course. Note that both your path_cost and h methods will have to be sensitive to the problem's cost parameter. We've provided you with dictionary of legal English three and four letter words along with their rarity measures. See this datafile words34.txt.gz and the code in the dc.py stub that loads it: import gzip ... dict_file = "words34.txt.gz" 3. Testing your codeOnce you've written your dc.py file you can test it with dcsolve.py and dctest.py. The dcsolve.py script takes an initial and goal word and an optional cost measure and shows the solution found by our dc.py problem along with the cost and time taken. HW2> python dcsolve.py dog cat The dctest.py script takes no arguments and runs a number of examples using each of the three cost measure. See this example of its use. Note that your program may not produce exactly he same answers, since the A* algorithm with an admissible heuristic finds one of shortest solutions to a problem -- there may be several that are equally short. Is your heuristic admissible?How can you confirm that your heuristic is admissible? The standard way is by reasoning via a formal or informal proof. But you can also get some feedback through experimentation. The dcsolve.py program shows 'deltas', a list of how much the solver underestimated the distance to a goal for each node on the path it found. The values should always be negative or 0 if your solution is valid. If your solution is valid but one or more of the deltas is > 0, then your heuristic is not admissible. If you are having trouble with yout heuristic function, take a look at these slides. What to hand inThe assignment is due by midnight on Thursday, March 2. After you have written, debugged and tested your dc.py file, you should do the following.
Background reading
|
BIT.LY/471S23 • CMSC 471 Spring 2023 • CSEE • UMBC |