相同并行機排程(Identical Parallel Machine Scheduling):
多機排程問題可表達為:n 個工件由 k 個可并行工作的機器加工,完成任務 i 需要的時間為 ti,排程目标是确定這 n 個工件完成的最佳加工順序,使得完成全部任務的時間最早
數學描述:
聲明:
首先申明,暴力窮舉法肯定是最愚蠢的(也是最聰明的)方法,得到的結果(如果能在有限時間計算出來)肯定是100%正确的。
Why 我要寫一個暴力窮舉法?
論文裡的小資料對比需要,而網上翻了一圈,也沒有看到可以copy的代碼
代碼:
from itertools import product as product
def machine_sum(jobs, groups, machines):
# example:
# jobs: [10, 11, 12, 13, 14, 15, 16, 17, 18, 19]
# groups: [0, 0, 0, 0, 0, 1, 1, 1, 2, 2]
# machines: 3
result = [0 for _ in range(machines)]
for i in range(machines):
result[i] = sum([jobs[i] for i in get_location_in_list(groups, i)])
return max(result)
def get_location_in_list(x, target):
step = -1
items = list()
for i in range(x.count(target)):
y = x[step + 1:].index(target)
step = step + y + 1
items.append(step)
return items
# print(machine_sum([10, 11, 12, 13, 14, 15, 16, 17, 18, 19], [0, 0, 0, 0, 0, 1, 1, 1, 2, 2], 3))
groups = list(product(* [range(4)]*10))
jobs = [10, 11, 12, 13, 14, 15, 16, 17, 18, 19] # 每個工作的時長,可以根據代碼調整
machines = 4 # 并行機數量
y = [machine_sum(jobs, group, machines) for group in groups] # 所有情況的makespan
print(min(y))
itertools用法詳見https://docs.python.org/ko/3.7/library/itertools.html
備注:
時間空間開銷是O(
)(不嚴謹的表達)
m: m machines
n: n jobs
重要:隻能在資料規模較小的情況使用
比如4機器10工件的并行機,暴力窮舉法會有
種情況(PS:實際每月這麼多配置設定情況)