//[FUNCTION - DeepCopySingleSchedule] //Function is mainly the answer from the following post on how to copy a complex object //https://stackoverflow.com/questions/16696448/how-to-make-a-copy-of-an-object-in-c-sharp //Copies instance of a SingleCourse Object into an identical new object public static SingleSchedule DeepCopySingleSchedule(SingleSchedule other) { using (MemoryStream ms = new MemoryStream()) { BinaryFormatter formatter = new BinaryFormatter(); formatter.Serialize(ms, other); ms.Position = 0; return((SingleSchedule)formatter.Deserialize(ms)); } }
public OptimizationSettingsForm(SingleSchedule oldSchedule, CourseSelectionForm CourseSelectForm, LoadingResultsForm LoadResultsForm) { //Build references RefToCourseSelectForm = CourseSelectForm; RefToLoadResultsForm = LoadResultsForm; this.oldSchedule = oldSchedule; InitializeComponent(); UpdateCheckBoxes(oldSchedule); }
public void UpdateCheckBoxes(SingleSchedule oldSchedule) { //Remove last checkboxes foreach (var cb in allCB) { this.Controls.Remove(cb); } allCB = new List <CheckBox>(); //causes bug if just clear this.oldSchedule = oldSchedule; //Find checkbox apperence info // - color // - overlap amount int courseAmount = oldSchedule.getAllSections().Count(); List <int> amountOverlap = new List <int>(courseAmount); for (int i = 0; i < courseAmount; i++) { amountOverlap.Add(0); } foreach (var day in oldSchedule.getAllDays()) { foreach (var timeSlot in day.getDayTimes()) { if (timeSlot.getOverlapState() == true) { amountOverlap[timeSlot.getSectionID()]++; } } } //Create new checkboxes int locationCounter = 0; foreach (var section in oldSchedule.getAllSections()) { allCB.Add(new CheckBox()); allCB[allCB.Count() - 1].Location = new Point(70, 120 + (locationCounter * 25)); allCB[allCB.Count() - 1].Text = section.getID().Substring(0, section.getID().IndexOf("-", 4)) + " | " + section.getCourseName() + " | Overlaps: " + amountOverlap[locationCounter]; if (amountOverlap[locationCounter] > 0) { allCB[allCB.Count() - 1].ForeColor = Color.Red; } else { allCB[allCB.Count() - 1].ForeColor = Color.Green; } allCB[allCB.Count() - 1].Size = new Size(500, 20); this.Controls.Add(allCB[allCB.Count() - 1]); locationCounter++; } }
//[FUNCTION - ChooseOptimizationCourses] //Adds sections that can be substituted based on user defined settings (revise so courses fit better) public void ChooseOptimizationCourses(List <bool> canOptimize, SingleSchedule oldSchedule, LoadingResultsForm ScheduleSelectForm) { //Create copy of selected courses & set optimization state RefToScheduleSelectForm = ScheduleSelectForm; List <SingleCourse> selectedCoursesMod = new List <SingleCourse>(selectedCourses.Count()); foreach (var course in selectedCourses) { selectedCoursesMod.Add(DeepCopySingleCourse(course)); } isOptimization = true; //Add all similar courses to section list (revise to get more accurate substitutions) int optimizeCounter = 0; foreach (var optimizeOption in canOptimize) { if (optimizeOption == true) { string matchCourseID = oldSchedule.getAllSections()[optimizeCounter].getID(); string matchCourseIDTrim = matchCourseID.Substring(0, matchCourseID.IndexOf("-", 4)); string depID = matchCourseID.Substring(0, matchCourseID.IndexOf("-", 0)); string levelID = matchCourseID.Substring((matchCourseID.IndexOf("-", 0) + 1), 1) + "00"; bool isLab = matchCourseIDTrim[matchCourseIDTrim.Length - 1] == 'L' ? true : false; Debug.WriteLine("Dep ID: " + depID + " | Level ID: " + levelID + " | Lab State: " + isLab); bool isLabCourse = false; foreach (var course in availableCourses) { isLabCourse = course.getAbrvCourseName()[course.getAbrvCourseName().Length - 1] == 'L' ? true : false; if ((course.getCourseLevel() == levelID && course.getAbrvCourseName().Contains(depID)) && (course.getAbrvCourseName() != matchCourseID.Substring(0, matchCourseID.IndexOf("-", 4))) && (isLab == isLabCourse)) { foreach (var section in course.getSections()) { Debug.WriteLine("Added a suggested section: " + section.getID()); selectedCoursesMod[optimizeCounter].getSections().Add(new SingleSection(section, true)); } } } } optimizeCounter++; } ComputeOptimalTimes(selectedCoursesMod); }