public Group() { for (int i = 0; i < 5; i++) { for (int j = 0; j < 6; j++) { TimeTable[i, j] = new Rozklad(); } } }
static public Group CreatRoz(ref TeacherList[] Gr, Group OK) { Group OKKT = OK; TeacherList temp; //список преподов для сортировки for (int i = 0; i < Gr.Length - 1; i++) //Сортировка списка преподавателей перед созданием расписанию. Не уверен в полезности, но пусть будет { for (int j = i + 1; j < Gr.Length; j++) { if (Num_TOpp(Gr[i].TOpp) - OccHours(Gr[i]) > (Num_TOpp(Gr[j].TOpp) - OccHours(Gr[j]))) { temp = Gr[i]; Gr[i] = Gr[j]; Gr[j] = temp; } } } for (int id = 0, N = Gr.Length; GroupHours(Gr, OK.Name) > 0 && N > 0; id++, N--) //Условие выхода из функции. Если вдруг расписание не собирается, то перемешать массив преподавателей { OKKT = OK; for (int l = 1; l < 5; l++) //Пары { for (int k = 0; k < 5; k++) //Дни { for (int i = 0; i < Gr.Length; i++) //цикл для выбора преподавателей { for (int j = 0; j < Gr[i].subjects.Length; j++) //цикл для выбора предметов { if (Rozklad.IsTrue(k, Gr[i].subjects[j].Subject, OKKT.TimeTable) && Gr[i].opportunities[k, l] && (Gr[i].subjects[j].Group == OKKT.Name) && (Gr[i].TOpp[k, l, 1] || Gr[i].TOpp[k, l, 0]))//условие выбора дня { if (Gr[i].subjects[j].hoursPerWeek > 1 && OKKT.TimeTable[k, l].EvenWeek.Subject == null && OKKT.TimeTable[k, l].OddWeek.Subject == null && (Gr[i].TOpp[k, l, 1] && Gr[i].TOpp[k, l, 0])) //ставим пару предмета в свободный день { if (IsWindow(k, l, OKKT.TimeTable, 0) == false) { OKKT.TimeTable[k, l].EvenWeek.Subject = Gr[i].subjects[j].Subject; OKKT.TimeTable[k, l].OddWeek.Subject = Gr[i].subjects[j].Subject; OKKT.TimeTable[k, l].EvenWeek.Teacher = Gr[i].teacherName; OKKT.TimeTable[k, l].OddWeek.Teacher = Gr[i].teacherName; OKKT.TimeTable[k, l].EvenWeek.Cabinet = Gr[i].Cabinet; OKKT.TimeTable[k, l].OddWeek.Cabinet = Gr[i].Cabinet; Gr[i].subjects[j].hoursPerWeek -= 2; Gr[i].TOpp[k, l, 1] = false; Gr[i].TOpp[k, l, 0] = false; } } else if ((Gr[i].subjects[j].hoursPerWeek > 0) && ((OKKT.TimeTable[k, l].EvenWeek.Subject == null) && (Gr[i].TOpp[k, l, 0] == true)) && ((OKKT.TimeTable[k, l].OddWeek.Subject != null) || (Gr[i].TOpp[k, l, 1] == false) || (Gr[i].subjects[j].hoursPerWeek == 1)))//Пара в числитель { if (IsWindow(k, l, OKKT.TimeTable, 1) == false) { OKKT.TimeTable[k, l].EvenWeek.Subject = Gr[i].subjects[j].Subject; OKKT.TimeTable[k, l].EvenWeek.Teacher = Gr[i].teacherName; OKKT.TimeTable[k, l].EvenWeek.Cabinet = Gr[i].Cabinet; Gr[i].subjects[j].hoursPerWeek -= 1; Gr[i].TOpp[k, l, 0] = false; } } else if ((Gr[i].subjects[j].hoursPerWeek > 0) && ((OKKT.TimeTable[k, l].OddWeek.Subject == null) && (Gr[i].TOpp[k, l, 1] == true)) && ((OKKT.TimeTable[k, l].EvenWeek.Subject != null) || (Gr[i].TOpp[k, l, 0] == false) || (Gr[i].subjects[j].hoursPerWeek == 1)))//Пара в знаменатель { if (IsWindow(k, l, OKKT.TimeTable, 2) == false) { OKKT.TimeTable[k, l].OddWeek.Subject = Gr[i].subjects[j].Subject; OKKT.TimeTable[k, l].OddWeek.Teacher = Gr[i].teacherName; OKKT.TimeTable[k, l].OddWeek.Cabinet = Gr[i].Cabinet; Gr[i].subjects[j].hoursPerWeek -= 1; Gr[i].TOpp[k, l, 1] = false; } } } } } } } for (int l = 1; l < 5; l++) //Пары //Повторный цикл, чтобы доставить, например, половинчатые пары. Целесообразность под сомнением но пусть будет { for (int k = 0; k < 5; k++) //Дни { for (int i = 0; i < Gr.Length; i++) //цикл для выбора преподавателей { for (int j = 0; j < Gr[i].subjects.Length; j++) //цикл для выбора предметов { if (Rozklad.IsTrue(k, Gr[i].subjects[j].Subject, OKKT.TimeTable) && Gr[i].opportunities[k, l] && Gr[i].subjects[j].Group == OKKT.Name && (Gr[i].TOpp[k, l, 1] || Gr[i].TOpp[k, l, 0]))//условие выбора дня { if ((Gr[i].subjects[j].hoursPerWeek > 1) && (OKKT.TimeTable[k, l].EvenWeek.Subject == null) && (OKKT.TimeTable[k, l].OddWeek.Subject == null) && (Gr[i].TOpp[k, l, 1] && Gr[i].TOpp[k, l, 0])) //ставим пару предмета в свободный день { OKKT.TimeTable[k, l].EvenWeek.Subject = Gr[i].subjects[j].Subject; OKKT.TimeTable[k, l].OddWeek.Subject = Gr[i].subjects[j].Subject; OKKT.TimeTable[k, l].EvenWeek.Teacher = Gr[i].teacherName; OKKT.TimeTable[k, l].OddWeek.Teacher = Gr[i].teacherName; OKKT.TimeTable[k, l].EvenWeek.Cabinet = Gr[i].Cabinet; OKKT.TimeTable[k, l].OddWeek.Cabinet = Gr[i].Cabinet; Gr[i].subjects[j].hoursPerWeek -= 2; Gr[i].TOpp[k, l, 1] = false; Gr[i].TOpp[k, l, 0] = false; } else if ((Gr[i].subjects[j].hoursPerWeek > 0) && ((OKKT.TimeTable[k, l].EvenWeek.Subject == null) && (Gr[i].TOpp[k, l, 0] == true)) && ((OKKT.TimeTable[k, l].OddWeek.Subject != null) || (Gr[i].TOpp[k, l, 1] == false) || (Gr[i].subjects[j].hoursPerWeek == 1))) { OKKT.TimeTable[k, l].EvenWeek.Subject = Gr[i].subjects[j].Subject; OKKT.TimeTable[k, l].EvenWeek.Teacher = Gr[i].teacherName; OKKT.TimeTable[k, l].EvenWeek.Cabinet = Gr[i].Cabinet; Gr[i].subjects[j].hoursPerWeek -= 1; Gr[i].TOpp[k, l, 0] = false; } else if ((Gr[i].subjects[j].hoursPerWeek > 0) && ((OKKT.TimeTable[k, l].OddWeek.Subject == null) && (Gr[i].TOpp[k, l, 1] == true)) && ((OKKT.TimeTable[k, l].EvenWeek.Subject != null) || (Gr[i].TOpp[k, l, 0] == false) || (Gr[i].subjects[j].hoursPerWeek == 1))) { OKKT.TimeTable[k, l].OddWeek.Subject = Gr[i].subjects[j].Subject; OKKT.TimeTable[k, l].OddWeek.Teacher = Gr[i].teacherName; OKKT.TimeTable[k, l].OddWeek.Cabinet = Gr[i].Cabinet; Gr[i].subjects[j].hoursPerWeek -= 1; Gr[i].TOpp[k, l, 1] = false; } } } } } } for (int DayInWeek = 0; DayInWeek < 5; DayInWeek++) { if (HasWindows(DayInWeek, OKKT.TimeTable)) { LicWindow(OKKT.TimeTable, Gr, DayInWeek); } } } return(OKKT); }