Created
June 9, 2020 22:18
-
-
Save TheFo2sh/8d8ae6410761e80583f365e6012abd46 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
using (var dataContext = new DataContext()) | |
{ | |
Population population = new Population(1000, new TimeTableChromosome(dataContext), | |
new TimeTableChromosome.FitnessFunction(), new EliteSelection()); | |
int i = 0; | |
while (true) | |
{ | |
population.RunEpoch(); | |
i++; | |
if (population.FitnessMax >= 0.99 || i >= 1000) | |
{ | |
break; | |
} | |
} | |
var timetable = (population.BestChromosome as TimeTableChromosome).Value.Select(chromosome => | |
new TimeSlot() | |
{ | |
CourseId = chromosome.CourseId, | |
PlaceId = chromosome.PlaceId, | |
Day = (DayOfWeek) chromosome.Day, | |
Start = chromosome.StartAt, End = chromosome.EndAt, | |
Id = Guid.NewGuid().ToString() | |
} | |
).ToList(); | |
dataContext.TimeSlots.AddRange(timetable); | |
dataContext.SaveChanges(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment