//группировка пар, если пара встречается только четыре раза за две недели public static StudentsClass[,] GetGroupFourSameClasses(StudentsClass[] classes) { List<StudentClassQuad> quadsClasses = new List<StudentClassQuad>(); List<StudentsClass> classesList = classes.ToList(); foreach (StudentsClass sClass in classesList) { if (quadsClasses.FindAll((pc) => pc.c1 == sClass || pc.c2 == sClass || pc.c3 == sClass || pc.c4 == sClass).Count == 0) { if (classesList.FindAll(c => StudentsClass.StudentClassEquals(c, sClass) && c != sClass).Count > 3) { //пара встречается больше четырех раз за две недели continue; } StudentsClass secondClass = classesList.Find(c => StudentsClass.StudentClassEquals(c, sClass) && c != sClass); StudentsClass thirdClass = classesList.Find(c => StudentsClass.StudentClassEquals(c, sClass) && c != sClass && c != secondClass); StudentsClass fourthClass = classesList.Find(c => StudentsClass.StudentClassEquals(c, sClass) && c != sClass && c != secondClass && c != thirdClass); if (secondClass != null && thirdClass != null && fourthClass != null) { quadsClasses.Add(new StudentClassQuad(sClass, secondClass, thirdClass, fourthClass)); } } } StudentsClass[,] quadsClassesArray = new StudentsClass[quadsClasses.Count, 4]; for (int pairClassesIndex = 0; pairClassesIndex < quadsClasses.Count; pairClassesIndex++) { quadsClassesArray[pairClassesIndex, 0] = quadsClasses[pairClassesIndex].c1; quadsClassesArray[pairClassesIndex, 1] = quadsClasses[pairClassesIndex].c2; quadsClassesArray[pairClassesIndex, 2] = quadsClasses[pairClassesIndex].c3; quadsClassesArray[pairClassesIndex, 3] = quadsClasses[pairClassesIndex].c4; } return quadsClassesArray; }
//группировка пар, если пара встречается больше двух раз за две недели public static StudentsClass[,] GetGroupSameClassesMoreTwoInTwoWeeks(StudentsClass[] classes) { List<StudentClassPair> pairsClasses = new List<StudentClassPair>(); List<StudentsClass> classesList = classes.ToList(); foreach (StudentsClass sClass in classesList) { if (pairsClasses.FindAll((pc) => pc.c1 == sClass || pc.c2 == sClass || StudentsClass.StudentClassEquals(pc.c1, sClass)).Count == 0) { List<StudentsClass> sameClasses = classesList.FindAll(c => StudentsClass.StudentClassEquals(c, sClass)); int countClasses = sameClasses.Count; if (countClasses % 2 == 1) countClasses--; for (int pairIndex = 0; pairIndex < countClasses; pairIndex += 2) { pairsClasses.Add(new StudentClassPair(sameClasses[pairIndex], sameClasses[pairIndex + 1])); } } } StudentsClass[,] pairsClassesArray = new StudentsClass[pairsClasses.Count, 2]; for (int pairClassesIndex = 0; pairClassesIndex < pairsClasses.Count; pairClassesIndex++) { pairsClassesArray[pairClassesIndex, 0] = pairsClasses[pairClassesIndex].c1; pairsClassesArray[pairClassesIndex, 1] = pairsClasses[pairClassesIndex].c2; } return pairsClassesArray; }
//группировка пар, если пара встречается только два раза за две недели public static StudentsClass[,] GetGroupTwoSameClasses(StudentsClass[] classes) { List<StudentClassPair> pairsClasses = new List<StudentClassPair>(); List<StudentsClass> classesList = classes.ToList(); foreach (StudentsClass sClass in classesList) { if (pairsClasses.FindAll((pc) => pc.c1 == sClass || pc.c2 == sClass).Count == 0) { if (classesList.FindAll(c => StudentsClass.StudentClassEquals(c, sClass) && c != sClass).Count > 1) { //пара встречается больше двух раз за две недели continue; } StudentsClass secondClass = classesList.Find(c => StudentsClass.StudentClassEquals(c, sClass) && c != sClass); if (secondClass != null) { pairsClasses.Add(new StudentClassPair(sClass, secondClass)); } } } StudentsClass[,] pairsClassesArray = new StudentsClass[pairsClasses.Count, 2]; for (int pairClassesIndex = 0; pairClassesIndex < pairsClasses.Count; pairClassesIndex++) { pairsClassesArray[pairClassesIndex, 0] = pairsClasses[pairClassesIndex].c1; pairsClassesArray[pairClassesIndex, 1] = pairsClasses[pairClassesIndex].c2; } return pairsClassesArray; }
//группировка пар, если пара встречается больше двух раз за две недели static List<StudentClassPair> GetGroupSameClassesMoreTwoInTwoWeeks(StudentsClass[] classes) { List<StudentClassPair> pairsClasses = new List<StudentClassPair>(); List<StudentsClass> classesList = classes.ToList(); foreach (StudentsClass sClass in classesList) { if (pairsClasses.FindAll((pc) => pc.c1 == sClass || pc.c2 == sClass || StudentsClass.StudentClassEquals(pc.c1, sClass)).Count == 0) { List<StudentsClass> sameClasses = classesList.FindAll(c => StudentsClass.StudentClassEquals(c, sClass)); int countClasses = sameClasses.Count; if (countClasses % 2 == 1) { countClasses--; } for (int pairIndex = 0; pairIndex < countClasses; pairIndex += 2) { pairsClasses.Add(new StudentClassPair(sameClasses[pairIndex], sameClasses[pairIndex + 1], sameClasses[pairIndex].SubGroups.Length)); } } } return pairsClasses; }
//Поиск пар-лекций List<StudentsClass> GetLectureClasses(StudentsClass[] classes) { List<StudentsClass> classesList = classes.ToList(); List<StudentsClass> lectureList = new List<StudentsClass>(); foreach (StudentsClass sClass in classesList) { foreach (ClassRoomType cRoomType in sClass.RequireForClassRoom) { if (cRoomType.Description.Equals("Лекция")) { lectureList.Add(sClass); } } } return lectureList; }
//группировка всех одинаковых пар - чтобы не ставились по две одинаковые в день public static List<StudentsClass>[] GetGroupSameClasses(StudentsClass[] classes) { List<List<StudentsClass>> listOfGroupSameClasses = new List<List<StudentsClass>>(); List<StudentsClass> classesList = classes.ToList(); foreach (StudentsClass sClass in classesList) { if (listOfGroupSameClasses.FindAll((list) => list.FindAll((c) => c == sClass).Count > 0).Count == 0) { List<StudentsClass> groupSameClasses = new List<StudentsClass>(); foreach (var cl in classesList.FindAll((c) => StudentsClass.StudentClassEquals(c, sClass))) { groupSameClasses.Add(cl); } if (groupSameClasses.Count > 1) { listOfGroupSameClasses.Add(groupSameClasses); } } } return listOfGroupSameClasses.ToArray<List<StudentsClass>>(); }
void RealignClassesArray(ref StudentsClass[] sortedStudentsClasses, int[] indexForRollback, int indexTo) { StudentsClass[] classesForRollback = new StudentsClass[indexForRollback.Length]; for (int classIndex = 0; classIndex < classesForRollback.Length; classIndex++) { classesForRollback[classIndex] = sortedStudentsClasses[indexForRollback[indexForRollback.Length - classIndex - 1]]; } List<StudentsClass> tempList = sortedStudentsClasses.ToList<StudentsClass>(); for (int classIndex = 0; classIndex < classesForRollback.Length; classIndex++) { tempList.Remove(classesForRollback[classIndex]); } int k = 0; for (int classIndex = indexTo - indexForRollback.Length + 1; classIndex <= indexTo; classIndex++) { tempList.Insert(classIndex, classesForRollback[k]); k++; } sortedStudentsClasses = tempList.ToArray<StudentsClass>(); }