void save(HostView host) { var rule = base.GetCLAlgoRule(base.LocalID); if (this.GetCurrentRuleEnum() == MixedAlgoRuleEnum.ClassHoursRequiredStartingTimes) { rule.ClassHoursRequiredStartingTimes.Clear(); foreach (var r in Rules) { var model = new ClassHoursRequiredStartingTimesRule { UID = r.UID, Times = r.Periods, Weight = r.Weight, Active = r.IsActive, ClassID = r.ClassID, CourseID = r.CourseID, TeacherID = r.TeacherID, TagID = r.TagID }; rule.ClassHoursRequiredStartingTimes.Add(model); } } else if (this.GetCurrentRuleEnum() == MixedAlgoRuleEnum.ClassHoursRequiredTimes) { rule.ClassHoursRequiredTimes?.Clear(); foreach (var r in Rules) { var model = new ClassHoursRequiredTimesRule() { UID = r.UID, Times = r.Periods, Active = r.IsActive, Weight = r.Weight, ClassID = r.ClassID, CourseID = r.CourseID, TeacherID = r.TeacherID, TagID = r.TagID }; rule.ClassHoursRequiredTimes?.Add(model); } } base.SerializePatternAlgo(rule, base.LocalID); this.ShowDialog("提示信息", "保存成功", CustomControl.Enums.DialogSettingType.NoButton, CustomControl.Enums.DialogType.None); }
void save(HostView host) { var rule = CommonDataManager.GetAminAlgoRule(base.LocalID); if (this.GetCurrentRuleEnum() == AdministrativeAlgoRuleEnum.ClassHoursRequiredStartingTimes) { rule.ClassHoursRequiredStartingTimes.Clear(); foreach (var r in Rules) { var model = new ClassHoursRequiredStartingTimesRule { UID = r.UID, Times = r.Periods, Weight = (int)r.Weight, Active = r.IsActive, ClassID = r.ClassID, CourseID = r.CourseID, TeacherID = r.TeacherID }; rule.ClassHoursRequiredStartingTimes.Add(model); } } else if (this.GetCurrentRuleEnum() == AdministrativeAlgoRuleEnum.ClassHoursRequiredTimes) { rule.ClassHoursRequiredTimes?.Clear(); foreach (var r in Rules) { var model = new ClassHoursRequiredTimesRule() { UID = r.UID, Times = r.Periods, Active = r.IsActive, Weight = (int)r.Weight, ClassID = r.ClassID, CourseID = r.CourseID, TeacherID = r.TeacherID }; rule.ClassHoursRequiredTimes?.Add(model); } } rule.Serialize(base.LocalID); this.ShowDialog("提示信息", "保存成功", CustomControl.Enums.DialogSettingType.NoButton, CustomControl.Enums.DialogType.None); }
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)); }