def test_consecutive_course_scheduleing3(self):
        # when one of the course were assigned at [2,4]
        consecutive_courses = []
        for C in self.status.list_of_unassigned_Courses:
            if C.name in ['G5_5_自然實驗_1', 'G5_5_自然實驗_2']:
                consecutive_courses.append(C)

        bm.Course.assign_Rooms_and_Teacher_to_Course(
            self.status, consecutive_courses[0].name, '自然教室(五)', 'G5_5', '秀玲')
        bm.Course.assign_Course_period(self.status,
                                       consecutive_courses[0].name,
                                       ('Monday', 2))

        scheduling_results = cs.repeated_course_assignments_until_feasibility(
            self.status, [consecutive_courses[1]], max_count=1)
        self.assertEqual(consecutive_courses[1].period, ('Monday', 1))

        self.assertTrue(scheduling_results)
        self.assertEqual(consecutive_courses[0].Room.name,
                         consecutive_courses[1].Room.name)
        self.assertEqual(len(consecutive_courses[0].Room.schedule_in_tuples),
                         2)
    def test_consecutive_course_scheduleing1(self):
        # when none of the course were assigned
        consecutive_courses = []
        for C in self.status.list_of_unassigned_Courses:
            if C.name in ['G5_5_自然實驗_1', 'G5_5_自然實驗_2']:
                consecutive_courses.append(C)

        scheduling_results = cs.repeated_course_assignments_until_feasibility(
            self.status, consecutive_courses, max_count=1)
        room = consecutive_courses[0].Room
        s1 = room.schedule_in_tuples[0]
        s2 = room.schedule_in_tuples[1]
        self.assertEqual(s1[0], s2[0])
        if s1[1] > s2[1]:
            self.assertTrue(s1[1] == s2[1] + 1)
        else:
            self.assertTrue(s1[1] == s2[1] - 1)
        self.assertTrue(scheduling_results)
        self.assertEqual(consecutive_courses[0].Room.name,
                         consecutive_courses[1].Room.name)
        self.assertEqual(len(consecutive_courses[0].Room.schedule_in_tuples),
                         2)
def solving_zhes_with_sequencial_LNS(seed=None, n_iteration=100):

    #    random.seed()

    subject_set = {
        '閱讀', '彈性英語', '電腦', '綜合', '數', '彈性', '生活', '音樂', '健康', '閩南語', '英語',
        '自然', '社會', '彈性音樂', '國', '自然實驗', '體育', '美勞', '英語12a', '彈性英語12a',
        '英語12b', '彈性英語12b', '英語12c', '彈性英語12c', '英語34a', '彈性英語34a', '英語34b',
        '彈性英語34b', '英語34c', '彈性英語34c', '英語56a', '彈性英語56a', '英語56b', '彈性英語56b',
        '英語56c', '彈性英語56c'
    }

    best_status = zhes_scheduling_problem.initate_zhes_status()

    def only_keep_subjects(best_status, list_of_subjects):
        for C in best_status.list_of_unassigned_Courses.copy():
            if (C.subject not in list_of_subjects):  #
                best_status.change_unassigned_Course_to_stalled_list(C)

    only_keep_subjects(best_status, ["自然", "自然實驗"])

    best_status, score = cs.large_neighbourhood_search_with_scoring(
        best_status, max_iteration=n_iteration)
    if not best_status.list_of_unassigned_Courses == []:
        return best_status, None
    best_status.fix_assigned_Courses()
    #    best_status.free_stalled_Courses()

    #    only_keep_subjects(best_status, ['英語12a', '彈性英語12a','英語12b', '彈性英語12b', '英語12c', '彈性英語12c',
    #        '英語34a', '彈性英語34a','英語34b', '彈性英語34b', '英語34c', '彈性英語34c',
    #        '英語56a', '彈性英語56a','英語56b', '彈性英語56b','英語56c', '彈性英語56c',"英語", "彈性英語"])
    #
    #    best_status , score = cs.large_neighbourhood_search_with_scoring(best_status, max_iteration = n_iteration)
    #    if not best_status.list_of_unassigned_Courses == []:
    #        return best_status, None
    #    best_status.fix_assigned_Courses()
    #    best_status.free_stalled_Courses()

    #    only_keep_subjects(best_status, ["音樂", "彈性音樂", '體育','美勞'])
    #    best_status , score = cs.large_neighbourhood_search_with_scoring(best_status, max_iteration = n_iteration)
    #    if not best_status.list_of_unassigned_Courses == []:
    #        return best_status, None
    #    best_status.fix_assigned_Courses()
    #    best_status.free_stalled_Courses()

    #    only_keep_subjects(best_status, ['閩南語','社會'])
    #    best_status , score = cs.large_neighbourhood_search_with_scoring(best_status, max_iteration = n_iteration)
    #    if not best_status.list_of_unassigned_Courses == []:
    #        print([c.name for c in best_status.list_of_unassigned_Courses])
    #        return best_status, None
    #    best_status.fix_assigned_Courses()
    #    best_status.free_stalled_Courses()
    #
    #    only_keep_subjects(best_status, subject_set - {'國', '數', '綜合', '彈性', '生活'})
    #    best_status , score = cs.large_neighbourhood_search_with_scoring(best_status, max_iteration = n_iteration)
    #    if not best_status.list_of_unassigned_Courses == []:
    #        print([c.name for c in best_status.list_of_unassigned_Courses])
    #        return best_status, None
    #    best_status.fix_assigned_Courses()
    #    best_status.free_stalled_Courses()
    #
    #
    #    best_status, scoring = cs.large_neighbourhood_search_with_scoring(best_status, max_iteration = n_iteration)
    #    if not best_status.list_of_unassigned_Courses == []:
    #        print([c.name for c in best_status.list_of_unassigned_Courses])
    #        return best_status, None

    #    print("not assigned: "+ str([C.name for C in best_status.list_of_unassigned_Courses]))

    print('Assigned {} out of {} courses'.format(
        len(best_status.list_of_assigned_Courses +
            best_status.list_of_fixed_Courses),
        len(best_status.list_of_Courses) -
        len(best_status.list_of_stalled_Courses)))

    return best_status, score
Exemplo n.º 4
0
__author__ = "Jenny Zeng"
__email__ = "*****@*****.**"

if __name__ == '__main__':
    start_time = time.time()

    # config upper standing units
    upper_units = 90
    # load taken info
    startQ, applied_units, taken = DataLoading.load_taken(
        filename="info/taken2.txt")
    # load avoid info
    avoid = DataLoading.load_avoid(filename="info/avoid.txt")
    # load graph, config if user is upper standing
    G = DataLoading.load_courses(prereq_filename="info/fullcourses_new.txt",
                                 show_upper=cs.is_upper_standing(
                                     applied_units, upper_units))
    # load requirement sheet
    R_detail, R = DataLoading.load_requirements(
        requirements=[
            "University", "GEI", "GEII", "GEIII", "GEIV", "GEV", "GEVI",
            "GEVII", "GEVIII", "CS-Lower-division", "CS-Upper-division",
            "Intelligent Systems"
        ],
        filename="info/specializations.txt")

    # update requirement table based on the taken information
    cs.update_requirements(R_detail, R, taken)
    print(R_detail)
    print(R)
    # load max width for each quarter
    max_widths = DataLoading.load_width_func_table("info/widthFunc.txt")