Beispiel #1
0
        public bool addExam(ExamEntity entity)
        {
            if (entity == null)
            {
                return(false);
            }

            solution.Add(entity);
            return(true);
        }
Beispiel #2
0
        private List <ExamEntity> normalArrange(CourseEntity ce, List <SessionEntity> remainSessions, TimeValueInterval timeData)
        {
            List <ExamEntity> ret = new List <ExamEntity>();
            int sessionCt         = remainSessions.Count;
            int sessionIndex      = 0;

            foreach (RoomEntity r in allRoom)
            {
                if (r.roomType == ce.requiredRoomType && getConflictTimeData(r.occupied, timeData) == null)
                {
                    ExamEntity entity = new ExamEntity();
                    entity.courseId    = ce.courseId;
                    entity.roomId      = r.roomId;
                    entity.roomType    = r.roomType;
                    entity.startMinute = TimeValueInterval.value2Min(timeData.startValue);
                    entity.startHour   = TimeValueInterval.value2Hour(timeData.startValue);
                    entity.weekDay     = TimeValueInterval.value2Weekday(timeData.startValue);

                    entity.endMinute = TimeValueInterval.value2Min(timeData.endValue);
                    entity.endHour   = TimeValueInterval.value2Hour(timeData.endValue);

                    r.arrangeExam(timeData);

                    // Jane: added null check 20180426 if (allLevelTimeLine[ce.level] != null)
                    if (allLevelTimeLine[ce.level] != null)
                    {
                        allLevelTimeLine[ce.level].Add(timeData);
                    }

                    int sessionsThisRoom = r.roomCapacity / SESSION_CAPACITY;
                    for (int i = 0; i < sessionsThisRoom; ++i, ++sessionIndex)
                    {
                        if (sessionIndex >= remainSessions.Count)
                        {
                            break;
                        }

                        entity.sessionIds.Add(remainSessions[sessionIndex]);
                        //if (protorId <= 0) protorId = remainSessions[sessionIndex].facultyId;
                    }

                    bool         hasProtor      = false;
                    ProtorEntity sessionFaculty = null;
                    foreach (SessionEntity se in entity.sessionIds)
                    {
                        int protorId = se.facultyId;
                        foreach (ProtorEntity pe in allProtor)
                        {
                            if (pe.protorId == protorId)
                            {
                                sessionFaculty = pe;
                                break;
                            }
                        }

                        if (sessionFaculty != null)
                        {
                            if (getConflictTimeData(sessionFaculty.occupied, timeData) == null)
                            {
                                entity.protorId = sessionFaculty.protorId;
                                sessionFaculty.arrangeExam(timeData);
                                hasProtor = true;
                                break;
                            }
                        }
                    }

                    if (!hasProtor)
                    {
                        bool valid = true;
                        foreach (ProtorEntity pe in allProtor)
                        {
                            valid = true;
                            foreach (SessionEntity ss in ce.sessionIds)
                            {
                                if (pe.protorId == ss.sessionId && pe.protorId > 0)
                                {
                                    valid = false;
                                    break;
                                }
                            }

                            if (!valid)
                            {
                                continue;
                            }

                            if (getConflictTimeData(pe.occupied, timeData) == null)
                            {
                                entity.protorId = pe.protorId;
                                pe.arrangeExam(timeData);
                                break;
                            }
                        }

                        Console.WriteLine("DOES NOT use teacher as protor!!!");
                    }

                    ret.Add(entity);
                }

                if (sessionCt <= sessionIndex)
                {
                    break;
                }
            }

            remainSessions.Clear();
            return(ret);
        }
