-
Notifications
You must be signed in to change notification settings - Fork 0
/
LPT_rule.py
59 lines (44 loc) · 1.53 KB
/
LPT_rule.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# read a list of the processing times for the jobs
ptimes = []
input_file = open("ptimes.txt", "r")
for p in input_file:
ptimes.append(int(p))
print("number of jobs in input: {}".format(len(ptimes)))
# sort list in descending order
ptimes.sort(reverse=True)
# number of machines
m = 10
# make a list of m empty lists
# each machine gets a list of currently assigned jobs
machine_jobs = [[] for x in range(m)]
# keep track of which jobs are assigned to which machines already
# pick the machine with the lowest current workload as the next machine to
# assign the next job to
# keep track of the minimum current workload
min_ci = 0
# and also keep track of which machine attains this minimum workload
# (as a first choice, we can pick any machine, so for convenience we just pick the first)
min_i = 0
# assign jobs following the Longest Processing Time (LPT) rule.
for p in ptimes:
# add the current job to the machine which has the current minimum workload
machine_jobs[min_i].append(p)
# determine the machine with the current minimum workload
min_ci = sum(machine_jobs[min_i])
for i in range(m):
c_i = sum(machine_jobs[i])
if c_i < min_ci:
min_ci = c_i
min_i = i
# compute the makespan
makespan = 0
for i in range(m):
print(machine_jobs[i])
c_i = sum(machine_jobs[i])
print(c_i)
if c_i > makespan:
makespan = c_i
# print the final makespand
print("Final makespan: {}".format(makespan))
# print in scientific notation as well
print("{:e}".format(makespan))