// <param name="mainCurriculum">updated curriculum</param> public void Run(List <OfferedCourse> inputs, MainCurriculum mainCurriculum, int minUnitsRequired, int maxUnitsRequired, bool examCollideCheck, int timeout, AnimateStatusObjectModel model) { ChoosedWeeklyProgram.Clear(); double[] courseScore = new double[mainCurriculum.Courses.Count]; double numberOfGreenUnits = 0; List <OfferedCourse> greenCourses = new List <OfferedCourse>(); List <OfferedCourse> whiteCourses = new List <OfferedCourse>();//white courses that have at least one white row int greenUnits = 0; for (int i = 0; i < inputs.Count; i++) { var offeredCourse = inputs[i]; if (offeredCourse.Color == ReductionStep2ColorStatus.Green) { greenCourses.Add(offeredCourse); greenUnits += offeredCourse.Course.Units; } else if (offeredCourse.Color == ReductionStep2ColorStatus.WHITE) { for (int r = 0; r < offeredCourse.OfferedCourseRows.Count; r++) { var offeredCourseRow = offeredCourse.OfferedCourseRows[r]; if (offeredCourseRow.Color == ReductionStep2ColorStatus.WHITE) { whiteCourses.Add(offeredCourse); break; } } } var course = offeredCourse.Course; courseScore[course.Id] += (course.Units * 2 - 1) * 1; for (int c = 0; c < course.PrerequisiteCourses.Count; c++) { var preCourse = course.PrerequisiteCourses[c]; if (!preCourse.IsPassed && preCourse.IsAvailable()) { if (preCourse.NumberOfFailed > 1) { courseScore[preCourse.Id] += (course.Units * 2 - 1) * 0.20; } else { courseScore[preCourse.Id] += (course.Units * 2 - 1) * 0.25; } } } for (int c = 0; c < course.RequisiteCourses.Count; c++) { var reqCourse = course.RequisiteCourses[c]; if (!reqCourse.IsPassed && reqCourse.IsAvailable()) { courseScore[reqCourse.Id] += (course.Units * 2 - 1) * 0.20; } } } double totalScore = 0; whiteCourses.ForEach(i => { totalScore += courseScore[i.Course.Id]; }); List <Box> greenCoursesBoxes = new List <Box>(); greenCourses.ForEach(gc => { numberOfGreenUnits += gc.Course.Units; Box b = ReductionStep2ServiceProvider.CreateBoxForOfferedCourse(gc); greenCoursesBoxes.Add(b); }); if (greenCoursesBoxes.Count > 0) { List <Box> res = ReductionStep2ServiceProvider.Validate(greenCoursesBoxes, examCollideCheck); if (res != null) { greenCoursesBoxes.Clear(); greenCoursesBoxes.Add(res[0]); } } new AlgorithmLogicProvider().Run(courseScore, whiteCourses, greenCourses, minUnitsRequired, maxUnitsRequired, greenUnits, totalScore, mainCurriculum, greenCoursesBoxes, examCollideCheck, ChoosedWeeklyProgram, timeout); if (ChoosedWeeklyProgram.Count > 0) { model.Succ = true; } else { model.Succ = false; } }//end method Run
public void Run(double[] courseScore, List <OfferedCourse> whiteCourses, List <OfferedCourse> greenCourses, int minUnits, int maxUnits, int greenCoursesUnits, double whiteCoursesTotalScore, MainCurriculum mainCurriculum, List <Box> GreenCoursesBoxes, bool examCollideCheck, AlgorithmTopWeeklyProgramManager ChoosedWeeklyProgram, int timeout) { bool x = false; Task.Run(() => { Thread.Sleep(timeout); x = true; }); List <int> takenCoursesId = new List <int>(); while (true) { if (x) { return; } while (true) { if (x) { return; } do { if (x) { return; } Selected = new bool[whiteCourses.Count]; Score = 0; CurrentSelectedUnits = 0; takenCoursesId.Clear(); //init and assigning values to Selected array for (int i = 0; i < Selected.Length; i++) { var offeredCourse = whiteCourses[i]; var course = whiteCourses[i].Course; var pc = random.Next(100); if (CurrentSelectedUnits + course.Units + greenCoursesUnits > maxUnits) { continue; } if (pc <= courseScore[course.Id] * 100.0 / whiteCoursesTotalScore) { Selected[i] = true; CurrentSelectedUnits += course.Units; takenCoursesId.Add(course.Id); } } if (minUnits > CurrentSelectedUnits + greenCoursesUnits) { //no valid } }while (minUnits > CurrentSelectedUnits + greenCoursesUnits); greenCourses.ForEach(gc => takenCoursesId.Insert(0, gc.Course.Id)); //two step validation bool o = MainCurriculumSateValidator.IsValidState(mainCurriculum, takenCoursesId); if (o) { break; } } List <Box> boxes = new List <Box>(); GreenCoursesBoxes.ForEach(b => boxes.Add(b)); for (int i = 0; i < Selected.Length; i++) { if (Selected[i]) { Box b = ReductionStep2ServiceProvider.CreateBoxForOfferedCourse(whiteCourses[i]); boxes.Add(b); } } List <Box> res = ReductionStep2ServiceProvider.Validate(boxes, examCollideCheck); if (res != null) { //break; ChoosedWeeklyProgram.AddUpdateRangeData(res[0].Rows); } } }//end method Run