private int[] getShiftCandidateOrigine(Individ _parent, Curriculum _c) { int[] shiftCandidate = new int[2]; List <int> periodList = BasicFunctions.getRandomPeriodList(_c.noPeriods); //List<int> periodList = BasicFunctions.getCreditLoadSortedPeriodList(parentA.PeriodCreditLoad); int candidatePeriod = -1; int candidateCourse = -1; while (periodList.Count > 0) { //Console.WriteLine("periodList.Count: " + periodList.Count); candidatePeriod = periodList[0]; int candidatePeriodCourseLoad = _parent.Representation[candidatePeriod].Count; if (candidatePeriodCourseLoad - 1 >= _c.minCourses) { int candidatePeriodCreditLoad = _parent.PeriodCreditLoad[candidatePeriod]; //choosing randomly a course from this period, check minPeriodCreditLoad List <int> RandomListOfCourses = BasicFunctions.getRandomCourseList(_parent.Representation[candidatePeriod]); int CourseIndex; for (CourseIndex = 0; CourseIndex < RandomListOfCourses.Count; CourseIndex++) { int tempCourseCredit = _c.courses.FirstOrDefault(a => a.ID == RandomListOfCourses[CourseIndex]).credit; if ((candidatePeriodCreditLoad - tempCourseCredit) >= _c.minCredits) { candidateCourse = _c.courses.FirstOrDefault(a => a.ID == RandomListOfCourses[CourseIndex]).ID; return(new int[] { candidatePeriod, candidateCourse }); } } if (CourseIndex == RandomListOfCourses.Count) { periodList.RemoveAt(0); } } else { periodList.RemoveAt(0); } } return(new int[] { -1, -1 }); }
public Individ SwapCourses(int CurrentPeriod, int MinMaxCreditLoadPeriod, Curriculum _c, Individ _individ) { Individ ResultingIndivid = (Individ)_individ.Clone(); int LeftPeriodIndex, RightPeriodIndex; List <int> LeftPeriodSwapCandidates, RightPeriodSwapCandidates; if (CurrentPeriod < MinMaxCreditLoadPeriod) { LeftPeriodIndex = CurrentPeriod; RightPeriodIndex = MinMaxCreditLoadPeriod; } else { LeftPeriodIndex = MinMaxCreditLoadPeriod; RightPeriodIndex = CurrentPeriod; } LeftPeriodSwapCandidates = this.getLeftPeriodSwapCandidates(_c, ResultingIndivid.Representation, LeftPeriodIndex, RightPeriodIndex); RightPeriodSwapCandidates = this.getRightPeriodSwapCandidates(_c, ResultingIndivid.Representation, LeftPeriodIndex, RightPeriodIndex); if (LeftPeriodSwapCandidates.Count > 0 && RightPeriodSwapCandidates.Count > 0) { List <int> RandomLeftList = BasicFunctions.getRandomCourseList(LeftPeriodSwapCandidates); List <int> RandomRightList = BasicFunctions.getRandomCourseList(RightPeriodSwapCandidates); for (int IL = 0; IL < RandomLeftList.Count; IL++) { int LeftListCourseID = RandomLeftList[IL]; for (int IR = 0; IR < RandomRightList.Count; IR++) { int RightListCourseID = RandomRightList[IR]; int LeftPeriodForeseenCreditLoad = ResultingIndivid.PeriodCreditLoad[LeftPeriodIndex] + _c.courses[RightListCourseID - 1].credit - _c.courses[LeftListCourseID - 1].credit; int RightPeriodForeseenCreditLoad = ResultingIndivid.PeriodCreditLoad[RightPeriodIndex] + _c.courses[LeftListCourseID - 1].credit - _c.courses[RightListCourseID - 1].credit; bool LeftPeriodCreditLoadFeasible = LeftPeriodForeseenCreditLoad >= _c.minCredits && LeftPeriodForeseenCreditLoad <= _c.maxCredits; bool RightPeriodCreditLoadFeasible = RightPeriodForeseenCreditLoad >= _c.minCredits && RightPeriodForeseenCreditLoad <= _c.maxCredits; if (LeftPeriodCreditLoadFeasible && RightPeriodCreditLoadFeasible) { ResultingIndivid.Representation[LeftPeriodIndex].Remove(LeftListCourseID); ResultingIndivid.Representation[LeftPeriodIndex].Add(RightListCourseID); ResultingIndivid.Representation[RightPeriodIndex].Remove(RightListCourseID); ResultingIndivid.Representation[RightPeriodIndex].Add(LeftListCourseID); ResultingIndivid.PeriodCreditLoad[LeftPeriodIndex] += (_c.courses[RightListCourseID - 1].credit - _c.courses[LeftListCourseID - 1].credit); ResultingIndivid.PeriodCreditLoad[RightPeriodIndex] += (_c.courses[LeftListCourseID - 1].credit - _c.courses[RightListCourseID - 1].credit); goto ReturnIndivid; } } } } ReturnIndivid: ResultingIndivid.Evaluation = BasicFunctions.AssessFitnessMaximumLoad(ResultingIndivid); return(ResultingIndivid); }