use of org.acme.schooltimetabling.domain.Lesson in project optaplanner-quickstarts by kiegroup.
the class TimeTableMessagingHandlerTest method createTestTimeTable.
private TimeTable createTestTimeTable() {
List<Room> rooms = Collections.singletonList(new Room(1L, "room-A"));
List<Timeslot> timeslots = Arrays.asList(new Timeslot(1L, DayOfWeek.MONDAY, LocalTime.NOON, LocalTime.NOON.plusMinutes(30)), new Timeslot(2L, DayOfWeek.TUESDAY, LocalTime.NOON, LocalTime.NOON.plusMinutes(30)), new Timeslot(3L, DayOfWeek.WEDNESDAY, LocalTime.NOON, LocalTime.NOON.plusMinutes(30)));
List<Lesson> lessons = Arrays.asList(new Lesson(1L, "Math", "A. Touring", "10th grade"), new Lesson(2L, "Biology", "C. Darwin", "11th grade"), new Lesson(3L, "Physics", "M. Curie", "12th grade"));
return new TimeTable(timeslots, rooms, lessons);
}
use of org.acme.schooltimetabling.domain.Lesson in project optaplanner-quickstarts by kiegroup.
the class TimeTableResourceTest method prepareTestTimeTable.
private void prepareTestTimeTable() {
List<Room> rooms = Collections.singletonList(new Room(1L, "room-A"));
List<Timeslot> timeslots = Collections.singletonList(new Timeslot(1L, DayOfWeek.WEDNESDAY, LocalTime.NOON, LocalTime.NOON));
List<Lesson> lessons = Collections.singletonList(new Lesson(1L, "Physics", "M. Curie", "12th grade"));
timeTableRepository.update(new TimeTable(timeslots, rooms, lessons));
}
use of org.acme.schooltimetabling.domain.Lesson in project optaplanner-quickstarts by kiegroup.
the class TimeTableResourceTest method solveAndRetrieve.
@Test
@Timeout(60L)
void solveAndRetrieve() throws JsonProcessingException {
timeTableResource.solve();
await().timeout(AWAIT_TIMEOUT).until(solverRequestSink::received, messages -> messages.size() == 1);
Message<String> solverRequestMessage = solverRequestSink.received().get(0);
SolverRequest solverRequest = objectMapper.readValue(solverRequestMessage.getPayload(), SolverRequest.class);
// Assign one lesson to simulate solving.
TimeTable requestTimeTable = solverRequest.getTimeTable();
Lesson firstLesson = requestTimeTable.getLessonList().get(0);
firstLesson.setRoom(requestTimeTable.getRoomList().get(0));
firstLesson.setTimeslot(requestTimeTable.getTimeslotList().get(0));
SolverResponse solverResponse = new SolverResponse(solverRequest.getProblemId(), requestTimeTable);
solverResponseSource.send(objectMapper.writeValueAsString(solverResponse));
// Wait until the client receives the message and saves the new timetable to a database.
await().timeout(AWAIT_TIMEOUT).until(timeTableResource::getTimeTable, timeTable -> timeTable.getLessonList().get(0).getRoom() != null);
Lesson solvedFirstLesson = timeTableResource.getTimeTable().getLessonList().get(0);
assertThat(solvedFirstLesson.getRoom()).isNotNull();
assertThat(solvedFirstLesson.getTimeslot()).isNotNull();
}
use of org.acme.schooltimetabling.domain.Lesson in project optaplanner-quickstarts by kiegroup.
the class TimeTableApp method printTimetable.
private static void printTimetable(TimeTable timeTable) {
LOGGER.info("");
List<Room> roomList = timeTable.getRoomList();
List<Lesson> lessonList = timeTable.getLessonList();
Map<Timeslot, Map<Room, List<Lesson>>> lessonMap = lessonList.stream().filter(lesson -> lesson.getTimeslot() != null && lesson.getRoom() != null).collect(Collectors.groupingBy(Lesson::getTimeslot, Collectors.groupingBy(Lesson::getRoom)));
LOGGER.info("| | " + roomList.stream().map(room -> String.format("%-10s", room.getName())).collect(Collectors.joining(" | ")) + " |");
LOGGER.info("|" + "------------|".repeat(roomList.size() + 1));
for (Timeslot timeslot : timeTable.getTimeslotList()) {
List<List<Lesson>> cellList = roomList.stream().map(room -> {
Map<Room, List<Lesson>> byRoomMap = lessonMap.get(timeslot);
if (byRoomMap == null) {
return Collections.<Lesson>emptyList();
}
List<Lesson> cellLessonList = byRoomMap.get(room);
if (cellLessonList == null) {
return Collections.<Lesson>emptyList();
}
return cellLessonList;
}).collect(Collectors.toList());
LOGGER.info("| " + String.format("%-10s", timeslot.getDayOfWeek().toString().substring(0, 3) + " " + timeslot.getStartTime()) + " | " + cellList.stream().map(cellLessonList -> String.format("%-10s", cellLessonList.stream().map(Lesson::getSubject).collect(Collectors.joining(", ")))).collect(Collectors.joining(" | ")) + " |");
LOGGER.info("| | " + cellList.stream().map(cellLessonList -> String.format("%-10s", cellLessonList.stream().map(Lesson::getTeacher).collect(Collectors.joining(", ")))).collect(Collectors.joining(" | ")) + " |");
LOGGER.info("| | " + cellList.stream().map(cellLessonList -> String.format("%-10s", cellLessonList.stream().map(Lesson::getStudentGroup).collect(Collectors.joining(", ")))).collect(Collectors.joining(" | ")) + " |");
LOGGER.info("|" + "------------|".repeat(roomList.size() + 1));
}
List<Lesson> unassignedLessons = lessonList.stream().filter(lesson -> lesson.getTimeslot() == null || lesson.getRoom() == null).collect(Collectors.toList());
if (!unassignedLessons.isEmpty()) {
LOGGER.info("");
LOGGER.info("Unassigned lessons");
for (Lesson lesson : unassignedLessons) {
LOGGER.info(" " + lesson.getSubject() + " - " + lesson.getTeacher() + " - " + lesson.getStudentGroup());
}
}
}
use of org.acme.schooltimetabling.domain.Lesson in project optaplanner-quickstarts by kiegroup.
the class TimeTableConstraintProviderTest method studentGroupSubjectVariety.
@Test
void studentGroupSubjectVariety() {
String studentGroup = "Group1";
String repeatedSubject = "Subject1";
Lesson mondayLesson = new Lesson(1, repeatedSubject, "Teacher1", studentGroup, TIMESLOT1, ROOM1);
Lesson firstTuesdayLesson = new Lesson(2, repeatedSubject, "Teacher2", studentGroup, TIMESLOT2, ROOM1);
Lesson secondTuesdayLesson = new Lesson(3, repeatedSubject, "Teacher3", studentGroup, TIMESLOT3, ROOM1);
Lesson thirdTuesdayLessonWithDifferentSubject = new Lesson(4, "Subject2", "Teacher4", studentGroup, TIMESLOT4, ROOM1);
Lesson lessonInAnotherGroup = new Lesson(5, repeatedSubject, "Teacher5", "Group2", TIMESLOT1, ROOM1);
constraintVerifier.verifyThat(TimeTableConstraintProvider::studentGroupSubjectVariety).given(mondayLesson, firstTuesdayLesson, secondTuesdayLesson, thirdTuesdayLessonWithDifferentSubject, lessonInAnotherGroup).penalizesBy(// Second tuesday lesson immediately follows the first.
1);
}
Aggregations