Exemplo n.º 1
0
        public void TestSubGroup()
        {
            List <Lesson>      lessons      = new List <Lesson>();
            List <Teacher>     teachers     = new List <Teacher>();
            List <Group>       groups       = new List <Group>();
            List <Subject>     subjects     = new List <Subject>();
            List <Room>        rooms        = new List <Room>();
            List <SubjectType> subjectTypes = new List <SubjectType>();
            List <RoomType>    roomTypes    = new List <RoomType>();
            STGCfg             config       = new STGCfg(1, 1, 2, 1, 5, 10);

            teachers.Add(new Teacher(0));
            teachers.Add(new Teacher(1));

            List <Group> subGroups = new List <Group>();

            subGroups.Add(new Group(0, 10, 1, 1));
            subGroups.Add(new Group(1, 15, 1, 2));
            groups.Add(new Group(2, 25, subGroups));

            roomTypes.Add(new RoomType(1));

            rooms.Add(new Room(0, 40, roomTypes[0]));
            rooms.Add(new Room(1, 40, roomTypes[0]));

            subjectTypes.Add(new SubjectType(0, 2));

            subjects.Add(new Subject(0, subjectTypes[0]));


            foreach (Group g in groups)
            {
                lessons.Add(new Lesson(teachers[0], g.getSubGroup()[0], subjects[0], roomTypes[0], 2));
                lessons.Add(new Lesson(teachers[0], g.getSubGroup()[0], subjects[0], roomTypes[0], 2));

                lessons.Add(new Lesson(teachers[1], g.getSubGroup()[1], subjects[0], roomTypes[0], 2));
                lessons.Add(new Lesson(teachers[1], g.getSubGroup()[1], subjects[0], roomTypes[0], 2));
            }

            SchoolTimetable stt = new SchoolTimetable(teachers, groups, rooms, lessons, 3, 3, config);

            stt.generateSchoolTimetable();
            stt.print();
            Console.WriteLine("################");
            SchoolTimetable stt2 = new SchoolTimetable(stt);

            stt2.print();

            foreach (Lesson l in stt.getLessons())
            {
                Console.WriteLine(l.ToString());
            }

            Console.WriteLine(stt.isCorrect() + " " + stt.fitness());

            stt.genWeb("subGroupTest");
        }
Exemplo n.º 2
0
        private void setSchoolTimetableToDAtaBaseTimetable(Schools school, SchoolTimetable stt)
        {
            foreach (Lesson l in stt.getLessons())
            {
                //--------------------------------
                Groups gr = db.Groups.Find(l.getGroup().getName());
                //--------------------------------

                //--------------------------------
                Teachers te = db.Teachers.Find(l.getTeacher().getName());
                //--------------------------------

                //--------------------------------
                Rooms ro = db.Rooms.Find(l.getRoom().getName());
                //--------------------------------

                //--------------------------------
                Lessons        le      = null;
                List <Lessons> lessons = (from b in db.Lessons
                                          where b.SchoolsId.Equals(school.Id)
                                          select b).ToList();
                foreach (Lessons ls in lessons)
                {
                    if (ls.Groups.Equals(gr) &&
                        ls.Teachers.Equals(te) &&
                        ls.Subjects.Id.Equals(l.getSubject().getName())
                        )
                    {
                        le = ls;
                        break;
                    }
                }
                //--------------------------------

                for (int i = 0; i < l.getSize(); i++)
                {
                    Timetables timetable = new Timetables();
                    timetable.Hour      = l.getSlots()[i].hour;
                    timetable.Day       = l.getSlots()[i].day;
                    timetable.LessonsId = le.Id;
                    timetable.Part      = i + 1;
                    timetable.SchoolsId = school.Id;
                    timetable.RoomsId   = ro.Id;
                    timetable.Size      = l.getSize();

                    db.Timetables.Add(timetable);
                    db.SaveChanges();
                }
            }
        }