算法来计算等待时间,先来先服务调度在python [英] algorithm to compute waiting time for FCFS scheduling in python
问题描述
考虑以下code表示需要输入的过程和他们的到达时间,并对其进行排序,根据先到先得的算法,所以我一直在思考的算法来计算平均等待时间,但一切都是假的那么有什么建议?
制程=输入(输入过程时间和放大器;以逗号分隔到达时间)
BurstTimes =流程[:: 2]
ArrivalTimes =过程[1:2]
打印突发时报:,BurstTimes,'\ N',到达时间,ArrivalTimes,'\ N',
List1中,list2中= BurstTimes,ArrivalTimes
indices1 =范围(LEN(List1中))
indices1.sort(键=拉姆达X:List1的[X])
List1中=图(拉姆达我:List1的[I],indices1)
打印按此顺序执行的处理:,的List1
Wt_Time = 0
在code计算的总时间:
打印按此顺序执行的处理:,的List1
process_queue = []
total_wtime = 0
因为我在范围内(LEN(list2中)):
process_queue [I] .append(INT(List1的[I])
total_wtime + = process_queue [I] [1]
和它给错误在最后一行
process_queue [I] .append(INT(List1的[I])
要附加List1中的第i个元素的process_queue列表中,你应该注意到,List1的[I]是不是列表而是一个整数。并在下一行您试图访问
total_wtime + = process_queue [I] [1]
的process_queue的第一元素[I],但它不是一个二维数组
total_wtime + = process_queue [I]
应该工作。
Consider the following code that takes input processes and their arrival times and sort them according to FCFS algorithm, so i've been thinking about algorithms to compute avg waiting time but all is false so any suggestions ?
Processes = input(" Enter the processes times & arrival times separated by a comma: ")
BurstTimes = Processes[::2]
ArrivalTimes = Processes[1::2]
print ' Burst Times:', BurstTimes, '\n', ' Arrival Times', ArrivalTimes,'\n',
list1, list2 = BurstTimes, ArrivalTimes
indices1 = range(len(list1))
indices1.sort(key=lambda x: list1[x])
list1 = map(lambda i: list1[i], indices1)
print 'The Processes executed in this order: ', list1
Wt_Time = 0
the code for calculating the total time:
print 'The Processes executed in this order: ', list1
process_queue = []
total_wtime = 0
for i in range(len(list2)):
process_queue[i].append(int(list1[i])
total_wtime += process_queue[i][1]
and it gives error at the last line
process_queue[i].append(int(list1[i])
you are appending the i'th element of list1 to the process_queue list , You should note that list1[i] is not a list but an integer . and in next line you are trying to access
total_wtime += process_queue[i][1]
1st element of the process_queue[i] but it is not a 2d array
total_wtime += process_queue[i]
should work .
这篇关于算法来计算等待时间,先来先服务调度在python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!