Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- tmp_all_proccess = []
- all_proccess = []
- result = []
- class Procces():
- def __init__(self, time_spawn, CPUBurst):
- self.time_spawn = time_spawn
- self.CPUBurst = CPUBurst
- self.done = False
- self.index = len(tmp_all_proccess)
- self.lead_time = 0
- self.waiting_time = 0
- tmp_all_proccess.append(self)
- all_proccess.append(self)
- result.append([])
- Procces(0, 10)
- Procces(2, 8)
- Procces(4, 4)
- Procces(6, 5)
- Procces(8, 6)
- Procces(8, 9)
- Procces(6, 1)
- Procces(4, 2)
- Procces(2, 3)
- Procces(0, 7)
- time_now = 0
- def GetProcces():
- global time_now, tmp_all_proccess
- def tmp():
- global time_now
- rarray = []
- for pr in tmp_all_proccess:
- if time_now >= pr.time_spawn:
- rarray.append(pr)
- return rarray
- tmp_prs_now = tmp()
- if not len(tmp_prs_now):
- time_now += 1
- if len(tmp_all_proccess):
- GetProcces()
- else:
- return
- r_procces = tmp_prs_now[0]
- # for pr in tmp_prs_now[1:]:
- # if pr.CPUBurst < r_procces.CPUBurst:
- # r_procces = pr
- while r_procces.CPUBurst > 0:
- r_procces.CPUBurst -= 1
- time_now += 1
- result[r_procces.index].append('И')
- r_procces.lead_time += 1
- for pr in all_proccess:
- if pr != r_procces:
- if pr.done or (not pr.done and not (time_now >= pr.time_spawn)):
- result[pr.index].append('-')
- else:
- result[pr.index].append('Г')
- pr.waiting_time += 1
- r_procces.done = True
- tmp_all_proccess.remove(r_procces)
- while len(tmp_all_proccess):
- GetProcces()
- for i in range(len(result[0])):
- text = ' '
- for j in range(len(result)):
- text += result[j][i]
- text += ' ' + str(i)
- print(text)
- text = ''
- lead_time = 0
- waiting_time = 0
- for pr in all_proccess:
- lead_time += pr.lead_time
- waiting_time += pr.waiting_time
- text += 'Среднее время ожидания: ' + str(waiting_time/10) + ' Среднее время выполнения: ' + str(lead_time/10)
- print(text)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement