public MasterSchema GenerateSchema(IMoodle moodle) { List <SchemaCourse> schemaCourses = new List <SchemaCourse>(); List <Lokale> allRooms = moodle.Rooms; //Set all the possible timeslots in all the rooms as free Dictionary <Lokale, List <LectureTime> > freeRoomTimes = new Dictionary <Lokale, List <LectureTime> >(); foreach (Lokale r in allRooms) { freeRoomTimes.Add(r, moodle.AllTimes()); } // make each course into a SchemaCourse, and remove the used lectureTimes from the room foreach (Kursus course in moodle.Courses) { // Get all the rooms with sufficient capacity, based on the total number of students taking the course List <Lokale> possibleRooms = FindPossibleRooms(course, allRooms); //A possible lecture time must have no teacher clash or hold clash. //We already know there is no room clash because we remove the used times from the room. Dictionary <Lokale, List <LectureTime> > possibleRoomTimes = FindPossibleRoomTimes(schemaCourses, course, freeRoomTimes, possibleRooms); //Filter the lecturetimes in the room to select only the preferred day(s)/time Dictionary <Lokale, List <LectureTime> > possibleRoomTimesFiltered = filterPossibleRoomTimes(possibleRoomTimes, course); //Select those rooms where the number of possible lecturetimes is enough for the total number of modules in the course List <Lokale> possibleRoomsWithEnoughLectureTimes = FindPossibleRoomsWithEnoughLectureTimes(possibleRoomTimesFiltered, course); Lokale selectedRoom; try { // the selected room is the first room on the list selectedRoom = possibleRoomsWithEnoughLectureTimes.First(); } catch { throw new ExceptionSchemaPlanning(course); } //Select a list of lecturetimes to be used in the selected room List <LectureTime> selectedLectureTimes = SelectLectureTimes(course, possibleRoomTimesFiltered[selectedRoom]); // create a new SchemaCourse and add it to the list of already planned schemacourses. schemaCourses.Add(new SchemaCourse() { Course = course, Place = selectedRoom, LectureTimes = selectedLectureTimes }); // remove the used lecturetimes from the selected room. foreach (LectureTime lt in selectedLectureTimes) { freeRoomTimes[selectedRoom].Remove(lt); } } return(new MasterSchema() { SchemaCourse = schemaCourses }); }
public Kursus(string code, string name, int moduleCount, List <string> holdCodes, string teacherCode, List <DayOfWeek> inputPreferredDays, TimeOfDay inputTimeOfday, IMoodle moodle) { this.KursusKode = code; this.KursusName = name; this.HoldObjs = new List <Hold>(); foreach (string holdCode in holdCodes) { this.HoldObjs.Add(moodle.LookupHold(holdCode)); } this.ModuleCount = moduleCount; this.LaererObj = moodle.LookupTeacher(teacherCode); this.PreferredDays = new List <DayOfWeek>(); foreach (DayOfWeek prefDays in inputPreferredDays) { PreferredDays.Add(prefDays); } PreferredTimeOfday = inputTimeOfday; //this.PreferredDays = inputPreferredDays; //alternative way of setting the value of preferredDays }