Exemple #1
0
        private bool arrangeSuperGroups(int sgInd, int day)
        {
            ScheduleGenerator3 sg = null;

            if (sgInd == superGroups.Count)
            {
                /*
                 * for (int t = 0; t < teachers.Count; t++)
                 * {
                 *  int demand = teacherDemand[t];
                 *  int today = minLessons - dayState[day].teacherLeftLessons[t];
                 *
                 *  if (demand > (workDays - day) * minLessons) return false;
                 * }
                 */

                sg = new ScheduleGenerator3(groups, teachers, subjects, higharchy, multilessons, supergroupMultilessons);
                if (sg.gen(day, (day == workDays)) == null)
                {
                    return(false);
                }

                Console.WriteLine($"--------------> {day} {sgInd}");

                if (day == workDays)
                {
                    return(arrangeMultilessons(1, 0));
                }
                return(arrangeSuperGroups(0, day + 1));
            }

            for (int t = 0; t < teachers.Count; t++)
            {
                int demand = teacherDemand[t];
                int today  = minLessons - dayState[day].teacherLeftLessons[t];

                if (demand > (workDays - day + 1) * minLessons - today)
                {
                    return(false);
                }
            }

            if (day != workDays)
            {
                sg = new ScheduleGenerator3(groups, teachers, subjects, higharchy, multilessons, supergroupMultilessons);
                if (sg.gen(day, false) == null)
                {
                    return(false);
                }
            }


            return(solveSuperGroup(day, sgInd, 0));
        }
Exemple #2
0
        private bool arrangeMultilessons(int day, int ind)
        {
            while (day != workDays + 1 && ind == allMultilessons.Count)
            {
                ind = 0;
                day++;
            }
            if (day == workDays + 1)
            {
                int cnt = 0;
                for (int i = 0; i < usedMultilessons.Length; i++)
                {
                    if (usedMultilessons[i] == true)
                    {
                        cnt++;
                    }
                }

                System.Console.WriteLine($"---------------------------------------------------managed to achieve: {cnt}");
                if (cnt != usedMultilessons.Length)
                {
                    return(false);
                }

                ScheduleGenerator3 sg    = new ScheduleGenerator3(groups, teachers, subjects, higharchy, multilessons, supergroupMultilessons);
                WeekSchedule       sgRes = sg.gen(workDays, true);
                if (sgRes is null)
                {
                    return(false);
                }

                ans = sgRes;
                return(true);
            }

            for (int i = 0; i < allMultilessons.Count; i++)
            {
                if (usedMultilessons[i] == true)
                {
                    continue;
                }

                bool fitted = false;
                for (int d = day; d <= workDays; d++)
                {
                    fitted |= applyMultilesson(d, i, allMultilessons[i].val.l, +1);
                    applyMultilesson(d, i, allMultilessons[i].val.l, -1);
                }

                if (fitted == false)
                {
                    return(false);
                }
            }
            for (int t = 0; t < teachers.Count; t++)
            {
                int demand = Enumerable.Range(0, allMultilessons.Count).Where(ind => usedMultilessons[ind] == false)
                             .Where(ind => allMultilessons[ind].t.Equals(teachers[t]) == true)
                             .Sum(ind => allMultilessons[ind].val.l);

                for (int d = day; d <= workDays; d++)
                {
                    demand -= dayState[d].teacherLeftLessons[t];
                }
                if (demand > 0)
                {
                    return(false);
                }
            }

            bool res = false;

            if (usedMultilessons[ind] == false)
            {
                usedMultilessons[ind] = true;
                multilessons[day].Add(allMultilessons[ind]);

                bool successful = applyMultilesson(day, ind, allMultilessons[ind].val.l, +1);

                if (successful == true)
                {
                    ScheduleGenerator3 sg = new ScheduleGenerator3(groups, teachers, subjects, higharchy, multilessons, supergroupMultilessons);
                    if (sg.gen(workDays, true) != null)
                    {
                        res |= arrangeMultilessons(day, ind + 1);
                    }
                }


                applyMultilesson(day, ind, allMultilessons[ind].val.l, -1);

                multilessons[day].RemoveAt(multilessons[day].Count - 1);
                usedMultilessons[ind] = false;

                if (res == true)
                {
                    return(true);
                }
            }

            if ((usedMultilessons[ind] == true || day != workDays) && arrangeMultilessons(day, ind + 1) == true)
            {
                res = true;
                return(true);
            }

            System.Console.WriteLine($"em pone {usedMultilessons.Count(x => x==true)}");
            return(false);
        }