Add a TimeSlot object, refactor
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
using Core.Entities;
|
||||
|
||||
namespace Core.Calculation;
|
||||
|
||||
public class TeamScheduleTimeSlot
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public Team[] Teams;
|
||||
public Student[] UnscheduledStudents;
|
||||
public IEnumerable<Tuple<Student, IEnumerable<Team>>> StudentOverlaps;
|
||||
|
||||
public bool StudentHasOverlaps(Student student)
|
||||
{
|
||||
return StudentOverlaps.FirstOrDefault(o => o.Item1.Equals(student)) != null;
|
||||
}
|
||||
}
|
||||
@@ -92,7 +92,7 @@ public class TeamScheduler
|
||||
var timeSlotTeams = new Team[_timeSlots.Length][];
|
||||
|
||||
if (cpSolverStatus is not (CpSolverStatus.Optimal or CpSolverStatus.Feasible))
|
||||
return new TeamSchedulerSolution(timeSlotTeams, cpSolverStatus.ToString());
|
||||
return new TeamSchedulerSolution(timeSlotTeams, _studentObjects.ToArray(), cpSolverStatus.ToString());
|
||||
|
||||
Debug.WriteLine($"Total cost: {solver.ObjectiveValue}\n");
|
||||
|
||||
@@ -102,6 +102,6 @@ public class TeamScheduler
|
||||
timeSlotTeams[s] = teams;
|
||||
}
|
||||
//Debug.WriteLine("No solution found.");
|
||||
return new TeamSchedulerSolution(timeSlotTeams, cpSolverStatus.ToString());
|
||||
return new TeamSchedulerSolution(timeSlotTeams, _studentObjects.ToArray(), cpSolverStatus.ToString());
|
||||
}
|
||||
}
|
||||
@@ -4,11 +4,18 @@ namespace Core.Calculation;
|
||||
|
||||
public class TeamSchedulerSolution(
|
||||
Team[][] timeSlots,
|
||||
Student[] students,
|
||||
string status)
|
||||
{
|
||||
public Team[][] TimeSlots { get; set; } = timeSlots;
|
||||
public string Status { get; set; } = status;
|
||||
public string Status { get; } = status;
|
||||
|
||||
public TeamScheduleTimeSlot[] TimeSlots { get; set; }
|
||||
= timeSlots.Select( (teams,i) =>
|
||||
new TeamScheduleTimeSlot{Name = i.ToString(), Teams = teams,
|
||||
StudentOverlaps = GetStudentTeamOverlaps(teams),
|
||||
UnscheduledStudents = GetStudentsNotInTimSlot(teams, students)
|
||||
}
|
||||
).ToArray();
|
||||
|
||||
public static int GetStudentTeamOverlapCount(Team[][] timeSlots)
|
||||
{
|
||||
@@ -30,7 +37,6 @@ public class TeamSchedulerSolution(
|
||||
select Tuple.Create(gs.First(), gs.Key);
|
||||
}
|
||||
|
||||
|
||||
public static Student[] GetStudentsNotInTimSlot(Team[] timeSlot, Student[] students)
|
||||
{
|
||||
var studentsInTimeSlot = timeSlot.SelectMany(ts => ts.Students).Distinct();
|
||||
@@ -39,12 +45,11 @@ public class TeamSchedulerSolution(
|
||||
where studentsInTimeSlot.FirstOrDefault(e => e.Equals(allStudent)) == null
|
||||
select allStudent
|
||||
).ToArray();
|
||||
|
||||
}
|
||||
|
||||
public Team[] StudentUnassignedTeams(Student student)
|
||||
{
|
||||
var meetingTeams = TimeSlots.SelectMany(t => t);
|
||||
var meetingTeams = TimeSlots.SelectMany(t => t.Teams);
|
||||
return
|
||||
student.Teams.Where(e => !meetingTeams.Contains(e)).ToArray();
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ public class TeamScheduler_DecisionTree
|
||||
|
||||
timeSlots[overlaps.First().Item1].Add(team);
|
||||
}
|
||||
return new TeamSchedulerSolution(timeSlots.Select(e => e.ToArray()).ToArray(), "Success?");
|
||||
return new TeamSchedulerSolution(timeSlots.Select(e => e.ToArray()).ToArray(), [], "Success?");
|
||||
}
|
||||
|
||||
//public Team[][] SolveRecursive()
|
||||
|
||||
@@ -5,13 +5,17 @@ namespace Core.Calculation;
|
||||
public class UnassignedStudentScheduler
|
||||
{
|
||||
private readonly Student[] _students;
|
||||
private readonly Team[] _teams;
|
||||
private readonly Team[] _allTeams;
|
||||
private readonly IList<Team>[] _timeSlots;
|
||||
|
||||
public UnassignedStudentScheduler(Team[] teams, Team[][] timeslots)
|
||||
public UnassignedStudentScheduler(Team[] allTeams, TeamScheduleTimeSlot[] timeslots)
|
||||
: this(allTeams, timeslots.Select(e => e.Teams).ToArray())
|
||||
{ }
|
||||
|
||||
public UnassignedStudentScheduler(Team[] allTeams, Team[][] timeslots)
|
||||
{
|
||||
_teams = teams;
|
||||
_students = teams.SelectMany(t => t.Students).Distinct().ToArray();
|
||||
_allTeams = allTeams;
|
||||
_students = allTeams.SelectMany(t => t.Students).Distinct().ToArray();
|
||||
_timeSlots = timeslots.Select(ts => ts.Select(t => t.Clone()).ToList()).ToArray<IList<Team>>();
|
||||
}
|
||||
public static IEnumerable<Student> UnassignedStudents(IList<Student> students, IList<Team> timeSlot)
|
||||
@@ -68,7 +72,7 @@ public class UnassignedStudentScheduler
|
||||
// find teams where several unassigned students can work together
|
||||
private IEnumerable<Team> GetAvailableTeams_BiggestGroup(
|
||||
IEnumerable<Team> scheduledTeams, IEnumerable<Student> assignedStudents) =>
|
||||
_teams
|
||||
_allTeams
|
||||
.Where(t => scheduledTeams.All(st => st.Id != t.Id))
|
||||
.Select(t => t.CloneWithOmittedStudents(assignedStudents))
|
||||
.Where(t => t.Students.Count > 1) //|| t.Event.EventFormat is EventFormat.Individual
|
||||
@@ -79,7 +83,7 @@ public class UnassignedStudentScheduler
|
||||
// find individual events unassigned students can work on
|
||||
private IEnumerable<Team> GetAvailableTeams_Individual(
|
||||
IEnumerable<Team> scheduledTeams, IEnumerable<Student> assignedStudents) =>
|
||||
_teams
|
||||
_allTeams
|
||||
.Where(t => scheduledTeams.All(st => st.Id != t.Id))
|
||||
.Where(t => t.Event.EventFormat == EventFormat.Individual || t.Students.Count == 1)
|
||||
.Select(t => t.CloneWithOmittedStudents(assignedStudents))
|
||||
@@ -88,14 +92,14 @@ public class UnassignedStudentScheduler
|
||||
// find any unassigned eventDefinition students can work on
|
||||
private IEnumerable<Team> GetAvailableTeams_AnyNotMeetingAlready(
|
||||
IEnumerable<Team> scheduledTeams, IEnumerable<Student> assignedStudents) =>
|
||||
_teams
|
||||
_allTeams
|
||||
.Where(t => scheduledTeams.All(st => st.Id != t.Id))
|
||||
.Select(t => t.CloneWithOmittedStudents(assignedStudents))
|
||||
.Where(t => t.Students.Count > 0);
|
||||
|
||||
private IEnumerable<Team> GetAvailableTeams_Any(
|
||||
IEnumerable<Team> scheduledTeams, IEnumerable<Student> assignedStudents) =>
|
||||
_teams
|
||||
_allTeams
|
||||
.Select(t => t.CloneWithOmittedStudents(assignedStudents))
|
||||
.Where(t => t.Students.Count > 0);
|
||||
|
||||
@@ -103,7 +107,7 @@ public class UnassignedStudentScheduler
|
||||
// find teams where several unassigned students can work together
|
||||
private IEnumerable<Team> GetAvailableTeams_LevelOfEffort(
|
||||
IEnumerable<Team> scheduledTeams, IEnumerable<Student> assignedStudents) =>
|
||||
_teams
|
||||
_allTeams
|
||||
.Where(t => scheduledTeams.All(st => st.Id != t.Id))
|
||||
.Select(t => t.CloneWithOmittedStudents(assignedStudents))
|
||||
.Where(t => t.Students.Count > 1) //|| t.Event.EventFormat is EventFormat.Individual
|
||||
|
||||
Reference in New Issue
Block a user