static public ScheduleOptions GenerateSchedules(Sequence seq, int semester, int year) { int s2 = semester + 1; int y2 = year; if (s2 > 5) { s2 = 2; y2++; } List <Course> semester1 = new List <Course>(); List <Course> semester2 = new List <Course>(); Hashtable semester1_sec = new Hashtable(); List <Section> semester1_c1 = new List <Section>(); List <Section> semester1_c2 = new List <Section>(); List <Section> semester1_c3 = new List <Section>(); List <Section> semester1_c4 = new List <Section>(); List <Section> semester1_c5 = new List <Section>(); semester1_sec[0] = semester1_c1; semester1_sec[1] = semester1_c2; semester1_sec[2] = semester1_c3; semester1_sec[3] = semester1_c4; semester1_sec[4] = semester1_c5; Hashtable semester2_sec = new Hashtable(); List <Section> semester2_c1 = new List <Section>(); List <Section> semester2_c2 = new List <Section>(); List <Section> semester2_c3 = new List <Section>(); List <Section> semester2_c4 = new List <Section>(); List <Section> semester2_c5 = new List <Section>(); semester2_sec[0] = semester2_c1; semester2_sec[1] = semester2_c2; semester2_sec[2] = semester2_c3; semester2_sec[3] = semester2_c4; semester2_sec[4] = semester2_c5; int[] course1 = new int[5]; int[] course2 = new int[5]; Course tmp; int tmpInt; List <Section> tmpList = new List <Section>(); int i = 0; ScheduleTable scT = new ScheduleTable(); Boolean approved = false; Section General_Elective = new Section(); General_Elective.CourseID = 111111; Section Basic_Science = new Section(); Basic_Science.CourseID = 222222; Section Elective = new Section(); Elective.CourseID = 333333; Section EmptySection = new Section(); while (i < 5) { tmp = seq.sequence[year, semester, i]; semester1.Add(tmp); if (tmp == null) { tmpList = (List <Section>)semester1_sec[i]; tmpList.Add(EmptySection); } else if (tmp.CourseID == 111111 || tmp.CourseID == 222222 || tmp.CourseID == 333333) { tmpList = (List <Section>)semester1_sec[i]; if (tmp.CourseID == 111111) { tmpList.Add(General_Elective); } else if (tmp.CourseID == 222222) { tmpList.Add(Basic_Science); } else if (tmp.CourseID == 333333) { tmpList.Add(Elective); } course1[i] = tmp.CourseID; } else { course1[i] = tmp.CourseID; } i++; } i = 0; while (i < 5) { tmp = seq.sequence[y2, s2, i]; semester2.Add(tmp); if (tmp == null) { tmpList = (List <Section>)semester2_sec[i]; tmpList.Add(EmptySection); } else if (tmp.CourseID == 111111 || tmp.CourseID == 222222 || tmp.CourseID == 333333) { tmpList = (List <Section>)semester2_sec[i]; if (tmp.CourseID == 111111) { tmpList.Add(General_Elective); } else if (tmp.CourseID == 222222) { tmpList.Add(Basic_Science); } else if (tmp.CourseID == 333333) { tmpList.Add(Elective); } course2[i] = tmp.CourseID; } else { course2[i] = tmp.CourseID; } i++; } i = 0; Schedule schedule = new Schedule(); List <Section> items = DBInterfacer.GetSections(); foreach (Section item in items) { if (item.Availability == semester && Array.IndexOf(course1, item.CourseID) != -1) { tmpInt = item.CourseID; tmpInt = Array.IndexOf(course1, tmpInt); tmpList = (List <Section>)semester1_sec[tmpInt]; tmpList.Add(item); } if (item.Availability == s2 && Array.IndexOf(course2, item.CourseID) != -1) { tmpInt = item.CourseID; tmpInt = Array.IndexOf(course2, tmpInt); tmpList = (List <Section>)semester2_sec[tmpInt]; tmpList.Add(item); } } foreach (Section a in semester1_c1) { foreach (Section b in semester1_c2) { foreach (Section c in semester1_c3) { foreach (Section d in semester1_c4) { foreach (Section e in semester1_c5) { approved = checkSection(a, b, c, d, e); if (approved == true) { approvedSchedule(1, ref scT, a, b, c, d, e); } } } } } } foreach (Section a in semester2_c1) { foreach (Section b in semester2_c2) { foreach (Section c in semester2_c3) { foreach (Section d in semester2_c4) { foreach (Section e in semester2_c5) { approved = checkSection(a, b, c, d, e); if (approved == true) { approvedSchedule(2, ref scT, a, b, c, d, e); } } } } } } i = 0; ScheduleOptions op = new ScheduleOptions(scT.sem1.Count, scT.sem2.Count); foreach (Schedule s in scT.sem1) { op.scheduleOptions[0][i, 0] = s.schedule[0]; op.scheduleOptions[0][i, 1] = s.schedule[1]; op.scheduleOptions[0][i, 2] = s.schedule[2]; op.scheduleOptions[0][i, 3] = s.schedule[3]; op.scheduleOptions[0][i, 4] = s.schedule[4]; i++; } i = 0; foreach (Schedule s in scT.sem2) { op.scheduleOptions[1][i, 0] = s.schedule[0]; op.scheduleOptions[1][i, 1] = s.schedule[1]; op.scheduleOptions[1][i, 2] = s.schedule[2]; op.scheduleOptions[1][i, 3] = s.schedule[3]; op.scheduleOptions[1][i, 4] = s.schedule[4]; i++; } return(op); }
public static Sequence GenerateSequence(Student student, int semester_int, int summer_bool) { Course[,,] sequence = new Course[6, 6, 5]; int[] engr = { 68, 69, 70, 71 }; List <int> engr2 = engr.OfType <int>().ToList(); int[] soen = { 84, 85 }; List <int> soen2 = soen.OfType <int>().ToList(); int[] comp = { 77, 78, 79 }; List <int> comp2 = comp.OfType <int>().ToList(); int i = 0, j = 0, k = 0; int general_elective = 1; int science = 2; int elective = 5; int[] student_p = { 96, 93, 91, 90, 88, 89 }; // This will be default, but we can change these to student preference. Hashtable important = new Hashtable(); Course General_Elective = new Course(); General_Elective.CourseID = 111111; General_Elective.CourseName = "General Elective"; Course Basic_Science = new Course(); Basic_Science.CourseID = 222222; Basic_Science.CourseName = "Basic Science"; Course Elective = new Course(); Elective.CourseID = 333333; Elective.CourseName = "Elective Based on Option"; bool chk = false; //ignore option//int tech_elective = 2; string student_Option = student.Record.Option; List <Student.AcademicRecord> academicRecords; List <Course> items; String[] student_Completed = null; if (student.Record.CompletedCourses != null) { student_Completed = student.Record.CompletedCourses.Split('/'); } if (student.SavedPreferences.priorityCourse != String.Empty) { student_p = student.SavedPreferences.priorityCourse.Split('/').Select(pref => Int32.Parse(pref)).ToArray(); } bool approved = false; items = DBInterfacer.GetCourses(); String[] copyCompleted = new String[student_Completed.Length]; Array.Copy(student_Completed, copyCompleted, student_Completed.Length); Hashtable neededCourses = new Hashtable(); Hashtable allCourses = new Hashtable(); foreach (var item in items) { allCourses.Add(item.CourseID, item); if (item.CourseType == "Eng Core" || item.CourseType == "Comp-Sci" || item.CourseType == "Software Eng Core") { int tmp = Array.IndexOf(copyCompleted, item.CourseID.ToString()); if (tmp == -1) { neededCourses.Add(item.CourseID, item); if (Array.IndexOf(student_p, item.CourseID) != -1) { important.Add(item.CourseID, item); } } else { copyCompleted[tmp] = null; if (soen2.Contains(item.CourseID)) { soen2.Remove(item.CourseID); } else if (engr2.Contains(item.CourseID)) { engr2.Remove(item.CourseID); } else if (comp2.Contains(item.CourseID)) { comp2.Remove(item.CourseID); } } } } int c = 0; Course tmp_cse; String wut; while (c < copyCompleted.Length) { if (copyCompleted[c] != null) { i = 0; Int32.TryParse(copyCompleted[c], out i); tmp_cse = (Course)allCourses[i]; if (tmp_cse != null) { wut = tmp_cse.CourseType; if (wut == "General Elective") { general_elective--; } else if (wut == "Basic Science") { science--; } else //ignore option// { elective--; } } } c++; } //begining of sequencer // i: semester, j:year k: courses(sequence) //i = 0 online,1 fall/winter,2 fall,3 winter,4 summer1, 5 summer2 -- assume the student generate sequence for september //j= 0 current year i = semester_int; j = 0; k = 0; Course tmpCourse2; int z; int loopTwice = 0; Course tmpCourse; bool ready = false; int cr, ci; String[] co_req = new String[0]; int counter = 0; Course co = null; int loopC = 0; bool abc = true; int[] removeA = new int[5]; Course priority; List <String> complst = student_Completed.OfType <String>().ToList(); while (general_elective != 0 || science != 0 || elective != 0 || neededCourses.Count != 0) { //Console.WriteLine(general_elective + " " + science + " " + elective + " " + neededCourses.Count); loopTwice = 0; loopC = 0; while (loopC < 20) { abc = true; while (loopTwice < 2) { ci = 0; foreach (int key in important.Keys) { priority = (Course)important[key]; if (complst.Contains(priority.CourseID.ToString()) == false && Array.IndexOf(removeA, priority.CourseID) == -1) { approved = verifyPrereq(priority, i, complst, engr2, comp2, soen2, removeA); if (approved == false) { if (priority.Corequisites != null) { co_req = priority.Corequisites.Split('/'); cr = co_req.Length; } else { cr = 0; } foreach (String cor in co_req) { Int32.TryParse(cor, out z); tmpCourse = (Course)allCourses[z]; if (complst.Contains(tmpCourse.CourseID.ToString()) == false) { approved = verifyPrereq(tmpCourse, i, complst, engr2, comp2, soen2, removeA); if (approved != true) { approved = false; break; } } } if (approved == true && k + cr + 2 < 4 && i != 4 && i != 5) { foreach (String cor in co_req) { Int32.TryParse(cor, out z); tmpCourse = (Course)allCourses[z]; if (complst.Contains(tmpCourse.CourseID.ToString()) == false) { sequence[j, i, k] = tmpCourse; removeA[k] = tmpCourse.CourseID; loopC = 0; k++; if (tmpCourse.CourseID == 89) { tmpCourse2 = (Course)allCourses[90]; sequence[j, i, k] = tmpCourse2; removeA[k] = tmpCourse2.CourseID; loopC = 0; k++; if (neededCourses.ContainsKey(tmpCourse2.CourseID)) { neededCourses.Remove(tmpCourse2.CourseID); } } if (neededCourses.ContainsKey(tmpCourse.CourseID)) { neededCourses.Remove(tmpCourse.CourseID); } } } sequence[j, i, k] = priority; removeA[k] = priority.CourseID; loopC = 0; k++; if (neededCourses.ContainsKey(priority.CourseID)) { neededCourses.Remove(priority.CourseID); } } } else if (approved == true) { sequence[j, i, k] = priority; removeA[k] = priority.CourseID; loopC = 0; k++; if (neededCourses.ContainsKey(priority.CourseID)) { neededCourses.Remove(priority.CourseID); } if (((priority.CourseID == 91 && Array.IndexOf(removeA, 93) != -1) || (priority.CourseID == 93 && Array.IndexOf(removeA, 91) != -1) && k + 1 < 4 && i != 4 && i != 5)) { tmpCourse = (Course)allCourses[96]; sequence[j, i, k] = tmpCourse; removeA[k] = tmpCourse.CourseID; loopC = 0; k++; if (neededCourses.ContainsKey(tmpCourse.CourseID)) { neededCourses.Remove(tmpCourse.CourseID); } } if (priority.CourseID == 89 && k + 1 < 4 && i != 4 && i != 5) { tmpCourse = (Course)allCourses[90]; sequence[j, i, k] = tmpCourse; removeA[k] = tmpCourse.CourseID; loopC = 0; k++; if (neededCourses.ContainsKey(tmpCourse.CourseID)) { neededCourses.Remove(tmpCourse.CourseID); } } if (i == 4 || i == 5) { if (k >= 1) { break; } } if (k >= 4) { break; } } } } foreach (int key in neededCourses.Keys) { co = (Course)neededCourses[key]; approved = false; c = 0; if (Array.IndexOf(removeA, co.CourseID) == -1) { approved = verifyPrereq(co, i, complst, engr2, comp2, soen2, removeA); if (approved == true) { sequence[j, i, k] = co; removeA[k] = co.CourseID; if (important.ContainsKey(co.CourseID)) { important.Remove(co.CourseID); } loopC = 0; k++; if (i == 4 || i == 5) { if (k >= 1) { break; } } if (k >= 4 && (science != 0 || general_elective != 0)) { break; } else if (k > 4) { break; } } } } if (k < 4 && loopTwice == 0) { loopTwice++; } else { break; } } while (abc == true) { chk = false; if ((i == 2 || i == 3) && k < 5) { if (general_elective > 0 || science > 0 || elective > 0) { if (general_elective > 0 && i != 0 && i != 1) { general_elective--; sequence[j, i, k] = General_Elective; chk = true; } else if (science > 0 && i != 0 && i != 1) { science--; sequence[j, i, k] = Basic_Science; chk = true; } else if (elective > 0 && i != 0 && i != 1 && i != 4 && i != 5 && engr2.Any() == false && comp2.Any() == false && soen2.Any() == false) { elective--; sequence[j, i, k] = Elective; chk = true; } else { abc = false; } if (chk == true) { k++; loopC = 0; if (k > 4) { abc = false; } } } else { abc = false; } } else if ((i == 4 || i == 5) && k < 2) { if (general_elective > 0 || science > 0) { if (general_elective > 0 && i != 0 && i != 1) { general_elective--; sequence[j, i, k] = General_Elective; chk = true; } else if (science > 0 && i != 0 && i != 1) { science--; sequence[j, i, k] = Basic_Science; chk = true; } if (chk == true) { k++; loopC = 0; if (k >= 1) { abc = false; } } } else { abc = false; } } else { abc = false; } } if (i == 4 || i == 5) { if (k >= 1) { break; } } if (k >= 4) { break; } loopC++; } k = 0; i++; if (summer_bool == 0) { if (i > 3) { i = 0; j++; if (j > 5) { break; } } } else { if (i > 5) { i = 0; j++; if (j > 5) { break; } } } counter = 0; while (counter < 5) { neededCourses.Remove(removeA[counter]); complst.Add(removeA[counter].ToString()); if (soen2.Contains(removeA[counter])) { soen2.Remove(removeA[counter]); } else if (engr2.Contains(removeA[counter])) { engr2.Remove(removeA[counter]); } else if (comp2.Contains(removeA[counter])) { comp2.Remove(removeA[counter]); } if (important.ContainsKey(removeA[counter])) { important.Remove(removeA[counter]); } counter++; } } counter = 0; Sequence seq = new Sequence(); seq.sequence = sequence; return(seq); }