<jupyter_start><jupyter_text>**Installing the packages**<jupyter_code>#!pip install simpy
import random
import simpy as sy<jupyter_output><empty_output><jupyter_text>**Intializing the variable and creating the simulation**<jupyter_code>#Declaring the variables

num_checkers = 10  # Number of Checkers 
num_scanners = 5   #Number of scanners 
wait_time = 0      #Initial Waiting Time set to 0
total_pax = 1      #Total number of passengers initialized to 1
num_pax = 100      #Overall Passengers set to 100
runtime =  500     #End simulation when runtime crosses 500 mins

arrival_rate = 50  #To simulate a busy airport
check_rate = 0.75  #As mentioned in the 

class Airport(object):
    def __init__(self, env, num_checkers, num_scanners):
        self.env = env
        self.checker = sy.Resource(env, num_checkers)  #Number of boarding pass checkers 
        self.scanners = []
        for i in range(0, num_scanners):              #Number of scanners 
            self.scanners.append(sy.Resource(env))
            
    def BP_check(self, pax):
        service_time = random.expovariate(1/check_rate)
        yield self.env.timeout(service_time)
        
    def scan(self, pax):
        scan_time = random.uniform(0.5, 1)
        yield self.env.timeout(scan_time)
        
    def Passenger(self, env, number):
        global wait_time #global average wait time
        global total_pax  
        arrival_time = env.now
        scan_queue = []  #Every scanner has its own queue
        
        with self.checker.request() as request:
            yield request
            yield env.process(self.BP_check(number))
            
        for scanner in self.scanners:
            scan_queue.append(len(scanner.queue))  #getting the length of each scanner 
            
        #Find the shortest scanner queue
        min_index = min(scan_queue)
        short_queue_index = scan_queue.index(min_index)
        
        with self.scanners[short_queue_index].request() as request:
            yield request
            yield env.process(self.scan(number))
            
        exit_time = env.now
        wait_time += (exit_time - arrival_time)
        total_pax += 1

    def setup(self, env, num_pax):
        yield env.timeout(random.expovariate(arrival_rate)) 
        env.process(self.Passenger(env, num_pax))
        
        
#Running the simulation
env = sy.Environment()
api = Airport(env, num_checkers, num_scanners)

for i in range(0,num_pax):
    env.process(api.setup(env, i))

env.run(until = runtime)
avg_wait_time = wait_time / total_pax

print("Avg waiting time is %f"  %avg_wait_time)<jupyter_output>Avg waiting time is 8.104722
{'fraction_non_alphanumeric': 0.08273517189270872, 'fraction_numerical': 0.014355874574990555, 'mean_word_length': 2.612551159618008, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '667502', 'license': 'Apache-2.0', 'n_tokens_mistral': 858, 'n_tokens_neox': 806, 'n_words': 219, 'path': 'isye_6501_sim_hw/aarti_solution/Question 13.2.ipynb', 'repo_name': 'oskrgab/isye-6644_project', 'size': '2647'}