def test3a_0(): profile = util.Profile(bulletin, 'profile3a.txt') cspConstructor = submission.SchedulingCSPConstructor(bulletin, copy.deepcopy(profile)) csp = cspConstructor.get_basic_csp() cspConstructor.add_quarter_constraints(csp) alg = submission.BacktrackingSearch() alg.solve(csp) # Verify correctness. grader.requireIsEqual(3, alg.numOptimalAssignments) sol = util.extract_course_scheduling_solution(profile, alg.optimalAssignment) for assignment in alg.allAssignments: sol = util.extract_course_scheduling_solution(profile, assignment) grader.requireIsTrue(verify_schedule(bulletin, profile, sol, False))
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
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))
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)
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 list(alg.optimalAssignment.items()): print((key, '=', value)) for assignment in alg.allOptimalAssignments: solution = util.extract_course_scheduling_solution(profile, assignment) if solution: # displays one of the best assignments util.print_course_scheduling_solution(solution) break elif alg.numOptimalAssignments == 1: print("The best schedule is to take 0 units every quarter.")
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, mac = True) if alg.optimalAssignment: print alg.optimalWeight for key, value in alg.optimalAssignment.items(): print key, '=', value if alg.numOptimalAssignments > 0: solution = util.extract_course_scheduling_solution(profile, alg.optimalAssignment) util.print_course_scheduling_solution(solution)