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

Extremely stuck on this assignment, please read it fully as the assignment is sl

ID: 3804471 • Letter: E

Question

Extremely stuck on this assignment, please read it fully as the assignment is slightly confusing: PYTHON

The code provided is the code needed to do the program below, using the code provided modify it to the speifications in the instructions below. Basically figure out the times if another printer was added to do tasks and output it in a seperate file. The program will take a file which has the specifiations of a printer and determine the time it takes to do a task.

This assignment, modify the printer simulation which is given in the code provided below (Attached at the bottom of these instructions), to make it possible to investigate how adding another printer to the lab would affect wait times. 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. Also, assumptions about how frequently print tasks are submitted should remain unchanged.

The modified simulation should also make it possible for the user to specify the minimum and maximum size of a print task (In the code provided, the range is 1-20). As before, the size of the print task is a random integer that falls within the specified range.

The simulation configurations should be specified in an input file printer_config.txt that the program reads. The program should not prompt the user for any input. The input file should contain the following values in the exact order specified, one per line:

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)

The input file contains 6 or 7 integers, depending on whether 1 or 2 printers were 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. To help you test your program, provided are 5 sample runs of the solution with different input files (attached photo). Run your program with the same inputs. The results you obtain should come very close from the ones shown in the table.

Make sure your code is readable and well commented, especially code you’ve modified or added.

The printer code:

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()

Printer Assignment [Compatibility Mode] Search in Document Share Home Insert Design Layout References Mailings Review View Table Design Layout AaBbc AaBbCcDdEE No spacing Heading 1 Heading 2 Title subtitle Pat Styles Normal ane Contents of printer config.txt Output from simulation program Average Mait TT Sec3 asks remaining 10 Average Mait 34 26 secs 0 tasks remaining. Average Wait 45.15 secs 0 tasks remaining 40 Average Mait 44 81 secs 1 tasks remaining Average Wait 36 89 secs 0 tasks remaining 15 Average 0 tasks remaining Average 0 tasks remaining SecS Average Wait 41.17 secs 1 tasks remaining. Average 0 tasks remaining SecS Average wait 32.26 secs 0 tasks remaining. Overal average wait tine 13 secs Average asks remaining 10 Average Mait B1.12 secs 0 tasks remaining. Average Wait 29A10 secs 0 tasks remaining 40 Average Mait 24 21 secs 0 tasks remaining Average Wait 21 19 secs 0 tasks remaining 10 Average 2 tasks remaining Average 0 tasks remaining SecS Average Wait 39.79 secs 0 tasks remaining. Average 0 tasks remaining SecS Average Wait 12.19 secs 0 tasks remaining. Overal average wait tine 28.85 secs Average asks remaining 10 Average Wait 8.17 secs 0 tasks remaining Average Wait 10.11 secs 0 tasks remaining 40 Average Wait 12 secs 0 tasks remaining Average Wait 98 secs 0 tasks remaining 10 Average Wait 0 tasks remaining e secs 10 Average 0 tasks remaining SecS Average Wait 3.53 secs 0 tasks remaining Average 0 tasks remaining SecS Average Wait 12.28 secs 0 tasks remaining. Overal average wait tine 10.80 secs xiting 10 1.5 40 10 Invatid number of printers Exiting. 10 40 10 10 E E Focus 121% 908 Words English (US) Page 2 of 4

Explanation / Answer

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

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote