private void buttonCreateConstraint_Click(object sender, RoutedEventArgs e)
        {
            if (comboConstraintType.SelectedIndex == -1)
            {
                MessageBox.Show("A selected Constraint is required.");
            }

            if (comboConstraintType.SelectedIndex == 0)
            {
                AllProfessorsDayLimitWindow constraintWindow = new AllProfessorsDayLimitWindow();
                var dialogResult = constraintWindow.ShowDialog();
                if (dialogResult.Value)
                {
                    var constraint = new AllProfessorsDayLimitConstraint(constraintWindow.ConstraintName, constraintWindow.MaximumClassesPerDay);
                    if (!Configuration.Instance.Constraints.Contains(constraint))
                    {
                        Configuration.Instance.Constraints.Add(constraint);
                    }
                    else
                    {
                        MessageBox.Show("Ooops. This constraint already exists!");
                        return;
                    }
                }
            }

            if (comboConstraintType.SelectedIndex == 1)
            {
                ClassCountDayLimitWindow constraintWindow = new ClassCountDayLimitWindow();
                var dialogResult = constraintWindow.ShowDialog();
                if (dialogResult.Value)
                {
                    var constraint = new ClassCountDayLimitConstraint(constraintWindow.ConstraintName, constraintWindow.MaximumSameClassesPerDay);
                    if (!Configuration.Instance.Constraints.Contains(constraint))
                    {
                        Configuration.Instance.Constraints.Add(constraint);
                    }
                    else
                    {
                        MessageBox.Show("Ooops. This constraint already exists!");
                        return;
                    }
                }
            }

            if (comboConstraintType.SelectedIndex == 2)
            {
                ProfessorDayAndTimeWindow constraintWindow = new ProfessorDayAndTimeWindow();
                var dialogResult = constraintWindow.ShowDialog();
                if (dialogResult.Value)
                {
                    var constraint = new ProfessorDayAndTimeConstraint(constraintWindow.ConstraintName, constraintWindow.Requirements.ToList());
                    if (!Configuration.Instance.Constraints.Contains(constraint))
                    {
                        Configuration.Instance.Constraints.Add(constraint);
                    }
                    else
                    {
                        MessageBox.Show("Ooops. This constraint already exists!");
                        return;
                    }
                }
            }

            if (comboConstraintType.SelectedIndex == 3)
            {
                ProfessorDaysOffWindow constraintWindow = new ProfessorDaysOffWindow();
                var dialogResult = constraintWindow.ShowDialog();
                if (dialogResult.Value)
                {
                    var constraint = new ProfessorDayConstraint(constraintWindow.ConstraintName, (constraintWindow.comboProf.SelectedItem as Professor), constraintWindow.Days);
                    if (!Configuration.Instance.Constraints.Contains(constraint))
                    {
                        Configuration.Instance.Constraints.Add(constraint);
                    }
                    else
                    {
                        MessageBox.Show("Ooops. This constraint already exists!");
                        return;
                    }
                }
            }

            if (comboConstraintType.SelectedIndex == 4)
            {
                ProfessorTimeOffWindow constraintWindow = new ProfessorTimeOffWindow();
                var dialogResult = constraintWindow.ShowDialog();
                if (dialogResult.Value)
                {
                    var constraint = new ProfessorTimeConstraint(constraintWindow.ConstraintName, (constraintWindow.comboProf.SelectedItem as Professor), constraintWindow.Start, constraintWindow.End);
                    if (!Configuration.Instance.Constraints.Contains(constraint))
                    {
                        Configuration.Instance.Constraints.Add(constraint);
                    }
                    else
                    {
                        MessageBox.Show("Ooops. This constraint already exists!");
                        return;
                    }
                }
            }

            if (comboConstraintType.SelectedIndex == 5)
            {
                SingleProfessorDayLimitWindow constraintWindow = new SingleProfessorDayLimitWindow();
                var dialogResult = constraintWindow.ShowDialog();
                if (dialogResult.Value)
                {
                    var constraint = new SingleProfessorDayLimitConstraint(constraintWindow.ConstraintName, (constraintWindow.comboProf.SelectedItem as Professor), constraintWindow.MaximumClassesPerDay);
                    if (!Configuration.Instance.Constraints.Contains(constraint))
                    {
                        Configuration.Instance.Constraints.Add(constraint);
                    }
                    else
                    {
                        MessageBox.Show("Ooops. This constraint already exists!");
                        return;
                    }
                }
            }
        }
Exemplo n.º 2
0
        private void TestProfessorDaysOff()
        {
            config.Clear();

            Stopwatch s = new Stopwatch();

            var mitov = new Professor("Kiril Mitov");
            var abrama = new Professor("Janet Abramowitch");

            var r12 = new Room("12", CourseType.NormalCourse);
            var r24 = new Room("24", CourseType.NormalCourse);
            var r32 = new Room("32", CourseType.ComputerCourse);

            var g11a = new StudentGroup("11A");
            var g11g = new StudentGroup("11G");

            var tp = new Course("TP", mitov, CourseType.ComputerCourse);
            var maths = new Course("Maths", abrama, CourseType.NormalCourse);

            var tp11a = new Class(g11a, tp, new TimeSpan(1, 20, 0), r32);
            var tp11g = new Class(g11g, tp, new TimeSpan(1, 20, 0), r24);

            config.Rooms.Add(r12);
            config.Rooms.Add(r24);
            config.Rooms.Add(r32);

            config.Groups.Add(g11a);
            config.Groups.Add(g11g);

            config.Professors.Add(mitov);
            config.Professors.Add(abrama);

            config.Courses.Add(tp);
            config.Courses.Add(maths);

            Schedule sched = new Schedule();
            for (int i = 0; i < 7; i++)
            {
                sched.SetStartTime(i, g11a, new TimeSpan(8, 0, 0));
                sched.SetStartTime(i, g11g, new TimeSpan(9, 20, 0));
            }
            sched[0][g11a] = new ObservableCollection<Class>();
            sched[0][g11g] = new ObservableCollection<Class>();

            sched[0][g11a].Add(tp11a);//11A class has TP from 8AM to 9:20AM in room 32 on monday
            sched[0][g11g].Add(tp11g);//11G class has TP from 9:20AM to 10:40AM in room 24 on monday
            //result should be false as professor day conflict
            List<int> daysOff = new List<int> {0,2,5};
            s.Start();
            IConstraint c = new ProfessorDayConstraint(mitov, daysOff);
            var result = c.Check(sched);
            s.Stop();

            string pass = result.ConstraintFulfilled == false ? "succeeded" : "failed";
            Console.WriteLine("TestProfessorDayConstraint() " + pass);
            Console.WriteLine(result.ErrorMessage);
            Console.WriteLine("{0} ms.", s.ElapsedMilliseconds);
        }