示例#1
0
        private static bool PutLeftoverCourseOnOldPosition(Period period, SchedulableElement blockingCourse, Course unsuccessfulCourse, List <Room> rooms)
        {
            bool wasSetable = false;
            List <SchedulableElement> coursesAtPeriod = period.Elements;

            foreach (SchedulableElement courseElement in period.Elements.ToList())
            {
                if (courseElement.Id == blockingCourse.Id)
                {
                    period.Elements.Remove(blockingCourse);
                    period.RemovedElements.Add(blockingCourse.Id);
                }
                List <Room> freeRooms            = GetFreeRoomsAtPeriod(period, rooms);
                bool        semesterIsUnoccupied = CheckWhetherSemesterIsOccupied(period.Elements, unsuccessfulCourse);

                bool lecturerIsUnoccupied = CheckWhetherLecturerIsOccupied(coursesAtPeriod, courseElement.Course.Lecturer);
                foreach (Room freeRoom in freeRooms)
                {
                    bool hasRequirements = CheckWhetherEquipmentSuffices(freeRoom, unsuccessfulCourse);

                    if (freeRoom.Size >= unsuccessfulCourse.Size && lecturerIsUnoccupied && hasRequirements && semesterIsUnoccupied)
                    {
                        period.Elements.Add(new SchedulableElement(unsuccessfulCourse, freeRoom));
                        wasSetable = true;
                        break;
                    }
                }
            }
            if (!wasSetable)
            {
                period.Elements.Add(blockingCourse);
            }
            return(wasSetable);
        }
示例#2
0
        private static Course ReadjustLeftoverCourses(Period thisPeriod, Course unsuccessfulCourse, List <Room> rooms, Period[] periods)
        {
            SchedulableElement blockingCourse = FindBlockingElement(thisPeriod, unsuccessfulCourse);

            if (blockingCourse == null)
            {
                return(null);
            }
            Course possiblySetable = CalcForCourse(blockingCourse.Course, periods, rooms, true);

            if (possiblySetable != null)
            {
                bool wasSetable = PutLeftoverCourseOnOldPosition(thisPeriod, blockingCourse, unsuccessfulCourse, rooms);
                if (wasSetable)
                {
                    return(CalcForCourse(blockingCourse.Course, periods, rooms));
                }
            }
            return(unsuccessfulCourse);
        }