Exemplo n.º 1
0
        public void CalculateCourseScheduleFitness()
        {
            int _score         = 0;
            int _numberOfRooms = Configuration.GetInstance.GetNumberOfRooms();
            int _daySize       = DAY_HOURS * DAYS_COUNT;
            int _ci            = 0;

            foreach (KeyValuePair <CourseClass, int> it in _classes.ToList())
            {
                int _pos     = it.Value;
                int _roomId  = _pos / _daySize;
                int _dayTime = _pos % _daySize;
                int _day     = _dayTime / DAY_HOURS;
                int _time    = _dayTime % DAY_HOURS;
                int _dur     = it.Key.Duration;

                CourseClass _cc   = it.Key;
                Room        _room = Configuration.GetInstance.GetRoomById(_roomId);

                #region Score 1 (check for room overlapping of classes)                                                                     [+10]

                bool _overlapping = false;
                for (int i = 0; i < _dur; i++)
                {
                    if (_slots[_pos + i].Count > 1)
                    {
                        _overlapping = true;
                        break;
                    }
                }

                if (!_overlapping)
                {
                    _score += 10;
                }

                Criteria[_ci + 0] = !_overlapping;

                #endregion

                #region Score 2 (does current room have enough seats)                                                                       [+7]

                Criteria[_ci + 1] = _room.Capacity >= _cc.StudentCount;
                if (Criteria[_ci + 1])
                {
                    _score += 7;
                }

                #endregion

                #region Score 3 (does current room fair)                                                                                    [+4]

                Criteria[_ci + 2] = _cc.RequiresLab.Equals(_room.IsLab);
                if (Criteria[_ci + 2])
                {
                    _score += 4;
                }

                #endregion

                #region Score 4 and 5 and 6 (check overlapping of classes for prelectors and student groups and sequential student groups)  [+10][+10][+5]

                bool _pre = false, _gro = false, _seqGro = false;
                List <CourseClass> _courseClassesOnSameTime = new List <CourseClass>();
                for (int j = 0; j < _numberOfRooms; j++)
                {
                    for (int i = 0; i < _dur; i++)
                    {
                        List <CourseClass> _ccs = _slots[(j * DAYS_COUNT * DAY_HOURS) + (_day * DAY_HOURS) + _time + i];
                        foreach (CourseClass cc in _ccs)
                        {
                            if (cc.ID != _cc.ID && !_courseClassesOnSameTime.Contains(cc))
                            {
                                _courseClassesOnSameTime.Add(cc);
                            }
                        }
                    }
                }

                foreach (CourseClass it_cc in _courseClassesOnSameTime)
                {
                    if (!_pre && _cc.PrelectorOverlaps(it_cc))
                    {
                        _pre = true;
                    }

                    if (!_gro && _cc.GroupsOverlap(it_cc))
                    {
                        _gro = true;
                    }

                    if (!_seqGro && _cc.SequentialGroupsOverlap(it_cc))
                    {
                        _seqGro = true;
                    }

                    if (_pre && _gro && _seqGro)
                    {
                        break;
                    }
                }

                if (!_pre)
                {
                    _score += 10;
                }
                Criteria[_ci + 3] = !_pre;

                if (!_gro)
                {
                    _score += 10;
                }
                Criteria[_ci + 4] = !_gro;

                if (!_seqGro)
                {
                    _score += 5;
                }
                Criteria[_ci + 5] = !_seqGro;

                #endregion

                #region Score 7 (check course limit in one day for student groups)                                                          [+2]

                List <CourseClass> _courseClassesOnSameDay  = new List <CourseClass>();
                for (int k = 0; k < _numberOfRooms; k++)
                {
                    for (int t = 0; t < DAY_HOURS; t++)
                    {
                        foreach (CourseClass cc in _slots[(DAYS_COUNT * DAY_HOURS * k) + (_day * DAY_HOURS) + t])
                        {
                            if (!_courseClassesOnSameDay.Contains(cc))
                            {
                                _courseClassesOnSameDay.Add(cc);
                            }
                        }
                    }
                }

                bool _limitExceeded = false;
                foreach (StudentGroup group in _cc.StudentGroups)
                {
                    List <CourseClass> _courseClassesInSameDayForGroup = new List <CourseClass>();
                    int _totalCourseHourInADayForGroup = 0;
                    foreach (CourseClass cc_it in _courseClassesOnSameDay)
                    {
                        if (_limitExceeded)
                        {
                            break;
                        }

                        if (!_courseClassesInSameDayForGroup.Contains(cc_it) && cc_it.StudentGroups.Contains(group))
                        {
                            _courseClassesInSameDayForGroup.Add(cc_it);
                            _totalCourseHourInADayForGroup += cc_it.Duration;
                        }
                    }

                    if (!_limitExceeded && _totalCourseHourInADayForGroup > group.MaxHourInDay)
                    {
                        _limitExceeded = true;
                        break;
                    }
                }

                if (!_limitExceeded)
                {
                    _score += 2;
                }
                Criteria[_ci + 6] = !_limitExceeded;

                #endregion

                #region Score 8 (check this class day in prelector schedule table)                                                          [+2]

                Criteria[_ci + 7] = _cc.Prelector.ScheduleDays[_day];
                if (Criteria[_ci + 7])
                {
                    _score += 2;
                }

                #endregion

                _ci += 8;
            }

            Fitness = (float)_score / (Configuration.GetInstance.GetNumberOfCourseClasses() * NUMBER_OF_SCORES);
        }
