Homework Three

Search II

out 9/24, due 10/3

(1) Thinking about search spaces

There are N roomba robots that are lined up along the top row of an N by N square grid, i.e., in cells (1, 1) through (N, 1). The robots must move to the bottom row but in reverse order; so the robot that starts in (i, 1) must end up in (N-i+1, N). At each time step, each of the robots can move one cell up, down, left, or right, or stay put; but if a robot stays put, one other adjacent robot (but not more than one) can hop over it, effectively moving two steps. Robots are never allowed to move off the grid. Two robots cannot occupy the same cell at the end of any time step.

  • Calculate the size of the state space as a function of N.
  • Calculate the branching factor as a function of n.
  • Suppose that a robot is at (xi, yi). Write a nontrivial admissible heuristic Hi for the number of moves it needs to get to its goal location at (n - i + 1, n), assuming that no other robots are on the grid.
  • Which of the following heuristics are admissible for the problem of moving all n robots to their destinations? Explain each answer.
    • The sum of Hi for i=1 to N
    • max{H1, . . . , Hn}
    • min{H1, . . . , Hn}

(2) Heuristics for CSP

We covered several heuristics for CSP search. Explain why when selecting a variable to assign a value next, it is a good to choose the variable that is most constrained, but the value that is least constraining.

(3) Magic Squares

In class we showed examples of using the python constraint package to generate magic squares of size three and four. In general, there is always a magic square of size N whose magic sum is equal to N*(N**2+1)/2 for n>2. (Others may also exist.)

(a) Write a function magic_square that takes a single integer argument and generates a magic square of that size. Use this function to measure how long it takes to generate magic squares of sizes 3, 4, and 5 using each of the three solvers that the constraint package supports: BacktrackingSolver, RecursiveBacktrackingSolver, and MinConflictsSolver. Show a solution for each size and print a table of the running times for each solver. Note: Use Python's time module to capture run times. For example:

import time
...
start = time.time()
foo(x, y, z)
stop =  time.time()
print "Calling foo took %.3f seconds." % (stop-start,)
...

You will probably discover that the RecursiveBacktracking() solver takes an inordinately long time to find a solution for a magic square of size 5. If so, feel free to skip that test. An elegant solution is to create a Problem subclass that includes a timeout property such that if getSolution() exceeds its allotted time to run it will stop and return None. You can use Python's signal library to do this. We'll give extra credit for those who do this.

(b) Note that the MinConflicts() solver fails to solve even the smallest problem. You can examine to code for this solver to see why it fails to find a solution. Explain why MinConflicts() does not work well for this problem.

(c) Can you get a solution for a magic square of size six using any of the solvers and if so, how long does it take? Do you think that using CSP is a good approach for generating magic squares? Why or why not.

What to hand in

SUbmit in your assignment via cvs by 23:59:50 on Wednesday, October 3. It should consist of readme.txt, hw3.txt or .pdf, and ms.py. In emergenizes, mail mail your assignment as a zip or gzip file to cmsc671hw@cs.umbc.edu.