*** Below is the assignment description. if you want a detailed version, read project3.pdf file *** **You are to make a modification on a existing Python code to complete the below parts** Your task...

1 answer below »
*** Below is the assignment description. if you want a detailed version, read project3.pdf file ***
**You are to make a modification on a existing Python code to complete the below parts**
Your task for this assignment is to make all three of the following improvements for a more realistic grocery store simulation:
 currently when a customer arrives at the check-out lines, the customer goes into the cashier queue with the fewest number of customers. However, a real arriving customer would look not just at the number of customers in a line, but also how many items those customers have to gauge their check-out time. Modify the simulator to add an arriving customer to the shortest line based on the total check-out time for all customers currently in line. You should not need to modify the FIFO queue class, but just keep an accumulator for each line to track the total check-out minutes of customers in line.
 currently when the simulation ends, it outputs for each check-out lane the number of customers served and the length of the line at the end of the simulation. Additional information would be helpful since customers get frustrated if they have to wait along time in line. Modify the simulation to calculate and print the average waiting time in line across all customers checked-out. Hint: modify the information stored about each customer waiting in the FIFO queue to include the clock-time when they entered the line.
 currently when the simulation starts, the number of cashiers/check-out lines is entered and fixed for the duration of the simulation. However, a real grocery stores might have 20 check-out lanes with only 8 cashiers open. If the open lines all get too long, then a new check-out line is opened and customers at the rear of existing lines shift into it. Modify the simulator to allow the user to specify additional simulation parameters for maximum number of check-out lines, initial number of open check-out lines, and a threshold for opening a new check-out line (i.e., length of shortest line in terms of total minutes across all customers in that line). Hint: use Deque instead of FIFO queue to model each waiting line so you can use the Deque’s removeRear method when shifting customers into the newly opened check-out line. For our simulation we will not worry about closing check-out lanes when they get too small. After completing your modifications, make sure that your simulation results seem reasonable.
I would expect all the check-out lines at the end of the simulation to be about the same length since arriving customers always get added to the smallest line based on the number of customers in line.
***BELOW is the script files available for you to make the right modification. ***
binheap.py - the BinHeap class previously used with a new peekMin method which returns the minimum item without removing it queue_text.py - the textbook’s Python-list based FIFO queue implementation priority_queue.py - the PriorityQueue and PriorityQueueEntry class implementations. The PriorityQueue uses a BinHeap to order PriorityQueueEntry items which bundle together a Priority and its corresponding Value. project3.py - the working discrete-event simulation of multiple check-out lines (e.g., like at a grocery store). The simulation is based on user inputs of: # of check-out lines, simulation length (# of minutes), probability of a customer finishes shopping within each minute, and average customer check-out time.
Answered Same DayAug 21, 2021

Answer To: *** Below is the assignment description. if you want a detailed version, read project3.pdf file ***...

Karthi answered on Aug 22 2021
147 Votes
89973/__pycache__/priority_queue.cpython-36.pyc
89973/__pycache__/binheap.cpython-36.pyc
89973/__pycache__/queue_text.cpython-36.pyc
89973/double_linked_deque.py
from node import Node
class Deque(object):
def __init__(self):
self._front = None
self._rear = None
self._size = 0
def isEmpty(self):
return self._size == 0
def addFront(self, item):
temp = Node(item)
temp.setPrevious(self._front)

if self._size == 0:
self._rear = temp
else:
self._front.setNext(temp)

self._front = temp
self._size += 1
def addRear(self, item):
temp = Node(item)
temp.setNext(self._rear)
if self._size == 0:
self._front = temp

else:
self._rear.setPrevious(temp)
self._rear = temp
self._size += 1

def removeFront(self):
""" Removes and returns the front item of the Deque. """
if self._size == 0:
raise AttributeError("Cannot removeFront from an empty Deque")

temp = self._front
self._front = self._front.getPrevious()
if self._size == 1:
self._rear = None
else:
self._front.setNext(None)
self._size -= 1

return temp.getData()

def removeRear(self):
""" Removes and returns the rear item of the Deque. """
if self._size == 0:
raise AttributeError("Cannot removeRear from an empty Deque")

temp = self._rear
self._rear = self._rear.getNext()
if self._size == 1:
self._front = None
else:
self._rear.setPrevious(None)
self._size -= 1

return temp.getData()

def peekFront(self):
""" Returns the front item of the Deque without removing it. """
if self._size == 0:
raise AttributeError("Cannot peekFront from an empty Deque")
return self._front.getData()
def peekRear(self):
""" Returns the rear item of the Deque without removing it. """
if self._size == 0:
raise AttributeError("Cannot peekFront from an empty Deque")
return self._rear.getData()

def size(self):
return self._size
def __str__(self):
""" Returns a string representation of all items from rear to front."""
resultStr = "(rear)"
current = self._rear
while current != None:
resultStr = resultStr + " " + str(current.getData())
current = current.getNext()
resultStr = resultStr + " (front)"
return resultStr


89973/node.py
class Node:
def __init__(self,initdata):
self.data = initdata
self.next = None
self.previous = None
def getData(self):
return self.data
def getPrevious(self):
return self.previous
def setPrevious(self,newprevious):
self.previous = newprevious
def getNext(self):
return self.next
def setData(self,newdata):
self.data = newdata
def setNext(self,newnext):
self.next = newnext
89973/simulatorTestCase.py
import unittest
from project3 import Simulator
# A few test cases for the Simulator class.
class SimulatorTestCase(unittest.TestCase):
def setUp(self):
numberCashiers = 1
simulationLength = 25
probabilityOfArrival = 0.5
averageCustomerTime = 3
maxCheckoutLines = 10
maxWaitThreshold = 5
self.sim = Simulator(numberCashiers, simulationLength, probabilityOfArrival, averageCustomerTime, maxCheckoutLines, maxWaitThreshold)
self.sim.checkOutLines[0].addRear({ "checkoutDuration": 6, "entryTimeForCurrentLine": 1})
self.sim.currentWaitTimeByLine[0] += (6 + 1)
def testShouldOpenNewLine(self):
assert self.sim.shouldOpenNewLine() is True
def testOpenNewLine(self):
sim = self.sim
sim.openNewLine()
assert sim.checkOutLines[1] is not None
assert sim.customersServedByCashierList[1] is not None
assert sim.cashierIdleList[1] is not None
assert sim.currentWaitTimeByLine is not None
assert sim.totalCustomerWaitTimeInCheckoutQueue is not None
# We only opened one ine
with self.assertRaises(IndexError):
sim.checkOutLines[2]
def testShiftCustomersToNewLine(self):
sim = self.sim
sim.openNewLine()
sim.openNewLine()
sim.checkOutLines[0].addRear({ "checkoutDuration": 3, "entryTimeForCurrentLine": 2})
sim.checkOutLines[0].addRear({ "checkoutDuration": 4, "entryTimeForCurrentLine": 3})
sim.checkOutLines[0].addRear({ "checkoutDuration": 7, "entryTimeForCurrentLine": 4})
sim.currentWaitTimeByLine[0] = (3 + 4 + 7 + 6 + (1*4)) # 6 is initial queue val. = 24
sim.checkOutLines[1].addRear({ "checkoutDuration": 1, "entryTimeForCurrentLine": 5})
sim.checkOutLines[1].addRear({ "checkoutDuration": 4, "entryTimeForCurrentLine": 6})
sim.checkOutLines[1].addRear({ "checkoutDuration": 7, "entryTimeForCurrentLine": 7})
sim.checkOutLines[1].addRear({ "checkoutDuration": 5, "entryTimeForCurrentLine": 8})
sim.checkOutLines[1].addRear({ "checkoutDuration": 3, "entryTimeForCurrentLine": 9})
sim.currentWaitTimeByLine[1] = (1 + 4 + 7 + 5 + 3 + (1*5)) # 25
sim.checkOutLines[2].addRear({ "checkoutDuration": 3, "entryTimeForCurrentLine": 10})
sim.checkOutLines[2].addRear({ "checkoutDuration": 3, "entryTimeForCurrentLine": 11})
sim.currentWaitTimeByLine[2] = (3 +3 + (1*2)) # 8
# Our shortest line by wait time should be 2, whose wait exceeds the max threshold
# secondShortestLine = 0, whose is 24
print(sim.currentWaitTimeByLine)
sim.shiftCustomersToNewLine(12)
print(sim.currentWaitTimeByLine)
# Should shift 3 from line 1 to line 2, total duration 7 + (3 + 1) = 11
# Then line 1 should be 25 - (3 + 1) = 21
# Should shift 7 from line 0 to 2, total duration for 2 is then 11 + (7 + 1) = 19
# Then 0's is 16
# checkoutline 2's 19 > 16, should stop here.
self.assertEqual(sim.currentWaitTimeByLine[0], 16)
self.assertEqual(sim.currentWaitTimeByLine[1], 21)
self.assertEqual(sim.currentWaitTimeByLine[2], 20)
def testDetermineShortestLine(self):
sim = self.sim
sim.openNewLine()
sim.openNewLine()
sim.checkOutLines[0].addRear({ "checkoutDuration": 3, "entryTimeForCurrentLine": 2})
sim.checkOutLines[0].addRear({ "checkoutDuration": 4, "entryTimeForCurrentLine": 3})
sim.checkOutLines[0].addRear({ "checkoutDuration": 7, "entryTimeForCurrentLine": 4})
# Line 0 wait time = (6 + 1) +(3 + 1) + (4+ 1) + (7+ 1) 6 is initial setup queue val. = 24
sim.checkOutLines[1].addRear({ "checkoutDuration": 1, "entryTimeForCurrentLine": 5})
sim.checkOutLines[1].addRear({ "checkoutDuration": 4, "entryTimeForCurrentLine": 6})
sim.checkOutLines[1].addRear({ "checkoutDuration": 7, "entryTimeForCurrentLine": 7})
sim.checkOutLines[1].addRear({ "checkoutDuration": 5, "entryTimeForCurrentLine": 8})
sim.checkOutLines[1].addRear({ "checkoutDuration": 3, "entryTimeForCurrentLine": 9})
# Line 1 wait time: 2 + 5 + 8 + 6 + 4 = 25
sim.checkOutLines[2].addRear({ "checkoutDuration": 3, "entryTimeForCurrentLine": 10})
sim.checkOutLines[2].addRear({ "checkoutDuration": 3, "entryTimeForCurrentLine": 11})
# Line 2 Wait time is 6 + 2 = 8
sim.currentWaitTimeByLine[0] = 24
sim.currentWaitTimeByLine[1] = 25
sim.currentWaitTimeByLine[2] = 8
smallestLine = 2
assert smallestLine == sim.determineSmallestLine()
#...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here