def start_simulation_less_than_n(no_of_jobs_server_1, no_of_jobs_server_2,
                                 arrival_rate, job_distribution, sim_time,
                                 scheduler):
    list_of_servers = init_servers(3, scheduler, job_distribution)
    global jobs_ran
    global final_data
    stopping_n = no_of_jobs_server_2
    # Create dispatcher
    policy_i = ShortestQueue()  #Join shortest queue policy
    dispatcher = Dispatcher(
        policy_i, list_of_servers)  #Create a dispatcher with JSQ policy
    statistics = Statistics()
    world = Global(statistics)
    p_arrivals = PoissonArrival(float(arrival_rate))
    arrival = 0

    init_server_to_state(no_of_jobs_server_1, list_of_servers[0], scheduler,
                         world)
    init_server_to_state(no_of_jobs_server_2, list_of_servers[1], scheduler,
                         world)
    init_server_to_state(no_of_jobs_server_2, list_of_servers[2], scheduler,
                         world)

    initial_arrival = random.expovariate(p_arrivals._rate)
    params = [dispatcher, world]
    world.schedule_event(p_arrivals.generate_arrival, initial_arrival,
                         params)  #Schedule first arrival to start chain
    last_event = 0
    world.number_of_arr_dep = 0  #resetting the number of events before we start
    # Now we need to schedule the initial arrivals to start the chain of events.
    # Now that each dispatcher has an arrival, we can start looping through events
    while world.next_event() <= float(
            sim_time
    ):  # while the virtual time of next event is less than our simulation time..
        if (list_of_servers[0]._total_jobs <= stopping_n
                and list_of_servers[1]._total_jobs <= stopping_n
                and list_of_servers[2]._total_jobs <= stopping_n):
            break
        last_event = world.next_event()
        world.process_event(
        )  # We take the event and process it (running the function(s))
    #for loop to step between while loops (every 10%)while world.next
    #We've reached a stopping state. Record event parameters and print to file
    jobs_ran += world._stats.number_of_jobs  # We stopped, we add the number of jobs ran this time to global variable
    recorded_x = list_of_servers[0]._total_jobs
    recorded_y = list_of_servers[1]._total_jobs
    recorded_T = last_event  #Last event that happened (e.g. departure that caused the total jobs to be < 4)
    recorded_N = world.number_of_arr_dep  #Get the number of events that happened'
    final_data.append((recorded_x, recorded_y, recorded_T, recorded_N))
 def reset_world(first_arrival):
     nonlocal list_of_servers, dispatcher, statistics, world  # if we want to modify variable from closure, must place as nonlocal
     list_of_servers.clear()  #clear the 2 servers
     list_of_servers = init_servers(2, scheduler, job_distribution)
     dispatcher = Dispatcher(
         policy_i,
         list_of_servers)  # resetting the dispatcher with new servers
     statistics = Statistics()
     world = Global(statistics)
     init_server_to_state(no_of_jobs_server_1, list_of_servers[0],
                          scheduler, world)
     init_server_to_state(no_of_jobs_server_2, list_of_servers[1],
                          scheduler, world)
     params = [dispatcher, world]
     world.schedule_event(p_arrivals.generate_arrival, first_arrival,
                          params)  #Schedule first arrival to start chain