Пример #1
0
def test3b_2():
    profile = util.Profile(bulletin, 'profile3b1.txt')
    cspConstructor = submission.SchedulingCSPConstructor(bulletin, copy.deepcopy(profile))
    csp = cspConstructor.get_basic_csp()
    cspConstructor.add_unit_constraints(csp)
    alg = submission.BacktrackingSearch()
    alg.solve(csp)
Пример #2
0
def test3b_4():
    profile = util.Profile(bulletin, 'profile3b3.txt')
    cspConstructor = submission.SchedulingCSPConstructor(bulletin, copy.deepcopy(profile))
    csp = cspConstructor.get_basic_csp()
    cspConstructor.add_all_additional_constraints(csp)
    alg = submission.BacktrackingSearch()
    alg.solve(csp, mcv = True, ac3 = True)
Пример #3
0
 def test_3(self):
     """3b-3-hidden:  Test MVC+AC-3+all additional constraints"""
     profile = util.Profile(bulletin, 'profile3b3.txt')
     cspConstructor = submission.SchedulingCSPConstructor(
         bulletin, copy.deepcopy(profile))
     csp = cspConstructor.get_basic_csp()
     cspConstructor.add_all_additional_constraints(csp)
     alg = submission.BacktrackingSearch()
     alg.solve(csp, mcv=True, ac3=True)
Пример #4
0
 def test_2(self):
     """3b-2-hidden:  Test unsatisfiable scheduling"""
     profile = util.Profile(bulletin, 'profile3b2.txt')
     cspConstructor = submission.SchedulingCSPConstructor(
         bulletin, copy.deepcopy(profile))
     csp = cspConstructor.get_basic_csp()
     cspConstructor.add_all_additional_constraints(csp)
     alg = submission.BacktrackingSearch()
     alg.solve(csp)
Пример #5
0
 def test_1(self):
     """3b-1-hidden:  Test add_unit_constraints with different profiles"""
     profile = util.Profile(bulletin, 'profile3b1.txt')
     cspConstructor = submission.SchedulingCSPConstructor(
         bulletin, copy.deepcopy(profile))
     csp = cspConstructor.get_basic_csp()
     cspConstructor.add_unit_constraints(csp)
     alg = submission.BacktrackingSearch()
     alg.solve(csp)
Пример #6
0
 def test_2(self):
     """3a-2-hidden:  Test add_quarter_constraints with no quarter specified"""
     profile = util.Profile(bulletin, 'profile3a2.txt')
     cspConstructor = submission.SchedulingCSPConstructor(
         bulletin, copy.deepcopy(profile))
     csp = cspConstructor.get_basic_csp()
     cspConstructor.add_quarter_constraints(csp)
     alg = submission.BacktrackingSearch()
     alg.solve(csp)
Пример #7
0
def test3b_4():
    profile = util.Profile(bulletin, 'profile3b3.txt')
    cspConstructor = submission.SchedulingCSPConstructor(
        bulletin, copy.deepcopy(profile))
    csp = cspConstructor.get_basic_csp()
    cspConstructor.add_all_additional_constraints(csp)
    alg = submission.BacktrackingSearch()
    alg.solve(csp, mcv=True, ac3=True)
    for assignment in alg.allAssignments:
        sol = util.extract_course_scheduling_solution(profile, assignment)
        print sol
Пример #8
0
def test3a_3():
    profile = util.Profile(bulletin, 'profile3a2.txt')
    cspConstructor = submission.SchedulingCSPConstructor(
        bulletin, copy.deepcopy(profile))
    csp = cspConstructor.get_basic_csp()
    cspConstructor.add_quarter_constraints(csp)
    alg = submission.BacktrackingSearch()
    alg.solve(csp)
    for assignment in alg.allAssignments:
        sol = util.extract_course_scheduling_solution(profile, assignment)
        grader.requireIsTrue(verify_schedule(bulletin, profile, sol, False))
