Team scheduler now considers all available students

This commit is contained in:
2025-11-23 11:05:29 -05:00
parent 87be3e9c68
commit 72da28992f
5 changed files with 19 additions and 9 deletions
+7 -5
View File
@@ -14,10 +14,11 @@ public class TeamScheduler
private readonly List<Tuple<int,int>> _scheduleSeparateTeams = [];
public TeamScheduler(IEnumerable<Team> teams, int numTimeSlots)
public TeamScheduler(IEnumerable<Team> teams, int numTimeSlots, IEnumerable<Student> allStudents)
{
_teamObjects = teams.ToArray();
_studentObjects = teams.SelectMany(t => t.Students).Distinct().ToList();
//_studentObjects = teams.SelectMany(t => t.Students).Distinct().ToList();
_studentObjects = allStudents.ToList();
_students = Enumerable.Range(0, _studentObjects.Count).ToArray();
_teams = Enumerable.Range(0, _teamObjects.Count).ToArray();
@@ -31,9 +32,9 @@ public class TeamScheduler
_scheduleSeparateTeams.Add(Tuple.Create(one,two));
}
public static TeamScheduler CreateInstance(IEnumerable<Team> teams, int numTimeSlots)
public static TeamScheduler CreateInstance(IEnumerable<Team> teams, int numTimeSlots, IEnumerable<Student> allStudents)
{
return new TeamScheduler(teams, numTimeSlots);
return new TeamScheduler(teams, numTimeSlots, allStudents);
}
public TeamSchedulerSolution Solve()
@@ -94,13 +95,14 @@ public class TeamScheduler
if (cpSolverStatus is not (CpSolverStatus.Optimal or CpSolverStatus.Feasible))
return new TeamSchedulerSolution(timeSlotTeams, _studentObjects.ToArray(), cpSolverStatus.ToString());
Debug.WriteLine($"Total cost: {solver.ObjectiveValue}\n");
// Debug.WriteLine($"Total cost: {solver.ObjectiveValue}\n");
foreach (var s in _timeSlots)
{
var teams = (from t in _teams where solver.Value(x[t, s]) > 0 select _teamObjects[t]).ToArray();
timeSlotTeams[s] = teams;
}
//Debug.WriteLine("No solution found.");
return new TeamSchedulerSolution(timeSlotTeams, _studentObjects.ToArray(), cpSolverStatus.ToString());
}