using Core.Entities; namespace Core.Calculation; /// /// Helper methods for calculating overlaps in team scheduling solutions. /// public static class OverlapCalculationHelper { /// /// Creates teams with excluded students and absent students filtered out for overlap calculation. /// /// The teams to filter /// The time slot index for exclusion lookups /// Dictionary of excluded students: key is (teamId, timeSlotIndex, studentId), value is true if excluded /// Set of absent student IDs to exclude from overlap calculations /// Teams with excluded and absent students removed public static Team[] GetTeamsWithoutExcludedStudents( Team[] teams, int timeSlotIndex, Dictionary<(int teamId, int timeSlotIndex, int studentId), bool> excludedStudents, HashSet absentStudentIds) { return teams.Select(team => { // Find excluded students for this team in this time slot // Also exclude absent students from overlap calculations var includedStudents = team.Students .Where(s => !IsStudentExcluded(team.Id, timeSlotIndex, s.Id, excludedStudents) && !absentStudentIds.Contains(s.Id)) .ToList(); // If no students are excluded, return original team if (includedStudents.Count == team.Students.Count) return team; // Create a temporary team with excluded and absent students removed return new Team { Id = team.Id, Event = team.Event, Students = includedStudents, Captain = team.Captain, Identifier = team.Identifier }; }).ToArray(); } private static bool IsStudentExcluded( int teamId, int timeSlotIndex, int studentId, Dictionary<(int teamId, int timeSlotIndex, int studentId), bool> excludedStudents) { var key = (teamId, timeSlotIndex, studentId); return excludedStudents.TryGetValue(key, out var isExcluded) && isExcluded; } }