private void MuatatePopulation() { currentPopulation.Sort(); for (int i = IdealCount; i < PopulationSize; ++i) { Shedule sh = Mutate(currentPopulation.shedules[i].Item1); currentPopulation.shedules[i] = new Tuple <Shedule, int>(sh, sh.GetConflictsCount()); } }
public Population(Data data, int PopulationSize, Random rand) { shedules = new List <Tuple <Shedule, int> >(); for (int i = 0; i < PopulationSize; ++i) { Shedule s = new Shedule(data, rand); shedules.Add(new Tuple <Shedule, int>(s, s.GetConflictsCount())); } }
private Shedule Mutate(Shedule sh) { Shedule k = new Shedule(data, rand); for (int i = 0; i < k.plans.Count(); ++i) { if (rand.NextDouble() > MutationRate) { k.plans[i] = sh.plans[i]; } } return(k); }
private Shedule CrossShedules(Shedule shedule1, Shedule shedule2) { Shedule res = new Shedule(data, rand); for (int i = 0; i < res.plans.Count(); ++i) { if (rand.NextDouble() > 0.5) { res.plans[i] = shedule1.plans[i]; } else { res.plans[i] = shedule2.plans[i]; } } return(res); }
private void CrossOverPopulation() { Population newPopulation = new Population(); currentPopulation.Sort(); for (int i = 0; i < IdealCount; ++i) { newPopulation.shedules.Add(currentPopulation.shedules[i]); } for (int i = IdealCount; i < PopulationSize; ++i) { Shedule sh1 = currentPopulation.shedules[rand.Next(currentPopulation.shedules.Count()) % TopForCrossOvering].Item1; Shedule sh2 = currentPopulation.shedules[rand.Next(currentPopulation.shedules.Count()) % TopForCrossOvering].Item1; Shedule newSh = CrossShedules(sh1, sh2); newPopulation.shedules.Add(new Tuple <Shedule, int>(newSh, newSh.GetConflictsCount())); } currentPopulation = newPopulation; }