private double GetSolutionWeight(IEnumerable<ScheduledTimeSlot> solution, IEnumerable<Group> groups)
        {
            var solutionWeight = solution.Sum(s =>
                s.subject.teachers.Sum(t =>
                    (t.requirements.availableTimeSlots.Any(a => a.Includes(s.timeSlot)) ? t.requirements.weight : 0) +
                    (t.requirements.requiredRooms.Any(r => r == s.room)                 ? t.requirements.weight : 0)));

            var personalSchedule = new PersonalSchedule(solution);

            var hasHoles = false;
            foreach (var group in groups)
            {
                var groupSchedule = personalSchedule.GetGroupProgram(group).ToList();
                groupSchedule.Sort((s1, s2) => s1.timeSlot.StartHour.CompareTo(s2.timeSlot.StartHour));
                var groupByDays = groupSchedule.GroupBy(s => s.timeSlot.Day);
                var totalGroupHoleHours = groupByDays.Sum(g => g.Zip(g.Skip(1), (s1, s2) => (int) s2.timeSlot.StartHour - s1.timeSlot.EndHour).Sum());
                if (totalGroupHoleHours > 5)
                {
                    hasHoles = true;
                    solutionWeight -= totalGroupHoleHours / 10;
                }
            }

            if (!hasHoles && solutionWeight == solution.Sum(s => s.subject.teachers.Sum(t => 2 * t.requirements.weight)))
            {
                return Double.MaxValue;
            }

            return solutionWeight;
        }
 private void buttonGenerate_Click(object sender, EventArgs e)
 {
     var schedules = new ProgramGenerator().GenerateProgram(rooms, subjects, teachers, groups);
     personalSchedule = new Helpers.PersonalSchedule(schedules.First());
     RefreshData();
 }