public void shouldReturnOnlyTheSameSlots() { Random rand = new Random(); Group g = new Group(1, "g1"); Teacher t = new Teacher(1, "t1"); TimeTable gtt = new TimeTable(g); TimeTable ttt = new TimeTable(t); Lesson lesson = new Lesson(t, g, new Subject(1, "s1", SubjectType.INN)); int day; int hour; for (int i = 0; i < 17; i++) { day = rand.Next(0, ConstVariable.NUMBER_OF_DAYS); hour = rand.Next(0, ConstVariable.NUMBER_OF_SLOTS_IN_DAY); gtt.addLesson(lesson, day, hour); day = rand.Next(0, ConstVariable.NUMBER_OF_DAYS); hour = rand.Next(0, ConstVariable.NUMBER_OF_SLOTS_IN_DAY); ttt.addLesson(lesson, day, hour); } List <TimeSlot> gts = gtt.getFreeTimeSlot(); List <TimeSlot> tts = ttt.getFreeTimeSlot(); List <TimeSlot> ts = new SchoolTimeTable().getTheSameSlots(gts, tts); gtt.printTimeTable(); foreach (TimeSlot s in gts) { Console.Write(s.ToString() + " "); } Console.WriteLine(""); ttt.printTimeTable(); foreach (TimeSlot s in tts) { Console.Write(s.ToString() + " "); } Console.WriteLine("\n\n"); foreach (TimeSlot s in ts) { Console.Write(s.ToString() + " "); } Console.WriteLine(""); Boolean result = true; foreach (TimeSlot ti in ts) { if (!(gtt.isEmpty(ti.day, ti.hour) && ttt.isEmpty(ti.day, ti.hour))) { result = false; } } Assert.IsTrue(result, "Time slots is not free"); }
public void TestGeneratingPopulation() { List <Lesson> lessons = new List <Lesson>(); List <Teacher> teachers = new List <Teacher>(); List <Group> groups = new List <Group>(); List <Subject> subjects = new List <Subject>(); // Console.WriteLine("create 6 teachers"); for (int j = 0; j < 7; j++) { teachers.Add(new Teacher(j, "t" + j)); } //Console.WriteLine("create 6 groups"); for (int j = 0; j < 6; j++) { groups.Add(new Group(j, "g" + j)); } //Console.WriteLine("create 10 subject"); int i = 0; subjects.Add(new Subject(i++, "pol", SubjectType.HUM)); subjects.Add(new Subject(i++, "ang", SubjectType.JEZ)); subjects.Add(new Subject(i++, "mat", SubjectType.SCI)); subjects.Add(new Subject(i++, "his", SubjectType.HUM)); subjects.Add(new Subject(i++, "wos", SubjectType.HUM)); subjects.Add(new Subject(i++, "fiz", SubjectType.SCI)); subjects.Add(new Subject(i++, "bio", SubjectType.SCI)); subjects.Add(new Subject(i++, "geo", SubjectType.SCI)); subjects.Add(new Subject(i++, "w-f", SubjectType.SPO)); subjects.Add(new Subject(i++, "rel", SubjectType.INN)); subjects.Add(new Subject(i++, "inf", SubjectType.SPE)); subjects.Add(new Subject(i++, "PRO", SubjectType.SPE)); Console.WriteLine("create list of lesson"); foreach (Group g in groups) { int tI = 0; int sI = 0; int amount = 0; //max = 45 //----------pol---------- tI = 0; sI = 0; amount = 5; lessons.Add(new Lesson(teachers[tI], g, subjects[sI], amount)); lessons.Add(new Lesson(teachers[tI], g, subjects[sI], amount)); lessons.Add(new Lesson(teachers[tI], g, subjects[sI], amount)); lessons.Add(new Lesson(teachers[tI], g, subjects[sI], amount, 2)); //----------ang---------- tI = 1; sI = 1; amount = 4; lessons.Add(new Lesson(teachers[tI], g, subjects[sI], amount)); lessons.Add(new Lesson(teachers[tI], g, subjects[sI], amount)); lessons.Add(new Lesson(teachers[tI], g, subjects[sI], amount)); lessons.Add(new Lesson(teachers[tI], g, subjects[sI], amount)); //----------mat---------- tI = 2; sI = 2; amount = 5; lessons.Add(new Lesson(teachers[tI], g, subjects[sI], amount)); lessons.Add(new Lesson(teachers[tI], g, subjects[sI], amount)); lessons.Add(new Lesson(teachers[tI], g, subjects[sI], amount)); lessons.Add(new Lesson(teachers[tI], g, subjects[sI], amount)); lessons.Add(new Lesson(teachers[tI], g, subjects[sI], amount)); //----------his---------- tI = 3; sI = 3; amount = 1; lessons.Add(new Lesson(teachers[tI], g, subjects[sI], amount)); //----------wos---------- tI = 3; sI = 4; amount = 2; lessons.Add(new Lesson(teachers[tI], g, subjects[sI], amount)); lessons.Add(new Lesson(teachers[tI], g, subjects[sI], amount)); //----------fiz---------- tI = 5; sI = 5; amount = 2; lessons.Add(new Lesson(teachers[tI], g, subjects[sI], amount)); lessons.Add(new Lesson(teachers[tI], g, subjects[sI], amount)); //----------bio---------- tI = 3; sI = 6; amount = 1; lessons.Add(new Lesson(teachers[tI], g, subjects[sI], amount)); //----------geo---------- tI = 3; sI = 7; amount = 2; lessons.Add(new Lesson(teachers[tI], g, subjects[sI], amount)); lessons.Add(new Lesson(teachers[tI], g, subjects[sI], amount)); //----------w-f---------- tI = 4; sI = 8; amount = 3; lessons.Add(new Lesson(teachers[tI], g, subjects[sI], amount)); lessons.Add(new Lesson(teachers[tI], g, subjects[sI], amount)); lessons.Add(new Lesson(teachers[tI], g, subjects[sI], amount)); //----------rel---------- tI = 5; sI = 9; amount = 3; lessons.Add(new Lesson(teachers[tI], g, subjects[sI], amount)); lessons.Add(new Lesson(teachers[tI], g, subjects[sI], amount)); lessons.Add(new Lesson(teachers[tI], g, subjects[sI], amount)); //----------inf---------- tI = 4; sI = 10; amount = 2; lessons.Add(new Lesson(teachers[tI], g, subjects[sI], amount)); lessons.Add(new Lesson(teachers[tI], g, subjects[sI], amount)); //----------pro---------- tI = 6; sI = 11; amount = 5; lessons.Add(new Lesson(teachers[tI], g, subjects[sI], amount, 2)); lessons.Add(new Lesson(teachers[tI], g, subjects[sI], amount, 3)); } Population population = new Population(); population.generatePopulation(10, lessons, teachers, groups); //population.generateNewPopulation(); population.start(5); SchoolTimeTable stt = population.getBestSchoolTimeTable(); stt.printTimeTable(); }
public void shouldReturnMoreThenOneDifferentSubjectTheSameGroup() { List <Lesson> lessons = new List <Lesson>(); List <Teacher> teachers = new List <Teacher>(); List <Group> groups = new List <Group>(); List <Subject> subjects = new List <Subject>(); for (int j = 0; j < 7; j++) { teachers.Add(new Teacher(j, "t" + j)); } for (int j = 0; j < 6; j++) { groups.Add(new Group(j, "g" + j)); } int i = 0; subjects.Add(new Subject(i++, "pol", SubjectType.HUM)); subjects.Add(new Subject(i++, "ang", SubjectType.JEZ)); subjects.Add(new Subject(i++, "mat", SubjectType.SCI)); subjects.Add(new Subject(i++, "his", SubjectType.HUM)); subjects.Add(new Subject(i++, "wos", SubjectType.HUM)); subjects.Add(new Subject(i++, "fiz", SubjectType.SCI)); subjects.Add(new Subject(i++, "bio", SubjectType.SCI)); subjects.Add(new Subject(i++, "geo", SubjectType.SCI)); subjects.Add(new Subject(i++, "w-f", SubjectType.SPO)); subjects.Add(new Subject(i++, "rel", SubjectType.INN)); subjects.Add(new Subject(i++, "inf", SubjectType.SPE)); subjects.Add(new Subject(i++, "PRO", SubjectType.SPE)); foreach (Group g in groups) { int tI = 0; int sI = 0; //max = 45 //----------pol---------- tI = 0; sI = 0; lessons.Add(new Lesson(teachers[tI], g, subjects[sI])); lessons.Add(new Lesson(teachers[tI], g, subjects[sI])); lessons.Add(new Lesson(teachers[tI], g, subjects[sI])); lessons.Add(new Lesson(teachers[tI], g, subjects[sI])); lessons.Add(new Lesson(teachers[tI], g, subjects[sI])); //----------ang---------- tI = 1; sI = 1; lessons.Add(new Lesson(teachers[tI], g, subjects[sI])); lessons.Add(new Lesson(teachers[tI], g, subjects[sI])); lessons.Add(new Lesson(teachers[tI], g, subjects[sI])); //----------mat---------- tI = 2; sI = 2; lessons.Add(new Lesson(teachers[tI], g, subjects[sI])); lessons.Add(new Lesson(teachers[tI], g, subjects[sI])); lessons.Add(new Lesson(teachers[tI], g, subjects[sI])); lessons.Add(new Lesson(teachers[tI], g, subjects[sI])); //----------his---------- tI = 3; sI = 3; lessons.Add(new Lesson(teachers[tI], g, subjects[sI])); //----------wos---------- tI = 3; sI = 4; lessons.Add(new Lesson(teachers[tI], g, subjects[sI])); lessons.Add(new Lesson(teachers[tI], g, subjects[sI])); //----------fiz---------- tI = 5; sI = 5; lessons.Add(new Lesson(teachers[tI], g, subjects[sI])); lessons.Add(new Lesson(teachers[tI], g, subjects[sI])); //----------bio---------- tI = 3; sI = 6; lessons.Add(new Lesson(teachers[tI], g, subjects[sI])); //----------geo---------- tI = 3; sI = 7; lessons.Add(new Lesson(teachers[tI], g, subjects[sI])); //----------w-f---------- tI = 4; sI = 8; lessons.Add(new Lesson(teachers[tI], g, subjects[sI])); lessons.Add(new Lesson(teachers[tI], g, subjects[sI])); lessons.Add(new Lesson(teachers[tI], g, subjects[sI])); //----------rel---------- tI = 5; sI = 9; lessons.Add(new Lesson(teachers[tI], g, subjects[sI])); lessons.Add(new Lesson(teachers[tI], g, subjects[sI])); //----------inf---------- tI = 4; sI = 10; lessons.Add(new Lesson(teachers[tI], g, subjects[sI])); lessons.Add(new Lesson(teachers[tI], g, subjects[sI])); //----------pro---------- tI = 6; sI = 11; lessons.Add(new Lesson(teachers[tI], g, subjects[sI])); lessons.Add(new Lesson(teachers[tI], g, subjects[sI])); lessons.Add(new Lesson(teachers[tI], g, subjects[sI])); lessons.Add(new Lesson(teachers[tI], g, subjects[sI])); } SchoolTimeTable stt = new SchoolTimeTable(lessons, teachers, groups); List <int> indexs = new List <int>(); indexs.Add(0); indexs = stt.findDifferentSubjectTheSameGroup(indexs); if (ConstVariable.NUMBER_OF_LESSONS_TO_POSITIONING > 1) { Assert.IsTrue((indexs.Count > 1), "not found more then one different subject the same group"); } else { Assert.IsTrue(indexs.Count > 0, "not found any different subject"); } }
public void TestCrossing() { List <Lesson> lessons = new List <Lesson>(); List <Teacher> teachers = new List <Teacher>(); List <Group> groups = new List <Group>(); List <Subject> subjects = new List <Subject>(); // Console.WriteLine("create 7 teachers"); for (int j = 0; j < 2; j++) { teachers.Add(new Teacher(j, "t" + j)); } //Console.WriteLine("create 6 groups"); for (int j = 0; j < 6; j++) { groups.Add(new Group(j, "g" + j)); } //Console.WriteLine("create 10 subject"); int i = 0; subjects.Add(new Subject(i++, "pol", SubjectType.HUM)); subjects.Add(new Subject(i++, "mat", SubjectType.SCI)); Console.WriteLine("create list of lesson"); foreach (Group g in groups) { int tI = 0; int sI = 0; int amount = 0; //max = 45 //----------pol---------- tI = 0; sI = 0; amount = 5; lessons.Add(new Lesson(teachers[tI], g, subjects[sI], amount)); lessons.Add(new Lesson(teachers[tI], g, subjects[sI], amount)); lessons.Add(new Lesson(teachers[tI], g, subjects[sI], amount)); lessons.Add(new Lesson(teachers[tI], g, subjects[sI], amount, 2)); tI = 1; sI = 1; amount = 6; lessons.Add(new Lesson(teachers[tI], g, subjects[sI], amount)); lessons.Add(new Lesson(teachers[tI], g, subjects[sI], amount)); lessons.Add(new Lesson(teachers[tI], g, subjects[sI], amount)); lessons.Add(new Lesson(teachers[tI], g, subjects[sI], amount)); lessons.Add(new Lesson(teachers[tI], g, subjects[sI], amount)); lessons.Add(new Lesson(teachers[tI], g, subjects[sI], amount)); } SchoolTimeTable stt1 = new SchoolTimeTable(lessons, teachers, groups); stt1.generateSchoolTimeTable(); stt1.printTimeTable(); SchoolTimeTable stt2 = new SchoolTimeTable(lessons, teachers, groups); stt2.generateSchoolTimeTable(); stt2.printTimeTable(); SchoolTimeTable stt3 = new SchoolTimeTable(lessons, teachers, groups); stt3.crossSchoolTimeTables(stt1, stt2); stt3.printSimpleTimeTable(); }
public void TestGenerating() { 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>(); // Console.WriteLine("create 6 teachers"); for (int j = 0; j < 7; j++) { teachers.Add(new Teacher(j, "t" + j)); } //Console.WriteLine("create 6 groups"); for (int j = 0; j < 6; j++) { groups.Add(new Group(j, "g" + j, 25 + j)); } int nr = 0; rooms.Add(new Room(nr, "nr" + nr++, 25, "A")); rooms.Add(new Room(nr, "nr" + nr++, 40, "A")); rooms.Add(new Room(nr, "nr" + nr++, 40, "A")); rooms.Add(new Room(nr, "nr" + nr++, 40, "A")); rooms.Add(new Room(nr, "nr" + nr++, 40, "B")); rooms.Add(new Room(nr, "nr" + nr++, 40, "B")); rooms.Add(new Room(nr, "nr" + nr++, 40, "C")); //Console.WriteLine("create 10 subject"); int i = 0; subjects.Add(new Subject(i++, "pol", SubjectType.HUM, "A")); subjects.Add(new Subject(i++, "ang", SubjectType.JEZ, "A")); subjects.Add(new Subject(i++, "mat", SubjectType.SCI, "A")); subjects.Add(new Subject(i++, "his", SubjectType.HUM, "A")); subjects.Add(new Subject(i++, "wos", SubjectType.HUM, "A")); subjects.Add(new Subject(i++, "fiz", SubjectType.SCI, "A")); subjects.Add(new Subject(i++, "bio", SubjectType.SCI, "A")); subjects.Add(new Subject(i++, "geo", SubjectType.SCI, "A")); subjects.Add(new Subject(i++, "w-f", SubjectType.SPO, "C")); subjects.Add(new Subject(i++, "rel", SubjectType.INN, "A")); subjects.Add(new Subject(i++, "inf", SubjectType.SPE, "B")); subjects.Add(new Subject(i++, "PRO", SubjectType.SPE, "B")); Console.WriteLine("create list of lesson"); foreach (Group g in groups) { int tI = 0; int sI = 0; int amount = 0; //max = 45 //----------pol---------- tI = 0; sI = 0; amount = 5; lessons.Add(new Lesson(teachers[tI], g, subjects[sI], amount)); lessons.Add(new Lesson(teachers[tI], g, subjects[sI], amount)); lessons.Add(new Lesson(teachers[tI], g, subjects[sI], amount)); lessons.Add(new Lesson(teachers[tI], g, subjects[sI], amount, 2)); //----------ang---------- tI = 1; sI = 1; amount = 4; lessons.Add(new Lesson(teachers[tI], g, subjects[sI], amount)); lessons.Add(new Lesson(teachers[tI], g, subjects[sI], amount)); lessons.Add(new Lesson(teachers[tI], g, subjects[sI], amount)); lessons.Add(new Lesson(teachers[tI], g, subjects[sI], amount)); //----------mat---------- tI = 2; sI = 2; amount = 5; lessons.Add(new Lesson(teachers[tI], g, subjects[sI], amount)); lessons.Add(new Lesson(teachers[tI], g, subjects[sI], amount)); lessons.Add(new Lesson(teachers[tI], g, subjects[sI], amount)); lessons.Add(new Lesson(teachers[tI], g, subjects[sI], amount)); lessons.Add(new Lesson(teachers[tI], g, subjects[sI], amount)); //----------his---------- tI = 3; sI = 3; amount = 1; lessons.Add(new Lesson(teachers[tI], g, subjects[sI], amount)); //----------wos---------- tI = 3; sI = 4; amount = 2; lessons.Add(new Lesson(teachers[tI], g, subjects[sI], amount)); lessons.Add(new Lesson(teachers[tI], g, subjects[sI], amount)); //----------fiz---------- tI = 5; sI = 5; amount = 2; lessons.Add(new Lesson(teachers[tI], g, subjects[sI], amount)); lessons.Add(new Lesson(teachers[tI], g, subjects[sI], amount)); //----------bio---------- tI = 3; sI = 6; amount = 1; lessons.Add(new Lesson(teachers[tI], g, subjects[sI], amount)); //----------geo---------- tI = 3; sI = 7; amount = 2; lessons.Add(new Lesson(teachers[tI], g, subjects[sI], amount)); lessons.Add(new Lesson(teachers[tI], g, subjects[sI], amount)); //----------w-f---------- tI = 4; sI = 8; amount = 3; lessons.Add(new Lesson(teachers[tI], g, subjects[sI], amount)); lessons.Add(new Lesson(teachers[tI], g, subjects[sI], amount)); lessons.Add(new Lesson(teachers[tI], g, subjects[sI], amount)); //----------rel---------- tI = 5; sI = 9; amount = 2; lessons.Add(new Lesson(teachers[tI], g, subjects[sI], amount)); lessons.Add(new Lesson(teachers[tI], g, subjects[sI], amount)); //lessons.Add(new Lesson(teachers[tI], g, subjects[sI], amount)); //----------inf---------- tI = 4; sI = 10; amount = 2; lessons.Add(new Lesson(teachers[tI], g, subjects[sI], amount)); lessons.Add(new Lesson(teachers[tI], g, subjects[sI], amount)); //----------pro---------- tI = 6; sI = 11; amount = 5; lessons.Add(new Lesson(teachers[tI], g, subjects[sI], amount, 2)); lessons.Add(new Lesson(teachers[tI], g, subjects[sI], amount, 3)); } SchoolTimeTable stt = new SchoolTimeTable(lessons, teachers, groups, rooms); stt.teacherTimeTables[5].getDays()[0].getSlots()[0].lockSlot(); stt.teacherTimeTables[5].getDays()[1].getSlots()[1].lockSlot(); stt.teacherTimeTables[5].getDays()[2].getSlots()[2].lockSlot(); stt.teacherTimeTables[5].getDays()[3].getSlots()[3].lockSlot(); stt.teacherTimeTables[5].getDays()[4].getSlots()[4].lockSlot(); stt.generateSchoolTimeTable(); stt.printTimeTable(); stt.timeTableCheckSume(); }