Пример #9
0
def test3c_0():
    profile = util.Profile(bulletin, 'profile3c.txt')
    cspConstructor = submission.SchedulingCSPConstructor(bulletin, copy.deepcopy(profile))
    csp = cspConstructor.get_basic_csp()
    cspConstructor.add_unit_constraints(csp)
    alg = submission.BacktrackingSearch()
    alg.solve(csp)

    # Verify correctness.
    grader.requireIsEqual(15, alg.numOptimalAssignments)
    for assignment in alg.allAssignments:
        sol = util.extract_course_scheduling_solution(profile, assignment)
        grader.requireIsTrue(verify_schedule(bulletin, profile, sol))
Пример #10
0
    def test_0(self):
        """3b-0-basic:  Basic test for add_unit_constraints"""
        profile = util.Profile(bulletin, 'profile3b.txt')
        cspConstructor = submission.SchedulingCSPConstructor(
            bulletin, copy.deepcopy(profile))
        csp = cspConstructor.get_basic_csp()
        cspConstructor.add_unit_constraints(csp)
        alg = submission.BacktrackingSearch()
        alg.solve(csp)

        # Verify correctness.
        self.assertEqual(15, alg.numOptimalAssignments)
        for assignment in alg.allAssignments:
            sol = util.extract_course_scheduling_solution(profile, assignment)
            self.assertTrue(verify_schedule(bulletin, profile, sol))
Пример #11
0
def test33b_0():
    profile = util.Profile(bulletin, 'profile3b_rice.txt')
    cspConstructor = submission.SchedulingCSPConstructor(
        bulletin, copy.deepcopy(profile))
    csp = cspConstructor.get_basic_csp()
    cspConstructor.add_request_weights(csp)
    alg = submission.BacktrackingSearch()
    alg.solve(csp)

    # Verify correctness.
    grader.requireIsEqual(1, alg.numOptimalAssignments)
    grader.requireIsEqual(2, alg.numAssignments)
    grader.requireIsEqual(5, alg.optimalWeight)
    for assignment in alg.allAssignments:
        solution = util.extract_course_scheduling_solution(profile, assignment)
        grader.requireIsTrue(
            verify_schedule(bulletin, profile, solution, False))
Пример #12
0
import util, submission, sys

if len(sys.argv) < 2:
    print "Usage: %s <profile file (e.g., profile3d.txt)>" % sys.argv[0]
    sys.exit(1)

profilePath = sys.argv[1]
bulletin = util.CourseBulletin('courses.json')
profile = util.Profile(bulletin, profilePath)
profile.print_info()
cspConstructor = submission.SchedulingCSPConstructor(bulletin, profile)
csp = cspConstructor.get_basic_csp()
cspConstructor.add_all_additional_constraints(csp)

alg = submission.BacktrackingSearch()
alg.solve(csp, mcv=True, ac3=True)
if alg.optimalAssignment:
    print alg.optimalWeight
    for key, value in alg.optimalAssignment.items():
        print key, '=', value

print alg.numOptimalAssignments
if alg.numOptimalAssignments > 0:
    print "solution========================="
    solution = util.extract_course_scheduling_solution(profile,
                                                       alg.optimalAssignment)
    util.print_course_scheduling_solution(solution)

for assignment in alg.allAssignments:
    solution = util.extract_course_scheduling_solution(profile, assignment)
    util.print_course_scheduling_solution(solution)
Пример #13
0
import util
# load bulletin
bulletin = util.CourseBulletin('courses.json')
# retrieve information of CS221
cs221 = bulletin.courses['CS221']
print cs221
# look at various properties of the course
print cs221.cid
print cs221.minUnits
print cs221.maxUnits
print cs221.prereqs  # the prerequisites
print cs221.is_offered_in('Aut2016')
print cs221.is_offered_in('Win2017')

# load profile from profile_example.txt
profile = util.Profile(bulletin, 'profile_example.txt')
# see what it's about
profile.print_info()
# iterate over the requests and print out the properties
for req in profile.requests:
    print req.cids, req.quarters, req.prereqs, req.weight
Пример #14
0
def valid_profile_txt():
    try:
        profile = util.Profile(bulletin, 'profile.txt')
    except:
        grader.fail('profile.txt is not valid')
    grader.assignFullCredit()