Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python Please do not copy past my question ! Thank you from Queue import Queue import random class Printer: def __init__(self, ppm): self.pagerate = ppm

Python

Please do not copy past my question ! Thank you

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()image text in transcribedimage text in transcribed

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: # duration in seconds. Valid range [3600, 36000] experiments: # number of experiments. Valid range [1,50] min pages: # minimum task size in pages. Valid range [1-50] max pages: # maximum task size in pages. Valid range [1-100] and >-min printers: printer name: # name of printer ppm: # number of printers. Can be 1, 2 or 3 # Page rate in pages per minute. Valid range [1,50] The configurations should be listed exactly in the order specified above. The last two lines (Printer name and ppm) repeat according to the number of printers specified. For instance, if there are 3 printers, the file would contain a name entry and ppm for each printer. Below is an example of a valid input file for a configuration with 2 printers. Sample configuration file config1.txt duration: 7200 experiments: l0 min pages: 10 max pages: 50 printers: 2 printer name: lab-hp ppm: 10 printer name: lab-canon ppm: 5 Error handling Your program must implement input validation (Using exception handling and conditional statements as appropriate) to detect various types of errors. Appropriate error messages should be output to the terminal, after which point the program should terminate. Error conditions that your program should detect and report on must include 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: # duration in seconds. Valid range [3600, 36000] experiments: # number of experiments. Valid range [1,50] min pages: # minimum task size in pages. Valid range [1-50] max pages: # maximum task size in pages. Valid range [1-100] and >-min printers: printer name: # name of printer ppm: # number of printers. Can be 1, 2 or 3 # Page rate in pages per minute. Valid range [1,50] The configurations should be listed exactly in the order specified above. The last two lines (Printer name and ppm) repeat according to the number of printers specified. For instance, if there are 3 printers, the file would contain a name entry and ppm for each printer. Below is an example of a valid input file for a configuration with 2 printers. Sample configuration file config1.txt duration: 7200 experiments: l0 min pages: 10 max pages: 50 printers: 2 printer name: lab-hp ppm: 10 printer name: lab-canon ppm: 5 Error handling Your program must implement input validation (Using exception handling and conditional statements as appropriate) to detect various types of errors. Appropriate error messages should be output to the terminal, after which point the program should terminate. Error conditions that your program should detect and report on must include

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Graph Databases In Action

Authors: Dave Bechberger, Josh Perryman

1st Edition

1617296376, 978-1617296376

More Books

Students also viewed these Databases questions

Question

What do Dimensions represent in OLAP Cubes?

Answered: 1 week ago