Ejemplo n.º 1
0
        private void TestProfessorDayAndTimeOff()
        {
            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, 35, 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:35AM to 10:55AM in room 24 on monday
            //result should be false as professor day conflict
            TimeSpan start = new TimeSpan(9, 30, 0);
            TimeSpan end = new TimeSpan(16, 20, 0);
            List<TimeDayRequirement> prevents = new List<TimeDayRequirement>();
            TimeDayRequirement aPrevent = new TimeDayRequirement(mitov, 0, start, end);
            prevents.Add(aPrevent);
            s.Start();
            IConstraint c = new ProfessorDayAndTimeConstraint(prevents);
            var result = c.Check(sched);
            s.Stop();

            string pass = result.ConstraintFulfilled == false ? "succeeded" : "failed";
            Console.WriteLine("TestProfessorDayAndTimeConstraint() " + pass);
            Console.WriteLine(result.ErrorMessage);
            Console.WriteLine("{0} ms.", s.ElapsedMilliseconds);
        }
Ejemplo n.º 2
0
        private void TestRoomTimeOverlap3()
        {
            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 math11g = new Class(g11g, maths, new TimeSpan(2, 0, 0), r32);

            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(10, 0, 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
            sched[0][g11g].Add(math11g);//11G class has Maths from 10AM to 12AM in room 32
            //result should be true, rooms do not conflict
            s.Start();
            IConstraint c = new RoomTimeOverlapConstraint();
            var result = c.Check(sched);
            s.Stop();

            string pass = result.ConstraintFulfilled == true ? "succeeded" : "failed";
            Console.WriteLine("TestRoomTimeOverlap3() " + pass);
            Console.WriteLine(result.ErrorMessage);
            Console.WriteLine("{0} ms.", s.ElapsedMilliseconds);
        }
        void InitializeSchedule()
        {
            Conflicts = new ObservableCollection<ConstraintResult>();

            Configuration.Instance.Groups = new ObservableCollection<StudentGroup>();
            Configuration.Instance.Groups.Add(new StudentGroup("11A"));
            Configuration.Instance.Groups.Add(new StudentGroup("11B"));
            Configuration.Instance.Groups.Add(new StudentGroup("11V"));
            Configuration.Instance.Groups.Add(new StudentGroup("11G"));
            Configuration.Instance.Professors = new ObservableCollection<Professor>{new Professor("Abramowitch"),
                new Professor("Mitova"), new Professor("Mitov")};
            Configuration.Instance.Courses = new ObservableCollection<Course>
                {new Course("Maths", Configuration.Instance.Professors[0], CourseType.NormalCourse),
                new Course("BEL", Configuration.Instance.Professors[1], CourseType.NormalCourse), 
                new Course("TP", Configuration.Instance.Professors[2], CourseType.ComputerCourse),
                new Course("Break", Professor.Empty, CourseType.Break)};
            Configuration.Instance.Rooms = new ObservableCollection<Room>{new Room("42", CourseType.NormalCourse), new Room("21", CourseType.NormalCourse),
                new Room("34", CourseType.ComputerCourse)};

            Configuration.Instance.Constraints.Add(new AllProfessorsDayLimitConstraint("PREDEFINED", 9));
            Configuration.Instance.Constraints.Add(new ClassCountDayLimitConstraint("PREDEFINED", 3));
            Configuration.Instance.Constraints.Add(new ProfessorDayAndTimeConstraint("PREDEFINED", new List<TimeDayRequirement>
                {
                    new TimeDayRequirement(Configuration.Instance.Professors[0], 2, new TimeSpan(8,0,0), new TimeSpan(9,0,0)),
                    new TimeDayRequirement(Configuration.Instance.Professors[1], 3, new TimeSpan(9,0,0), new TimeSpan(10,0,0))
                }
            ));

            Configuration.Instance.Constraints.Add(new ProfessorDayConstraint("PREDEFINED", Configuration.Instance.Professors[0], new List<int> { 0, 1 }));
            Configuration.Instance.Constraints.Add(new ProfessorTimeConstraint("PREDEFINED", Configuration.Instance.Professors[0], new TimeSpan(9, 0, 0), new TimeSpan(10, 0, 0)));
            Configuration.Instance.Constraints.Add(new ProfessorTimeOverlapConstraint("PREDEFINED"));
            Configuration.Instance.Constraints.Add(new RoomTimeOverlapConstraint("PREDEFINED"));
            Configuration.Instance.Constraints.Add(new SingleProfessorDayLimitConstraint("PREDEFINED", Configuration.Instance.Professors[2], 4));

            var groups = Configuration.Instance.Groups;
            var courses = Configuration.Instance.Courses;
            var rooms = Configuration.Instance.Rooms;
            var profs = Configuration.Instance.Professors;
            var classes = Configuration.Instance.Classes;
            CurrentSchedule = new Schedule();
            for(int i = 0;i<7;i++)
            {
                CurrentSchedule[i][groups[0]] = new ObservableCollection<Class>();
                CurrentSchedule[i][groups[1]] = new ObservableCollection<Class>();
                CurrentSchedule[i][groups[2]] = new ObservableCollection<Class>();
                CurrentSchedule[i][groups[3]] = new ObservableCollection<Class>();
                CurrentSchedule.SetStartTime(i, groups[0], TimeSpan.FromHours(8));
                CurrentSchedule.SetStartTime(i, groups[1], TimeSpan.FromHours(8));
                CurrentSchedule.SetStartTime(i, groups[2], TimeSpan.FromHours(8));
                CurrentSchedule.SetStartTime(i, groups[3], TimeSpan.FromHours(8));
            }
            CurrentSchedule.DaysChangedGroupAdded(groups[0]);
            CurrentSchedule.DaysChangedGroupAdded(groups[1]);
            CurrentSchedule.DaysChangedGroupAdded(groups[2]);
            CurrentSchedule.DaysChangedGroupAdded(groups[3]);
            classes.Add(groups[0], new TrulyObservableCollection<ClassContainer>());
            classes.Add(groups[1], new TrulyObservableCollection<ClassContainer>());
            classes.Add(groups[2], new TrulyObservableCollection<ClassContainer>());
            classes.Add(groups[3], new TrulyObservableCollection<ClassContainer>());
            classes[groups[0]].Add(new ClassContainer(new Class(groups[0], courses[3], TimeSpan.FromMinutes(40), Room.Empty), 1000));
            classes[groups[0]].Add(new ClassContainer(new Class(groups[0], courses[0], TimeSpan.FromMinutes(80), rooms[1]), 10));
            classes[groups[0]].Add(new ClassContainer(new Class(groups[0], courses[1], TimeSpan.FromMinutes(80), rooms[0]), 4));
            classes[groups[0]].Add(new ClassContainer(new Class(groups[0], courses[2], TimeSpan.FromMinutes(80), rooms[2]), 5));
            classes[groups[1]].Add(new ClassContainer(new Class(groups[1], courses[0], TimeSpan.FromMinutes(80), rooms[1]), 2));
            classes[groups[1]].Add(new ClassContainer(new Class(groups[1], courses[1], TimeSpan.FromMinutes(80), rooms[0]), 6));
            classes[groups[1]].Add(new ClassContainer(new Class(groups[1], courses[2], TimeSpan.FromMinutes(80), rooms[2]), 4));
            classes[groups[2]].Add(new ClassContainer(new Class(groups[2], courses[0], TimeSpan.FromMinutes(80), rooms[1]), 2));
            classes[groups[2]].Add(new ClassContainer(new Class(groups[2], courses[1], TimeSpan.FromMinutes(80), rooms[0]), 6));
            classes[groups[2]].Add(new ClassContainer(new Class(groups[2], courses[2], TimeSpan.FromMinutes(80), rooms[2]), 4));
            classes[groups[3]].Add(new ClassContainer(new Class(groups[3], courses[0], TimeSpan.FromMinutes(80), rooms[1]), 2));
            classes[groups[3]].Add(new ClassContainer(new Class(groups[3], courses[1], TimeSpan.FromMinutes(80), rooms[0]), 6));
            classes[groups[3]].Add(new ClassContainer(new Class(groups[3], courses[2], TimeSpan.FromMinutes(80), rooms[2]), 4));
        }