Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Implement the Scheduler method in this Round Robin Scheduler Python program from linked_queue import LinkedQueue from array_queue import ArrayQueue class RoundRobinScheduler: Round Robin Scheduler Simulation.

Implement the Scheduler method in this Round Robin Scheduler Python program

from linked_queue import LinkedQueue from array_queue import ArrayQueue

class RoundRobinScheduler: """Round Robin Scheduler Simulation. Implement the scheduler Print each time slice or changes Print final reults: table of completion time, turnaround waiting time ?Experiment effect of slice time to performane """ """ Nested class for task definition """ class _Task: def __init__(self, id = None): self._PID = id #the task id, could be string self._arrivalTime = 0 #the arrival time, in ms self._taskTime = 0 #the task time required to finish the job, in ms self._taskTimeLeft = self._taskTime #task time left to be finished. It is initialized using the task time self._completeTime = 0 #task completed at clock time def print(self): print("Task ID: " + self._PID + "\t Arrival time: " + str(self._arrivalTime) + "\t Task time: " + str(self._taskTime) + "\t Complete at: " + str(self._completeTime) + "\t Completion time: " + str(self._completeTime - self._arrivalTime) + "\t Waiting time: " + str(self._completeTime - self._arrivalTime - self._taskTime)) def __init__(self): """Create an empty queue.""" self._tasksInQueue = LinkedQueue() #This is the Robin Queue self._clock = 0 #this clock keeps increase by timeslice (quantum time) or task remaining time when it <= timeslice self._timeSlice = 100 #Here we set the quantum time as 100 ms self._tasksList = LinkedQueue() #tasks list to be send into the round robin queue self._setUpTaskList() #method that set up some test data

def _setUpTaskList(self): """Initialize the waittime tasks list """ newTask = self._Task("P0") newTask._arrivalTime = 0 newTask._taskTimeLeft = newTask._taskTime = 250 self._tasksList.enqueue(newTask) newTask = self._Task("P1") newTask._arrivalTime = 50 newTask._taskTimeLeft = newTask._taskTime = 170 self._tasksList.enqueue(newTask) newTask = self._Task("P2") newTask._arrivalTime = 130 newTask._taskTimeLeft = newTask._taskTime = 75 self._tasksList.enqueue(newTask) def scheduling(self): """Scheduling algorithm""" """Some suggested notes might help your implementation, BUT YOU CAN ALWAYS DO YOUR OWN WAY! 1 keep running while both tasks list and robin queue is not empty 2 keep enqueue into Robin queue for those arrival time before next time slot 3 process the first task in the Robin Queue 3.1 if the task can be finished with next time slot (_taskTimeLeft <= self._timeSlice), clock increases by the task time left, task finished, record the complete time and print the finished task 3.2 else clock increases by time slice, _taskTimeLeft decreases by time slice, put back to the queue """ """ YOUR CODE GOES HERE """ if __name__ == '__main__': Q = RoundRobinScheduler() Q.scheduling()

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

Handbook Of Database Security Applications And Trends

Authors: Michael Gertz, Sushil Jajodia

1st Edition

1441943056, 978-1441943057

Students also viewed these Databases questions