level 2
子刻王5
楼主
写一个可以模拟FCFS SRT RR算法的一个程序,每种算法都要计算出来周转时间,等待时间,这个时间是每个job的平均值.
进程信息从一个文件读入 格式是 Process_id,Arrival_time,CPU_time 这样三个数字一行
就是读入一个文件
文件里面是类似这样的东西
1,0,8
2,1,4
3,2,9
4,3,5
这个文件表示的是几个作业 作业编号 作业到来的时间 和执行作业需要消耗的时间
然后用那三种算法分别模拟执行这些作业 执行完了 输入各种算法消耗的时间
我想问 shortest remaining time 的算法用heap怎么写???
高手 大神 求帮忙啦!
【原题如下】
Write a Java program that will simulate First Come First Serve, Shortest Remaining Time, and Round Robin scheduling algorithms. For each algorithm, the program should compute the turnaround time and the waiting time of every job as well as the average turnaround time and average waiting time.
The process information will be read from an input file. The format is as follows:
Process_id,Arrival_time,CPU_time
All fields are integers where:
Process_id is a unique numeric process ID
Arrival_time is the time when the process arrives in milliseconds
CPU_time is the amount of estimated CPU time requested by the process
All the fields will be delimited by a comma.
An example of a sample input file is as follows:
1,0,8
2,1,4
3,2,9
4,3,5
The program will accept command line arguments. The program usage will be as follows:
./Question1 input_file [FCFS|SRT|RR] [time_quantum]
where, Question1 is name of the java program and input_file is the input file containing the process information. FCFS refers to the First Come First Serve policy and is non-pre-emptive. SRT refers to Shortest Remaining Time and is pre-emptive. RR refers to Round Robin, which is pre-emptive and the time quantum only applies to this algorithm. Ignore context switching time. Note the last argument is only needed in case of Round Robin.
Suppose you want to run the SRT algorithm on a process list contained in input file called process.txt, then you would run your program as follows:
./Question1 process.txt SRT
If you want to run the RR algorithm on the same input file with a time quantum of 5 milliseconds, then you would run your program as follows:
COMPSCI.215 Assignment 1 Semester I, 2013
2
./Question1 process.txt RR 5
Turnaround time = completion time – arrival time
Waiting time = Turnaround time – CPU time taken by the process
When the program is run, it should print statistical information to the screen formatted in the following fashion:
============================================
Process ID | Turnaround time | Waiting time
============================================
| |
------------------------------------------------------------------------
| |
------------------------------------------------------------------------
……..
=============================================
Avg. | |
=============================================
For example, if you run the program with RR scheduling using a time quantum of 4 milliseconds on process.txt, then the output to the screen should be as follows:
============================================
Process ID | Turnaround time | Waiting time
============================================
1 | 20 |12
------------------------------------------------------------------------
2 |7 |3
------------------------------------------------------------------------
3 |24 |15
------------------------------------------------------------------------
4 |22 |17
=============================================
Avg. |18.25 |11.75
=============================================
2013年04月08日 08点04分
1
进程信息从一个文件读入 格式是 Process_id,Arrival_time,CPU_time 这样三个数字一行
就是读入一个文件
文件里面是类似这样的东西
1,0,8
2,1,4
3,2,9
4,3,5
这个文件表示的是几个作业 作业编号 作业到来的时间 和执行作业需要消耗的时间
然后用那三种算法分别模拟执行这些作业 执行完了 输入各种算法消耗的时间
我想问 shortest remaining time 的算法用heap怎么写???
高手 大神 求帮忙啦!
【原题如下】
Write a Java program that will simulate First Come First Serve, Shortest Remaining Time, and Round Robin scheduling algorithms. For each algorithm, the program should compute the turnaround time and the waiting time of every job as well as the average turnaround time and average waiting time.
The process information will be read from an input file. The format is as follows:
Process_id,Arrival_time,CPU_time
All fields are integers where:
Process_id is a unique numeric process ID
Arrival_time is the time when the process arrives in milliseconds
CPU_time is the amount of estimated CPU time requested by the process
All the fields will be delimited by a comma.
An example of a sample input file is as follows:
1,0,8
2,1,4
3,2,9
4,3,5
The program will accept command line arguments. The program usage will be as follows:
./Question1 input_file [FCFS|SRT|RR] [time_quantum]
where, Question1 is name of the java program and input_file is the input file containing the process information. FCFS refers to the First Come First Serve policy and is non-pre-emptive. SRT refers to Shortest Remaining Time and is pre-emptive. RR refers to Round Robin, which is pre-emptive and the time quantum only applies to this algorithm. Ignore context switching time. Note the last argument is only needed in case of Round Robin.
Suppose you want to run the SRT algorithm on a process list contained in input file called process.txt, then you would run your program as follows:
./Question1 process.txt SRT
If you want to run the RR algorithm on the same input file with a time quantum of 5 milliseconds, then you would run your program as follows:
COMPSCI.215 Assignment 1 Semester I, 2013
2
./Question1 process.txt RR 5
Turnaround time = completion time – arrival time
Waiting time = Turnaround time – CPU time taken by the process
When the program is run, it should print statistical information to the screen formatted in the following fashion:
============================================
Process ID | Turnaround time | Waiting time
============================================
| |
------------------------------------------------------------------------
| |
------------------------------------------------------------------------
……..
=============================================
Avg. | |
=============================================
For example, if you run the program with RR scheduling using a time quantum of 4 milliseconds on process.txt, then the output to the screen should be as follows:
============================================
Process ID | Turnaround time | Waiting time
============================================
1 | 20 |12
------------------------------------------------------------------------
2 |7 |3
------------------------------------------------------------------------
3 |24 |15
------------------------------------------------------------------------
4 |22 |17
=============================================
Avg. |18.25 |11.75
=============================================