private Buckets GenerateBueckets(Individual individual) { var datasets = Datasets.Get(); var buckets = new Buckets(datasets.TotalPeriods); for (int i = 0; i < datasets.TotalPeriods; ++i) { buckets.Add(new List <Chromosome>()); } foreach (var chromo in individual.Genome) { buckets[chromo.Gene.TimeId].Add(chromo); } return(buckets); }
public float BucketCheck(Func <List <Chromosome>, int> check) { int violations = 0; var datasets = Datasets.Get(); foreach (var bucket in mBuckets) { if (bucket.Count == 0) { continue; } violations += check(bucket); } return(violations); }
public float Evaluate() { var datasets = Datasets.Get(); var violations = 0; foreach (var chromo in mIndividual.Genome) { var teacher = datasets.Teachers.Find(t => t.Id == chromo.Gene.TeacherId); if (!teacher.ProvidedCourse.Contains(chromo.CourseId)) { violations += 1; } } var error = Convert.ToSingle(violations) / mIndividual.Genome.Count; var maxAllowed = mIndividual.Genome.Count / 6; var score = maxAllowed * (1 - error); score *= score; return(score); }
public DNA(DNA left, DNA right) { this.RoomId = RandomEngine.NextDouble() < 0.5 ? left.RoomId : right.RoomId; this.TeacherId = RandomEngine.NextDouble() < 0.5 ? left.TeacherId : right.TeacherId; this.TimeId = RandomEngine.NextDouble() < 0.5 ? left.TimeId : right.TimeId; var datasets = Datasets.Get(); if (RandomEngine.NextDouble() < Config.MutationRate) { if (RandomEngine.NextDouble() < 0.33) { this.RoomId = datasets.Rooms[RandomEngine.Next(datasets.Rooms.Count)].Id; } if (RandomEngine.NextDouble() < 0.33) { this.TeacherId = datasets.Teachers[RandomEngine.Next(datasets.Teachers.Count)].Id; } if (RandomEngine.NextDouble() < 0.33) { this.TimeId = RandomEngine.Next(datasets.TotalPeriods); } } }
public float Evaluate() { var datasets = Datasets.Get(); var violations = BucketCheck(bucket => { var marked = new List <Chromosome>(); var count = 0; foreach (var chromo in bucket) { if (marked.Contains(chromo)) { continue; } marked.Add(chromo); if (chromo.IsSubClass) { var rawClasses = datasets.SubClasses.Find(x => x.Id == chromo.ClassId).DerivingFrom; foreach (var other in bucket) { if (marked.Contains(other)) { continue; } if ((!other.IsSubClass && rawClasses.Contains(other.ClassId)) || (other.IsSubClass && other.ClassId == chromo.ClassId)) { count += 1; marked.Add(other); } } } else { foreach (var other in bucket) { if (marked.Contains(other)) { continue; } if (!other.IsSubClass && other.ClassId == chromo.ClassId) { count += 1; marked.Add(other); } } } } return(count); }); var maxAllowed = mIndividual.Genome.Count / 6; var score = Math.Max(maxAllowed - violations, 0); score *= score; return(score); }
public float Evaluate() { var datasets = Datasets.Get(); int violations = 0; foreach (var course in datasets.Courses) { var progress = new Dictionary <int, int>(); var list = new List <Chromosome>(); foreach (var chromo in mIndividual.Genome) { if (chromo.CourseId == course.Id) { list.Add(chromo); } } list.Sort(); int time = -1; var current = new List <Chromosome>(); foreach (var chromo in list) { if (!progress.Keys.Contains(chromo.ClassId)) { progress.Add(chromo.ClassId, 1); } else { progress[chromo.ClassId]++; } if (time < chromo.Gene.TimeId) { time = chromo.Gene.TimeId; current.Clear(); current.Add(chromo); continue; } else if (time == chromo.Gene.TimeId) { foreach (var other in current) { if (chromo.Gene.RoomId != other.Gene.RoomId || progress[chromo.ClassId] != progress[other.ClassId]) { violations += 1; } } } else { throw new Exception("Time mismatch."); } } } var maxAllowed = mIndividual.Genome.Count / 6; var score = Math.Max(maxAllowed - violations, 0); score *= score; return(score); }