public DaySchedule(ClassSchedule owner, int lessonsPerDay = 7, int dayOfWeek = 6) { _class = owner; _dayOfWeek = dayOfWeek; _lessons = new List <Lesson>(lessonsPerDay); AddLessons(lessonsPerDay); }
/// <summary> /// 交叉算子,双亲交配并产生下一代种群 /// </summary> private void Cross() { int first, second; for (int i = 0; i < _populationSize; i++) { Schedule s; //交叉概率80% if (Global.Random.Next(100) < Global.CrossRate) { Global.RandomGeneric2Value(_populationSize, out first, out second); //切分的标志,标志以前用第一个个体的基因,标志之后用第二个个体的基因. int f = Global.Random.Next(Global.ClassCount); s = new Schedule(Global.ClassCount); for (int j = 0; j < f; j++) { s[j] = new ClassSchedule(_selectedSchedule[first], Global.DayPerWeek, Global.LessonPerDay); } for (int j = f; j < Global.ClassCount; j++) { s[j] = new ClassSchedule(_selectedSchedule[second], Global.DayPerWeek, Global.LessonPerDay); } s.Dirty(); } else { s = new Schedule(_selectedSchedule[Global.Random.Next(_populationSize)]); } //将新个体放入新种群 _newPopulation.Add(s); } }
/// <summary> /// 复制构造函数 /// </summary> /// <param name="other">源对象</param> /// <param name="owner">新对象属于的Schedule</param> public ClassSchedule(ClassSchedule other, Schedule owner = null) { this._days = new List <DaySchedule>(other._days.Count); foreach (DaySchedule d in other._days) { this._days.Add(new DaySchedule(d, this)); } this._classID = other._classID; this._schedule = owner; }
public override bool Equals(object other) { if (other is ClassSchedule) { ClassSchedule cs = other as ClassSchedule; return(cs._classID == _classID); } else { return(false); } }
/// <summary> /// 复制构造函数 /// </summary> /// <param name="other"></param> /// <param name="_class"></param> public DaySchedule(DaySchedule other, ClassSchedule _class = null) { _dayOfWeek = other._dayOfWeek; _assginedCount = other._assginedCount; _lessons = new List <Lesson>(other._lessons.Count); foreach (Lesson l in other._lessons) { _lessons.Add(new Lesson(l, this)); } if (_class == null) { this._class = other._class; } else { this._class = _class; } }
/// <summary> /// 深度复制 /// </summary> /// <param name="owner">源对象</param> /// <returns></returns> public ClassSchedule DeepClone(Schedule owner = null) { ClassSchedule cs = new ClassSchedule(this, owner); return(cs); }