CS 662: AI Programming
Homework #2: OO Python and Agents

Assigned: September 5
Due: September 12.

What to turn in: hard copies of the source code you write. (we don't need copies of the sample code). Also, please turn in typed answers to each of the questions indicated in boldface (there are four of them).

Also, please put a copy of your code in the submit directory for this class: /home/submit/cs662/(yourname)/assignment2. Everything necessary to run your code should be in this directory. If anything out of the ordinary is needed to run your code, please provide a README.

For this homework, you'll extend some existing code to build a set of agents that can successfully operate in the Vacuum Environment.

Important Note:

The AIMA book provides code that solves a very similar problem to this. DO NOT USE THE AIMA CODE!!! I have made some changes and simplifications that make the code clearer and easier to understand. This means that the AIMA code will not work with what I've provided. Using the AIMA code will just give you a lot of headaches.

  1. Start by running the existing code on the NbyMVacuumEnvironment, just to get comfortable with how it works. Here's a sample session:

    >>> import environment
    >>> import sampleAgent
    >>> v=environment.NbyMVacuumEnvironment()
    >>> ag = sampleAgent.RandomAgent(sampleAgent.agent_actions)
    >>> v.add_agent(ag)
    
    >>> v.run(10)
    Initial room config:  {(1, 2): 'Dirty', (1, 1): 'Clean', (0, 2): 'Dirty', (1, 0): 'Dirty', (0, 0): 'Dirty', (0, 1): 'Dirty', (2, 0): 'Clean', (2, 1): 'Dirty', (2, 2): 'Dirty'}
    Percept: ((1, 0), 'Dirty') Action: Left
    Location: (1, 0) Action: Left
    Percept: ((0, 0), 'Dirty') Action: Left
    Location: (0, 0) Action: Left
    Percept: ((0, 0), 'Dirty') Action: Suck
    Location: (0, 0) Action: Suck
    Percept: ((0, 0), 'Clean') Action: Suck
    Location: (0, 0) Action: Suck
    Percept: ((0, 0), 'Clean') Action: Left
    Location: (0, 0) Action: Left
    Percept: ((0, 0), 'Clean') Action: Suck
    Location: (0, 0) Action: Suck
    Percept: ((0, 0), 'Clean') Action: Suck
    Location: (0, 0) Action: Suck
    Percept: ((0, 0), 'Clean') Action: Suck
    Location: (0, 0) Action: Suck
    Percept: ((0, 0), 'Clean') Action: Suck
    Location: (0, 0) Action: Suck
    Percept: ((0, 0), 'Clean') Action: Left
    Location: (0, 0) Action: Left
    Final room config:  {(1, 2): 'Dirty', (1, 1): 'Clean', (0, 2): 'Dirty', (1, 0): 'Dirty', (0, 0): 'Clean', (0, 1): 'Dirty', (2, 0): 'Clean', (2, 1): 'Dirty', (2, 2): 'Dirty'}
    >>> 
    

    As you can see, the random agent isn't very bright (it just randomly wanders around), but it should give you a starting point. In particular, notice that the agent starts in a random location; your program cannot assume a particular starting point.

  2. Next, run the TableDrivenAgent in the 3x3 environment. Unfortunately, the TableDrivenAgent is not able to guarantee that all of the rooms will be cleaned.
    (1) Concisely explain why it is that the TableDrivenAgent is unable to accomplish this task.
  3. Next, create a subclass of Agent called ModelBasedAgent. The ModelBasedAgent is able to keep a 'model' (or state, or memory) of the environment. (you may choose to implement this however you wish - it does not need to be very elaborate). You will need to implement two methods (you may find that you want helper methods also):

    (2) Is your ModelBasedAgent guaranteed to eventually clean all rooms in a 3x3 grid environment? If so, show why. If not, show why not. Note: please do not solve the problem by modifying the TableDrivenAgent to choose random actions. This will eventually visit all the rooms, but doesn't really get at the point of the assignment.

    (3) Is your ModelBasedAgent guaranteed to be optimal? In other words, does it clean all rooms in the minimum possible number of moves? If so, prove that this is the case. If not, explain what limitations of your agent prevent it from solving the problem optimally. (It's not required that your agent be optimal - just that you indicate whether it is or not.)
  4. Now let's make the problem more challenging: build a ModelBasedAgent that can solve the NxMVacuumEnvironment for other values of N and M. Notice that the values of N and M are NOT available to the agent; the only way it can figure out how large the grid is is through exploration. In other words, you cannot modify the NByMVacuumEnvironment; just the agent.

    Hint: how can an agent figure out whether there is another room to the south/east, given that its percepts tell it only the coordinates of the current room and whether it is clean or dirty? You might want to modify your model somewhat.
  5. Finally, let's make the problem stochastic.

    If we have a particularly dirty environment, it may take several 'Sucks' to clean a room. Simulate this by making a class called ExtraDirtyVacuumEnvironment. (4) What changes to your agent are needed in general to deal with stochastic environments?