public void AddAlgoRule(string localID, AlgoRule model)
 {
     if (Algoes.ContainsKey(localID))
     {
         Algoes[localID] = model;
     }
     else
     {
         Algoes.Add(localID, model);
     }
 }
Exemplo n.º 2
0
        public void SerializePatternAlgo(AlgoRule algo, string localID)
        {
            var caseModel = CommonDataManager.GetLocalCase(localID);

            if (caseModel.Pattern == Models.Enums.PatternTypeEnum.None)
            {
                algo.Serialize(localID);
            }
            else
            {
                algo.SerializePatternAlgo(localID);
            }
        }
        public static void ClassHourChanged(string localID, Rule rule, AlgoRule algo, CLCase cl, bool isPatern)
        {
            if (rule != null)
            {
                rule.ClassHourSameOpens?.Clear();
                rule.ClassHourAverages?.Clear();
                rule.CourseTimes?.Clear();
                rule.ArrangeContinuous?.Clear();
                rule.AmPmClassHours?.Clear();

                if (isPatern)
                {
                    OSKernel.Presentation.Models.Enums.MixedRuleEnum.ClassHourSameOpen.DeletePaternRule(localID);
                    rule.SerializePatternRule(localID);
                }
                else
                {
                    OSKernel.Presentation.Models.Enums.MixedRuleEnum.ClassHourSameOpen.DeleteRule(localID);
                    rule.Serialize(localID);
                }
            }

            if (algo != null)
            {
                algo.ClassHoursSameStartingDays?.Clear();
                algo.ClassHoursSameStartingTimes?.Clear();
                algo.ClassHoursSameStartingHours?.Clear();
                algo.TwoClassHoursContinuous?.Clear();
                algo.TwoClassHoursOrdered?.Clear();
                algo.TwoClassHoursGrouped?.Clear();
                algo.ThreeClassHoursGrouped?.Clear();
                algo.MinDaysBetweenClassHours?.Clear();
                algo.ClassHourRequiredStartingTimes?.Clear();
                algo.ClassHourRequiredTimes?.Clear();
                algo.MaxDaysBetweenClassHours?.Clear();
                algo.ClassHoursNotOverlaps?.Clear();
                algo.ClassHourRequiredStartingTime?.Clear();
                algo.ClassHoursMaxConcurrencyInSelectedTimes?.Clear();
                algo.ClassHoursOccupyMaxTimeFromSelections?.Clear();

                if (isPatern)
                {
                    algo.SerializePatternAlgo(localID);
                }
                else
                {
                    algo.Serialize(localID);
                }
            }
        }
        public AlgoRule GetAlgoRule(string localID)
        {
            if (Algoes.ContainsKey(localID))
            {
                return(Algoes[localID]);
            }
            else
            {
                var algoRule = new AlgoRule();
                Algoes.Add(localID, algoRule);

                return(algoRule);
            }
        }
        /// <summary>
        /// 时间发生改变(清除所有时间规则)
        /// </summary>
        public static void TimeChanged(string localID, Rule rule, AlgoRule algo, bool hasPatern)
        {
            if (rule != null)
            {
                rule.TeacherTimes?.Clear();
                rule.CourseLimits?.Clear();
                rule.CourseTimes?.Clear();
                rule.ArrangeContinuous?.Clear();
                if (hasPatern)
                {
                    rule.SerializePatternRule(localID);
                }
                else
                {
                    rule.Serialize(localID);
                }
            }

            if (algo != null)
            {
                algo.TeacherNotAvailableTimes?.Clear();
                algo.ClassHourRequiredStartingTimes?.Clear();
                algo.ClassHourRequiredTimes?.Clear();
                algo.ClassHoursRequiredStartingTimes?.Clear();
                algo.ClassHoursRequiredTimes?.Clear();
                algo.ClassHourRequiredStartingTime?.Clear();
                algo.ClassHoursMaxConcurrencyInSelectedTimes?.Clear();
                algo.ClassHoursOccupyMaxTimeFromSelections?.Clear();
                if (hasPatern)
                {
                    algo.SerializePatternAlgo(localID);
                }
                else
                {
                    algo.Serialize(localID);
                }
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// 常规排课模式
        /// </summary>
        /// <param name="cLCase"></param>
        /// <param name="rule"></param>
        /// <param name="algoRule"></param>
        /// <param name="normalModel"></param>
        /// <returns></returns>
        public Tuple <CLCase, bool, List <DataValidationResultInfo> > GetModelByNormal(CLCase cLCase, Rule rule, AlgoRule algoRule, NormalModel normalModel)
        {
            List <DataValidationResultInfo> mydvri = new List <DataValidationResultInfo>()
            {
            };
            bool checkResult = ModelValidation.ValidateModel(cLCase, algoRule, rule, out mydvri);

            if (!checkResult)
            {
                return(Tuple.Create(cLCase, false, mydvri));
            }

            if (cLCase != null && normalModel != null)
            {
                //remove selected combinations
                if (normalModel.RemovedCombination != null)
                {
                    cLCase = Utility.GetCaseByRemovedCombination(cLCase, normalModel.RemovedCombination);
                }

                //Update Capacity
                if (normalModel.ClassCapacity != null)
                {
                    normalModel.ClassCapacity.ForEach(x => {
                        cLCase?.Classes?.Where(c => c.ID == x.ClassId)?.ToList()?.ForEach(c => {
                            c.Capacity = x.Capacity;
                        });
                    });
                }

                //Update Positions
                if (normalModel.Positions != null)
                {
                    cLCase.Positions = normalModel.Positions;
                }
            }

            return(Tuple.Create(cLCase, true, mydvri));
        }
Exemplo n.º 7
0
        public static Tuple <CLCase, AlgoRule> GetCasePositionsUpdateByTimeCompressionRatio(CLCase cLCase, AlgoRule algoRule, int CompressionRatio)
        {
            List <TeacherTagClassHour> teacherTagClassHour   = new List <TeacherTagClassHour>();
            List <StudentTagClassHour> studentTagClassHour   = new List <StudentTagClassHour>();
            List <StudentTagClassHour> studentTagClassHourBK = new List <StudentTagClassHour>();

            //统计教师的课时(压缩与非压缩)
            cLCase.Teachers.ForEach(x => {
                cLCase.ClassHours?.Where(c => c.TeacherIDs != null && c.TagIDs != null && c.TeacherIDs.Contains(x.ID))
                ?.Select(c => new { TeacherId = x.ID, Tags = c.TagIDs, c.ClassID })
                ?.ToList()?.ForEach(c => {
                    if (c.Tags.Contains(SystemTag.XYTagN.ToString()))
                    {
                        teacherTagClassHour.Add(new TeacherTagClassHour()
                        {
                            ClassID = c.ClassID, TagType = SystemTag.XYTagN.ToString(), TeacherId = x.ID
                        });
                    }
                    else if (c.Tags.Contains(SystemTag.XYTag1.ToString()))
                    {
                        teacherTagClassHour.Add(new TeacherTagClassHour()
                        {
                            ClassID = c.ClassID, TagType = SystemTag.XYTag1.ToString(), TeacherId = x.ID
                        });
                    }
                });
            });

            //统计学生的课时(压缩与非压缩)
            cLCase.Students?.ForEach(x => {
                x.Preselections.ForEach(s => {
                    studentTagClassHourBK.Add(new StudentTagClassHour()
                    {
                        StudentId = x.ID, CourseID = s.CourseID, LevelID = s.LevelID, TagType = ""
                    });
                });
            });

            cLCase.Courses.ForEach(co => {
                co.Levels.ForEach(le => {
                    ClassModel classInfo = cLCase.Classes.FirstOrDefault(cl => cl.CourseID == co.ID && cl.LevelID == le.ID);

                    if (classInfo != null)
                    {
                        string ClassID = cLCase.Classes.First(cl => cl.CourseID == co.ID && cl.LevelID == le.ID).ID;
                        var classHours = cLCase.ClassHours.Where(c => c.ClassID == ClassID);
                        int tagNCount  = classHours.Where(x => x.TagIDs != null && x.TagIDs.Contains(SystemTag.XYTagN.ToString())).Count();
                        int tag1Count  = classHours.Where(x => x.TagIDs != null && x.TagIDs.Contains(SystemTag.XYTag1.ToString())).Count();

                        for (int i = 0; i < tagNCount; i++)
                        {
                            studentTagClassHourBK.Where(x => x.CourseID == co.ID && x.LevelID == le.ID).ToList().ForEach(x => {
                                studentTagClassHour.Add(new StudentTagClassHour()
                                {
                                    StudentId = x.StudentId, CourseID = x.CourseID, LevelID = x.LevelID, TagType = SystemTag.XYTagN.ToString()
                                });
                            });
                        }

                        for (int i = 0; i < tag1Count; i++)
                        {
                            studentTagClassHourBK.Where(x => x.CourseID == co.ID && x.LevelID == le.ID).ToList().ForEach(x => {
                                studentTagClassHour.Add(new StudentTagClassHour()
                                {
                                    StudentId = x.StudentId, CourseID = x.CourseID, LevelID = x.LevelID, TagType = SystemTag.XYTag1.ToString()
                                });
                            });
                        }
                    }
                });
            });

            //如果班级都没有安排教师,且没有学生怎么办: 按照教学班统计最大课时
            var noTS     = cLCase.ClassHours.Where(x => (x.TeacherIDs == null || x.TeacherIDs.Count == 0));
            int noTSMaxN = 0;

            if (noTS.Where(x => x.TagIDs != null && x.TagIDs.Contains(SystemTag.XYTagN.ToString())).Any())
            {
                noTSMaxN = noTS.Where(x => x.TagIDs != null && x.TagIDs.Contains(SystemTag.XYTagN.ToString()))
                           .Select(x => new { x.ClassID })
                           .GroupBy(x => new { x.ClassID })
                           .Select(x => new { x.Key.ClassID, Count = x.Count() }).Max(x => x.Count);
            }

            int noTSMax1 = 0;

            if (noTS.Where(x => x.TagIDs != null && x.TagIDs.Contains(SystemTag.XYTag1.ToString())).Any())
            {
                noTSMax1 = noTS.Where(x => x.TagIDs != null && x.TagIDs.Contains(SystemTag.XYTag1.ToString()))
                           .Select(x => new { x.ClassID })
                           .GroupBy(x => new { x.ClassID })
                           .Select(x => new { x.Key.ClassID, Count = x.Count() }).Max(x => x.Count);
            }

            //计算需要最大的压缩课位和非压缩课位
            int teacherMaxN = 0;

            if (teacherTagClassHour.Where(x => x.TagType == SystemTag.XYTagN.ToString()).Any())
            {
                teacherMaxN = teacherTagClassHour.Where(x => x.TagType == SystemTag.XYTagN.ToString())
                              .GroupBy(x => new { x.TeacherId, x.TagType })
                              .Select(x => new { x.Key.TeacherId, x.Key.TagType, Count = x.Count() }).Max(x => x.Count);
            }

            int teacherMax1 = 0;

            if (teacherTagClassHour.Where(x => x.TagType == SystemTag.XYTag1.ToString()).Any())
            {
                teacherMax1 = teacherTagClassHour.Where(x => x.TagType == SystemTag.XYTag1.ToString())
                              .GroupBy(x => new { x.TeacherId, x.TagType })
                              .Select(x => new { x.Key.TeacherId, x.Key.TagType, Count = x.Count() }).Max(x => x.Count);
            }

            //计算需要最大的压缩课位和非压缩课位
            int studentMaxN = 0;

            if (studentTagClassHour.Where(x => x.TagType == SystemTag.XYTagN.ToString()).Any())
            {
                studentMaxN = studentTagClassHour.Where(x => x.TagType == SystemTag.XYTagN.ToString())
                              .GroupBy(x => new { x.StudentId, x.TagType })
                              .Select(x => new { x.Key.StudentId, x.Key.TagType, Count = x.Count() }).Max(x => x.Count);
            }

            int studentMax1 = 0;

            if (studentTagClassHour.Where(x => x.TagType == SystemTag.XYTag1.ToString()).Any())
            {
                studentMax1 = studentTagClassHour.Where(x => x.TagType == SystemTag.XYTag1.ToString())
                              .GroupBy(x => new { x.StudentId, x.TagType })
                              .Select(x => new { x.Key.StudentId, x.Key.TagType, Count = x.Count() }).Max(x => x.Count);
            }

            int TSmaxN = Math.Max(teacherMaxN, studentMaxN);
            int TSmax1 = Math.Max(teacherMax1, studentMax1);

            int maxN = Math.Max(noTSMaxN, TSmaxN);
            int max1 = Math.Max(noTSMax1, TSmax1);

            //初始化课位
            cLCase.Positions.ForEach(x => { x.IsSelected = false; });

            //设定新的排课课位
            //TagN TimeSlot
            ClassHoursRequiredTimesRule tagNRules = new ClassHoursRequiredTimesRule();

            tagNRules.Times  = new List <XYKernel.OS.Common.Models.DayPeriodModel>();
            tagNRules.Active = true;
            tagNRules.Weight = 100;
            tagNRules.TagID  = SystemTag.XYTagN.ToString();

            for (int i = 0; i < maxN; i++)
            {
                var coursePosition = cLCase.Positions.Where(x => x.IsSelected == false && x.Position != Position.AB && x.Position != Position.Noon && x.Position != Position.PB && x.DayPeriod.Day > 0)
                                     .OrderBy(x => x.DayPeriod.Day).ThenBy(x => x.DayPeriod.Period).First();
                coursePosition.IsSelected = true;
                tagNRules.Times.Add(coursePosition.DayPeriod);
            }

            //Tag1 TimeSlot
            ClassHoursRequiredTimesRule tag1Rules = new ClassHoursRequiredTimesRule();

            tag1Rules.Times  = new List <XYKernel.OS.Common.Models.DayPeriodModel>();
            tag1Rules.Active = true;
            tag1Rules.Weight = 100;
            tag1Rules.TagID  = SystemTag.XYTag1.ToString();

            for (int i = 0; i < max1; i++)
            {
                var coursePosition = cLCase.Positions.Where(x => x.IsSelected == false && x.Position != Position.AB && x.Position != Position.Noon && x.Position != Position.PB && x.DayPeriod.Day == 0)
                                     .OrderBy(x => x.DayPeriod.Day).ThenBy(x => x.DayPeriod.Period).FirstOrDefault();
                if (coursePosition == null)
                {
                    coursePosition = cLCase.Positions.Where(x => x.IsSelected == false && x.Position != Position.AB && x.Position != Position.Noon && x.Position != Position.PB && x.DayPeriod.Day > 0)
                                     .OrderByDescending(x => x.DayPeriod.Day).ThenBy(x => x.DayPeriod.Period).FirstOrDefault();
                }

                if (coursePosition != null)
                {
                    coursePosition.IsSelected = true;
                    tag1Rules.Times.Add(coursePosition.DayPeriod);
                }
            }

            //将两种时间分别记录到规则中,形成约束
            algoRule = new AlgoRule();

            if (algoRule.ClassHoursRequiredTimes == null)
            {
                algoRule.ClassHoursRequiredTimes = new List <ClassHoursRequiredTimesRule>();
            }

            if (tag1Rules.Times.Count > 0)
            {
                algoRule.ClassHoursRequiredTimes.Add(tag1Rules);
            }
            if (tagNRules.Times.Count > 0)
            {
                algoRule.ClassHoursRequiredTimes.Add(tagNRules);
            }

            return(Tuple.Create(cLCase, algoRule));
        }
Exemplo n.º 8
0
        /// <summary>
        /// 仅排教师和分到班的学生,删除所有班级未固定的学生
        /// </summary>
        /// <param name="cLCase"></param>
        /// <param name="rule"></param>
        /// <param name="algoRule"></param>
        /// <returns></returns>
        public Tuple <CLCase, bool, List <DataValidationResultInfo> > GetModelWithOnlyStudentsAssignedToClass(CLCase cLCase, Rule rule, AlgoRule algoRule)
        {
            List <DataValidationResultInfo> mydvri = new List <DataValidationResultInfo>()
            {
            };
            bool checkResult = ModelValidation.ValidateModel(cLCase, algoRule, rule, out mydvri);

            if (!checkResult)
            {
                return(Tuple.Create(cLCase, false, mydvri));
            }

            //仅排教师和分到班的学生,删除所有班级未固定的学生
            cLCase?.Courses?.ForEach(x => {
                x.Levels?.ForEach(le => {
                    int classNumber = cLCase?.Classes?.Where(c => c.CourseID == x.ID && c.LevelID == le.ID)?.ToList()?.Count ?? 0;

                    if (classNumber > 1)
                    {
                        cLCase?.Students?.ForEach(s => {
                            s.Preselections.RemoveAll(p => p.CourseID == x.ID && p.LevelID == le.ID);
                        });
                    }
                });
            });

            return(Tuple.Create(cLCase, true, mydvri));
        }
Exemplo n.º 9
0
        /// <summary>
        /// 课位压缩排课后的优化步骤
        /// </summary>
        /// <param name="cLCase"></param>
        /// <param name="rule"></param>
        /// <param name="algoRule"></param>
        /// <param name="resultModel"></param>
        /// <returns></returns>
        public Tuple <CLCase, Rule, AlgoRule, bool, List <DataValidationResultInfo> > GetModelByStudentsClassificationResult(CLCase cLCase, Rule rule, AlgoRule algoRule, ResultModel resultModel)
        {
            List <DataValidationResultInfo> mydvri = new List <DataValidationResultInfo>()
            {
            };
            bool checkResult = ModelValidation.ValidateModel(cLCase, algoRule, rule, out mydvri);

            if (!checkResult)
            {
                return(Tuple.Create(cLCase, rule, algoRule, false, mydvri));
            }

            if (cLCase != null && resultModel != null)
            {
                resultModel.ResultClasses?.ToList()?.ForEach(x => {
                    var targetClass = cLCase.Classes?.FirstOrDefault(c => c.ID == x.ClassID);
                    if (targetClass != null)
                    {
                        if (targetClass.StudentIDs == null)
                        {
                            targetClass.StudentIDs = (x.ResultStudents?.ToList() ?? new List <string>());
                        }
                        else
                        {
                            targetClass.StudentIDs.AddRange(x.ResultStudents?.ToList() ?? new List <string>());
                        }
                    }
                });
            }

            //Check And add some rules if it's a auto schedule
            if (cLCase.IsAuto)
            {
                //
            }

            return(Tuple.Create(cLCase, rule, algoRule, true, mydvri));
        }
Exemplo n.º 10
0
        /// <summary>
        /// 课位压缩,根据设定参数压缩课位
        /// </summary>
        /// <param name="cLCase"></param>
        /// <param name="rule"></param>
        /// <param name="algoRule"></param>
        /// <param name="timeCompressionModel"></param>
        /// <returns></returns>
        public Tuple <CLCase, Rule, AlgoRule, bool, List <DataValidationResultInfo> > GetModelByTimeCompression(CLCase cLCase, Rule rule, AlgoRule algoRule, TimeCompressionModel timeCompressionModel)
        {
            List <DataValidationResultInfo> mydvri = new List <DataValidationResultInfo>()
            {
            };
            bool checkResult = ModelValidation.ValidateModel(cLCase, algoRule, rule, out mydvri);

            if (!checkResult)
            {
                return(Tuple.Create(cLCase, rule, algoRule, false, mydvri));
            }

            if (cLCase != null && timeCompressionModel != null)
            {
                if (timeCompressionModel.ClassCapacity != null)
                {
                    timeCompressionModel.ClassCapacity.ForEach(x => {
                        cLCase?.Classes?.Where(c => c.ID == x.ClassId)?.ToList()?.ForEach(c => {
                            c.Capacity = x.Capacity;
                        });
                    });
                }

                if (timeCompressionModel.RemovedCombination != null)
                {
                    cLCase = Utility.GetCaseByRemovedCombination(cLCase, timeCompressionModel.RemovedCombination);
                }

                if (timeCompressionModel.CompressionRatio > 1)
                {
                    //调整课时
                    cLCase = Utility.GetCaseClassHourUpdateByTimeCompressionRatio(cLCase, timeCompressionModel.CompressionRatio);

                    //调整课位
                    Tuple <CLCase, AlgoRule> cLCaseAndAlgoRule = Utility.GetCasePositionsUpdateByTimeCompressionRatio(cLCase, algoRule, timeCompressionModel.CompressionRatio);
                    cLCase   = cLCaseAndAlgoRule.Item1;
                    algoRule = cLCaseAndAlgoRule.Item2;

                    //Add Tags
                    if (cLCase.Tags == null)
                    {
                        cLCase.Tags = new List <TagModel>();
                    }

                    if (!cLCase.Tags.Exists(t => t.ID == SystemTag.XYTagN.ToString()))
                    {
                        cLCase.Tags.Add(new TagModel()
                        {
                            ID = SystemTag.XYTagN.ToString(), Name = SystemTag.XYTagN.ToString()
                        });
                    }

                    if (!cLCase.Tags.Exists(t => t.ID == SystemTag.XYTag1.ToString()))
                    {
                        cLCase.Tags.Add(new TagModel()
                        {
                            ID = SystemTag.XYTag1.ToString(), Name = SystemTag.XYTag1.ToString()
                        });
                    }
                }
            }

            return(Tuple.Create(cLCase, new Rule()
            {
            }, algoRule, true, mydvri));
        }
Exemplo n.º 11
0
        /// <summary>
        /// 仅排教师
        /// </summary>
        /// <param name="cLCase"></param>
        /// <param name="rule"></param>
        /// <param name="algoRule"></param>
        /// <returns></returns>
        public Tuple <CLCase, bool, List <DataValidationResultInfo> > GetModelWithoutStudents(CLCase cLCase, Rule rule, AlgoRule algoRule)
        {
            List <DataValidationResultInfo> mydvri = new List <DataValidationResultInfo>()
            {
            };
            bool checkResult = ModelValidation.ValidateModel(cLCase, algoRule, rule, out mydvri);

            if (!checkResult)
            {
                return(Tuple.Create(cLCase, false, mydvri));
            }

            try
            {
                //remove all students
                cLCase?.Students?.Clear();

                cLCase?.Classes?.ForEach(x => {
                    x.StudentIDs.Clear();
                });
            }
            catch (Exception ex)
            {
                ErrorMessage = ex.Message;
            }

            return(Tuple.Create(cLCase, true, mydvri));
        }
Exemplo n.º 12
0
        /// <summary>
        /// 抽样排课后的优化步骤
        /// </summary>
        /// <param name="cLCase"></param>
        /// <param name="algoRule"></param>
        /// <param name="normalModel"></param>
        /// <param name="resultModel"></param>
        /// <param name="IncreasedCapacity"></param>
        /// <returns></returns>
        public Tuple <CLCase, AlgoRule, bool, List <DataValidationResultInfo> > GetModelByFixedClassTimeTable(CLCase cLCase, Rule rule, AlgoRule algoRule, NormalModel normalModel, ResultModel resultModel, int IncreasedCapacity)
        {
            List <DataValidationResultInfo> mydvri = new List <DataValidationResultInfo>()
            {
            };
            bool checkResult = ModelValidation.ValidateModel(cLCase, algoRule, rule, out mydvri);

            if (!checkResult)
            {
                return(Tuple.Create(cLCase, algoRule, false, mydvri));
            }

            if (cLCase != null && resultModel != null)
            {
                //remove selected combinations
                if (normalModel?.RemovedCombination != null)
                {
                    cLCase = Utility.GetCaseByRemovedCombination(cLCase, normalModel.RemovedCombination);
                }

                //Update Capacity
                if (normalModel?.ClassCapacity != null)
                {
                    normalModel.ClassCapacity.ForEach(x => {
                        cLCase?.Classes?.Where(c => c.ID == x.ClassId)?.ToList()?.ForEach(c => {
                            c.Capacity = c.Capacity + x.Capacity;
                        });
                    });
                }

                if (IncreasedCapacity > 0)
                {
                    cLCase?.Classes?.ForEach(x => {
                        x.Capacity = x.Capacity + IncreasedCapacity;
                    });
                }

                //Update Positions
                if (normalModel?.Positions != null)
                {
                    cLCase.Positions = normalModel.Positions;
                }

                //Analysis ResultModel and add rule to algoRule
                if (resultModel.ResultClasses != null)
                {
                    if (algoRule == null)
                    {
                        algoRule = new AlgoRule();
                    }

                    if (algoRule.ClassHourRequiredStartingTime == null)
                    {
                        algoRule.ClassHourRequiredStartingTime = new List <ClassHourRequiredStartingTimeRule>()
                        {
                        };
                    }

                    resultModel.ResultClasses?.ToList()?.ForEach(x => {
                        x.ResultDetails?.ToList()?.ForEach(rd => {
                            algoRule.ClassHourRequiredStartingTime.Add(new ClassHourRequiredStartingTimeRule()
                            {
                                ID     = rd.ClassHourId,
                                Period = rd.DayPeriod,
                                Weight = 100
                            });
                        });
                    });
                }
            }

            return(Tuple.Create(cLCase, algoRule, true, mydvri));
        }
Exemplo n.º 13
0
        /// <summary>
        /// 学生抽样,仅根据设定保留部分学生
        /// </summary>
        /// <param name="cLCase"></param>
        /// <param name="rule"></param>
        /// <param name="algoRule"></param>
        /// <param name="studentExtractionModel"></param>
        /// <returns></returns>
        public Tuple <CLCase, bool, List <DataValidationResultInfo> > GetModelByStudentExtraction(CLCase cLCase, Rule rule, AlgoRule algoRule, StudentExtractionModel studentExtractionModel)
        {
            List <DataValidationResultInfo> mydvri = new List <DataValidationResultInfo>()
            {
            };
            bool checkResult = ModelValidation.ValidateModel(cLCase, algoRule, rule, out mydvri);

            if (!checkResult)
            {
                return(Tuple.Create(cLCase, false, mydvri));
            }

            if (cLCase != null && studentExtractionModel != null)
            {
                //update Positions
                if (studentExtractionModel.Positions != null)
                {
                    cLCase.Positions = studentExtractionModel.Positions;
                }

                //remove combination
                if (studentExtractionModel.RemovedCombination != null)
                {
                    cLCase = Utility.GetCaseByRemovedCombination(cLCase, studentExtractionModel.RemovedCombination);
                }

                if (studentExtractionModel.ExtractionRatio >= 1 && studentExtractionModel.ExtractionRatio <= 100)
                {
                    cLCase = Utility.GetCaseByExtractionRatio(cLCase, studentExtractionModel.ExtractionRatio);
                }

                //Increase Capacity
                if (studentExtractionModel.IncreasedCapacity > 0)
                {
                    cLCase.Classes?.ForEach(x => {
                        x.Capacity = x.Capacity + studentExtractionModel.IncreasedCapacity;
                    });
                }
            }

            return(Tuple.Create(cLCase, true, mydvri));
        }
Exemplo n.º 14
0
        public static void TeacherChanged(Models.Base.UITeacher teacher, string localID, Rule rule, AlgoRule algo, CLCase cl, bool hasPatern)
        {
            if (cl != null)
            {
                cl.Classes?.ForEach(c =>
                {
                    c.TeacherIDs?.RemoveAll(t => t.Contains(teacher.ID));
                });

                cl.ClassHours?.ForEach(ch =>
                {
                    ch.TeacherIDs?.RemoveAll(t => t.Contains(teacher.ID));
                });

                if (hasPatern)
                {
                    cl.SerializePatternCase(localID);
                }
                else
                {
                    cl.Serialize(localID);
                }
            }

            if (rule != null)
            {
                rule.TeacherTimes?.RemoveAll(t => t.TeacherID.Contains(teacher.ID));
                rule.MaxGapsPerDay?.RemoveAll(t => t.TeacherID.Contains(teacher.ID));
                rule.MaxDaysPerWeek?.RemoveAll(t => t.TeacherID.Contains(teacher.ID));
                rule.MaxHoursDaily?.RemoveAll(t => t.TeacherID.Contains(teacher.ID));
                if (hasPatern)
                {
                    rule.SerializePatternRule(localID);
                }
                else
                {
                    rule.Serialize(localID);
                }
            }

            if (algo != null)
            {
                algo.TeacherMaxGapsPerDays?.RemoveAll(t => t.TeacherID.Equals(teacher.ID));
                algo.TeacherMaxHoursDailys?.RemoveAll(t => t.TeacherID.Equals(teacher.ID));
                algo.TeacherMaxDaysPerWeeks?.RemoveAll(t => t.TeacherID.Equals(teacher.ID));
                algo.TeacherNotAvailableTimes?.RemoveAll(t => t.TeacherID.Equals(teacher.ID));
                if (hasPatern)
                {
                    algo.SerializePatternAlgo(localID);
                }
                else
                {
                    algo.Serialize(localID);
                }
            }
        }
Exemplo n.º 15
0
        public static void LevelChanged(List <Models.Mixed.UILevel> levels, string localID, Rule rule, AlgoRule algo, CLCase cl, bool isPatern)
        {
            if (rule != null)
            {
                levels.ForEach(c =>
                {
                    var classes = cl.Classes.Where(cc => cc.LevelID.Equals(c.ID) && cc.CourseID.Equals(c.CourseID))?.ToList();
                    classes?.ForEach(tc =>
                    {
                        rule.CourseTimes?.RemoveAll(r => r.ClassID.Equals(tc.ID));
                        rule.ArrangeContinuous?.RemoveAll(r => r.ClassID.Equals(tc.ID));
                        rule.ClassHourAverages?.RemoveAll(r => r.ClassID.Equals(tc.ID));
                    });
                    rule.AmPmClassHours?.RemoveAll(r => r.CourseID.Equals(c.ID));
                    rule.CourseLimits?.RemoveAll(r => r.CourseID.Equals(c.ID));
                });

                rule.ClassHourSameOpens?.Clear();

                if (isPatern)
                {
                    OSKernel.Presentation.Models.Enums.MixedRuleEnum.ClassHourSameOpen.DeletePaternRule(localID);
                    rule.SerializePatternRule(localID);
                }
                else
                {
                    OSKernel.Presentation.Models.Enums.MixedRuleEnum.ClassHourSameOpen.DeleteRule(localID);
                    rule.Serialize(localID);
                }
            }

            if (algo != null)
            {
                var classHours = cl.ClassHours.Where(ch => levels.Any(c => ch.LevelID.Equals(c.ID)))?.ToList();

                classHours?.ForEach(ch =>
                {
                    algo.ClassHoursSameStartingDays?.ForEach(a =>
                    {
                        var ids = a.ID?.ToList();
                        ids?.RemoveAll(ri => ri.Equals(ch.ID));
                        a.ID = ids?.ToArray();
                    });
                    algo.ClassHoursSameStartingDays?.RemoveAll(a => a.ID?.Count() == 0);

                    algo.ClassHoursSameStartingTimes?.ForEach(a =>
                    {
                        var ids = a.ID?.ToList();
                        ids?.RemoveAll(ri => ri.Equals(ch.ID));
                        a.ID = ids?.ToArray();
                    });
                    algo.ClassHoursSameStartingTimes?.RemoveAll(a => a.ID?.Count() == 0);

                    algo.ClassHoursSameStartingHours?.ForEach(a =>
                    {
                        var ids = a.ID?.ToList();
                        ids?.RemoveAll(ri => ri.Equals(ch.ID));
                        a.ID = ids?.ToArray();
                    });
                    algo.ClassHoursSameStartingHours?.RemoveAll(a => a.ID?.Count() == 0);

                    algo.MinDaysBetweenClassHours?.ForEach(a =>
                    {
                        var ids = a.ID?.ToList();
                        ids?.RemoveAll(ri => ri.Equals(ch.ID));
                        a.ID = ids?.ToArray();
                    });
                    algo.MinDaysBetweenClassHours?.RemoveAll(a => a.ID?.Count() == 0);

                    algo.MaxDaysBetweenClassHours?.ForEach(a =>
                    {
                        var ids = a.ID?.ToList();
                        ids?.RemoveAll(ri => ri.Equals(ch.ID));
                        a.ID = ids?.ToArray();
                    });
                    algo.MaxDaysBetweenClassHours?.RemoveAll(a => a.ID?.Count() == 0);

                    algo.ClassHoursNotOverlaps?.ForEach(a =>
                    {
                        var ids = a.ID?.ToList();
                        ids?.RemoveAll(ri => ri.Equals(ch.ID));
                        a.ID = ids?.ToArray();
                    });
                    algo.ClassHoursNotOverlaps?.RemoveAll(a => a.ID?.Count() == 0);

                    algo.ClassHoursMaxConcurrencyInSelectedTimes?.ForEach(a =>
                    {
                        var ids = a.ID?.ToList();
                        ids?.RemoveAll(ri => ri.Equals(ch.ID));
                        a.ID = ids?.ToArray();
                    });
                    algo.ClassHoursMaxConcurrencyInSelectedTimes?.RemoveAll(a => a.ID?.Count() == 0);

                    algo.ClassHoursOccupyMaxTimeFromSelections?.ForEach(a =>
                    {
                        var ids = a.ID?.ToList();
                        ids?.RemoveAll(ri => ri.Equals(ch.ID));
                        a.ID = ids?.ToArray();
                    });
                    algo.ClassHoursOccupyMaxTimeFromSelections?.RemoveAll(a => a.ID?.Count() == 0);

                    algo.TwoClassHoursContinuous?.RemoveAll(r => r.FirstID.Equals(ch.ID) || r.SecondID.Equals(ch.ID));
                    algo.TwoClassHoursOrdered?.RemoveAll(r => r.FirstID.Equals(ch.ID) || r.SecondID.Equals(ch.ID));
                    algo.TwoClassHoursGrouped?.RemoveAll(r => r.FirstID.Equals(ch.ID) || r.SecondID.Equals(ch.ID));
                    algo.ThreeClassHoursGrouped?.RemoveAll(r => r.FirstID.Equals(ch.ID) || r.SecondID.Equals(ch.ID) || r.ThirdID.Equals(ch.ID));

                    algo.ClassHourRequiredStartingTimes?.RemoveAll(r => r.ID.Equals(ch.ID));
                    algo.ClassHourRequiredTimes?.RemoveAll(r => r.ID.Equals(ch.ID));
                    algo.ClassHourRequiredStartingTime?.RemoveAll(r => r.ID.Equals(ch.ID));
                });

                if (isPatern)
                {
                    algo.SerializePatternAlgo(localID);
                }
                else
                {
                    algo.Serialize(localID);
                }
            }

            if (cl != null)
            {
                levels.ForEach(c =>
                {
                    var courseInfo = cl.Courses.FirstOrDefault(cc => cc.ID.Equals(c.CourseID));
                    if (courseInfo != null)
                    {
                        courseInfo.Levels.RemoveAll(rl => rl.ID.Equals(c.ID));
                    }

                    cl.Classes.RemoveAll(ch => ch.LevelID.Equals(c.ID) && ch.CourseID.Equals(c.CourseID));

                    cl.ClassHours.RemoveAll(ch => ch.LevelID.Equals(c.ID) && ch.CourseID.Equals(c.CourseID));

                    cl.Students?.ForEach(st =>
                    {
                        st.Preselections?.Clear();
                        //st.Preselections?.RemoveAll(p => p.LevelID.Equals(c.ID) && p.CourseID.Equals(c.CourseID));
                    });
                });

                if (isPatern)
                {
                    cl.SerializePatternCase(localID);
                }
                else
                {
                    cl.Serialize(localID);
                }
            }
        }
Exemplo n.º 16
0
        public static void SerializePatternAlgo(this AlgoRule model, string localID)
        {
            string path = GetAlgoPath(localID);

            path.SerializeObjectToJson(model);
        }