Question: Extremely stuck on this assignment, please help, read the entire instructions, using python. Using the code provided below which simulates a printer, the code is

Extremely stuck on this assignment, please help, read the entire instructions, using python. Using the code provided below which simulates a printer, the code is to be modified so it can simulate the wait times if another printer is added. Given a configuration with two printers, if one printer is busy and a print task is submitted to a empty queue, the task is dispatched to the idle printer. If both printers are busy, the task is enqueued to a common queue until a printer frees up. If both printers are free when a task is submitted, the task is assigned to the printer with the higher page rate. Note that the simulation should still allow the user to specify a configuration with 1 printer.

The program does not ask user for inputs, the program takes a file with a printer configuration from a text file, the input file has the following attributes:

1. Duration of simulation in seconds (valid range is 3600-36000).

2. Number of simulation experiments (valid range is 1-100. In the existing program, this value is set to 10).

3. Minimum task size (must be in range 1-100)

4. Maximum task size (must be in range 1-100 and >= minimum)

5. Number of printers (must be 1 or 2)

6. Page rate of printer 1 (must be in the range 1-50)

7. Page rate of printer 2 (if number of printers is 1, this value would not be specified)

Your program must implement input validation (Using exception handling and conditional statements as appropriate) to detect format error and out of range errors. Appropriate error messages should be output to the terminal, after which point the program should terminate.

The program should output to a file named printer_out.txt the average wait time for each experiment along with the length of the queue when the simulation terminated, and finally the overall average wait time for all experiments. Below is a concept of how the input file looks and the results look, if ran seperately with different numbers inputted into the input file..

INPUT NUMBERS FROM FILE What the output file should read

36000

10

1

40

1

15

Average Wait 47.11 secs 0 tasks remaining.

Average Wait 34.06 secs 0 tasks remaining.

Average Wait 45.15 secs 0 tasks remaining.

Average Wait 44.81 secs 1 tasks remaining.

Average Wait 36.89 secs 0 tasks remaining.

Average Wait 46.70 secs 0 tasks remaining.

Average Wait 47.14 secs 0 tasks remaining.

Average Wait 41.17 secs 1 tasks remaining.

Average Wait 30.52 secs 0 tasks remaining.

Average Wait 37.76 secs 0 tasks remaining.

Overall average wait time: 41.13 secs

36000

10

1.5

40

2

10

10

Format error: minimum task size. Exiting.

36000

10

1

40

3

10

10

Invalid number of printers. Exiting.

PRINTER SIMULATION CODE TO BE MODIFIED:

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 <= 0: self.currentTask = None 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 10 times for i in range(10): simulation(3600, 10) if __name__ == "__main__": main()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!