PriorityQueue class, which is to have methods to support simulations as described below. You needn't implement all the binary heap methods of the text. You may ignore the possibility of overflow by making the heap large enough to handle all of the test cases, as long as you document this feature.
Elements of the priority queue are to be of a class Task. Note that this class will have to implement the Comparable interface.
All simulations are to be of a one-processor system where tasks are simply added to the queue randomly, with random priorities and random time requirements. Tasks may not be interrupted once they begin executing, even if a higher-priority task enters the queue. The priorities and time requirements are to be integers taken uniformly from the range 0 through maxPriority and 1 through maxTimeRequired. Higher priorites are to correspond to larger integers. The probability of a task being added in a given time step is to be 1/m for some integer m. The PriorityQueue should have a constructor with arguments corresponding to maxPriority, maxTimeRequired, and m.
You should be able to support the two types of simulations described on p. 197 of the Weiss text. In the first type, each time step is simulated explicitly. At each time step, a task should be added to the queue with probability 1/m. In the second type of simulation, the only time steps that are simulated explicitly are those in which a task is added or deleted from the queue. The times in which tasks are added to the queue are to be determined by adding a random integer value to the previous time at which a task is added. This value is to be chosen uniformly from the range 1 through 2m-1, again for some integer m. Note that even if the same m is used for the two types of simulations, the distribution of task arrival times will be different, even though one task arrives at every m time steps on the average in each case.
In each type of simulation, if a task is added during a given time step, then it should be considered for processing during that time step, if the processor becomes available at that time step. In any case, if a task completes during a time step and the queue is not empty, a task from the queue should be started at that same time step (rather than waiting for a time step to start it).
In this assignment, you needn't actually simulate the processor or the processing except as described above.
Discrete time steps are to be used in the simulation, beginning with time 0. If the processor is not in use at the beginning of a given time step, the task in the priority queue, if any, with the highest (meaning highest-numbered) priority is deleted from the queue and its execution is simulated for whatever time it requires.
The PriorityQueue class is to have a constructor as described above, and methods simulate1 and simulate2to run a simulation for a given integer number of time steps. It should also have a method printStatistics, with no arguments, to print the statistics given below to System.out. This method may delete any items remaining in the priority queue. As always, you may provide any additional classes and methods that you find useful.
Please use separate Random objects, seeded with the values 1, 2, and 3 respectively, to generate the arrival time of events, the priorities, and the execution times. You need only seed these objects once for eacah priority queue, when it is constructed.
Use test file A3.java (available on the class web site) to test your implementation. The summary statistics that should be printed for each simulation are
PriorityQueue class will need a way of keeping track of the number of comparisons it uses.Note that in the first two simulations of each type, the mean interval between task arrivals is greater that the average task length, while it is smaller in the third simulation.