def test_should_return_correct_domain_for_spring_2008(self):
     filename = "spring_2008.txt"
     student = Student(filename)
     courses_offered = CoursesOffered(student)
     domains = courses_offered.get_domain_for_variables()
     self.assertEqual(
         {
             'S1C1': ['CS400'],
             'S1C2': ['CS404'],
             'S1C3': [
                 'CS327', 'CS331', 'CS335', 'CS355', 'CS400', 'CS404',
                 'CS408', 'CS411', 'CS412', 'CS417', 'CS420', 'CS442',
                 'CS490'
             ],
             'S2C1': ['CS331', 'CS401', 'CS413', 'CS415', 'CS419', 'CS490'],
             'S2C2': ['CS331', 'CS401', 'CS413', 'CS415', 'CS419', 'CS490'],
             'S2C3': ['CS331', 'CS401', 'CS413', 'CS415', 'CS419', 'CS490'],
             'S3C1': ['CS331', 'CS345', 'CS460'],
             'S3C2': ['CS412'],
             'S3C3': ['CS335', 'CS416'],
             'S4C1': [
                 'CS327', 'CS331', 'CS335', 'CS355', 'CS400', 'CS401',
                 'CS404', 'CS413', 'CS415', 'CS417', 'CS419', 'CS442',
                 'CS490'
             ],
             'S4C2': ['CS420'],
             'S4C3': ['CS490']
         }, domains,
         "test that should get the correct domain for spring 2008")
 def test_should_return_correct_domain_for_fall_2019(self):
     filename = "fall_2019.txt"
     student = Student(filename)
     courses_offered = CoursesOffered(student)
     domains = courses_offered.get_domain_for_variables()
     self.assertEqual(
         {
             'S1C1': ['CS400'],
             'S1C2': ['CS404'],
             'S1C3': [
                 'CS325', 'CS331', 'CS335', 'CS345', 'CS400', 'CS401',
                 'CS404', 'CS413', 'CS415', 'CS419', 'CS460', 'CS490'
             ],
             'S2C1': ['CS331', 'CS355', 'CS442'],
             'S2C2': ['CS411', 'CS412'],
             'S2C3': ['CS335'],
             'S3C1': ['CS331', 'CS401', 'CS413', 'CS415', 'CS419', 'CS490'],
             'S3C2': ['CS331', 'CS401', 'CS413', 'CS415', 'CS419', 'CS490'],
             'S3C3': ['CS331', 'CS401', 'CS413', 'CS415', 'CS419', 'CS490'],
             'S4C1': [
                 'CS325', 'CS331', 'CS335', 'CS345', 'CS400', 'CS404',
                 'CS412', 'CS416', 'CS420', 'CS440', 'CS460', 'MATH305',
                 'ECON401', 'CS490'
             ],
             'S4C2': ['CS420'],
             'S4C3': ['CS490']
         }, domains,
         "test that should get the correct domain for fall 2019")
Esempio n. 3
0
 def test_should_return_correct_domain_for_summer_2008(self):
     filename = "summer_2008.txt"
     student = Student(filename)
     courses_offered = CoursesOffered(student)
     csp = CSP(courses_offered)
     domains = csp.domains
     self.assertEqual(
         {
             'S1C1': ['CS400'],
             'S1C2': ['CS404'],
             'S1C3': [
                 'CS325', 'CS331', 'CS335', 'CS345', 'CS400', 'CS404',
                 'CS412', 'CS416', 'CS420', 'CS440', 'CS460', 'MATH305',
                 'ECON401', 'CS490'
             ],
             'S2C1': ['CS331', 'CS355', 'CS442'],
             'S2C2': ['CS401', 'CS413'],
             'S2C3': ['CS335', 'CS415', 'CS419'],
             'S3C1': ['CS331', 'CS412', 'CS420', 'CS440', 'CS490'],
             'S3C2': ['CS331', 'CS412', 'CS420', 'CS440', 'CS490'],
             'S3C3': ['CS331', 'CS412', 'CS420', 'CS440', 'CS490'],
             'S4C1': [
                 'CS325', 'CS331', 'CS335', 'CS345', 'CS400', 'CS401',
                 'CS404', 'CS413', 'CS415', 'CS419', 'CS460', 'CS490'
             ],
             'S4C2': ['CS420'],
             'S4C3': ['CS490']
         }, domains,
         "test that should get the correct domain for summer 2008")
Esempio n. 4
0
class CSP:
    def __init__(self, student):
        self.variables = self.get_variables()
        self.num_constraints = self.get_constraints_updated_so_far({})
        self.courses_offered = CoursesOffered(student)
        self.domains = self.get_domains()

    def get_variables(self):
        return [
            "S1C1", "S1C2", "S1C3", "S2C1", "S2C2", "S2C3", "S3C1", "S3C2",
            "S3C3", "S4C1", "S4C2", "S4C3"
        ]

    def get_domains(self):
        my_domains = self.courses_offered.get_domain_for_variables()
        print("\nDomains: \n", my_domains)
        return my_domains

    def get_constraints_updated_so_far(self, current_assignment):
        # TODO: load the contraints given the asignment
        return {
            "S1C1": 1,
            "S1C2": 1,
            "S1C3": 1,
            "S2C1": 1,
            "S2C2": 1,
            "S2C3": 1,
            "S3C1": 1,
            "S3C2": 1,
            "S3C3": 1,
            "S4C1": 1,
            "S4C2": 1,
            "S4C3": 1
        }

    def is_assign_consistent(self, candidate, val, assignment_input):
        """ returns true if the same course is not taken more than once"""
        assignment1 = dict.copy(assignment_input)
        assignment1[candidate] = val

        return self.__check_consistency(assignment1)

    def __check_consistency(self, assignment):
        unique_values = list()
        for value in assignment.values():
            if value not in unique_values or value is None:
                unique_values.append(value)
        # print(assignment, "      ",unique_values)
        return len(assignment) == len(unique_values)

    def is_assign_complete(self, assignment_input):
        return (self.__check_consistency(assignment_input)
                and len(assignment_input) == len(self.variables))
Esempio n. 5
0
 def test_should_return_true_for_consistency(self):
     assignment = {
         'S1C1': 'CS400',
         'S1C2': 'CS404',
         'S2C3': 'CS335',
         'S4C2': 'CS420',
         'S4C3': 'CS490',
         'S2C2': 'CS411',
         'S2C1': 'CS331'
     }
     candidate = "S3C2"
     val = "419"
     filename = "fall_2021.txt"
     student = Student(filename)
     courses_offered = CoursesOffered(student)
     csp = CSP(courses_offered)
     test_consistency = csp.is_assign_consistent(candidate, val, assignment)
     self.assertEqual(True, test_consistency,
                      "consistency test epic fail :D ")
Esempio n. 6
0
 def __init__(self, student):
     self.variables = self.get_variables()
     self.num_constraints = self.get_constraints_updated_so_far({})
     self.courses_offered = CoursesOffered(student)
     self.domains = self.get_domains()