Search in sources :

Example 1 with Lesson

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);
}
Also used : TimeTable(org.acme.schooltimetabling.domain.TimeTable) Room(org.acme.schooltimetabling.domain.Room) Timeslot(org.acme.schooltimetabling.domain.Timeslot) Lesson(org.acme.schooltimetabling.domain.Lesson)

Example 2 with Lesson

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));
}
Also used : TimeTable(org.acme.schooltimetabling.domain.TimeTable) Room(org.acme.schooltimetabling.domain.Room) Timeslot(org.acme.schooltimetabling.domain.Timeslot) Lesson(org.acme.schooltimetabling.domain.Lesson)

Example 3 with Lesson

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();
}
Also used : SolverRequest(org.acme.schooltimetabling.message.SolverRequest) TimeTable(org.acme.schooltimetabling.domain.TimeTable) SolverResponse(org.acme.schooltimetabling.message.SolverResponse) Lesson(org.acme.schooltimetabling.domain.Lesson) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test) Timeout(org.junit.jupiter.api.Timeout)

Example 4 with Lesson

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());
        }
    }
}
Also used : SolverConfig(org.optaplanner.core.config.solver.SolverConfig) Solver(org.optaplanner.core.api.solver.Solver) Logger(org.slf4j.Logger) TimeTableConstraintProvider(org.acme.schooltimetabling.solver.TimeTableConstraintProvider) LoggerFactory(org.slf4j.LoggerFactory) SolverFactory(org.optaplanner.core.api.solver.SolverFactory) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) TimeTable(org.acme.schooltimetabling.domain.TimeTable) List(java.util.List) Lesson(org.acme.schooltimetabling.domain.Lesson) DayOfWeek(java.time.DayOfWeek) Duration(java.time.Duration) Map(java.util.Map) LocalTime(java.time.LocalTime) Collections(java.util.Collections) Room(org.acme.schooltimetabling.domain.Room) Timeslot(org.acme.schooltimetabling.domain.Timeslot) ArrayList(java.util.ArrayList) List(java.util.List) Room(org.acme.schooltimetabling.domain.Room) Lesson(org.acme.schooltimetabling.domain.Lesson) Timeslot(org.acme.schooltimetabling.domain.Timeslot) Map(java.util.Map)

Example 5 with Lesson

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);
}
Also used : Lesson(org.acme.schooltimetabling.domain.Lesson) Test(org.junit.jupiter.api.Test) QuarkusTest(io.quarkus.test.junit.QuarkusTest)

Aggregations

Lesson (org.acme.schooltimetabling.domain.Lesson)18 Test (org.junit.jupiter.api.Test)12 QuarkusTest (io.quarkus.test.junit.QuarkusTest)11 TimeTable (org.acme.schooltimetabling.domain.TimeTable)8 Room (org.acme.schooltimetabling.domain.Room)6 Timeslot (org.acme.schooltimetabling.domain.Timeslot)6 Timeout (org.junit.jupiter.api.Timeout)4 ArrayList (java.util.ArrayList)3 Transactional (javax.transaction.Transactional)2 SolverRequest (org.acme.schooltimetabling.message.SolverRequest)2 SolverResponse (org.acme.schooltimetabling.message.SolverResponse)2 DayOfWeek (java.time.DayOfWeek)1 Duration (java.time.Duration)1 LocalTime (java.time.LocalTime)1 Collections (java.util.Collections)1 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 TimeTableConstraintProvider (org.acme.schooltimetabling.solver.TimeTableConstraintProvider)1 Solver (org.optaplanner.core.api.solver.Solver)1