'''simple docstring'''




from __future__ import annotations

from statistics import mean

def _UpperCamelCase   (       SCREAMING_SNAKE_CASE_  ,       SCREAMING_SNAKE_CASE_  ,       SCREAMING_SNAKE_CASE_							):
     lowercase_					:       List[Any]     				=					[0] * no_of_processes
     lowercase_					:       Optional[int]     				=					[0] * no_of_processes

     # Initialize remaining_time to waiting_time.

     for i in range(SCREAMING_SNAKE_CASE_							):
          lowercase_					:       Union[str, Any]     				=					burst_time[i]
     lowercase_					:       list[int]     				=					[]

     lowercase_					:       List[str]     				=					0
     lowercase_					:       List[Any]     				=					0

     # When processes are not completed,
     # A process whose arrival time has passed \
     # and has remaining execution time is put into the ready_process.
     # The shortest process in the ready_process, target_process is executed.

     while completed != no_of_processes:
          lowercase_					:       Optional[Any]     				=					[]
          lowercase_					:       List[Any]     				=					-1

          for i in range(SCREAMING_SNAKE_CASE_							):
               if (arrival_time[i] <= total_time) and (remaining_time[i] > 0):
                    ready_process.append(SCREAMING_SNAKE_CASE_							)

          if len(SCREAMING_SNAKE_CASE_							) > 0:
               lowercase_					:       Any     				=					ready_process[0]
               for i in ready_process:
                    if remaining_time[i] < remaining_time[target_process]:
                         lowercase_					:       List[str]     				=					i
               total_time += burst_time[target_process]
               completed += 1
               lowercase_					:       List[str]     				=					0
               lowercase_					:       Tuple     				=					(
                   total_time - arrival_time[target_process] - burst_time[target_process]
               )
          else:
               total_time += 1

     return waiting_time

def _UpperCamelCase   (       SCREAMING_SNAKE_CASE_  ,       SCREAMING_SNAKE_CASE_  ,       SCREAMING_SNAKE_CASE_							):
     lowercase_					:       int     				=					[0] * no_of_processes
     for i in range(SCREAMING_SNAKE_CASE_							):
          lowercase_					:       Optional[int]     				=					burst_time[i] + waiting_time[i]
     return turn_around_time


if __name__ == "__main__":
 print('[TEST CASE 01]')

 _A								=   4
 _A								=   [2, 5, 3, 7]
 _A								=   [0, 0, 0, 0]
 _A								=   calculate_waitingtime(arrival_time, burst_time, no_of_processes)
 _A								=   calculate_turnaroundtime(
     burst_time, no_of_processes, waiting_time
 )

 # Printing the Result
 print('PID\tBurst Time\tArrival Time\tWaiting Time\tTurnaround Time')
 for i, process_id in enumerate(list(range(1, 5))):
  print(
      F"""{process_id}\t{burst_time[i]}\t\t\t{arrival_time[i]}\t\t\t\t"""
      F"""{waiting_time[i]}\t\t\t\t{turn_around_time[i]}"""
  )
 print(F"""\nAverage waiting time = {mean(waiting_time):.5f}""")
 print(F"""Average turnaround time = {mean(turn_around_time):.5f}""")





'''simple docstring'''




class       UpperCAmelCase__  (       _snake_case			):






   """simple docstring"""
   pass



class       UpperCAmelCase__  (       _snake_case			):






   """simple docstring"""
   pass



class       UpperCAmelCase__  :






   """simple docstring"""
   def __init__(self				)    ->     List[str]:
        lowercase_					:       Optional[int]     				=					[
            [],
            [],
            [],
        ]
   def 		_lowerCamelCase (self       ,				_a       ,				_a				)    ->     None:
        try:
             if len(self.queues[priority]				) >= 100:
                  raise OverflowError('Maximum queue size is 100'				)
             self.queues[priority].append(_a				)
        except IndexError:
             raise ValueError('Valid priorities are 0, 1, and 2'				)
   def 		_lowerCamelCase (self				)    ->     int:
        for queue in self.queues:
             if queue:
                  return queue.pop(0				)
        raise UnderFlowError('All queues are empty'				)





   def __str__(self				)    ->     str:
        return "\n".join(f'''Priority {i}: {q}''' for i, q in enumerate(self.queues				)				)



class       UpperCAmelCase__  :






   """simple docstring"""
   def __init__(self				)    ->     str:
        lowercase_					:       List[Any]     				=					[]
   def 		_lowerCamelCase (self       ,				_a				)    ->     None:
        if len(self.queue				) == 100:
             raise OverFlowError('Maximum queue size is 100'				)
        self.queue.append(_a				)
   def 		_lowerCamelCase (self				)    ->     int:
        if not self.queue:
             raise UnderFlowError('The queue is empty'				)
        else:
             lowercase_					:       Tuple     				=					min(self.queue				)
             self.queue.remove(_a				)
             return data





   def __str__(self				)    ->     str:
        return str(self.queue				)



def _UpperCamelCase   (       ):
     lowercase_					:       Any     				=					FixedPriorityQueue()
     fpq.enqueue(0  ,       10							)
     fpq.enqueue(1  ,       70							)
     fpq.enqueue(0  ,       100							)
     fpq.enqueue(2  ,       1							)
     fpq.enqueue(2  ,       5							)
     fpq.enqueue(1  ,       7							)
     fpq.enqueue(2  ,       4							)
     fpq.enqueue(1  ,       64							)
     fpq.enqueue(0  ,       128							)
     print(SCREAMING_SNAKE_CASE_							)
     print(fpq.dequeue()							)
     print(fpq.dequeue()							)
     print(fpq.dequeue()							)
     print(fpq.dequeue()							)
     print(fpq.dequeue()							)
     print(SCREAMING_SNAKE_CASE_							)
     print(fpq.dequeue()							)
     print(fpq.dequeue()							)
     print(fpq.dequeue()							)
     print(fpq.dequeue()							)
     print(fpq.dequeue()							)

def _UpperCamelCase   (       ):
     lowercase_					:       Optional[int]     				=					ElementPriorityQueue()
     epq.enqueue(10							)
     epq.enqueue(70							)
     epq.enqueue(100							)
     epq.enqueue(1							)
     epq.enqueue(5							)
     epq.enqueue(7							)
     epq.enqueue(4							)
     epq.enqueue(64							)
     epq.enqueue(128							)
     print(SCREAMING_SNAKE_CASE_							)
     print(epq.dequeue()							)
     print(epq.dequeue()							)
     print(epq.dequeue()							)
     print(epq.dequeue()							)
     print(epq.dequeue()							)
     print(SCREAMING_SNAKE_CASE_							)
     print(epq.dequeue()							)
     print(epq.dequeue()							)
     print(epq.dequeue()							)
     print(epq.dequeue()							)
     print(epq.dequeue()							)


if __name__ == "__main__":
 fixed_priority_queue()
 element_priority_queue()