Beispiel #3
0
        private ExamEntity specialArrange(CourseEntity course, SpecialEntity special, TimeValueInterval timeData, List <SessionEntity> remainSessions, List <SpecialEntity> specialsOfThisCourse)
        {
            int        sessionCt    = remainSessions.Count;
            int        sessionIndex = 0;
            RoomEntity room         = null;

            foreach (RoomEntity r in allRoom)
            {
                if (special.roomId > 0)
                {
                    if (r.roomId == special.roomId)
                    {
                        room = r;
                        break;
                    }
                }
                else
                {
                    if (r.roomType == course.requiredRoomType && getConflictTimeData(r.occupied, timeData) == null)
                    {
                        room = r;
                        foreach (SpecialEntity sot in specialsOfThisCourse)
                        {
                            if (sot.roomId <= 0)
                            {
                                continue;
                            }
                            if (r.roomId == sot.roomId)
                            {
                                room = null;
                                break;
                            }
                        }

                        if (room != null)
                        {
                            break;
                        }
                    }
                }
            }

            if (room == null)
            {
                return(null);
            }

            bool       hasSpecialProtor = special.protorId > 0;
            ExamEntity exam             = new ExamEntity();

            exam.courseId    = special.courseId;
            exam.roomId      = special.roomId;
            exam.roomType    = room.roomType;
            exam.startMinute = TimeValueInterval.value2Min(timeData.startValue);
            exam.startHour   = TimeValueInterval.value2Hour(timeData.startValue);
            exam.weekDay     = TimeValueInterval.value2Weekday(timeData.startValue);

            exam.endMinute = TimeValueInterval.value2Min(timeData.endValue);
            exam.endHour   = TimeValueInterval.value2Hour(timeData.endValue);

            int sessionsThisRoom = room.roomCapacity / SESSION_CAPACITY;

            if (special.sessionId > 0)
            {
                SessionEntity target = null;
                foreach (SessionEntity s in remainSessions)
                {
                    if (s.sessionId == special.sessionId)
                    {
                        target = s;
                        break;
                    }
                }

                if (target != null)
                {
                    exam.sessionIds.Add(target);
                    remainSessions.Remove(target);
                }
                --sessionsThisRoom;
            }

            for (int i = 0; i < sessionsThisRoom; ++sessionIndex)
            {
                if (sessionIndex >= remainSessions.Count)
                {
                    break;
                }

                bool sessionInSpecial = false;
                foreach (SpecialEntity e in specialsOfThisCourse)
                {
                    if (e.courseId == course.courseId && e.roomId != room.roomId && e.sessionId == remainSessions[sessionIndex].sessionId)
                    {
                        sessionInSpecial = true;
                        break;
                    }
                }

                if (!sessionInSpecial)
                {
                    exam.sessionIds.Add(remainSessions[sessionIndex]);
                    ++i;
                }
            }

            remainSessions.RemoveRange(0, sessionIndex);

            if (hasSpecialProtor)
            {
                exam.protorId = special.protorId;
                ProtorEntity pe = null;
                foreach (ProtorEntity p in allProtor)
                {
                    if (p.protorId == special.protorId)
                    {
                        pe = p;
                        break;
                    }
                }

                if (pe != null)
                {
                    pe.arrangeExam(timeData);
                }
            }
            else
            {
                ProtorEntity sessionFaculty = null;
                foreach (SessionEntity ss in exam.sessionIds)
                {
                    foreach (ProtorEntity pe in allProtor)
                    {
                        if (ss.facultyId == pe.protorId)
                        {
                            sessionFaculty = pe;
                            break;
                        }
                    }

                    if (sessionFaculty != null)
                    {
                        if (getConflictTimeData(sessionFaculty.occupied, timeData) == null)
                        {
                            break;
                        }
                        else
                        {
                            sessionFaculty = null;
                        }
                    }
                }

                if (sessionFaculty != null)
                {
                    exam.protorId = sessionFaculty.protorId;
                    sessionFaculty.arrangeExam(timeData);
                }
                else
                {
                    foreach (ProtorEntity pe in allProtor)
                    {
                        sessionFaculty = pe;
                        foreach (SpecialEntity e in specialsOfThisCourse)
                        {
                            if (sessionFaculty.protorId == e.protorId)
                            {
                                sessionFaculty = null;
                                break;
                            }
                        }

                        if (sessionFaculty == null)
                        {
                            continue;
                        }

                        if (getConflictTimeData(sessionFaculty.occupied, timeData) == null && sessionFaculty.protorId != special.protorId)
                        {
                            exam.protorId = sessionFaculty.protorId;
                            sessionFaculty.arrangeExam(timeData);
                            break;
                        }
                    }
                }
            }

            room.arrangeExam(timeData);

            // Jane: added null check 20180426 if (allLevelTimeLine[ce.level] != null)
            if (allLevelTimeLine[course.level] != null)
            {
                allLevelTimeLine[course.level].Add(timeData);
            }

            return(exam);
        }
Beispiel #4
0
        public ExamTables arrangeExam()
        {
            ExamTables ret = new ExamTables();

            maxLevel = -1;
            sortExamCourse();
            getProtorRoomAndSpecial();
            allLevelTimeLine = new List <TimeValueInterval> [maxLevel + 1];
            for (int i = 0; i < maxLevel; ++i)
            {
                allLevelTimeLine[i] = new List <TimeValueInterval>();
            }

            while (allSpecial.Count > 0)
            {
                int courseId            = allSpecial[0].courseId;
                List <SpecialEntity> s  = checkInSpecial(courseId);
                CourseEntity         ce = null;
                foreach (CourseEntity c in allExamCourse)
                {
                    if (c.courseId == courseId)
                    {
                        ce = c;
                        break;
                    }
                }

                if (ce == null)
                {
                    foreach (SpecialEntity se in s)
                    {
                        allSpecial.Remove(se);
                    }
                    continue;
                }

                List <SessionEntity> remainSessions = new List <SessionEntity>(ce.sessionIds);
                TimeValueInterval    timeData       = allSpecial[0].timeData;

                if (s.Count > 0) // special arrangement(course with a specified room an start time)
                {
                    foreach (SpecialEntity se in s)
                    {
                        ExamEntity e = specialArrange(ce, se, timeData, remainSessions, s);
                        ret.addExam(e);
                    }
                }

                if (remainSessions.Count > 0)
                {
                    List <ExamEntity> el = normalArrange(ce, remainSessions, timeData);
                    foreach (ExamEntity exam in el)
                    {
                        ret.addExam(exam);
                    }
                }

                foreach (SpecialEntity se in s)
                {
                    allSpecial.Remove(se);
                }

                allExamCourse.Remove(ce);
            }

            while (allExamCourse.Count > 0)
            {
                CourseEntity         ce             = allExamCourse[0];
                List <SessionEntity> remainSessions = new List <SessionEntity>(ce.sessionIds);
                TimeValueInterval    timeData       = getEarlistTimeData(ce);
                if (timeData == null)
                {
                    allExamCourse.Remove(ce);
                    Console.WriteLine("Course " + ce.courseId + " required impoosible resourses");
                    continue;
                }

                if (remainSessions.Count > 0)
                {
                    List <ExamEntity> el = normalArrange(ce, remainSessions, timeData);
                    foreach (ExamEntity exam in el)
                    {
                        ret.addExam(exam);
                    }
                }

                allExamCourse.Remove(ce);
            }

            foreach (CourseEntity ce in nonExamCourse)
            {
                ExamEntity ex = new ExamEntity();
                ex.courseId   = ce.courseId;
                ex.protorId   = -1;
                ex.sessionIds = ce.sessionIds;
                ex.roomType   = ce.requiredRoomType;
                ret.addExam(ex);
            }

            return(ret);
        }