Question: Task 4: The Scheduling Algorithms Requires: knowing how to implement a class understanding inheritance solid understanding of the scheduling algorithms described above. In the file


Task 4: The Scheduling Algorithms Requires: knowing how to implement a class understanding inheritance solid understanding of the scheduling algorithms described above. In the file scheduler.py, we have provided you with a class called Scheduler. It is an abstract class: the schedule method is not implemented, so no instances of the class should be made. Its purpose is to define what any sort of scheduler must be able to do. Your task is to implement two subclasses of Scheduler called RandomScheduler and GreedyScheduler, which implement the scheduling algorithms defined above. This is the heart of the code. Your code in this module will make use of the various classes you have completed in the earlier steps. For example, the schedule method takes a list of Parcel objects and a list of Truck objects. You'll find use for class PriorityQueue in your Greedy Scheduler, since it needs to get the parcels into the desired order (as specified in the configuration dictionary). A priority queue is perfect for this. When you create an instance of PriorityQueue, it needs to be told what function you want it to use to dictate which of two things has higher priority. You will need to define a (very simple) function for each of the four kinds of parcel priority you may have to deal with, described above. Define these four functions at the module level (outside of any class) and name each with a leading underscore to indicate that it is private. When your greedy schedule needs to put the parcels in order, it can create a priority queue that uses the appropriate one of these priority functions. (It will look at the configuration dictionary to determine which.) You may need to add one or two attributes to your scheduler classes. If you do, make them private. You may also need to define an initializer for one of your child scheduler classes that has a different parameter list than the one it inherits. This is permitted. Just be sure not to change the interface of any other methods in the starter code. This module contains the abstract Scheduler class, as well as the two subclasses RandomScheduler and Greedy Scheduler, which implement the two scheduling algorithms described in the handout. from typing import List, Dict, Union, Callable from random import shuffle, choice from container import Priority Queue from domain import Parcel, Truck class Scheduler: """A scheduler, capable of deciding what parcels go onto which trucks, and what route each truck will take. This is an abstract class. Only child classes should be instantiated. def schedule(self, parcels: List[Parcel], trucks: List[Truck), verbose: bool = False) -> List[Parcel]: "Schedule the given onto the given , that is, decide which parcels will go on which trucks, as well as the route each truck will take. Mutate the Truck objects in , or any of the parcel objects in that list. Return a list containing the parcels that did not get scheduled onto any truck, due to lack of capacity. If is True, print step-by-step details regarding the scheduling algorithm as it runs. This is only* for debugging purposes for your benefit, so the content and format of this information is your choice; we will not test your code with set to True. raise NotimplementedError # TODO: Implement classes RandomScheduler and Greedy Scheduler. _name__ == _main__': import doctest doctest.testmod() import python_ta python_ta.check_all(config={ 'allowed-io': ['compare_algorithms'), 'allowed-import-modules': ['doctest', 'python_ta', 'typing: 'random', 'container', 'domain'), 'disable': ['E1136'), 'max-attributes': 15, }) Task 4: The Scheduling Algorithms Requires: knowing how to implement a class understanding inheritance solid understanding of the scheduling algorithms described above. In the file scheduler.py, we have provided you with a class called Scheduler. It is an abstract class: the schedule method is not implemented, so no instances of the class should be made. Its purpose is to define what any sort of scheduler must be able to do. Your task is to implement two subclasses of Scheduler called RandomScheduler and GreedyScheduler, which implement the scheduling algorithms defined above. This is the heart of the code. Your code in this module will make use of the various classes you have completed in the earlier steps. For example, the schedule method takes a list of Parcel objects and a list of Truck objects. You'll find use for class PriorityQueue in your Greedy Scheduler, since it needs to get the parcels into the desired order (as specified in the configuration dictionary). A priority queue is perfect for this. When you create an instance of PriorityQueue, it needs to be told what function you want it to use to dictate which of two things has higher priority. You will need to define a (very simple) function for each of the four kinds of parcel priority you may have to deal with, described above. Define these four functions at the module level (outside of any class) and name each with a leading underscore to indicate that it is private. When your greedy schedule needs to put the parcels in order, it can create a priority queue that uses the appropriate one of these priority functions. (It will look at the configuration dictionary to determine which.) You may need to add one or two attributes to your scheduler classes. If you do, make them private. You may also need to define an initializer for one of your child scheduler classes that has a different parameter list than the one it inherits. This is permitted. Just be sure not to change the interface of any other methods in the starter code. This module contains the abstract Scheduler class, as well as the two subclasses RandomScheduler and Greedy Scheduler, which implement the two scheduling algorithms described in the handout. from typing import List, Dict, Union, Callable from random import shuffle, choice from container import Priority Queue from domain import Parcel, Truck class Scheduler: """A scheduler, capable of deciding what parcels go onto which trucks, and what route each truck will take. This is an abstract class. Only child classes should be instantiated. def schedule(self, parcels: List[Parcel], trucks: List[Truck), verbose: bool = False) -> List[Parcel]: "Schedule the given onto the given , that is, decide which parcels will go on which trucks, as well as the route each truck will take. Mutate the Truck objects in , or any of the parcel objects in that list. Return a list containing the parcels that did not get scheduled onto any truck, due to lack of capacity. If is True, print step-by-step details regarding the scheduling algorithm as it runs. This is only* for debugging purposes for your benefit, so the content and format of this information is your choice; we will not test your code with set to True. raise NotimplementedError # TODO: Implement classes RandomScheduler and Greedy Scheduler. _name__ == _main__': import doctest doctest.testmod() import python_ta python_ta.check_all(config={ 'allowed-io': ['compare_algorithms'), 'allowed-import-modules': ['doctest', 'python_ta', 'typing: 'random', 'container', 'domain'), 'disable': ['E1136'), 'max-attributes': 15, })