the subject of this programming assignment is to run a simul

the subject of this programming assignment is to run a simulation of waiting queues. we consider, for example, the queues of passengers at a check-in counter of an airline. - we have two classes of service: coach and first class. - there is one queue for each class of service - there are three coach check-in stations and two first-class stations - each class of service is characterized by two parameters: rate of arrival of passengers, and average length of service (for example: we have one first-class passenger every three minutes on average, and each first class passenger requires an average of eight minutes of service). - The input to the simulation is: the average rate of arrival and the average rate of service of each class of service, as well as the length of simulation (in minutes) and whether the simulation ends abruptly or when all queues and stations are flushed out. - The output of the simulation is any type of metrics you may be interested to collect, such as (for each class of service): max waiting time, average waiting time, rate of occupancy of service stations, average length of waiting queues, max length of waiting queues, number of passengers served, number of unserved passengers at the end of the simulation (if an abrupt end). you may, if you like, illustrate the evolution of the queue in real time. ---------------------------------- design hints: - you define your own time variable; just use an integer. DO NOT use the system time nor real-time. - define a queue ADT and use it/ instantiate it to implement the waiting queues. - make the program as simple as possible.

Solution

simulationcoachclass.py

from random import randint
from collections import deque
from time import sleep
class Customer:
    arr_time = 0
    arr_count = 0
    def __init__(self, arr_time, arr_count):
        self.arr_time = arr_time
        self.arr_count = arr_count

t = 0

customers = deque()

arr_count = 0

arrival_time = randint(1, 4)

departure_time = arrival_time + 3

max_wait = 0

max_size = 0

print \"For first class with 3 minutes of service time.\"
print \"Each arrival is between 1 and 4 minutes.\"
sleep(5) #added for readability
while t<720:

    if arrival_time == t:
        arr_count += 1
        customers.append(Customer(t, arr_count))
        print \"Customer\", arr_count, \"has arrived\"
        arrival_time = randint(1, 4)+t

    if departure_time == t:
        if len(customers)>0:
            customer_departed = customers[0].arr_count
            wait_time = t - customers[0].arr_time
            if wait_time > max_wait:
                max_wait = wait_time
            customers.popleft()
            print \"Service was completed for customer\", customer_departed
            departure_time = 3+t

    queue_size = len(customers)
    if max_size < queue_size:
        max_size = queue_size
    t += 1

print \"Total Number of customers serviced: \", customers[0].arr_count

print \"Maximum number of customers in queue at any time: \", max_size

print \"Longest wait any one customer experienced: \", max_wait

simulationfirstclass.py

from random import randint
from collections import deque
from time import sleep
class Customer:
    arr_time = 0
    arr_count = 0
    def __init__(self, arr_time, arr_count):
        self.arr_time = arr_time
        self.arr_count = arr_count

t = 0

customers = deque()

arr_count = 0

arrival_time = randint(1, 4)

departure_time = arrival_time + 8

max_wait = 0

max_size = 0

print \"For first class with 8 minutes of service time.\"
print \"Each arrival is between 1 and 4 minutes.\"
sleep(5) #added for readability
while t<720:

    if arrival_time == t:
        arr_count += 1
        customers.append(Customer(t, arr_count))
        print \"Customer\", arr_count, \"has arrived\"
        arrival_time = randint(1, 4)+t

    if departure_time == t:
        if len(customers)>0:
            customer_departed = customers[0].arr_count
            wait_time = t - customers[0].arr_time
            if wait_time > max_wait:
                max_wait = wait_time
            customers.popleft()
            print \"Service was completed for customer\", customer_departed
            departure_time = 8+t

    queue_size = len(customers)
    if max_size < queue_size:
        max_size = queue_size
    t += 1

print \"Total Number of customers serviced: \", customers[0].arr_count

print \"Maximum number of customers in queue at any time: \", max_size

print \"Longest wait any one customer experienced: \", max_wait

the subject of this programming assignment is to run a simulation of waiting queues. we consider, for example, the queues of passengers at a check-in counter of
the subject of this programming assignment is to run a simulation of waiting queues. we consider, for example, the queues of passengers at a check-in counter of
the subject of this programming assignment is to run a simulation of waiting queues. we consider, for example, the queues of passengers at a check-in counter of

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site