private static void CreateTimetable() { int lengthLecturer = _allLecturers.Count(); int lenghtSemester = _allSemesters.Count(); int lenghtBlocks = 50; for (int b = 0; b < lenghtBlocks; b++) { for (int a = 0; a < lengthLecturer; a++) { Lecturer selectedLecturer = _allLecturers[a]; for (int c = 0; c < lenghtSemester; c++) { Semester selectedSemester = _allSemesters[c]; if (selectedSemester.Availability[b] != "reserved") { foreach (Subject selectedSubject in selectedLecturer.Subjects) { if (selectedLecturer.Availability[b] == "free") { if (selectedSemester.Subjects.Exists(s => s.Name == selectedSubject.Name)) { List <Classroom> matchingRooms = new List <Classroom>(); foreach (Classroom room in _allClassrooms) { if (room.Availability[b] != "reserved" && room.Seats >= selectedSemester.Students) { foreach (string require in selectedSubject.Requirements) { if (room.Equipment.Contains(require)) { matchingRooms.Add(room); } } } } bool isEmpty = !matchingRooms.Any(); if (isEmpty == false) { Classroom smallestRoom = matchingRooms[0]; foreach (Classroom matching in matchingRooms) { if (matching.Seats < smallestRoom.Seats) { smallestRoom = matching; } } smallestRoom.Availability[b] = "reserved"; selectedSemester.Subjects.Remove(selectedSubject); selectedSemester.Availability[b] = "reserved"; selectedLecturer.Availability[b] = "reserved"; SaveInTimetable(b, selectedSemester, selectedSubject, smallestRoom, selectedLecturer); } } } } } } } } Console.WriteLine("Stundenplan wurde erstellt."); }
private static void ReadData() { XmlTextReader reader = new XmlTextReader("timetableData.xml"); while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element) { switch (reader.Name) { case "semester": Semester semester = new Semester(); _allSemesters.Add(semester); if (reader.HasAttributes) { while (reader.MoveToNextAttribute()) { if (reader.Name == "name") { semester.Name = reader.Value; } Timetable timetable = new Timetable(); _allTimetables.Add(timetable); timetable.Name = reader.Value; for (int i = 0; i < 50; i++) { timetable.Table.Add("Block " + i + "\nFREI\n"); } if (reader.Name == "students") { semester.Students = Int32.Parse(reader.Value); } if (reader.Name.Contains("subject")) { Subject semestersubject = _allSubjects.Find(s => s.Name == reader.Value); semester.Subjects.Add(semestersubject); } } } break; case "lecturer": Lecturer lecturer = new Lecturer(); _allLecturers.Add(lecturer); if (reader.HasAttributes) { while (reader.MoveToNextAttribute()) { if (reader.Name == "name") { lecturer.Name = reader.Value; } Timetable timetable = new Timetable(); _allTimetables.Add(timetable); timetable.Name = reader.Value; for (int i = 0; i < 50; i++) { timetable.Table.Add("Block " + i + "\nFREI\n"); } if (reader.Name.Contains("subject")) { Subject lecturersubject = _allSubjects.Find(s => s.Name == reader.Value); lecturer.Subjects.Add(lecturersubject); } if (reader.Name == "presence") { string[] words = reader.Value.Split(','); foreach (string word in words) { lecturer.Availability[System.Convert.ToInt32(word)] = "free"; } } } } break; case "classroom": Classroom classroom = new Classroom(); _allClassrooms.Add(classroom); if (reader.HasAttributes) { while (reader.MoveToNextAttribute()) { if (reader.Name == "name") { classroom.Name = reader.Value; } Timetable timetable = new Timetable(); _allTimetables.Add(timetable); timetable.Name = reader.Value; for (int i = 0; i < 50; i++) { timetable.Table.Add("Block " + i + "\nFREI\n"); } if (reader.Name == "seats") { classroom.Seats = Int32.Parse(reader.Value); } if (reader.Name == "building") { classroom.Building = reader.Value; } if (reader.Name.Contains("equipment")) { classroom.Equipment.Add(reader.Value); } } } break; case "subject": Subject subject = new Subject(); _allSubjects.Add(subject); if (reader.HasAttributes) { while (reader.MoveToNextAttribute()) { if (reader.Name == "name") { subject.Name = reader.Value; } if (reader.Name == "description") { subject.Description = reader.Value; } if (reader.Name.Contains("requirement")) { subject.Requirements.Add(reader.Value); } } } break; } } } reader.Close(); Console.WriteLine("Daten erfolgreich eingelesen"); }