Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#@title ` AND _ OR _ Scheduler ` implementation class AND _ OR _ Scheduler ( object ) : def _ _ init _ _

#@title `AND_OR_Scheduler` implementation
class AND_OR_Scheduler(object):
def __init__(self):
# It is up to you to implement the initialization.
### YOUR SOLUTION HERE
def add_and_task(self, t, dependencies):
"""Adds an AND task t with given dependencies."""
### YOUR SOLUTION HERE
def add_or_task(self, t, dependencies):
"""Adds an OR task t with given dependencies."""
### YOUR SOLUTION HERE
@property
def done(self):
### YOUR SOLUTION HERE
@property
def available_tasks(self):
"""Returns the set of tasks that can be done in parallel.
A task can be done if:
- It is an AND task, and all its predecessors have been completed, or
- It is an OR task, and at least one of its predecessors has been completed.
And of course, we don't return any task that has already been
completed."""
### YOUR SOLUTION HERE
def mark_completed(self, t):
"""Marks the task t as completed, and returns the additional
set of tasks that can be done (and that could not be
previously done) once t is completed."""
### YOUR SOLUTION HERE
def show(self):
"""You can use the nx graph to display the graph. You may want to ensure
that you display AND and OR nodes differently."""
### YOUR SOLUTION HERE
# Tests 10 points: Simple tests for AND nodes.
s = AND_OR_Scheduler()
s.add_and_task('a',['b','c'])
assert s.available_tasks =={'b','c'}
r = s.mark_completed('b')
assert r == set()
assert s.available_tasks =={'c'}
r = s.mark_completed('c')
assert r =={'a'}
assert s.available_tasks =={'a'}
r = s.mark_completed('a')
assert r == set()
assert s.available_tasks == set()
# Tests 10 points: Simple tests for OR nodes.
s = AND_OR_Scheduler()
s.add_or_task('a',['b','c'])
assert s.available_tasks =={'b','c'}
r = s.mark_completed('b')
# Now 'a' becomes available.
assert r =={'a'}
# But note that 'c' is also available, even if useless.
assert s.available_tasks =={'a','c'}
r = s.mark_completed('a')
assert r == set()
assert s.available_tasks =={'c'}
r = s.mark_completed('c')
assert r == set()
assert s.available_tasks == set()
# Tests 10 points: Tests with both AND and OR nodes.
s = AND_OR_Scheduler()
s.add_and_task('a',['b','c'])
s.add_or_task('b',['b1','b2'])
s.add_or_task('c',['c1','c2'])
r = s.mark_completed('b1')
assert s.available_tasks =={'b','b2','c1','c2'}
r = s.mark_completed('b')
assert 'a' not in s.available_tasks
r = s.mark_completed('c1')
assert 'a' not in s.available_tasks
r = s.mark_completed('c')
assert 'a' in s.available_tasks
s = AND_OR_Scheduler()
s.add_or_task('a',['b','c'])
s.add_and_task('b',['b1','b2'])
s.add_and_task('c',['c1','c2'])
r = s.mark_completed('b1')
assert s.available_tasks =={'b2','c1','c2'}
r = s.mark_completed('c1')
assert s.available_tasks =={'b2','c2'}
r = s.mark_completed('c2')
assert s.available_tasks =={'b2','c'}
r = s.mark_completed('c')
assert 'a' in s.available_tasks
can someone help me with this code. What do I even input at the parts where it says ###YOUR SOLUTION HERE to get through all of the tests? This is driving me nuts.

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

SQL Database Programming

Authors: Chris Fehily

1st Edition

1937842312, 978-1937842314

More Books

Students also viewed these Databases questions

Question

What are the workforce planning challenges at BCC?

Answered: 1 week ago