Exemplo n.º 2
0
        public void CalculateExamScheduleFitness()
        {
            int _score = 0;

            int _numberOfRooms = Configuration.GetInstance.GetNumberOfRooms();
            int _daySize       = DAY_HOURS * DAYS_COUNT;
            int _ci            = 0;

            foreach (KeyValuePair <CourseClass, int> it in _classes.ToList())
            {
                int _pos     = it.Value;
                int _roomId  = _pos / _daySize;
                int _dayTime = _pos % _daySize;
                int _day     = _dayTime / DAY_HOURS;
                int _time    = _dayTime % DAY_HOURS;
                int _dur     = it.Key.Duration;

                CourseClass _cc   = it.Key;
                Room        _room = Configuration.GetInstance.GetRoomById(_roomId);

                #region Score 1 (check for room overlapping of classes)                                                                          [+10]

                bool _overlapping = false;
                for (int i = _dur - 1; i >= 0; i--)
                {
                    if (_slots[_pos + i].Count > 1)
                    {
                        _overlapping = true;
                        break;
                    }
                }

                if (!_overlapping)
                {
                    _score += 10;
                }

                Criteria[_ci + 0] = !_overlapping;

                #endregion

                #region Score 2 (does current room have enough seats)                                                                            [+7]

                Criteria[_ci + 1] = _room.Capacity >= _cc.StudentCount;
                if (Criteria[_ci + 1])
                {
                    _score += 7;
                }

                #endregion

                #region Score 3 (does current room fair)                                                                                         [+3]

                Criteria[_ci + 2] = _cc.RequiresLab.Equals(_room.IsLab);
                if (Criteria[_ci + 2])
                {
                    _score += 3;
                }

                #endregion

                #region Score 4 and 5 (check for overlapping of classes for branches and student groups)                                         [+8][+10]

                List <CourseClass> _courseClassesOnSameTime = new List <CourseClass>();
                for (int j = 0; j < _numberOfRooms; j++)
                {
                    for (int i = 0; i < _dur; i++)
                    {
                        foreach (CourseClass cc in _slots[(j * DAYS_COUNT * DAY_HOURS) + (_day * DAY_HOURS) + _time + i])
                        {
                            if (cc != _cc && !_courseClassesOnSameTime.Contains(cc))
                            {
                                _courseClassesOnSameTime.Add(cc);
                            }
                        }
                    }
                }

                bool _bra = false, _gro = false;
                foreach (CourseClass it_cc in _courseClassesOnSameTime)
                {
                    if (_cc != it_cc)
                    {
                        if (!_bra && _cc.BranchsOverlaps(it_cc))
                        {
                            _bra = true;
                        }

                        if (!_gro && _cc.GroupsOverlap(it_cc))
                        {
                            _gro = true;
                        }

                        if (_bra && _gro)
                        {
                            break;
                        }
                    }
                }

                if (!_bra)
                {
                    _score += 8;
                }
                Criteria[_ci + 3] = !_bra;

                if (!_gro)
                {
                    _score += 10;
                }
                Criteria[_ci + 4] = !_gro;

                #endregion

                #region Score 6 (check for same course exams in same time)                                                                       [+7]

                List <CourseClass> _courseClassesWithSameCourse = _classes.Keys.Where(x => x.Course.ID == _cc.Course.ID).ToList();
                _courseClassesWithSameCourse.Remove(_cc);

                bool _sameExamsNotInSameTime = false;
                if (_courseClassesWithSameCourse.Count > 0)
                {
                    foreach (CourseClass it_cc in _courseClassesWithSameCourse)
                    {
                        if (!_sameExamsNotInSameTime && !_courseClassesOnSameTime.Contains(it_cc))
                        {
                            _sameExamsNotInSameTime = true;
                        }
                    }
                }

                if (!_sameExamsNotInSameTime)
                {
                    _score += 7;
                }
                Criteria[_ci + 5] = !_sameExamsNotInSameTime;

                #endregion

                #region Score 7 (check difficulty limit in one day for student groups)                                                           [+3]

                List <CourseClass> _courseClassesOnSameDay = new List <CourseClass>();
                for (int k = 0; k < _numberOfRooms; k++)
                {
                    for (int t = 0; t < DAY_HOURS; t++)
                    {
                        foreach (CourseClass cc in _slots[(DAYS_COUNT * DAY_HOURS * k) + (_day * DAY_HOURS) + t])
                        {
                            if (!_courseClassesOnSameDay.Contains(cc))
                            {
                                _courseClassesOnSameDay.Add(cc);
                            }
                        }
                    }
                }

                bool _limitExceeded          = false;
                foreach (StudentGroup group in _cc.StudentGroups)
                {
                    List <CourseClass> _courseClassesOnSameDayForGroup = new List <CourseClass>();
                    int _diffInDay = 0;
                    foreach (CourseClass cc_it in _courseClassesOnSameDay)
                    {
                        if (_limitExceeded)
                        {
                            break;
                        }

                        if (!_courseClassesOnSameDayForGroup.Contains(cc_it) && cc_it.StudentGroups.Contains(group))
                        {
                            _courseClassesOnSameDayForGroup.Add(cc_it);
                            _diffInDay += cc_it.Difficulty;
                        }
                    }

                    if (!_limitExceeded && _diffInDay > group.MaxDifficultyInDay)
                    {
                        _limitExceeded = true;
                        break;
                    }
                }

                if (!_limitExceeded)
                {
                    _score += 3;
                }
                Criteria[_ci + 6] = !_limitExceeded;


                #endregion

                #region Score 8 (check this exam day in prelector schedule table)                                                                [+2]

                Criteria[_ci + 7] = _cc.Prelector.ScheduleDays[_day];
                if (Criteria[_ci + 7])
                {
                    _score += 2;
                }

                #endregion

                _ci += 8;
            }

            Fitness = (float)_score / (Configuration.GetInstance.GetNumberOfCourseClasses() * NUMBER_OF_SCORES);
        }