Homework Two

Uninformed State Space Search

out 9/10, due 9/19 9/21

Approaching problem solving as a search through a state space is a common and powerful technique. The basic algorithms for searching the state space graph are well known and easy to implement. The real work lies in deciding how to model the problem as a graph of possible states and how to implement a function to generate the graph. This assignment asks you to set up a simple problem for solution using any of the standard 'uninformed' search algorithms and to use the implementations associated with the text in Python or Java to solve the problem.

Background

Our text has code in Java and Python that implement various search algorithms. You are encouraged to try the Python version but are free to use the Java one or write your own. We'll give examples for Python.

Missionaries and Cannibals

Solving the Missionaries and Cannibals problem is a classic example in AI. It was used in a seminal paper by Saul Amarel to demonstrate that changing a problem representation can have a big impact on the complexity of solving it. Here's one description of the problem.

Three missionaries and three cannibals are on the left bank of a river. A boat is available which will hold two people, and which can be navigated by any combination of missionaries and cannibals involving one or two people. If the missionaries on either bank of the river are outnumbered at any time by cannibals, the cannibals will indulge in their anthropophagic tendencies and do away with the missionaries who are outnumbered. Find a schedule of crossings that will permit all the missionaries and cannibals to cross the river from the left bank to the right bank safely.

Write a module, mc.py, for this standard problem using AIMA python code (search.py, utils.py and agents.py). If you copy these files to a directory, complete mc.py, and invoke 'python mc.py' you should get something like the output in mc.txt. As a worked example, wj.py implements the two water jugs problem, producing wj.txt as output.

Extra Credit

The M&C problem statement asks you to wolve solve the traditional Missionaries and Cannibals problem, which has an initial state with three of each and a boat on the left bank and a goal state with everybody on the right bank. Of course, it's good practice in computer science to write a more general solution if its impact on complexity and efficiency is minimal. It is not much harder to write a general MC problem that works for any initial state and goal state configurations. Doing allows us to check if other initial states (e.g., four missionaries and four cannibals on the left bank) can still get you to a state where everyone has crossed the river safely.

We encourage you to write this more general solution, but its not required. As an incentive, we will offer 'extra credit' for doing this in a way that allows us to call it with an arbitrary initial and goal state. We've updated the mc.py file (mc.v0.py is still the old one) to

  • Allow this to be called from the command line with an optional initial state and goal state;
  • Assume that the MC.__init__() method takes two arguments, initial and goal, that are the initial and goal state. Both are optional and have default values that you must supply, depending on your representation. (Defaults are taken from the traditional problem, with all Ms and Cs and the boat starting on the left and ending on the right).
  • Provide an additional function solutions() that can be used to prints an array showing MC problems that have solutions for initial states with 0..M_max and 0..C_max millionaires and cannibals, respectively. Its uses breadth_first_graph_search (from search.py) to test for a solution.

The changes should be backward compatible with the original task, which only requires solving the traditional problem. But in case not, mc.v0.py is the original stub file. See mc2.txt for examples of how an enhanced version should work when calling from the command line.

Jealous husbands

The jealous husbands problem is similar to the Missionaries and cannibals and, in fact, predates it.

Three traditional, but jealous, couples need to cross a river. Each couple consists of a husband and a wife. They find a small boat that can contain no more than two persons. Find the simplest schedule of crossings that will permit all six people to cross the river so that none of the women shall be left in company with any of the men, unless her husband is present. It is assumed that all passengers on the boat onboard before the next trip and at least one person has to be in the boat for each crossing.

Note that the number of men and women on each side of the river bank is not what is important in this problem, but which man is with which woman. While an unmarried man and woman can be in the boat without violating the constraint, when they reach the other side of the river, they must both disembark before the next action is taken. After disembarking on the shore, the people on that shore must satisfy the constraint.

Develop a module jh.py that sets up this problem for solution with the AIMA code.

What to hand in

Turn in your code for the two problems along with output showing them solving the standard problem for each.

We've extended the deadline for HW2 to 23:59:59 Friday 9/21. We hope to have the cvs working on 9/20. You can submit via that if you are able to or, alternatively, send a .zip or .gz file with your hw2 files to cmsc671hw@cs.umbc.edu.

The HW2 files should include a readme.txt file with your name and user ID and any comments you want to provide, the source (my.py and jh.py), two files with sample output (my.txt, jh.txt). You can capture the output easily on a UNIX system using the Unix script command. If you modified the AIMA code (e.g., search.py, agent.py) or wrote any other Python modules, you should include those as well. We will test your code on on python 2.6.6 on gl.umbc.edu. I you are relying on any features that were introduced in later versions, please let us know in your readme.txt.

Background reading

  • Python tutorial
  • Amarel, S. (1968). On representations of problems of reasoning about actions, Machine Intelligence.