Advertisement
BdW44222

07. Robotics

Sep 13th, 2021
1,211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.71 KB | None | 0 0
  1. from collections import deque
  2. from datetime import datetime, timedelta
  3.  
  4. data  = input().split(";")
  5. time = datetime.strptime(input(), '%H:%M:%S')
  6.  
  7.  
  8. robots = []
  9. available_robots = deque([])
  10. products = []
  11.  
  12. for el in data:
  13.     robot_data = el.split('-')
  14.     robot = {}
  15.     robot['name'] = robot_data[0]
  16.     robot['processing_time'] = int(robot_data[1])
  17.     robot['avaible_at'] = time
  18.     robots.append(robot)
  19.     available_robots.append(robot)
  20.  
  21. product = input()
  22.  
  23. while not product == "End":
  24.     products.append(product)
  25.     product = input()
  26.  
  27. products = deque(products)
  28. time = time + timedelta(seconds=1)
  29.  
  30. while len(products) > 0:
  31.     current_product = products.popleft()
  32.  
  33.     if available_robots:
  34.         current_robot = available_robots.popleft()
  35.         current_robot['avaible_at'] = time + timedelta(seconds=robot['processing_time'])
  36.         robot = [el for el in robots if el == current_robot][0]
  37.         robot['avaible_at'] = time + timedelta(seconds=robot['processing_time'])
  38.         print (f"{robot['name']} - {current_product} [{time.strftime('%H:%M:%S')}]")
  39.     else:
  40.         for r in robots:
  41.             if time >= r['avaible_at']:
  42.                 available_robots.append(r)
  43.         if not available_robots:
  44.             products.append(current_product)
  45.  
  46.         else:
  47.             current_robot = available_robots.popleft()
  48.             current_robot['avaible_at'] = time + timedelta(seconds=robot['processing_time'])
  49.             robot = [el for el in robots if el == current_robot][0]
  50.             robot['avaible_at'] = time + timedelta(seconds=robot['processing_time'])
  51.             print(f"{robot['name']} - {current_product} [{time.strftime('%H:%M:%S')}]")
  52.     time = time + timedelta(seconds=1)
  53.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement