Question
from Queue import Queue import random class Printer: def __init__(self, ppm): self.pagerate = ppm self.currentTask = None self.timeRemaining = 0 def tick(self): if self.currentTask !=
from Queue import Queue import random
class Printer: def __init__(self, ppm): self.pagerate = ppm self.currentTask = None self.timeRemaining = 0
def tick(self): if self.currentTask != None: self.timeRemaining = self.timeRemaining - 1 if self.timeRemaining
def busy(self): if self.currentTask != None: return True else: return False
def startNext(self,newtask): self.currentTask = newtask self.timeRemaining = newtask.getPages() * 60/self.pagerate
class Task: def __init__(self,time): self.timestamp = time self.pages = random.randrange(1,21)
def getStamp(self): return self.timestamp
def getPages(self): return self.pages
def waitTime(self, currenttime): return currenttime - self.timestamp
def simulation(numSeconds, pagesPerMinute):
labprinter = Printer(pagesPerMinute) printQueue = Queue() waitingtimes = []
for currentSecond in range(numSeconds): if newPrintTask(): task = Task(currentSecond) printQueue.enqueue(task)
if (not labprinter.busy()) and (not printQueue.is_empty()): nexttask = printQueue.dequeue() waitingtimes.append(nexttask.waitTime(currentSecond)) labprinter.startNext(nexttask)
labprinter.tick()
averageWait = sum(waitingtimes)/len(waitingtimes) print("Average Wait %6.2f secs %3d tasks remaining." \ %(averageWait, printQueue.size()))
def newPrintTask(): num = random.randrange(1,181) if num == 180: return True else: return False
def main(): # run simulation 20 times for i in range(20): simulation(36000, 15) if __name__ == "__main__": main()
Printer Simulation (25 points) Overview For this project, you are to modify the printer simulation implemented in Printersimulation.py (part of queues.zip posted orn the course site under Source Code) to make it possible to investigate how having two or three printers in the lab would affect wait times. The existing program simulates a computer lab with a single printer and outputs the waiting times for such a configuration. To make it easier to run the simulation program with different printer settings, the program must be extended to read in configurations values from an input file instead of hardcoding the values into the code as is currently the case in the program. The simulation must prompt the user to input the names of the configuration file and the results file. No other input should be required. The program runs the simulation according to the values specified in the configuration file and outputs the results to the results file. Any error messages are output to the screen, but nothing else. Before you begin working on the project, make sure you have a good understanding of the code you're provided Configuration file format The configuration file specifies all the values needed by the program to run a simulation. It will contain values such as the duration of the simulation, number of experiments, min and max task sizes, number of printers and associated page rates. The rate at which tasks are submitted by users should stay the same as what's specified in the program provided. The configuration file must be a plain text file (.txt extension), that conforms to the following format: duration:Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started