P. 1
3760 Assignment 2 Jan 2008 Mice v3

3760 Assignment 2 Jan 2008 Mice v3

|Views: 23|Likes:

Published by: Cthulhon on Mar 22, 2008

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
See more
See less

06/16/2009

pdf

text

original

Comp 3760

Assignment 2: Mice

v3

Due date: 11:00pm Friday March 21, 2008 Introduction
A team of laboratory mice are being trained to escape a maze. The maze is made up of cells, and some cells are interconnected by passageways. All passageways are exactly the same length, however, some passageways allow mice to travel one-direction but not the other. Suppose that all mice are now trained and, when placed in an arbitrary cell in the maze, take a path that leads them to the exit cell in minimum time (as long as such a path exists). We are going to conduct an experiment: A mouse is placed in each cell of the maze and a count-down timer is started. a. b. When the timer stops we count the number of mice that have reached the exit cell, assuming it takes one time unit for a mouse to travel from one cell to a connected adjacent cell. Now we will restart the timer and determine the minimum number of time units that are required for all mice to reach the exit cell, as well as the longest path taken by the mouse that is last to reach the exit.

For this experiment you will write a program that, given a description of a maze and a time limit, predicts the number of mice that will reach the exit cell by the time the timer expires, as well as the minimum time that would be required for all the mice in the maze to reach the exit. The path for the last arriving mouse will be displayed (in the case that multiple mice are simultaneously last to arrive, you will display the path that each of them took). You should assume that there are no bottlenecks in the maze, i.e. that all cells and passageways have room for an arbitrary number of mice.

1

1

Image courtesy of http://www.pabook.libraries.psu.edu/familylit/FFN/workshop3/mouseMaze.pdf

Page 1 of 4

Comp 3760
Program Input

Assignment 2: Mice

v3

The maze cells are numbered 1, 2, …, N, where N is the total number of cells. You can assume that N ≤ 1000. The first three input lines contain N, the number of cells in the maze, E, the number of the exit cell, and the starting value T for the count-down timer (in some arbitrary time unit). The fourth line contains the number M of connections in the maze, and is followed by M lines, each specifying a connection with two integer numbers: two cell numbers a and b (in the range 1, 2, …, N). Notice that each connection is one-way, i.e., the mice can't travel from b to a unless there is another line specifying that passageway. Input is from a file. There may be multiple tests in each file. Each test ends with a line containing a single colon (:). The last test in the input file will be immediately followed by EOF (end of file). You can assume that test output files are formatted correctly as per this specification (ie: you will not encounter invalid input).

Program Output
For each test, the first line of output is a single number indicating the number of mice that reached the exit cell E in at most T time units. Note that the minimum output value on this line is 1, as there is always a mouse at the exit cell to begin with. The second line of output is another integer indicating the minimum time required for all mice to reach the exit cell. If there are any mice that cannot ever reach the exit, we will display the minimum time as zero. Following the minimum time is the list of paths, one per line, taken by the mice that are last to arrive. If the minimum time is zero no paths will be displayed. A blank line is printed between each test case. The output should be formatted exactly as shown in the sample output below.

Sample Input
4 2 1 8 1 1 2 2 3 3 4 4 : 3 1 2 3 1 1 2 : 4 4 1 3 1 2 3 :

Sample Output
3 2 3-1-2

2 3 1 4 1 4 2 3

1 0 2 2 1-2-4 3-2-4

2 3 3

2 4 2

Page 2 of 4

Comp 3760

Assignment 2: Mice

v3

Other Requirements and Guidelines

Submission Details

b.

How do I test your assignment? 1. 2. I don't use NetBeans. I just compile your program using javac. Your program must compile fine when I use the following commands to compile it: javac mice\Main.java (assuming I am in directory rneilson_awei). Next I will execute your program, passing the name of one of my input files, and redirecting the output to a file. For example: java mice\Main a2data.txt > rneilson_awei_a2data_out.txt

Page 3 of 4

Comp 3760

Assignment 2: Mice

v3