Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a0eac4ae95 | |||
| 22e9377062 | |||
| 11e6aab8fd | |||
| 13f313d4a0 | |||
| 64951c579f | |||
| 4130c36335 | |||
| 7f2fc99d0b | |||
| eb640ff749 | |||
| 54a564df04 | |||
| 71dc63f2a2 | |||
| 68f673c8d7 | |||
| d5b7fd7af3 | |||
| 573e7c86e8 |
@@ -12,6 +12,7 @@
|
|||||||
<!-- <MenuItem Click="MnuSettings_OnClick" x:Name="MnuSettings" Header="Einstellungen" /> -->
|
<!-- <MenuItem Click="MnuSettings_OnClick" x:Name="MnuSettings" Header="Einstellungen" /> -->
|
||||||
<!-- <Separator /> -->
|
<!-- <Separator /> -->
|
||||||
<MenuItem x:Name="MnuExpSettings" Header="Einstellungen exportieren" Click="MnuExpSettings_OnClick" />
|
<MenuItem x:Name="MnuExpSettings" Header="Einstellungen exportieren" Click="MnuExpSettings_OnClick" />
|
||||||
|
<MenuItem x:Name="MnuImpResult" Header="Berechnung importieren" Click="MnuImpResult_OnClick" />
|
||||||
<MenuItem x:Name="MnuExit" Header="Beenden" Click="MnuExit_OnClick"/>
|
<MenuItem x:Name="MnuExit" Header="Beenden" Click="MnuExit_OnClick"/>
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
<MenuItem Header="Hilfe">
|
<MenuItem Header="Hilfe">
|
||||||
|
|||||||
@@ -442,4 +442,21 @@ public partial class MainWindow : Window
|
|||||||
ExportUtility.ExportToCSV(file.Path.AbsolutePath);
|
ExportUtility.ExportToCSV(file.Path.AbsolutePath);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async void MnuImpResult_OnClick(object? sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
// Hier importieren
|
||||||
|
var topLevel = GetTopLevel(this);
|
||||||
|
var file = await topLevel!.StorageProvider.OpenFilePickerAsync(new FilePickerOpenOptions
|
||||||
|
{
|
||||||
|
Title = "CSV-Datei laden",
|
||||||
|
SuggestedFileType = new FilePickerFileType(".csv-Datei")
|
||||||
|
{
|
||||||
|
Patterns = new[] { "*.csv" }
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
if (file == null) return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
Plattformunabhängiger (Windows, Linux, Mac), interaktiver Sportkursplaner für Oberstufen auf Basis einer Sportkurswahl durch SuS.
|
Plattformunabhängiger (Windows, Linux, Mac), interaktiver Sportkursplaner für Oberstufen auf Basis einer Sportkurswahl durch SuS.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
* \+ Import von CSV-Dateien mit Kurswahl
|
* \+ Import von CSV-Dateien mit Kurswahl
|
||||||
* \+ Wahlansicht
|
* \+ Wahlansicht
|
||||||
@@ -21,3 +23,5 @@ Plattformunabhängiger (Windows, Linux, Mac), interaktiver Sportkursplaner für
|
|||||||
* Suche `spplus` bzw. `spplus.exe` und führe aus
|
* Suche `spplus` bzw. `spplus.exe` und führe aus
|
||||||
* Linux/MacOS evl.: `chmod +x spplus`
|
* Linux/MacOS evl.: `chmod +x spplus`
|
||||||
|
|
||||||
|
|
||||||
|

|
||||||
+517
-80
@@ -48,12 +48,11 @@ public class CourseCrafter
|
|||||||
{
|
{
|
||||||
if (item.Item2.Count >= item.Item1.MinStudents)
|
if (item.Item2.Count >= item.Item1.MinStudents)
|
||||||
{
|
{
|
||||||
int semester = getSemesterForSport(item.Item1);
|
int semester = getSemesterForSport(item.Item1, item.Item2);
|
||||||
if (semester <= 0) goto semeq0;
|
if (semester <= 0) goto semeq0;
|
||||||
var inst = new CourseInstance();
|
var inst = new CourseInstance();
|
||||||
inst.Sport = item.Item1;
|
inst.Sport = item.Item1;
|
||||||
inst.Students = new List<string>();
|
inst.Students = new List<string>();
|
||||||
// int dist = 1;
|
|
||||||
for (int i = item.Item2.Count - 1; i >= 0; i--)
|
for (int i = item.Item2.Count - 1; i >= 0; i--)
|
||||||
{
|
{
|
||||||
if (inst.Students.Count >= inst.Sport.MaxStudents)
|
if (inst.Students.Count >= inst.Sport.MaxStudents)
|
||||||
@@ -68,7 +67,7 @@ public class CourseCrafter
|
|||||||
item.Item2.RemoveAt(i);
|
item.Item2.RemoveAt(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (inst.Students.Count < inst.Sport.MinStudents)
|
if (inst.Students.Count < getEffectiveMinStudents(inst.Sport, semester))
|
||||||
{
|
{
|
||||||
// Rückgängig machen
|
// Rückgängig machen
|
||||||
foreach (var s in inst.Students)
|
foreach (var s in inst.Students)
|
||||||
@@ -79,55 +78,14 @@ public class CourseCrafter
|
|||||||
continue; // Kurs nicht erstellen
|
continue; // Kurs nicht erstellen
|
||||||
}
|
}
|
||||||
GeneratedCourses.Add((semester, inst));
|
GeneratedCourses.Add((semester, inst));
|
||||||
|
|
||||||
//MainWindow.Instance.TbResultLog.Text += ($"{semester} -> {inst.Students.Count}\n");
|
|
||||||
//MainWindow.Instance.TbResultLog.Text += ($"{students_in_semester[0].Count} - {students_in_semester[1].Count} - {students_in_semester[2].Count} - {students_in_semester[3].Count}\n\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
semeq0: ;
|
semeq0: ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Kurse auffüllen (mit restl. Leuten)
|
FillExistingCourses();
|
||||||
foreach (var item in initial_sportlist)
|
|
||||||
{
|
|
||||||
if (item.Item2.Count > 0)
|
|
||||||
{
|
|
||||||
foreach (var ci in GeneratedCourses)
|
|
||||||
{
|
|
||||||
|
|
||||||
if (item.Item1.ID == ci.Instance.Sport.ID)
|
|
||||||
{
|
|
||||||
int semester = ci.Semester;
|
|
||||||
List<string> added = new();
|
|
||||||
foreach (string stud in item.Item2)
|
|
||||||
{
|
|
||||||
if (ci.Instance.Students.Count >= ci.Instance.Sport.MaxStudents) break;
|
|
||||||
if (!students_in_semester[semester-1].Contains(stud))
|
|
||||||
{
|
|
||||||
ci.Instance.Students.Add(stud);
|
|
||||||
students_in_semester[semester-1].Add(stud);
|
|
||||||
//ci.Instance.Students.Add(stud);
|
|
||||||
added.Add(stud);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Hinzugefügte aus Initialkurs entfernen
|
|
||||||
foreach (string s in added)
|
|
||||||
{
|
|
||||||
item.Item2.Remove(s);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//MainWindow.Instance.TbResultLog.Text += ($"{ci.Semester} -> {ci.Instance.Students.Count}\n");
|
|
||||||
//MainWindow.Instance.TbResultLog.Text += ($"{students_in_semester[0].Count} - {students_in_semester[1].Count} - {students_in_semester[2].Count} - {students_in_semester[3].Count}\n\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// Kurs umdisponieren (besser verteilen)
|
|
||||||
// Kurs umdisponieren (besser verteilen)
|
// Kurs umdisponieren (besser verteilen)
|
||||||
bool changed;
|
bool changed;
|
||||||
int maxIterations = 20;
|
int maxIterations = 20;
|
||||||
@@ -138,15 +96,13 @@ public class CourseCrafter
|
|||||||
changed = false;
|
changed = false;
|
||||||
iteration++;
|
iteration++;
|
||||||
|
|
||||||
// nach Sport gruppieren
|
|
||||||
var sports = GeneratedCourses
|
var sports = GeneratedCourses
|
||||||
.GroupBy(c => c.Instance.Sport.ID);
|
.GroupBy(c => c.Instance.Sport.Name);
|
||||||
|
|
||||||
foreach (var sportGroup in sports)
|
foreach (var sportGroup in sports)
|
||||||
{
|
{
|
||||||
var courses = sportGroup.ToList();
|
var courses = sportGroup.ToList();
|
||||||
|
|
||||||
// paarweise vergleichen
|
|
||||||
for (int i = 0; i < courses.Count; i++)
|
for (int i = 0; i < courses.Count; i++)
|
||||||
{
|
{
|
||||||
for (int j = 0; j < courses.Count; j++)
|
for (int j = 0; j < courses.Count; j++)
|
||||||
@@ -156,28 +112,23 @@ public class CourseCrafter
|
|||||||
var cA = courses[i];
|
var cA = courses[i];
|
||||||
var cB = courses[j];
|
var cB = courses[j];
|
||||||
|
|
||||||
// nur sinnvoll, wenn Unterschied
|
|
||||||
if (cA.Instance.Students.Count <= cB.Instance.Students.Count + 1)
|
if (cA.Instance.Students.Count <= cB.Instance.Students.Count + 1)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Kandidaten aus A nach B verschieben
|
|
||||||
for (int k = cA.Instance.Students.Count - 1; k >= 0; k--)
|
for (int k = cA.Instance.Students.Count - 1; k >= 0; k--)
|
||||||
{
|
{
|
||||||
string stud = cA.Instance.Students[k];
|
string stud = cA.Instance.Students[k];
|
||||||
|
|
||||||
// 1. Zielsemester frei?
|
|
||||||
if (!isStudentFree(cB.Semester, stud))
|
if (!isStudentFree(cB.Semester, stud))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// 2. Zielkurs hat noch Platz?
|
|
||||||
if (cB.Instance.Students.Count >= cB.Instance.Sport.MaxStudents)
|
if (cB.Instance.Students.Count >= cB.Instance.Sport.MaxStudents)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// 3. Quellkurs darf nicht unter Min fallen
|
// Quellkurs darf nicht unter effektives Min fallen
|
||||||
if (cA.Instance.Students.Count - 1 < cA.Instance.Sport.MinStudents)
|
if (cA.Instance.Students.Count - 1 < getEffectiveMinStudents(cA.Instance.Sport, cA.Semester))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// --- MOVE durchführen ---
|
|
||||||
cA.Instance.Students.RemoveAt(k);
|
cA.Instance.Students.RemoveAt(k);
|
||||||
students_in_semester[cA.Semester - 1].Remove(stud);
|
students_in_semester[cA.Semester - 1].Remove(stud);
|
||||||
|
|
||||||
@@ -185,7 +136,7 @@ public class CourseCrafter
|
|||||||
students_in_semester[cB.Semester - 1].Add(stud);
|
students_in_semester[cB.Semester - 1].Add(stud);
|
||||||
|
|
||||||
changed = true;
|
changed = true;
|
||||||
break; // nach jedem Move neu bewerten
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -193,6 +144,194 @@ public class CourseCrafter
|
|||||||
|
|
||||||
} while (changed && iteration < maxIterations);
|
} while (changed && iteration < maxIterations);
|
||||||
|
|
||||||
|
// --- Kurse nachträglich aufteilen, um NumCoursesPerSemester exakt zu erreichen ---
|
||||||
|
for (int semester = 1; semester <= 4; semester++)
|
||||||
|
{
|
||||||
|
int cancel = 0;
|
||||||
|
while (GeneratedCourses.Count(c => c.Semester == semester) < Settings.Instance.NumCoursesPerSemester)
|
||||||
|
{
|
||||||
|
cancel++;
|
||||||
|
if (cancel >= 20) break;
|
||||||
|
|
||||||
|
var candidate = GeneratedCourses
|
||||||
|
.Where(c => c.Semester == semester)
|
||||||
|
.Where(c => c.Instance.Students.Count >= getEffectiveMinStudents(c.Instance.Sport, c.Semester) * 2)
|
||||||
|
.Where(c =>
|
||||||
|
{
|
||||||
|
int sportCount = GeneratedCourses.Count(g =>
|
||||||
|
g.Semester == semester &&
|
||||||
|
g.Instance.Sport.Name == c.Instance.Sport.Name);
|
||||||
|
|
||||||
|
int allowed = c.Instance.Sport.Semester[semester - 1];
|
||||||
|
return sportCount < allowed;
|
||||||
|
})
|
||||||
|
.OrderByDescending(c => c.Instance.Students.Count)
|
||||||
|
.FirstOrDefault();
|
||||||
|
|
||||||
|
if (candidate.Instance == null)
|
||||||
|
break;
|
||||||
|
|
||||||
|
var students = candidate.Instance.Students;
|
||||||
|
int totalStudents = students.Count;
|
||||||
|
int movedCount = totalStudents / 2;
|
||||||
|
int remainingCount = totalStudents - movedCount;
|
||||||
|
|
||||||
|
if (movedCount < getEffectiveMinStudents(candidate.Instance.Sport, candidate.Semester) ||
|
||||||
|
remainingCount < getEffectiveMinStudents(candidate.Instance.Sport, candidate.Semester))
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
var newCourse = new CourseInstance
|
||||||
|
{
|
||||||
|
Sport = candidate.Instance.Sport,
|
||||||
|
Students = new List<string>()
|
||||||
|
};
|
||||||
|
|
||||||
|
var moved = students
|
||||||
|
.Skip(remainingCount)
|
||||||
|
.Take(movedCount)
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
foreach (var s in moved)
|
||||||
|
{
|
||||||
|
candidate.Instance.Students.Remove(s);
|
||||||
|
newCourse.Students.Add(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
GeneratedCourses.Add((semester, newCourse));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool rescueChanged;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
rescueChanged = FillExistingCourses();
|
||||||
|
|
||||||
|
foreach (var item in initial_sportlist)
|
||||||
|
{
|
||||||
|
if (TryCreateRescueCourse(item.Item1, item.Item2))
|
||||||
|
{
|
||||||
|
rescueChanged = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} while (rescueChanged);
|
||||||
|
|
||||||
|
OptimizeStudentWishCoverage();
|
||||||
|
|
||||||
|
// --- Ringtausch: Schüler mit 4 Wünschen aber < 4 Zuteilungen neu zuordnen ---
|
||||||
|
foreach (var student in Settings.Instance.Students)
|
||||||
|
{
|
||||||
|
if (student.SelectedCourseNames.Count < 4)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
var currentAssignments = GetAssignmentsBySemester(student.ID);
|
||||||
|
int currentCount = currentAssignments.Count(a => a != null);
|
||||||
|
|
||||||
|
if (currentCount >= 4)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// Alle aktuellen Zuteilungen entfernen (temporär)
|
||||||
|
foreach (var assignment in currentAssignments)
|
||||||
|
{
|
||||||
|
if (assignment == null) continue;
|
||||||
|
assignment.Value.Instance.Students.Remove(student.ID);
|
||||||
|
students_in_semester[assignment.Value.Semester - 1].Remove(student.ID);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Alle gewünschten Sports ermitteln
|
||||||
|
var desiredSports = student.SelectedCourseNames
|
||||||
|
.Select(ResolveSportFromSelection)
|
||||||
|
.Where(s => s != null)
|
||||||
|
.DistinctBy(s => s!.Name)
|
||||||
|
.Select(s => s!)
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
// Kandidatenkurse pro Semester: Kurse mit freiem Platz, die einem Wunschsport entsprechen
|
||||||
|
var candidatesPerSemester = new List<(int Semester, CourseInstance Instance)>[4];
|
||||||
|
for (int si = 0; si < 4; si++)
|
||||||
|
{
|
||||||
|
candidatesPerSemester[si] = GeneratedCourses
|
||||||
|
.Where(c => c.Semester == si + 1)
|
||||||
|
.Where(c => c.Instance.Students.Count < c.Instance.Sport.MaxStudents)
|
||||||
|
.Where(c => desiredSports.Any(ds => ds.Name == c.Instance.Sport.Name))
|
||||||
|
.ToList();
|
||||||
|
candidatesPerSemester[si].Insert(0, default); // default = kein Kurs
|
||||||
|
}
|
||||||
|
|
||||||
|
(int Semester, CourseInstance Instance)?[] bestAssignment = currentAssignments;
|
||||||
|
int bestScore = currentCount;
|
||||||
|
|
||||||
|
int s0 = candidatesPerSemester[0].Count;
|
||||||
|
int s1 = candidatesPerSemester[1].Count;
|
||||||
|
int s2 = candidatesPerSemester[2].Count;
|
||||||
|
int s3 = candidatesPerSemester[3].Count;
|
||||||
|
|
||||||
|
var sportSelectedCounts = student.SelectedCourseNames
|
||||||
|
.Select(ResolveSportFromSelection)
|
||||||
|
.Where(sp => sp != null)
|
||||||
|
.GroupBy(sp => sp!.Name)
|
||||||
|
.ToDictionary(g => g.Key, g => g.Count());
|
||||||
|
|
||||||
|
for (int i0 = 0; i0 < s0; i0++)
|
||||||
|
for (int i1 = 0; i1 < s1; i1++)
|
||||||
|
for (int i2 = 0; i2 < s2; i2++)
|
||||||
|
for (int i3 = 0; i3 < s3; i3++)
|
||||||
|
{
|
||||||
|
var c0 = candidatesPerSemester[0][i0];
|
||||||
|
var c1 = candidatesPerSemester[1][i1];
|
||||||
|
var c2 = candidatesPerSemester[2][i2];
|
||||||
|
var c3 = candidatesPerSemester[3][i3];
|
||||||
|
|
||||||
|
var chosen = new (int Semester, CourseInstance Instance)?[]
|
||||||
|
{
|
||||||
|
c0.Instance != null ? (c0.Semester, c0.Instance) : null,
|
||||||
|
c1.Instance != null ? (c1.Semester, c1.Instance) : null,
|
||||||
|
c2.Instance != null ? (c2.Semester, c2.Instance) : null,
|
||||||
|
c3.Instance != null ? (c3.Semester, c3.Instance) : null
|
||||||
|
};
|
||||||
|
|
||||||
|
bool valid = true;
|
||||||
|
var sportUsageCounts = new Dictionary<string, int>();
|
||||||
|
|
||||||
|
for (int si = 0; si < 4; si++)
|
||||||
|
{
|
||||||
|
if (chosen[si] == null) continue;
|
||||||
|
string sportName = chosen[si]!.Value.Instance.Sport.Name;
|
||||||
|
sportUsageCounts.TryGetValue(sportName, out int used);
|
||||||
|
int allowed = sportSelectedCounts.GetValueOrDefault(sportName, 0);
|
||||||
|
if (used >= allowed) { valid = false; break; }
|
||||||
|
sportUsageCounts[sportName] = used + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!valid) continue;
|
||||||
|
|
||||||
|
int score = chosen.Count(c => c != null);
|
||||||
|
if (score > bestScore)
|
||||||
|
{
|
||||||
|
bestScore = score;
|
||||||
|
bestAssignment = chosen;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Beste Zuteilung anwenden
|
||||||
|
foreach (var assignment in bestAssignment)
|
||||||
|
{
|
||||||
|
if (assignment == null) continue;
|
||||||
|
assignment.Value.Instance.Students.Add(student.ID);
|
||||||
|
students_in_semester[assignment.Value.Semester - 1].Add(student.ID);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// Lokale Hilfsfunktionen
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
int getEffectiveMinStudents(Sport sport, int semester)
|
||||||
|
{
|
||||||
|
int reduction = (semester >= 3) ? 2 : 0;
|
||||||
|
return Math.Max(1, sport.MinStudents - reduction);
|
||||||
|
}
|
||||||
|
|
||||||
bool isStudentFree(int semester, string studentID)
|
bool isStudentFree(int semester, string studentID)
|
||||||
{
|
{
|
||||||
@@ -201,22 +340,17 @@ public class CourseCrafter
|
|||||||
if (semester != inst.Semester) continue;
|
if (semester != inst.Semester) continue;
|
||||||
foreach (string stud in inst.Instance.Students)
|
foreach (string stud in inst.Instance.Students)
|
||||||
{
|
{
|
||||||
if (stud == studentID) return false; // Schüler in genanntem Semester bereits gefunden
|
if (stud == studentID) return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Schüler nicht gefunden:
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool requestExit()
|
bool requestExit()
|
||||||
{
|
{
|
||||||
globalCount++;
|
globalCount++;
|
||||||
// max Kursanzahl
|
|
||||||
if (GeneratedCourses.Count >= Settings.Instance.NumCoursesPerSemester * 4) return true;
|
if (GeneratedCourses.Count >= Settings.Instance.NumCoursesPerSemester * 4) return true;
|
||||||
|
|
||||||
|
|
||||||
int low = 0;
|
int low = 0;
|
||||||
foreach (var item in initial_sportlist)
|
foreach (var item in initial_sportlist)
|
||||||
{
|
{
|
||||||
@@ -224,18 +358,308 @@ public class CourseCrafter
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (low >= initial_sportlist.Count) return true;
|
if (low >= initial_sportlist.Count) return true;
|
||||||
|
|
||||||
if (globalCount >= 20) return true;
|
if (globalCount >= 20) return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int total_missing = 0;
|
||||||
foreach (var tuple in initial_sportlist)
|
foreach (var tuple in initial_sportlist)
|
||||||
{
|
{
|
||||||
MainWindow.Instance.TbResultTextout.Text += $"{tuple.Item1}: {tuple.Item2.Count} remaining\n";
|
int[] missingPerSemester = new int[4];
|
||||||
|
foreach (var studentId in tuple.Item2.Distinct())
|
||||||
|
{
|
||||||
|
for (int semesterIndex = 0; semesterIndex < 4; semesterIndex++)
|
||||||
|
{
|
||||||
|
if (!students_in_semester[semesterIndex].Contains(studentId))
|
||||||
|
{
|
||||||
|
missingPerSemester[semesterIndex]++;
|
||||||
|
total_missing++;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ...existing code...
|
MainWindow.Instance.TbResultTextout.Text +=
|
||||||
int getSemesterForSport2(Sport sp)
|
$"{tuple.Item1}: {tuple.Item2.Count} remaining ({missingPerSemester[0]},{missingPerSemester[1]},{missingPerSemester[2]},{missingPerSemester[3]})\n";
|
||||||
|
}
|
||||||
|
MainWindow.Instance.TbResultTextout.Text += $"\n total remaining: {total_missing}";
|
||||||
|
|
||||||
|
bool FillExistingCourses()
|
||||||
|
{
|
||||||
|
bool changed = false;
|
||||||
|
|
||||||
|
foreach (var item in initial_sportlist)
|
||||||
|
{
|
||||||
|
if (item.Item2.Count == 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
foreach (var ci in GeneratedCourses
|
||||||
|
.Where(ci => ci.Instance.Sport.Name == item.Item1.Name)
|
||||||
|
.OrderBy(ci => ci.Instance.Students.Count))
|
||||||
|
{
|
||||||
|
int semester = ci.Semester;
|
||||||
|
List<string> added = new();
|
||||||
|
|
||||||
|
foreach (string stud in item.Item2)
|
||||||
|
{
|
||||||
|
if (ci.Instance.Students.Count >= ci.Instance.Sport.MaxStudents)
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (students_in_semester[semester - 1].Contains(stud))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
ci.Instance.Students.Add(stud);
|
||||||
|
students_in_semester[semester - 1].Add(stud);
|
||||||
|
added.Add(stud);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (string s in added)
|
||||||
|
{
|
||||||
|
item.Item2.Remove(s);
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return changed;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool TryCreateRescueCourse(Sport sport, List<string> remainingStudents)
|
||||||
|
{
|
||||||
|
if (remainingStudents.Count == 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
for (int semester = 1; semester <= 4; semester++)
|
||||||
|
{
|
||||||
|
int semesterIndex = semester - 1;
|
||||||
|
|
||||||
|
if (sport.Semester[semesterIndex] == 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
int sportCoursesInSemester = GeneratedCourses.Count(c =>
|
||||||
|
c.Semester == semester && c.Instance.Sport.Name == sport.Name);
|
||||||
|
if (sportCoursesInSemester >= sport.Semester[semesterIndex])
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (GeneratedCourses.Count(c => c.Semester == semester) >= Settings.Instance.NumCoursesPerSemester)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
var directlyPlaceable = remainingStudents
|
||||||
|
.Distinct()
|
||||||
|
.Where(studentId => !students_in_semester[semesterIndex].Contains(studentId))
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
var donorMoves = new List<((int Semester, CourseInstance Instance) Course, string StudentId)>();
|
||||||
|
foreach (var course in GeneratedCourses
|
||||||
|
.Where(c => c.Instance.Sport.Name == sport.Name && c.Semester != semester)
|
||||||
|
.OrderByDescending(c => c.Instance.Students.Count))
|
||||||
|
{
|
||||||
|
int movableCount = course.Instance.Students.Count - getEffectiveMinStudents(sport, course.Semester);
|
||||||
|
if (movableCount <= 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
foreach (var studentId in course.Instance.Students.ToList())
|
||||||
|
{
|
||||||
|
if (movableCount <= 0)
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (students_in_semester[semesterIndex].Contains(studentId))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
donorMoves.Add((course, studentId));
|
||||||
|
movableCount--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (directlyPlaceable.Count + donorMoves.Count < getEffectiveMinStudents(sport, semester))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
var newCourse = new CourseInstance
|
||||||
|
{
|
||||||
|
Sport = sport,
|
||||||
|
Students = new List<string>()
|
||||||
|
};
|
||||||
|
|
||||||
|
foreach (var studentId in directlyPlaceable)
|
||||||
|
{
|
||||||
|
if (newCourse.Students.Count >= sport.MaxStudents)
|
||||||
|
break;
|
||||||
|
|
||||||
|
newCourse.Students.Add(studentId);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var move in donorMoves)
|
||||||
|
{
|
||||||
|
if (newCourse.Students.Count >= sport.MaxStudents)
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (newCourse.Students.Contains(move.StudentId))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
move.Course.Instance.Students.Remove(move.StudentId);
|
||||||
|
students_in_semester[move.Course.Semester - 1].Remove(move.StudentId);
|
||||||
|
newCourse.Students.Add(move.StudentId);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (newCourse.Students.Count < getEffectiveMinStudents(sport, semester))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
foreach (var studentId in newCourse.Students)
|
||||||
|
{
|
||||||
|
remainingStudents.Remove(studentId);
|
||||||
|
students_in_semester[semesterIndex].Add(studentId);
|
||||||
|
}
|
||||||
|
|
||||||
|
GeneratedCourses.Add((semester, newCourse));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void OptimizeStudentWishCoverage()
|
||||||
|
{
|
||||||
|
bool changed;
|
||||||
|
int iterations = 0;
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
changed = false;
|
||||||
|
iterations++;
|
||||||
|
|
||||||
|
foreach (var student in Settings.Instance.Students)
|
||||||
|
{
|
||||||
|
if (TryImproveStudentCoverage(student))
|
||||||
|
{
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} while (changed && iterations < 20);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool TryImproveStudentCoverage(Student student)
|
||||||
|
{
|
||||||
|
var assignments = GetAssignmentsBySemester(student.ID);
|
||||||
|
if (assignments.All(a => a != null))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
var openSemesters = Enumerable.Range(0, 4)
|
||||||
|
.Where(i => assignments[i] == null)
|
||||||
|
.Select(i => i + 1)
|
||||||
|
.ToList();
|
||||||
|
if (openSemesters.Count == 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
var assignedSports = assignments
|
||||||
|
.Where(a => a != null)
|
||||||
|
.Select(a => a!.Value.Instance.Sport.Name)
|
||||||
|
.ToHashSet();
|
||||||
|
|
||||||
|
var preferredSports = student.SelectedCourseNames
|
||||||
|
.Select(ResolveSportFromSelection)
|
||||||
|
.Where(sport => sport != null)
|
||||||
|
.DistinctBy(sport => sport!.Name)
|
||||||
|
.Select(sport => sport!)
|
||||||
|
.Where(sport => !assignedSports.Contains(sport.Name))
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
foreach (var desiredSport in preferredSports)
|
||||||
|
{
|
||||||
|
for (int sourceSemester = 1; sourceSemester <= 4; sourceSemester++)
|
||||||
|
{
|
||||||
|
var currentCourse = assignments[sourceSemester - 1];
|
||||||
|
if (currentCourse == null)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
var currentCourseValue = currentCourse.Value;
|
||||||
|
|
||||||
|
var desiredCourse = GeneratedCourses
|
||||||
|
.FirstOrDefault(course =>
|
||||||
|
course.Semester == sourceSemester &&
|
||||||
|
course.Instance.Sport.Name == desiredSport.Name &&
|
||||||
|
course.Instance.Students.Count < course.Instance.Sport.MaxStudents);
|
||||||
|
|
||||||
|
if (desiredCourse.Instance == null)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
foreach (var targetSemester in openSemesters)
|
||||||
|
{
|
||||||
|
var relocationTarget = GeneratedCourses
|
||||||
|
.FirstOrDefault(course =>
|
||||||
|
course.Semester == targetSemester &&
|
||||||
|
course.Instance.Sport.Name == currentCourseValue.Instance.Sport.Name &&
|
||||||
|
course.Instance.Students.Count < course.Instance.Sport.MaxStudents);
|
||||||
|
|
||||||
|
if (relocationTarget.Instance == null)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (!CanRelocateStudent(student.ID, currentCourseValue, relocationTarget))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
currentCourseValue.Instance.Students.Remove(student.ID);
|
||||||
|
students_in_semester[sourceSemester - 1].Remove(student.ID);
|
||||||
|
|
||||||
|
relocationTarget.Instance.Students.Add(student.ID);
|
||||||
|
students_in_semester[targetSemester - 1].Add(student.ID);
|
||||||
|
|
||||||
|
desiredCourse.Instance.Students.Add(student.ID);
|
||||||
|
students_in_semester[sourceSemester - 1].Add(student.ID);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CanRelocateStudent(
|
||||||
|
string studentId,
|
||||||
|
(int Semester, CourseInstance Instance) sourceCourse,
|
||||||
|
(int Semester, CourseInstance Instance) targetCourse)
|
||||||
|
{
|
||||||
|
if (sourceCourse.Semester == targetCourse.Semester)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (sourceCourse.Instance.Students.Count - 1 < getEffectiveMinStudents(sourceCourse.Instance.Sport, sourceCourse.Semester))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (targetCourse.Instance.Students.Count >= targetCourse.Instance.Sport.MaxStudents)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (!isStudentFree(targetCourse.Semester, studentId))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
(int Semester, CourseInstance Instance)?[] GetAssignmentsBySemester(string studentId)
|
||||||
|
{
|
||||||
|
var assignments = new (int Semester, CourseInstance Instance)?[4];
|
||||||
|
|
||||||
|
foreach (var course in GeneratedCourses)
|
||||||
|
{
|
||||||
|
if (course.Instance.Students.Contains(studentId))
|
||||||
|
{
|
||||||
|
assignments[course.Semester - 1] = course;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return assignments;
|
||||||
|
}
|
||||||
|
|
||||||
|
Sport? ResolveSportFromSelection(string selectedCourseName)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(selectedCourseName) ||
|
||||||
|
string.Equals(selectedCourseName, "null", StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Settings.Instance.Sports
|
||||||
|
.FirstOrDefault(sport => sport.AlternativeNames.Contains(selectedCourseName));
|
||||||
|
}
|
||||||
|
|
||||||
|
int getSemesterForSport2(Sport sp, List<string> interestedStudents)
|
||||||
{
|
{
|
||||||
int[] semcount = new int[4];
|
int[] semcount = new int[4];
|
||||||
|
|
||||||
@@ -249,13 +673,19 @@ public class CourseCrafter
|
|||||||
{
|
{
|
||||||
if (sp.Semester[i] == 0) continue;
|
if (sp.Semester[i] == 0) continue;
|
||||||
|
|
||||||
// prüfen, ob für diesen Sport im Semester i schon die maximale Anzahl erreicht ist
|
|
||||||
int sportCoursesInSemester = GeneratedCourses
|
int sportCoursesInSemester = GeneratedCourses
|
||||||
.Count(g => g.Semester == i + 1 && g.Instance.Sport.ID == sp.ID);
|
.Count(g => g.Semester == i + 1 && g.Instance.Sport.Name == sp.Name);
|
||||||
|
|
||||||
if (sportCoursesInSemester >= sp.Semester[i])
|
if (sportCoursesInSemester >= sp.Semester[i])
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
int freeInterestedStudents = interestedStudents
|
||||||
|
.Distinct()
|
||||||
|
.Count(studentId => !students_in_semester[i].Contains(studentId));
|
||||||
|
|
||||||
|
if (freeInterestedStudents < getEffectiveMinStudents(sp, i + 1))
|
||||||
|
continue;
|
||||||
|
|
||||||
if (semcount[i] < Settings.Instance.NumCoursesPerSemester &&
|
if (semcount[i] < Settings.Instance.NumCoursesPerSemester &&
|
||||||
semcount[i] < minCourses)
|
semcount[i] < minCourses)
|
||||||
{
|
{
|
||||||
@@ -267,47 +697,51 @@ public class CourseCrafter
|
|||||||
return bestSem;
|
return bestSem;
|
||||||
}
|
}
|
||||||
|
|
||||||
int getSemesterForSport(Sport sp)
|
int getSemesterForSport(Sport sp, List<string> interestedStudents)
|
||||||
{
|
{
|
||||||
// 1. Zähle alle Kurse pro Semester (egal welche Sportart)
|
|
||||||
int[] totalCoursesPerSemester = new int[4];
|
int[] totalCoursesPerSemester = new int[4];
|
||||||
foreach (var inst in GeneratedCourses)
|
foreach (var inst in GeneratedCourses)
|
||||||
totalCoursesPerSemester[inst.Semester - 1]++;
|
totalCoursesPerSemester[inst.Semester - 1]++;
|
||||||
|
|
||||||
int bestSem = 0;
|
int bestSem = 0;
|
||||||
int minCourses = int.MaxValue;
|
int minCourses = int.MaxValue;
|
||||||
|
int maxFreeInterestedStudents = -1;
|
||||||
|
|
||||||
// 2. Kandidaten-Semester durchgehen
|
|
||||||
for (int i = 0; i < 4; i++)
|
for (int i = 0; i < 4; i++)
|
||||||
{
|
{
|
||||||
// a) Sport darf in diesem Semester gar nicht stattfinden?
|
|
||||||
if (sp.Semester[i] == 0)
|
if (sp.Semester[i] == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
int semesterNumber = i + 1;
|
int semesterNumber = i + 1;
|
||||||
|
|
||||||
// b) Wie viele Kurse DIESES Sports gibt es schon in diesem Semester?
|
|
||||||
int sportCoursesInThisSemester = GeneratedCourses
|
int sportCoursesInThisSemester = GeneratedCourses
|
||||||
.Count(g => g.Semester == semesterNumber &&
|
.Count(g => g.Semester == semesterNumber &&
|
||||||
g.Instance.Sport.Name == sp.Name);
|
g.Instance.Sport.Name == sp.Name);
|
||||||
|
|
||||||
// c) Pro-Sport-Limit erreicht?
|
|
||||||
if (sportCoursesInThisSemester >= sp.Semester[i])
|
if (sportCoursesInThisSemester >= sp.Semester[i])
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// d) Globales Limit pro Semester erreicht?
|
|
||||||
if (totalCoursesPerSemester[i] >= Settings.Instance.NumCoursesPerSemester)
|
if (totalCoursesPerSemester[i] >= Settings.Instance.NumCoursesPerSemester)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// e) Wähle das Semester mit bisher insgesamt den wenigsten Kursen
|
int freeInterestedStudents = interestedStudents
|
||||||
if (totalCoursesPerSemester[i] < minCourses)
|
.Distinct()
|
||||||
|
.Count(studentId => !students_in_semester[i].Contains(studentId));
|
||||||
|
|
||||||
|
if (freeInterestedStudents < getEffectiveMinStudents(sp, semesterNumber))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (freeInterestedStudents > maxFreeInterestedStudents ||
|
||||||
|
(freeInterestedStudents == maxFreeInterestedStudents &&
|
||||||
|
totalCoursesPerSemester[i] < minCourses))
|
||||||
{
|
{
|
||||||
|
maxFreeInterestedStudents = freeInterestedStudents;
|
||||||
minCourses = totalCoursesPerSemester[i];
|
minCourses = totalCoursesPerSemester[i];
|
||||||
bestSem = semesterNumber;
|
bestSem = semesterNumber;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return bestSem; // 0, falls kein zulässiges Semester gefunden
|
return bestSem;
|
||||||
}
|
}
|
||||||
|
|
||||||
var errors = ValidateCourses(GeneratedCourses);
|
var errors = ValidateCourses(GeneratedCourses);
|
||||||
@@ -323,6 +757,11 @@ public class CourseCrafter
|
|||||||
MainWindow.Instance.TbResultLog.Text += e + "\n";
|
MainWindow.Instance.TbResultLog.Text += e + "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
foreach (var student in Settings.Instance.Students)
|
||||||
|
{
|
||||||
|
student.Result = new string[4];
|
||||||
|
}
|
||||||
|
|
||||||
foreach (var course in GeneratedCourses)
|
foreach (var course in GeneratedCourses)
|
||||||
{
|
{
|
||||||
foreach (var student in Settings.Instance.Students)
|
foreach (var student in Settings.Instance.Students)
|
||||||
@@ -333,9 +772,7 @@ public class CourseCrafter
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string GenerateStatistics()
|
public static string GenerateStatistics()
|
||||||
{
|
{
|
||||||
GeneratedCourses.Sort((x,y) => x.Semester.CompareTo(y.Semester) );
|
GeneratedCourses.Sort((x,y) => x.Semester.CompareTo(y.Semester) );
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 82 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 194 KiB |
@@ -47,4 +47,45 @@ public static class import
|
|||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static List<Student> ImportResultFromFile(string path)
|
||||||
|
{
|
||||||
|
var dict = new Dictionary<string, (string Name, List<string> Courses)>();
|
||||||
|
|
||||||
|
foreach (var line in File.ReadLines(path).Skip(1)) // Header überspringen
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(line))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
var parts = line.Split(',');
|
||||||
|
if (parts.Length < 3)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
string nameWithId = parts[0].Trim();
|
||||||
|
string course = parts[2].Replace("(2)", "").Replace("(3)", "").Replace("(4)", "").Trim();
|
||||||
|
|
||||||
|
int open = nameWithId.LastIndexOf('(');
|
||||||
|
int close = nameWithId.LastIndexOf(')');
|
||||||
|
if (open < 0 || close < 0 || close <= open)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
string name = nameWithId[..open].Trim();
|
||||||
|
string id = nameWithId[(open + 1)..close].Trim();
|
||||||
|
|
||||||
|
if (!dict.ContainsKey(id))
|
||||||
|
dict[id] = (name, new List<string>());
|
||||||
|
|
||||||
|
dict[id].Courses.Add(course);
|
||||||
|
}
|
||||||
|
|
||||||
|
var result = new List<Student>();
|
||||||
|
|
||||||
|
foreach (var (id, data) in dict)
|
||||||
|
{
|
||||||
|
var student = new Student(id, data.Name, data.Courses);
|
||||||
|
result.Add(student);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 67 KiB |
+1
-1
@@ -85,7 +85,7 @@ public class Settings
|
|||||||
|
|
||||||
public List<Student> Students { get; set; } = [];
|
public List<Student> Students { get; set; } = [];
|
||||||
public List<Sport> Sports { get; set; } = [];
|
public List<Sport> Sports { get; set; } = [];
|
||||||
public int NumCoursesPerSemester { get; set; } = 10;
|
public int NumCoursesPerSemester { get; set; } = 10; // Exact Amount of courses, not a maximum
|
||||||
|
|
||||||
public Settings()
|
public Settings()
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user