[feat:] reordering courses if they are of the same sport and are not weighted equally

This commit is contained in:
2026-06-06 14:24:25 +02:00
parent c0da656331
commit 91c6ea1269
2 changed files with 148 additions and 9 deletions
+50
View File
@@ -383,6 +383,8 @@ public class CourseCrafter
}
}
BalanceCoursesBetweenSameSportAndSemester();
// ---------------------------------------------------------------------------
// Lokale Hilfsfunktionen
// ---------------------------------------------------------------------------
@@ -406,6 +408,54 @@ public class CourseCrafter
return true;
}
void BalanceCoursesBetweenSameSportAndSemester()
{
bool changed;
do
{
changed = false;
var groups = GeneratedCourses
.GroupBy(c => (c.Semester, c.Instance.Sport.Name))
.Where(g => g.Count() > 1);
foreach (var group in groups)
{
var courses = group
.OrderBy(c => c.Instance.Students.Count)
.ToList();
for (int sourceIndex = courses.Count - 1; sourceIndex > 0; sourceIndex--)
{
var sourceCourse = courses[sourceIndex];
for (int targetIndex = 0; targetIndex < sourceIndex; targetIndex++)
{
var targetCourse = courses[targetIndex];
if (sourceCourse.Instance.Students.Count <= targetCourse.Instance.Students.Count + 1)
break;
if (targetCourse.Instance.Students.Count >= targetCourse.Instance.Sport.MaxStudents)
continue;
if (sourceCourse.Instance.Students.Count - 1 < getEffectiveMinStudents(sourceCourse.Instance.Sport, sourceCourse.Semester))
continue;
var studentId = sourceCourse.Instance.Students[^1];
sourceCourse.Instance.Students.RemoveAt(sourceCourse.Instance.Students.Count - 1);
targetCourse.Instance.Students.Add(studentId);
changed = true;
break;
}
if (changed)
break;
}
if (changed)
break;
}
} while (changed);
}
bool requestExit()
{
globalCount++;