Skip to content

Instantly share code, notes, and snippets.

@TheFo2sh
Created June 9, 2020 22:18
Show Gist options
  • Save TheFo2sh/8d8ae6410761e80583f365e6012abd46 to your computer and use it in GitHub Desktop.
Save TheFo2sh/8d8ae6410761e80583f365e6012abd46 to your computer and use it in GitHub Desktop.
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