private ScheduleTime GetTimeAfterTwoWeek(ScheduleTime now) { ScheduleTime AfterTwoWeek = now.Copy(); AfterTwoWeek.Week = (Week)(AfterTwoWeek.WeekNumber + 2); return(AfterTwoWeek); }
public SchedulePointer(ScheduleTime time1, ScheduleTime time2, string room1, string room2) { Time1 = time1; Time2 = time2; Room1 = room1; Room2 = room2; }
protected decimal GoToHoursShedule(LoadItem item, decimal Load, ScheduleDay dayShedule, int Attempt) { //можно ли еще добалять пары в этот день или это день для группы заполнен if (dayShedule.LimitLessonsNotExceeded(item.Groups, dayShedule.Week, dayShedule.Day)) { List <Position> freePositions = new List <Position>(); //цикл по доступным часам для этого дня (в будни и выходные часы для проставления пар разные) for (int Hour = dayShedule.EarlierPossibleHour; Hour <= dayShedule.LastPossibleHour; Hour++) { ScheduleTime Time = new ScheduleTime(dayShedule.Week, dayShedule.Day, Hour); //выбираем аудиторию ScheduleRoom Room = FindRoom(item, Time); if (Room != null) { freePositions.Add(new Position(Room, Time)); } } // добавляем занятия if (freePositions.Count > 0) { Load = PutLessonsOnFreePositions(freePositions, Load, Attempt, item); } } return(Load); }
protected virtual bool CanPutToPosition(ScheduleTime time, ScheduleRoom room, LoadItem item) { ScheduleDay day = Shedule.GetDay(time.Week, time.Day); return(time.WeekNumber <= 4 && time.WeekNumber >= 1 && day != null && day.LimitLessonsNotExceeded(item.Groups, time.Week, time.Day, 1) && Employments.IsHourFree(item.Teacher, item.Groups, room.Name, time)); }
//свободна группа для проведения пары или у нее уже есть занятия, например в другом корпусе public bool GroupsFree(List <string> groups, ScheduleTime Time) { foreach (string Group in groups) { if (Groups.ItemExist(Group, Time)) { return(false); } } return(true); }
//проставить занятость public void Add(string Teacher, List <string> groups, string Room, ScheduleTime Time, ReasonEmployment Reason) { //добавить занятость по аудитории Rooms.Add(new Employment(Room, Time, Reason)); //добавить занятость по преподователю Teachers.Add(new Employment(Teacher, Time, Reason)); //добавить занятость по группе foreach (string group in groups) { Groups.Add(new Employment(group, Time, Reason)); } }
protected virtual decimal PutLesson(LoadItem item, ScheduleTime time, ScheduleRoom room, decimal Load) { //получить занятие из расписания ScheduleLesson Lesson = Shedule.GetLesson(time, room.Name); //задать параметры занятию Lesson.UpdateFields(item.Teacher, item.Discipline, item.Groups, item.LessonType); //проставить занятости Employments.Add(item.Teacher, item.Groups, room.Name, time, ReasonEmployment.GeneratorPutLesson); //уменьшить нагрузку на два академичаских часа или на одну пару return(Load - 2); }
public void Remove(string Teacher, List <string> groups, string Room, ScheduleTime Time) { //удалить занятость по аудитории Rooms.Remove(new Employment(Room, Time)); //удалить занятость по преподователю Teachers.Remove(new Employment(Teacher, Time)); //удалить занятость по группе //если занятие у нескольких групп foreach (string group in groups) { Groups.Remove(new Employment(group, Time)); } }
public ScheduleLesson(ScheduleTime time, string room, IEnumerable <DateTime> dates) { //main atributtes Teacher = String.Empty; Discipline = String.Empty; Groups = new List <string>(); Room = room; Type = LessonType.Lection; //set dates Dates = dates.ToList(); //set times Time = time; }
public ScheduleLesson(ScheduleTime time, string room, IEnumerable <DateTime> dates, string teaher, string discipline, IEnumerable <string> groups, LessonType type) { //main atributtes Teacher = teaher; Discipline = discipline; Groups = groups.ToList(); Room = room; Type = type; //set dates Dates = dates.ToList(); //set times Time = time; }
private decimal PutTwoLessonOnTwoWeek(List <Position> freePositions, decimal Load, LoadItem item) { for (int counter = 0; counter < freePositions.Count - 1 && Load > 0; counter++) { Position curr = freePositions[counter]; Position next = freePositions[counter + 1]; if (curr.Time.WeekNumber > 2 || next.Time.WeekNumber > 2) { continue; } ScheduleTime CurrAfterTwoWeek = GetTimeAfterTwoWeek(curr.Time); ScheduleTime NextAfterTwoWeek = GetTimeAfterTwoWeek(next.Time); ScheduleDay currDay = Shedule.GetDay(curr.Time); ScheduleDay nextDay = Shedule.GetDay(CurrAfterTwoWeek); if (!IsHoursNear(curr.Time, next.Time) || !currDay.LimitLessonsNotExceeded(item.Groups, currDay.Week, currDay.Day, 2) || !nextDay.LimitLessonsNotExceeded(item.Groups, CurrAfterTwoWeek.Week, CurrAfterTwoWeek.Day, 2)) { continue; } if (CanPutToPosition(curr.Time, curr.Room, item) && CanPutToPosition(next.Time, next.Room, item) && CanPutToPosition(CurrAfterTwoWeek, curr.Room, item) && CanPutToPosition(NextAfterTwoWeek, next.Room, item)) { Load = PutLesson(item, curr.Time, curr.Room, Load); Load = PutLesson(item, next.Time, next.Room, Load); Load = PutLesson(item, CurrAfterTwoWeek, curr.Room, Load); Load = PutLesson(item, NextAfterTwoWeek, next.Room, Load); counter++; return(Load); } } return(Load); }
protected virtual ScheduleRoom FindRoom(LoadItem item, ScheduleTime time) { //проверяем не привязан ли этот предмет к определенной аудитории var query = GetRoomsBindingDiscipline(item.LessonType, item.Discipline).ToList(); //если предмет не привязан то ищем по всем аудиториям, если же привязан то только по отобранным List <ScheduleRoom> rooms = (query.Count > 0) ? query : Rooms; //выбираем аудиторию, ищем пока не найдется подходящая не занятая foreach (ScheduleRoom room in rooms) { //можно ли в этой аудитории проводить данный вид занятия if (!PossibleAppointLessonRoom(room, item.LessonType)) { continue; // если нельзя то переходим к следующей аудитории } //проверяем накладки по аудитоиям, группам и преподам if (Employments.IsHourFree(item.Teacher, item.Groups, room.Name, time)) { return(room); //больше не ищем аудиторию } } return(null); }
public int Add(string Name, ScheduleTime Time, ReasonEmployment Reason) { if (_count < _contents.Length) { Employment item = new Employment(Name, Time, Reason); // добавляем если этот элемент еще не добавлен if (!ItemExist(item)) { _contents[_count] = item; _count++; return(_count - 1); } else { return(-1); } } else { return(-1); } }
public static string GetDescription(ScheduleTime time) { return(GetWeekDescription(time.Week) + ", " + GetDayDescription(time.Day) + ", " + GetHourDiscription(time.Hour)); }
private bool IsHoursNear(ScheduleTime time1, ScheduleTime time2) { return(IsHoursNear(time1.Hour, time2.Hour)); }
public Position(ScheduleRoom room, ScheduleTime time) { Room = room; Time = time; }
public Employment GetItem(string Name, ScheduleTime Time) { List <Employment> items = (from e in _contents where e.Name == Name && e.Time == Time select e).ToList(); return((items.Count > 0) ? items.First() : null); }
public bool ItemExist(string Name, ScheduleTime Time) { bool f = (from e in _contents where e.Name == Name && e.Time == Time select e).Count() > 0; return(f); }
public bool IsFree(string Name, ScheduleTime Time) { return(!ItemExist(Name, Time)); }
public Employment(string name, ScheduleTime time, ReasonEmployment reason) { Name = name; Time = time; Reason = reason; }
public Employment(string name, ScheduleTime time) { Name = name; Time = time; Reason = ReasonEmployment.Another; }
/// <summary> Получить расписание занятия </summary> public ScheduleLesson GetLesson(ScheduleTime Time, string Room) { IEnumerable <ScheduleLesson> query = Lessons.Where(x => x.Time == Time && x.Room == Room); return(query.Count() > 0 ? query.First() : null); }
//можно ли назначать занятие в этот день, в этой аудитории, для этого препода и для этой группы public bool IsHourFree(string Teacher, List <string> groups, string Room, ScheduleTime Time) { return(Teachers.IsFree(Teacher, Time) && Rooms.IsFree(Room, Time) && GroupsFree(groups, Time)); }
public bool Equals(ScheduleTime other) { return(Week == other.Week && Day == other.Day && Hour == other.Hour); }
/// <summary> Найти расписание занятия из списка занятий</summary> public ScheduleLesson FindLessonInList(IEnumerable <ScheduleLesson> items, ScheduleTime time) { IEnumerable <ScheduleLesson> query = items.Where(x => x.Time == time); return(query.Count() > 0 ? query.First() : null); }
public ScheduleDay GetDay(ScheduleTime time) { return(GetDay(time.Week, time.Day)); }