Compare commits
3 Commits
d70770e2f0
...
6753acc04f
| Author | SHA1 | Date | |
|---|---|---|---|
| 6753acc04f | |||
| 4468651373 | |||
| b6de508ea0 |
188
crafter.cs
188
crafter.cs
@@ -87,10 +87,6 @@ public class CourseCrafter
|
|||||||
semeq0: ;
|
semeq0: ;
|
||||||
}
|
}
|
||||||
|
|
||||||
// foreach (var item in initial_sportlist)
|
|
||||||
// {
|
|
||||||
// Console.WriteLine($"{item.Item1.Name}: {item.Item2.Count}x gewählt");
|
|
||||||
// }
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -130,6 +126,72 @@ public class CourseCrafter
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Kurs umdisponieren (besser verteilen)
|
||||||
|
// Kurs umdisponieren (besser verteilen)
|
||||||
|
bool changed;
|
||||||
|
int maxIterations = 20;
|
||||||
|
int iteration = 0;
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
changed = false;
|
||||||
|
iteration++;
|
||||||
|
|
||||||
|
// nach Sport gruppieren
|
||||||
|
var sports = GeneratedCourses
|
||||||
|
.GroupBy(c => c.Instance.Sport.ID);
|
||||||
|
|
||||||
|
foreach (var sportGroup in sports)
|
||||||
|
{
|
||||||
|
var courses = sportGroup.ToList();
|
||||||
|
|
||||||
|
// paarweise vergleichen
|
||||||
|
for (int i = 0; i < courses.Count; i++)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < courses.Count; j++)
|
||||||
|
{
|
||||||
|
if (i == j) continue;
|
||||||
|
|
||||||
|
var cA = courses[i];
|
||||||
|
var cB = courses[j];
|
||||||
|
|
||||||
|
// nur sinnvoll, wenn Unterschied
|
||||||
|
if (cA.Instance.Students.Count <= cB.Instance.Students.Count + 1)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// Kandidaten aus A nach B verschieben
|
||||||
|
for (int k = cA.Instance.Students.Count - 1; k >= 0; k--)
|
||||||
|
{
|
||||||
|
string stud = cA.Instance.Students[k];
|
||||||
|
|
||||||
|
// 1. Zielsemester frei?
|
||||||
|
if (!isStudentFree(cB.Semester, stud))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// 2. Zielkurs hat noch Platz?
|
||||||
|
if (cB.Instance.Students.Count >= cB.Instance.Sport.MaxStudents)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// 3. Quellkurs darf nicht unter Min fallen
|
||||||
|
if (cA.Instance.Students.Count - 1 < cA.Instance.Sport.MinStudents)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// --- MOVE durchführen ---
|
||||||
|
cA.Instance.Students.RemoveAt(k);
|
||||||
|
students_in_semester[cA.Semester - 1].Remove(stud);
|
||||||
|
|
||||||
|
cB.Instance.Students.Add(stud);
|
||||||
|
students_in_semester[cB.Semester - 1].Add(stud);
|
||||||
|
|
||||||
|
changed = true;
|
||||||
|
break; // nach jedem Move neu bewerten
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} while (changed && iteration < maxIterations);
|
||||||
|
|
||||||
int getSemester()
|
int getSemester()
|
||||||
{
|
{
|
||||||
@@ -173,17 +235,6 @@ public class CourseCrafter
|
|||||||
// max Kursanzahl
|
// max Kursanzahl
|
||||||
if (GeneratedCourses.Count >= Settings.Instance.NumCoursesPerSemester * 4) return true;
|
if (GeneratedCourses.Count >= Settings.Instance.NumCoursesPerSemester * 4) return true;
|
||||||
|
|
||||||
// // max Anzahl in allen Semestern
|
|
||||||
// foreach(int sem in new[]{1,2,3,4})
|
|
||||||
// {
|
|
||||||
// int count = 0;
|
|
||||||
// foreach (var inst in GeneratedCourses)
|
|
||||||
// {
|
|
||||||
// if (inst.Semester == sem) count++;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// if (sem >= Settings.Instance.NumCoursesPerSemester);
|
|
||||||
// }
|
|
||||||
|
|
||||||
int low = 0;
|
int low = 0;
|
||||||
foreach (var item in initial_sportlist)
|
foreach (var item in initial_sportlist)
|
||||||
@@ -228,113 +279,6 @@ public class CourseCrafter
|
|||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
public static void CraftOld()
|
|
||||||
{
|
|
||||||
GeneratedCourses = new();
|
|
||||||
|
|
||||||
var settings = Settings.Instance;
|
|
||||||
var students = settings.Students;
|
|
||||||
var sports = settings.Sports;
|
|
||||||
|
|
||||||
if (students.Count == 0 || sports.Count == 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
int semesterCount = sports.Max(s => s.Semester.Length);
|
|
||||||
|
|
||||||
foreach (var st in students)
|
|
||||||
st.Result = Enumerable.Repeat("Fehler", semesterCount).ToList();
|
|
||||||
|
|
||||||
var nameMap = new Dictionary<string, Sport>(StringComparer.OrdinalIgnoreCase);
|
|
||||||
foreach (var sp in sports)
|
|
||||||
{
|
|
||||||
nameMap[sp.Name] = sp;
|
|
||||||
foreach (var alt in sp.AlternativeNames)
|
|
||||||
nameMap[alt] = sp;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Nachfrage je Sport
|
|
||||||
var demand = new Dictionary<Sport, List<Student>>();
|
|
||||||
foreach (var sp in sports)
|
|
||||||
demand[sp] = new List<Student>();
|
|
||||||
|
|
||||||
foreach (var st in students)
|
|
||||||
{
|
|
||||||
foreach (var sel in st.SelectedCourseNames.Distinct())
|
|
||||||
{
|
|
||||||
if (nameMap.TryGetValue(sel, out var sp))
|
|
||||||
demand[sp].Add(st);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ===== Semesterweise echte Verteilung =====
|
|
||||||
for (int sem = 0; sem < semesterCount; sem++)
|
|
||||||
{
|
|
||||||
int remainingSemesterSlots = settings.NumCoursesPerSemester;
|
|
||||||
|
|
||||||
foreach (var sp in sports)
|
|
||||||
{
|
|
||||||
if (sem >= sp.Semester.Length)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (remainingSemesterSlots <= 0)
|
|
||||||
break;
|
|
||||||
|
|
||||||
var interested = demand[sp]
|
|
||||||
.Where(st =>
|
|
||||||
st.Result![sem] == "Fehler" &&
|
|
||||||
!st.Result.Contains(sp.Name))
|
|
||||||
.ToList();
|
|
||||||
|
|
||||||
if (interested.Count < sp.MinStudents)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
int maxInstances = Math.Min(sp.Semester[sem], remainingSemesterSlots);
|
|
||||||
int instanceCount = 0;
|
|
||||||
int index = 0;
|
|
||||||
|
|
||||||
while (interested.Count - index >= sp.MinStudents &&
|
|
||||||
instanceCount < maxInstances)
|
|
||||||
{
|
|
||||||
var inst = new CourseInstance
|
|
||||||
{
|
|
||||||
Sport = sp,
|
|
||||||
Remaining = sp.MaxStudents
|
|
||||||
};
|
|
||||||
|
|
||||||
GeneratedCourses.Add((sem, inst));
|
|
||||||
remainingSemesterSlots--;
|
|
||||||
instanceCount++;
|
|
||||||
|
|
||||||
int filled = 0;
|
|
||||||
|
|
||||||
while (filled < sp.MaxStudents &&
|
|
||||||
index < interested.Count)
|
|
||||||
{
|
|
||||||
var st = interested[index++];
|
|
||||||
|
|
||||||
if (st.Result![sem] != "Fehler")
|
|
||||||
continue;
|
|
||||||
|
|
||||||
//inst.Students.Add(st);
|
|
||||||
inst.Remaining--;
|
|
||||||
st.Result[sem] = sp.Name;
|
|
||||||
filled++;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Falls Mindestanzahl nicht erreicht → Instanz verwerfen
|
|
||||||
if (inst.Students.Count < sp.MinStudents)
|
|
||||||
{
|
|
||||||
//foreach (var st in inst.Students)
|
|
||||||
//st.Result[sem] = "Fehler";
|
|
||||||
|
|
||||||
GeneratedCourses.Remove((sem, inst));
|
|
||||||
remainingSemesterSlots++;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static string GenerateStatistics()
|
public static string GenerateStatistics()
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user