我正在编写一个用于测试目的的调度算法,并遵循“算法简介”一书,但这是我所能得到的。截至目前,这项工作正在“某处无休止的循环”中消亡。一般来说,算法应该有利润,我们根据利润对所有其他数组进行排序“但我现在只是忽略它”并且我的输入已经排序。因此,截止日期和通过的工作已经排序。需要一些帮助,因为它仍然无法正常工作。
#!/usr/bin/python3.6
class Scheduling:
def schedule(self, n, deadline, jobs):
self.fdeadline = deadline
self.J = []
self.J.append(jobs[0])
self.i = 1
while self.i <= n:
self.K = self.J.copy()
self.K.append(jobs[self.i])
self.i = self.i + 1
if self.feasible(self.K, self.fdeadline) == True :
self.J = self.K
return self.J
def feasible(self, K, fdl):
self.tmp = K
self.isFeasible = True
self.i = 0
self.j = 1
self.k = 0
while self.i < len(self.tmp):
while self.j < len(self.tmp):
self.index1 = self.i
self.index2 = self.j
if (fdl[self.index1] > fdl[self.index2]):
self.tmp[i], self.tmp[j] = self.tmp[j], self.tmp[i]
while self.k < len(self.tmp):
self.job = self.tmp[self.k]
if (fdl[self.job] < k + 1):
isFeasible = False
break
return isFeasible
def main():
sins = Scheduling()
n = 4
deadline = [1,1,2,2]
jobs = [4, 2, 1, 3]
sjobs = sins.schedule(n, deadline, jobs)
print (sjobs)
if __name__ == "__main__":
main()
holdtom
相关分类