Advertisement
Guest User

Untitled

a guest
Dec 11th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.31 KB | None | 0 0
  1. tmp_all_proccess = []
  2. all_proccess = []
  3. result = []
  4.  
  5. class Procces():
  6. def __init__(self, time_spawn, CPUBurst):
  7. self.time_spawn = time_spawn
  8.  
  9. self.CPUBurst = CPUBurst
  10. self.done = False
  11. self.index = len(tmp_all_proccess)
  12. self.lead_time = 0
  13. self.waiting_time = 0
  14. tmp_all_proccess.append(self)
  15. all_proccess.append(self)
  16.  
  17. result.append([])
  18. Procces(0, 10)
  19. Procces(2, 8)
  20. Procces(4, 4)
  21. Procces(6, 5)
  22. Procces(8, 6)
  23. Procces(8, 9)
  24. Procces(6, 1)
  25. Procces(4, 2)
  26. Procces(2, 3)
  27. Procces(0, 7)
  28.  
  29. time_now = 0
  30.  
  31. def GetProcces():
  32. global time_now, tmp_all_proccess
  33. def tmp():
  34. global time_now
  35. rarray = []
  36. for pr in tmp_all_proccess:
  37. if time_now >= pr.time_spawn:
  38. rarray.append(pr)
  39.  
  40. return rarray
  41. tmp_prs_now = tmp()
  42. if not len(tmp_prs_now):
  43. time_now += 1
  44. if len(tmp_all_proccess):
  45. GetProcces()
  46. else:
  47. return
  48.  
  49. r_procces = tmp_prs_now[0]
  50. # for pr in tmp_prs_now[1:]:
  51. # if pr.CPUBurst < r_procces.CPUBurst:
  52. # r_procces = pr
  53.  
  54. while r_procces.CPUBurst > 0:
  55.  
  56. r_procces.CPUBurst -= 1
  57. time_now += 1
  58. result[r_procces.index].append('И')
  59. r_procces.lead_time += 1
  60. for pr in all_proccess:
  61. if pr != r_procces:
  62. if pr.done or (not pr.done and not (time_now >= pr.time_spawn)):
  63. result[pr.index].append('-')
  64. else:
  65. result[pr.index].append('Г')
  66. pr.waiting_time += 1
  67.  
  68.  
  69. r_procces.done = True
  70. tmp_all_proccess.remove(r_procces)
  71.  
  72. while len(tmp_all_proccess):
  73. GetProcces()
  74.  
  75. for i in range(len(result[0])):
  76. text = ' '
  77. for j in range(len(result)):
  78. text += result[j][i]
  79. text += ' ' + str(i)
  80. print(text)
  81. text = ''
  82. lead_time = 0
  83. waiting_time = 0
  84. for pr in all_proccess:
  85. lead_time += pr.lead_time
  86. waiting_time += pr.waiting_time
  87. text += 'Среднее время ожидания: ' + str(waiting_time/10) + ' Среднее время выполнения: ' + str(lead_time/10)
  88.  
  89. print(text)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement