THINK FIRST·CODE LATER

← All labs

HEFT: reproduce a classic result

Problem

Implement HEFT and reproduce the makespan of 80 from the original paper's 10-task example.

Input: the Chapter 6 format (see OS6.1).

Algorithm:

  1. Compute rank_u (as in OS6.1). Priority order: decreasing rank_u; ties → smaller task number.
  2. For each task in that order and each processor k (in order P1, P2, …):
    • ready time = max over predecessors q of (finish(q) + (0 if q runs on k else c(q, i))), or 0 for entry tasks;
    • EST = the earliest start ≥ ready time such that the interval [EST, EST + w(i, k)) fits in an idle gap of k (insertion policy: gaps between already scheduled tasks count; otherwise after the last task);
    • EFT = EST + w(i, k). Choose the processor with the minimum EFT (ties → lowest processor number).

Output:

Upward ranks: T1=... T2=... (two decimals, task order)
Priority order: T1 T3 ...
T1 -> P3 start 0 finish 9        (one line per task, in scheduling order)
...
Makespan: 80
SLR: 1.951 (CP_MIN = 41)
Speedup: 1.588 (best sequential = 127)
Efficiency: 0.529

Times are printed as integers when they are whole numbers, otherwise with two decimals. CP_MIN = the longest path using each task's minimum cost and no communication; best sequential = the minimum over processors of the sum of all task costs on that processor.

The example input is the classic one (10 tasks, 3 processors) — see the test data in the model solution.

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.

os6-2-data-1.txt — first 14 lines of 27

10 3
14 16 9
13 19 18
11 13 19
13 8 17
12 13 10
13 16 9
7 15 11
5 11 14
18 12 20
21 7 16
15
1 2 18
1 3 12
What your program must print for os6-2-data-1.txt
Upward ranks: T1=108.00 T2=77.00 T3=80.00 T4=80.00 T5=69.00 T6=63.33 T7=42.67 T8=35.67 T9=44.33 T10=14.67
Priority order: T1 T3 T4 T2 T5 T6 T9 T7 T8 T10
T1 -> P3 start 0 finish 9
T3 -> P3 start 9 finish 28
T4 -> P2 start 18 finish 26
T2 -> P1 start 27 finish 40
T5 -> P3 start 28 finish 38
T6 -> P2 start 26 finish 42
T9 -> P2 start 56 finish 68
T7 -> P3 start 38 finish 49
T8 -> P1 start 57 finish 62
T10 -> P2 start 73 finish 80
Makespan: 80
SLR: 1.951 (CP_MIN = 41)
Speedup: 1.588 (best sequential = 127)
Efficiency: 0.529

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 < os6-2-data-1.txt

Windows PowerShell does not understand <:

Get-Content os6-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.