Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using a python queue data structure: Design a simulation experiment to evaluate

ID: 3746516 • Letter: U

Question

Using a python queue data structure:

Design a simulation experiment to evaluate the effectiveness of an express lane at the grocery store.

Use items in a queue to represent customers. Each customer has a service time and an arrival time (can use either two queues or one queue with tuples), which is to be generated from a random number generator. In one simulation, use two concurrent cashiers that handle the customers in order. In a second simulation divide the customers so that one cashier handles the customers with the shortest service times, but will taker longer service time customers if no customer's with shorter service times have arrived.

Measure the effectiveness by the average turn around time (wait + service) of the customers.

How could you modify this experiment to more closely model a real grocery store?

Hint: you may need a "peek" method like the Stack had that can look at an item without removing it from the queue.

Explanation / Answer

# Use python 3 to run this program

import random

def FCFS(l):

'''

FCFS: servers customer in order

Input: list containing processes, where ecah process is a list of [arrival time, service time]

Output: list containing processes, where ecah process is a list of [arrival time, service time, waiting time]

'''

timer=0

process_queue = l

for i in range(0,len(l)):

process_queue[i].append(0)

process_queue.sort(key = lambda process_queue:process_queue[0])

print(process_queue)

for i in range(0,len(l)):

if timer == 0:

process_queue[i][2] = 0

timer = process_queue[i][0] +process_queue[i][1]

else:

process_queue[i][2] = timer - process_queue[i][0]

timer =timer + process_queue[i][1]

print(process_queue)

exit(0)

def SJF(l):

size = len(l)

process_queue = l

start = [0] * size

turn = [0] * size

waiting_Time = [0] * size

turn_Time = [0] * size

# sort by service time

process_queue.sort(key = lambda process_queue:process_queue[1])

for j in range(size):

if j == 0:

start[j] = process_queue[j][0]

turn[j] = process_queue[j][0] + process_queue[j][1]

if j >= 1:

start[j] = turn[j - 1]

turn[j] = process_queue[j][1] + turn[j - 1]

for m in range(size):

waiting_Time[m] = start[m] - process_queue[j][0]

turn_Time[m] = turn[m] - process_queue[j][0]

sum1 = 0

sum2 = 0

awaiting_Time = sum1 / size

aturn_Time = sum2 / size

return (awaiting_Time, aturn_Time)

list = [[random.randint(0, 100), random.randint(0, 100) ] for k in range(10)]

print(list)

SJF(list)

FCFS(list)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote