(Latest Revision: 04/11/2004)

'Disk Scheduling' Program


RATIONALE:

Writing this program will help you get an appreciation for applications of priority queues, introduce you to an interesting algorithm, and give you additional experience with designing data structures.


THE ASSIGNMENT:

Write a program that simulates a (simplified) disk scheduler executing the "sweep algorithm" (aka the "elevator algorithm"). The program will keep track of the position & direction of the disk arm, respond to commands to enqueue & serve track requests, and respond to commands to print out the contents of the queues & state variables.


THE SWEEP ALGORITHM:

In a textbook written by authors Daniel F. Stubbs and Neil W. Webre the sweep algorithm is explained this way:

"Suppose that we let the disk arm sweep across the disk from the inner to outer tracks. Any requests that are in front of the head in the direction that it is traveling will be served using an SSTF [shortest seek time first] strategy. The head sweeps across the disk in one direction, stopping at each track that has an I/O request pending. It 'ignores' any requests that fall behind it. When it has satisfied the last request that it finds in front of it, it turns around and starts a reverse sweep from outer tracks to inner tracks, again serving any requests that it finds in front of it, using an SSTF strategy. ...

... The set of requests ahead of the read/write head in the direction of the current sweep is a priority queue based on track number. The set of requests behind the head is also a priority queue, but one that will not be served until the head turns about and begins to sweep in the opposite direction. The priorities of the second queue are inverted on track number. If higher (lower) track numbers were high priority in the inner-to-outer sweep, then lower (higher) track numbers would be given higher priority in the outer-to-inner sweep. Regardless of the details, conceptually we have two separate priority queues."

[Source: Stubbs & Webre; "Data Structures with Abstract Data Types and Pascal;" 2nd edition, pp. 103-4; Brooks/Cole Publishing, 1989; ISBN 0-534-09264-0.]


DETAILS:

  1. The disk we are simulating has only one surface and ten tracks numbered from 0 to 9.

  2. When the program starts the disk arm is initially positioned at track 0 and the scheduler is set to move the arm in the forward direction: from track 0 towards track 9.

  3. The program uses two priority queues (implemented as heaps) to save pending requests.

  4. The two priority queues are operated as described by Stubbs and Webre in the quotation above.

  5. Assume there will be no need to store more than 20 items in either of the priority queues.

  6. The scheduler serves from the forward priority queue when set to move in the forward direction and serves from the reverse priority queue when set to move in the reverse direction,

  7. The program has to carefully handle new requests for service on the track currently occupied by the disk arm. It must not be possible for continual requests of that type to indefinitely postpone further movement of the arm,

  8. To facilitate ordering elements of priority queues the program will maintain a counter T used as a timestamp. The program will increment T after placing an item in either of the priority queues. The items will have a field for the number of the requested track, and also a field for the value of T at the time of the request. The items in the priority queues will be ordered so that when there is more than one request in the queue for the same track the requests will be served in first-come-first-served order. (Probably the 'right way' to implement this would be to create an item class with overloaded '<' '==', and '>' operators.)


INPUT:

The program inputs a series of commands from standard input. The commands are described in detail below.

The program must not expect any other input.


OUTPUT:

After reading each command the program echoes the command to standard output. It then executes the command and prints an appropriate response to the command on standard output.

The program also writes separator strings to standard output to separate the outputs corresponding to each input command.

The program must not write output of any other kind.


COMMANDS:

Input to the program will consist of a series of commands in the following forms.

Note: the argument <trackNum> stands for an integer VARIABLE; 0 <= trackNum <= 9.

Command names given below, like EnqRequest, are literals and will appear in the input file exactly as they appear below.
HELP:

Come to class to get help and hints.


WHAT TO TURN IN:

You will turn in two "phases" of this assignment:
  1. a level 3 version, and
  2. a final version.
For each phase of the assignment, you will turn in a printer output (hardcopy) and you will send me an e-mail message. Please follow these rules: Here is the list of things you have to turn in: Note that there are no spaces in the subject lines given. It is important that you do not insert any spaces. My e-mail address is: john@ishi.csustan.edu.


DUE DATES:

For due dates, see the class schedule.