public Population(int[] i_arrayOfCoursesNumber, List<List<CourseBlock>> i_ListBlock, Student i_Student) { m_Vectors = new List<VectorOfCourses>(); for (; m_SizeOfVector < k_PopulationMaxSize; m_SizeOfVector++) { m_Vectors.Add(new VectorOfCourses(i_arrayOfCoursesNumber, i_ListBlock, i_Student)); } }
public VectorOfCourses(int[] i_arrayOfNumberOfCourses, List<List<CourseBlock>> i_BlockList, Student i_Student) { //MySqlConnection conn = null; //MySqlDataReader rdr = null; //List<int> testlist = new List<int>(); int[] rand; m_Vector = new List<CourseBlock>(); int count = 0; for (; count < i_Student.numberOfRequiredCourseTheStudentWantToTake; count++) { //testlist.Add(rnd.Next(i_BlockList[count].Count)); ; CourseBlock newBlock = new CourseBlock(i_BlockList[count][rnd.Next(i_BlockList[count].Count)]); m_Vector.Add(newBlock); } selectRandomCoursesPositions(i_Student.numberOfElectiveCourseTheStudentWantToTake, out rand); for (count = 0; count < i_Student.numberOfElectiveCourseTheStudentWantToTake; count++) { CourseBlock newBlock = new CourseBlock(i_BlockList[i_Student.numberOfRequiredCourseTheStudentWantToTake + rand[count]][rnd.Next(i_BlockList[i_Student.numberOfRequiredCourseTheStudentWantToTake + rand[count]].Count)]); m_Vector.Add(newBlock); } rateVector(i_Student); }
public GeneticAlgorithm(int i_studentId, int i_numberOfRequireds, int i_numberOfElectives) { int i; m_OrderList = new List<VectorOfCourses>(); m_Fathers = new List<VectorOfCourses>(); m_Student = new Student(i_studentId); m_Student.numberOfElectiveCourseTheStudentWantToTake = i_numberOfElectives; m_Student.numberOfRequiredCourseTheStudentWantToTake = i_numberOfRequireds; m_ArrayOfCourses = m_Student.modifyArrayOfCourses(i_numberOfRequireds); m_arrayOfCoursesNumbers = m_Student.modifyNumbersOfCoursesToArray(m_ArrayOfCourses); UpdateDataOfBlocksFromDB(); m_Population = new Population(m_arrayOfCoursesNumbers, courseBlockDB, m_Student); updateFatherList(m_Population.Vectors); crossOverFatherList(m_Fathers); for (i = 0; i < 3; i++) { updateFatherList(m_Fathers); crossOverFatherList(m_Fathers); } m_OrderList = m_Fathers.OrderBy(VectorOfCourses => VectorOfCourses.Rate).ToList(); removeDuplicateVectors(m_OrderList, ref m_OrderList); }
private void comboBoxUdersID_SelectedIndexChanged(object sender, EventArgs e) { /* string screenView = ""; buttonOK.Enabled = true; Student newStudent = new Student(int.Parse(comboBoxUdersID.Text)); screenView = string.Format(@"Student preferences are (Start hour at, Windows, Starting after hour, Is study at day): Sunday: {0}, {6}, {12}, {18} Monday: {1}, {7}, {13}, {19} Tuesday: {2}, {8}, {14}, {20} Wednesday: {3}, {9}, {15}, {21} Thursday: {4}, {10}, {16}, {22} Friday: {5}, {11}, {17}, {23}", newStudent.StartHourPreferenceList[0], newStudent.StartHourPreferenceList[1], newStudent.StartHourPreferenceList[2], newStudent.StartHourPreferenceList[3], newStudent.StartHourPreferenceList[4], newStudent.StartHourPreferenceList[5], newStudent.WindowsPreferenceList[0], newStudent.WindowsPreferenceList[1], newStudent.WindowsPreferenceList[2], newStudent.WindowsPreferenceList[3], newStudent.WindowsPreferenceList[4], newStudent.WindowsPreferenceList[5], newStudent.StartingAfterHourPreferenceList[0], newStudent.StartingAfterHourPreferenceList[1], newStudent.StartingAfterHourPreferenceList[2], newStudent.StartingAfterHourPreferenceList[3], newStudent.StartingAfterHourPreferenceList[4], newStudent.StartingAfterHourPreferenceList[5], newStudent.StudyDaysPreferenceList[0], newStudent.StudyDaysPreferenceList[1], newStudent.StudyDaysPreferenceList[2], newStudent.StudyDaysPreferenceList[3], newStudent.StudyDaysPreferenceList[4], newStudent.StudyDaysPreferenceList[5]); PreferenceLabel.Text = screenView; */ // NEW buttonOK.Enabled = true; Student newStudent = new Student(int.Parse(comboBoxUdersID.Text)); for (int i = 0; i < 6; i++) { PopualtePrefLabels(newStudent, i, this.LabelsMapping[i][0], this.LabelsMapping[i][1], this.LabelsMapping[i][2], this.LabelsMapping[i][3]); } }
private void StylizeLabelByPref(Label label, Student.ePreferences pref) { label.Font = new Font(label.Font, pref != Student.ePreferences.noPreference ? FontStyle.Bold : FontStyle.Regular); label.ForeColor = pref == Student.ePreferences.noPreference ? Color.LightGray : Color.Black; }
/// <summary> /// Populates the given labels with representative strings of the users preferences. /// </summary> /// <param name="student">The student to dispaly preferences of.</param> /// <param name="dayOfTheWeek">An integer indicating the day of the weeks (1-6).</param> /// <param name="windowsLabel">A label to display "Windows" preference.</param> /// <param name="startAtLabel">A label to display "Start At" preference.</param> /// <param name="startBeforeLabel">A label to display "Start Before" preference.</param> /// <param name="studyAtLabel">A label to display "Study At Day" preference.</param> private void PopualtePrefLabels(Student student, int dayOfTheWeek, Label windowsLabel, Label startAtLabel, Label startBeforeLabel, Label studyAtLabel) { if (windowsLabel != null) { Student.ePreferences windowsPref = student.WindowsPreferenceList[dayOfTheWeek]; windowsLabel.Text = windowsPref.RepresentativeStringOf(); StylizeLabelByPref(windowsLabel, windowsPref); } if (startAtLabel != null) { Student.ePreferences startAtPref = student.StartHourPreferenceList[dayOfTheWeek]; startAtLabel.Text = startAtPref.RepresentativeStringOf(); StylizeLabelByPref(startAtLabel, startAtPref); } if (startBeforeLabel != null) { Student.ePreferences startBeforePref = student.StartingAfterHourPreferenceList[dayOfTheWeek]; startBeforeLabel.Text = startBeforePref.RepresentativeStringOf(); StylizeLabelByPref(startBeforeLabel, startBeforePref); } if (studyAtLabel != null) { Student.ePreferences studyAtPref = student.StudyDaysPreferenceList[dayOfTheWeek]; studyAtLabel.Text = studyAtPref.RepresentativeStringOf(); StylizeLabelByPref(studyAtLabel, studyAtPref); } }
private bool isStarting(int i_Day, Student.ePreferences i_Preferences) { int startingAt = staringTimeToInt(i_Preferences); int i = 0; bool result = false; for (; i < k_MaximumNumberOfCourses; i++) { if (m_Vector[i].StartTimeSlotOfFirstClass != -1) { switch (i_Day) { case 0: if (m_Vector[i].StartTimeSlotOfFirstClass != -1) { if ((m_Vector[i].StartTimeSlotOfFirstClass > startingAt * 4) && (m_Vector[i].StartTimeSlotOfFirstClass <= (startingAt + 1) * 4)) { result = true; } } if (m_Vector[i].StartTimeSlotOfSecondClass != -1) { if ((m_Vector[i].StartTimeSlotOfSecondClass > startingAt * 4) && (m_Vector[i].StartTimeSlotOfSecondClass <= (startingAt + 1) * 4)) { result = true; } } if (m_Vector[i].StartTimeSlotOfThirdClass != -1) { if ((m_Vector[i].StartTimeSlotOfThirdClass > startingAt * 4) && (m_Vector[i].StartTimeSlotOfThirdClass <= (startingAt + 1) * 4)) { result = true; } } break; case 1: if (m_Vector[i].StartTimeSlotOfFirstClass != -1) { if ((m_Vector[i].StartTimeSlotOfFirstClass > ((startingAt * 4)+52)) && (m_Vector[i].StartTimeSlotOfFirstClass <= (((startingAt+1) * 4)+52))) { result = true; } } if (m_Vector[i].StartTimeSlotOfSecondClass != -1) { if ((m_Vector[i].StartTimeSlotOfSecondClass > ((startingAt * 4) + 52)) && (m_Vector[i].StartTimeSlotOfSecondClass <= (((startingAt + 1) * 4) + 52))) { result = true; } } if (m_Vector[i].StartTimeSlotOfThirdClass != -1) { if ((m_Vector[i].StartTimeSlotOfThirdClass > ((startingAt * 4) + 52)) && (m_Vector[i].StartTimeSlotOfThirdClass <= (((startingAt + 1) * 4) + 52))) { result = true; } } break; case 2: if (m_Vector[i].StartTimeSlotOfFirstClass != -1) { if ((m_Vector[i].StartTimeSlotOfFirstClass > ((startingAt * 4) + 104)) && (m_Vector[i].StartTimeSlotOfFirstClass <= (((startingAt + 1) * 4) + 104))) { result = true; } } if (m_Vector[i].StartTimeSlotOfSecondClass != -1) { if ((m_Vector[i].StartTimeSlotOfSecondClass > ((startingAt * 4) + 104)) && (m_Vector[i].StartTimeSlotOfSecondClass <= (((startingAt + 1) * 4) + 104))) { result = true; } } if (m_Vector[i].StartTimeSlotOfThirdClass != -1) { if ((m_Vector[i].StartTimeSlotOfThirdClass > ((startingAt * 4) + 104)) && (m_Vector[i].StartTimeSlotOfThirdClass <= (((startingAt + 1) * 4) + 104))) { result = true; } } break; case 3: if (m_Vector[i].StartTimeSlotOfFirstClass != -1) { if ((m_Vector[i].StartTimeSlotOfFirstClass > ((startingAt * 4) + 156)) && (m_Vector[i].StartTimeSlotOfFirstClass <= (((startingAt + 1) * 4) + 156))) { result = true; } } if (m_Vector[i].StartTimeSlotOfSecondClass != -1) { if ((m_Vector[i].StartTimeSlotOfSecondClass > ((startingAt * 4) + 156)) && (m_Vector[i].StartTimeSlotOfSecondClass <= (((startingAt + 1) * 4) + 156))) { result = true; } } if (m_Vector[i].StartTimeSlotOfThirdClass != -1) { if ((m_Vector[i].StartTimeSlotOfThirdClass > ((startingAt * 4) + 156)) && (m_Vector[i].StartTimeSlotOfThirdClass <= (((startingAt + 1) * 4) + 156))) { result = true; } } break; case 4: if (m_Vector[i].StartTimeSlotOfFirstClass != -1) { if ((m_Vector[i].StartTimeSlotOfFirstClass > ((startingAt * 4) + 208)) && (m_Vector[i].StartTimeSlotOfFirstClass <= (((startingAt + 1) * 4) + 208))) { result = true; } } if (m_Vector[i].StartTimeSlotOfSecondClass != -1) { if ((m_Vector[i].StartTimeSlotOfSecondClass > ((startingAt * 4) + 208)) && (m_Vector[i].StartTimeSlotOfSecondClass <= (((startingAt + 1) * 4) + 208))) { result = true; } } if (m_Vector[i].StartTimeSlotOfThirdClass != -1) { if ((m_Vector[i].StartTimeSlotOfThirdClass > ((startingAt * 4) + 208)) && (m_Vector[i].StartTimeSlotOfThirdClass <= (((startingAt + 1) * 4) + 208))) { result = true; } } break; case 5: if (m_Vector[i].StartTimeSlotOfFirstClass != -1) { if ((m_Vector[i].StartTimeSlotOfFirstClass > ((startingAt * 4) + 261)) && (m_Vector[i].StartTimeSlotOfFirstClass <= (((startingAt + 1) * 4) + 261))) { result = true; } } if (m_Vector[i].StartTimeSlotOfSecondClass != -1) { if ((m_Vector[i].StartTimeSlotOfSecondClass > ((startingAt * 4) + 261)) && (m_Vector[i].StartTimeSlotOfSecondClass <= (((startingAt + 1) * 4) + 261))) { result = true; } } if (m_Vector[i].StartTimeSlotOfThirdClass != -1) { if ((m_Vector[i].StartTimeSlotOfThirdClass > ((startingAt * 4) + 261)) && (m_Vector[i].StartTimeSlotOfThirdClass <= (((startingAt + 1) * 4) + 261))) { result = true; } } break; default: break; } } } return result; }
private void checkStartingAtSpecificHour(int i_Day, Student.ePreferences i_Preferences) { int i=0; bool study = true; if (isStudyInADay(i_Day)) { study = false; for (; i < k_MaximumNumberOfCourses; i++) { if (isStarting(i_Day, i_Preferences)) { study = true; } } } if (!study) { m_VectorRating += 15; } }
private void checkStartingAfterTime(int i_Day, Student.ePreferences i_startingTime) { int count = 0; int startCount = 0; for (; count < k_MaximumNumberOfCourses; count++) { if (m_Vector[count].StartTimeSlotOfFirstClass != -1) { startCount = (i_startingTime == Student.ePreferences.startingAfter9 ? 0 : (i_startingTime == Student.ePreferences.startingAfter10 ? 1 : (i_startingTime == Student.ePreferences.startingAfter11 ? 2 : (i_startingTime == Student.ePreferences.startingAfter12 ? 3 : (i_startingTime == Student.ePreferences.startingAfter13 ? 4 : (i_startingTime == Student.ePreferences.startingAfter14 ? 5 : (i_startingTime == Student.ePreferences.startingAfter15 ? 6 : (i_startingTime == Student.ePreferences.startingAfter16 ? 7 : (i_startingTime == Student.ePreferences.startingAfter17 ? 8 : 0))))))))); switch (i_Day) { case 0: if (m_Vector[count].StartTimeSlotOfFirstClass >= (5 + startCount * 4) && m_Vector[count].StartTimeSlotOfFirstClass <= (9 + startCount * 4)) { m_VectorRating += 5; } if (m_Vector[count].StartTimeSlotOfSecondClass != -1) { if (m_Vector[count].StartTimeSlotOfSecondClass >= (5 + startCount * 4) && m_Vector[count].StartTimeSlotOfSecondClass <= (9 + startCount * 4)) { m_VectorRating += 5; } } if (m_Vector[count].StartTimeSlotOfThirdClass != -1) { if (m_Vector[count].StartTimeSlotOfThirdClass >= (5 + startCount * 4) && m_Vector[count].StartTimeSlotOfThirdClass <= (9 + startCount * 4)) { m_VectorRating += 5; } } break; case 1: if (m_Vector[count].StartTimeSlotOfFirstClass >= (57 + startCount * 4) && m_Vector[count].StartTimeSlotOfFirstClass <= (60 + startCount * 4)) { m_VectorRating += 5; } if (m_Vector[count].StartTimeSlotOfSecondClass != -1) { if (m_Vector[count].StartTimeSlotOfSecondClass >= (57 + startCount * 4) && m_Vector[count].StartTimeSlotOfSecondClass <= (60 + startCount * 4)) { m_VectorRating += 5; } } if (m_Vector[count].StartTimeSlotOfThirdClass != -1) { if (m_Vector[count].StartTimeSlotOfThirdClass >= (57 + startCount * 4) && m_Vector[count].StartTimeSlotOfThirdClass <= (60 + startCount * 4)) { m_VectorRating += 5; } } break; case 2: if (m_Vector[count].StartTimeSlotOfFirstClass >= (109 + startCount * 4) && m_Vector[count].StartTimeSlotOfFirstClass <= (112 + startCount * 4)) { m_VectorRating += 5; } if (m_Vector[count].StartTimeSlotOfSecondClass != -1) { if (m_Vector[count].StartTimeSlotOfSecondClass >= (109 + startCount * 4) && m_Vector[count].StartTimeSlotOfSecondClass <= (112 + startCount * 4)) { m_VectorRating += 5; } } if (m_Vector[count].StartTimeSlotOfThirdClass != -1) { if (m_Vector[count].StartTimeSlotOfThirdClass >= (109 + startCount * 4) && m_Vector[count].StartTimeSlotOfThirdClass <= (112 + startCount * 4)) { m_VectorRating += 5; } } break; case 3: if (m_Vector[count].StartTimeSlotOfFirstClass >= (161 + startCount * 4) && m_Vector[count].StartTimeSlotOfFirstClass <= (164 + startCount * 4)) { m_VectorRating += 5; } if (m_Vector[count].StartTimeSlotOfSecondClass != -1) { if (m_Vector[count].StartTimeSlotOfSecondClass >= (161 + startCount * 4) && m_Vector[count].StartTimeSlotOfSecondClass <= (164 + startCount * 4)) { m_VectorRating += 5; } } if (m_Vector[count].StartTimeSlotOfThirdClass != -1) { if (m_Vector[count].StartTimeSlotOfThirdClass >= (161 + startCount * 4) && m_Vector[count].StartTimeSlotOfThirdClass <= (164 + startCount * 4)) { m_VectorRating += 5; } } break; case 4: if (m_Vector[count].StartTimeSlotOfFirstClass >= (213 + startCount * 4) && m_Vector[count].StartTimeSlotOfFirstClass <= (216 + startCount * 4)) { m_VectorRating += 5; } if (m_Vector[count].StartTimeSlotOfSecondClass != -1) { if (m_Vector[count].StartTimeSlotOfSecondClass >= (213 + startCount * 4) && m_Vector[count].StartTimeSlotOfSecondClass <= (216 + startCount * 4)) { m_VectorRating += 5; } } if (m_Vector[count].StartTimeSlotOfThirdClass != -1) { if (m_Vector[count].StartTimeSlotOfThirdClass >= (213 + startCount * 4) && m_Vector[count].StartTimeSlotOfThirdClass <= (216 + startCount * 4)) { m_VectorRating += 5; } } break; case 5: if (m_Vector[count].StartTimeSlotOfFirstClass >= (266 + startCount * 4) && m_Vector[count].StartTimeSlotOfFirstClass <= (269 + startCount * 4)) { m_VectorRating += 5; } if (m_Vector[count].StartTimeSlotOfSecondClass != -1) { if (m_Vector[count].StartTimeSlotOfSecondClass >= (266 + startCount * 4) && m_Vector[count].StartTimeSlotOfSecondClass <= (269 + startCount * 4)) { m_VectorRating += 5; } } if (m_Vector[count].StartTimeSlotOfThirdClass != -1) { if (m_Vector[count].StartTimeSlotOfThirdClass >= (266 + startCount * 4) && m_Vector[count].StartTimeSlotOfThirdClass <= (269 + startCount * 4)) { m_VectorRating += 5; } } break; default: break; } } } }
public void rateVector(Student i_Student) { m_VectorRating = 0; int count = 0; for (; count < i_Student.StartingAfterHourPreferenceList.Count; count++) { if (i_Student.StartingAfterHourPreferenceList[count] != Student.ePreferences.noPreference) { checkStartingAfterTime(count, i_Student.StartingAfterHourPreferenceList[count]); } if (i_Student.StartHourPreferenceList[count] != Student.ePreferences.noPreference) { checkStartingAtSpecificHour(count, i_Student.StartHourPreferenceList[count]); } if (i_Student.WindowsPreferenceList[count] != Student.ePreferences.noPreference) { } if (i_Student.StudyDaysPreferenceList[count] != Student.ePreferences.noPreference) { checkIfStudyInDay(count); } } checkCoursesOverlap(); checkForEmptyCourses(); }
private int staringTimeToInt(Student.ePreferences i_Preferences) { int result = 0; switch (i_Preferences) { case (Student.ePreferences.startingAt8): result = 0; break; case(Student.ePreferences.startingAt9): result = 1; break; case(Student.ePreferences.startingAt10): result = 2; break; case(Student.ePreferences.startingAt11): result = 3; break; case(Student.ePreferences.startingAt12): result = 4; break; case(Student.ePreferences.startingAt13): result = 5; break; case(Student.ePreferences.startingAt14): result = 6; break; case(Student.ePreferences.startingAt15): result = 7; break; case(Student.ePreferences.startingAt16): result = 8; break; } return result; }
public StudentPreference(Student i_Student) { List<Student.ePreferences> m_ListOfPreferences = new List<Student.ePreferences>(); //int count = 0; }