THINK FIRST·CODE LATER

← All labs

HRRN with the decision trace

Problem

Implement Highest Response Ratio Next (non-preemptive) and show the reasoning at every decision.

Input: lines name arrival burst until the end of input.

Whenever the CPU is free at time t, compute for every arrived, unfinished process the ratio R = (W + S) / S, where W = t − arrival and S = burst. Print

t=9: ratios C=2.25, D=1.60, E=1.50 -> run C

(ratios with two decimals, processes in input order; ties go to the earlier process in input order), then run the chosen process to completion. If nothing has arrived, the CPU is idle until the next arrival (no line is printed for the idle period, but it appears in the Gantt chart as idle s-e).

At the end print Gantt: | A 0-3 | ... |, Average turnaround: x.xx and Average waiting: x.xx.

Input:

A 0 3
B 2 6
C 4 4
D 6 5
E 8 2

Output:

t=0: ratios A=1.00 -> run A
t=3: ratios B=1.17 -> run B
t=9: ratios C=2.25, D=1.60, E=1.50 -> run C
t=13: ratios D=2.40, E=3.50 -> run E
t=15: ratios D=2.80 -> run D
Gantt: | A 0-3 | B 3-9 | C 9-13 | E 13-15 | D 15-20 |
Average turnaround: 8.00
Average waiting: 4.00

Data for this lab

Your program reads its data from standard input. Download the file, then give it to your program as shown below. Start with data set 1: its expected output is given.

os4-2-data-1.txt

A 0 3
B 2 6
C 4 4
D 6 5
E 8 2
What your program must print for os4-2-data-1.txt
t=0: ratios A=1.00 -> run A
t=3: ratios B=1.17 -> run B
t=9: ratios C=2.25, D=1.60, E=1.50 -> run C
t=13: ratios D=2.40, E=3.50 -> run E
t=15: ratios D=2.80 -> run D
Gantt: | A 0-3 | B 3-9 | C 9-13 | E 13-15 | D 15-20 |
Average turnaround: 8.00
Average waiting: 4.00

Run your program first, then open this and compare line by line: your output must contain these lines exactly.

How to give the file to my program

Terminal (macOS, Linux, or Windows Command Prompt), after compiling:

java Main < os4-2-data-1.txt

Windows PowerShell does not understand <:

Get-Content os4-2-data-1.txt | java Main

IntelliJ IDEA: Run → Edit Configurations → Redirect input from. Or simply paste the content of the file into the console when the program waits for input.

Write it here or in your IDE, then paste it. Compile and test it yourself before comparing. Your code stays in your browser — it is never sent to or stored on the server.