Lab 3: CPU Scheduling Simulator
Assigned: Thursday, March 27
Due: Thursday, April 3, 17, 29
Purpose
- To have a deep understanding of heap structure and priority queue.
- To be familiar with different algorithm techniques used in CPU Scheduling policies.
- To learn how to develop an event-based simulator
- To practice the empirical evaluation of the algorithms
Description
In this project, you will implement a discrete event simulator in Java with several different scheduling algorithms. The simulator selects a task to run from ready queue based on the scheduling algorithm. However, it does not require any actual process creation or execution. When a task is scheduled, the simulator will simply print out what task is selected to run at a time.
- (Due: April 3) Part 1: implement your own priority queue. Priority queue is a basic data structure used in many algorithms, including CPU scheduling. When a task arrives, it will enter the ready queue. At a scheduling point (such as the previous task finishes, or a new task with high priority arrives), the scheduler will select a task with the highest priority from the ready queue, and execute it. Different scheduling algorithms have different priority criteria. However, they all have the basic enqueue and dequeue operation for a priority queue. Priority queue is not only used in scheduling algorithm, it is also used in the event-based simulation. A core component of the Discrete Event Simulator (DES) is the event queue, which is ordered based on the event's time. When a new event is generated, it needs to insert into the event queue. The main operation of a simulator is repeatedly get the earliest event from the queue and handle the event until the event queue is empty. A priority queue can be used to implement event queue, where the event with the earliest start time has the higher priority. In the first part of this project, you will implement your own priority queue in two different way:
- MyArrayPriorityQueue: use an unordered array of key values for all potential elements. An enqueue(insertion) operation is fast (O(1)), but the dequeue(deletion) operation requires a linear-time scan of the list.
- MyHeapPrioirtyQueue: because of the frequent dequeue operation, a faster implementation is to use heap data structure. Both an enqueue(insertion) and dequeue(deletion) operation take O(log_2 n) time with a binary heap structure.
- Your priority queue should be able to support any comparable type of elements.
- Your submission should include the source code for two priority queue class, and a driving class to test your priority queue, with both string and integer elements.
- You are not allowed to use priority queue data structure provided by Java library directly. However, you can use array, arraylist, vector, list to implement your priority queue.
- An explanation of priority queue implementation can be found here
- Find here a sample java code: TestQueue.java, MyArrayPriorityQueue.java, Name.java, CompareName.java
- (Due: April 10) Part 2: implement a discrete event simulator for CPU scheduling with two simple scheduling algorithms: FCFS(first come first serve) and SJF(Shortest Job First).
- (Due: April 29) Part 4: Implement another preemptive scheduling algorithm, SRT (Shortest Remaining Time), and Empirically evaluate the performance of different scheduling algorithms, including waiting time/turnaround time and time overhead-
- Implement the preemptive scheduling algorithm SRT.
- Need to check if the preemption is needed, when a new process arrives.
- If the preemption is needed, scheduler is called to find a new process to run, at the same time, reinsert current running process in the ready queue.
- Delete the termination event of the previous running process in the event queue.
- Empirically evaluate the scheduling algorithms
Submission
- A hard copy of the source code and output of all your programs. You should use command ``a2ps'' or ``enscript -2rG'' to print them in two columns.
- A hard copy of your lab report written in Latex. It should include the following contents:
- Section 1 Introduction: a brief description of the problem and the purpose of the lab.
- Section 2 Implementation: a brief description of how to implement the algorithms to calculate Fibonacci numbers, and how to measure the time overhead.
- Section 4 Analysis: a brief description of the theoretical analysis of the algorithm.
- Section 3 Empirical Evaluation: a detailed description of your experiment setup, performance metrics, sample input, and analysis of experiment result.
- Section 5 Conclusion

Link to this Page