Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I need help ( in Python ) with the implementation of dependency _ scheduler _ cooking _ redo method and class AND _ OR _
I need help in Python with the implementation of dependencyschedulercookingredo method and class ANDORScheduler. My Dependency Scheduler almost works, but is failing a few tests. import networkx as nx # Library for displaying graphs.
import matplotlib.pyplot as
ptt
import random
class DependencySchedulerobject:
def self:
self.tasks set
# The successors of a task are the tasks that depend on it and can
# only be done once the task is completed.
# The predecessors of a task set
self.predecessors defaultdictset
self.completedtasks # completed tasks
def addtaskself dependencies:
Adds a task t'with given dependencies.
# Makes sure we know about all tasks mentioned
assert not in self.tasks or lenselfpredecessorst "The task was already present."
self.tasks.addt
self.tasks.updatedependencies
# The predecessors are the tasks that need to be done before.
self.predecessors t setdependencies
# The new task is a successor of its dependencies
for u in dependencies:
def resetself:
self.completedtasks set
@property
def doneself:
return self.completedtasks self.tasks
def showself:
We use the nx graph to display the graph."".
nxDiGraph
gaddnodesfromselftasks
hode colgesfromu v for u in self.tasks for v in self.successorsu
green if v in self.completedtasks
else 'red' if v in self.availabletasks
else 'gray'
nxdrawg withlabelsTrue, nodecolornodecolors
pltshow
@property
def uncompletedself:
Returns the tasks that have not been completed
This is a property, so you can say scheduler.uncompleted rather than
scheduler.uncompletedI
return self.tasks self.completedtasks
@property
def availabletasksself:
"Returns the available tasks.
This is just a placeholder; we will let you implement this.".".
return set
def markcompletedself t:
"Marks that the task is completed, and returns the set of tasks
that become available as a consequence.
This is just a placeholder, we will let you implement this.""!"
return set
def checkself:
We check that if is a successor of then is a predecessor
of t
for u in self.tasks
for in self.successorsu:
assert u in self.predecessorst
#@title Implementation of and
def scheduleravailabletasksself:
Returns the set of tasks that can be done in parallel.
A task can be done if all its predecessors have been completed
And of course, we don't return any task that has already been
availabletasks set
avallable in tasks.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started