Search in sources :

Example 11 with TimeTable

use of org.acme.schooltimetabling.domain.TimeTable in project optaplanner-quickstarts by kiegroup.

the class TimeTableControllerTest method solveDemoDataUntilFeasible.

@Test
@Timeout(600_000)
public void solveDemoDataUntilFeasible() throws InterruptedException {
    timeTableController.solve();
    TimeTable timeTable;
    do {
        // Use do-while to give the solver some time and avoid retrieving an early infeasible solution.
        // Quick polling (not a Test Thread Sleep anti-pattern)
        // Test is still fast on fast machines and doesn't randomly fail on slow machines.
        Thread.sleep(20L);
        timeTable = timeTableController.getTimeTable();
    } while (timeTable.getSolverStatus() != SolverStatus.NOT_SOLVING || !timeTable.getScore().isFeasible());
    assertFalse(timeTable.getLessonList().isEmpty());
    for (Lesson lesson : timeTable.getLessonList()) {
        assertNotNull(lesson.getTimeslot());
        assertNotNull(lesson.getRoom());
    }
    assertTrue(timeTable.getScore().isFeasible());
}
Also used : TimeTable(org.acme.schooltimetabling.domain.TimeTable) Lesson(org.acme.schooltimetabling.domain.Lesson) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Timeout(org.junit.jupiter.api.Timeout)

Example 12 with TimeTable

use of org.acme.schooltimetabling.domain.TimeTable in project optaplanner-quickstarts by kiegroup.

the class TimeTableResource method getTimeTable.

// To try, open http://localhost:8080/timeTable
@GET
public TimeTable getTimeTable() {
    // Get the solver status before loading the solution
    // to avoid the race condition that the solver terminates between them
    SolverStatus solverStatus = getSolverStatus();
    TimeTable solution = findById(SINGLETON_TIME_TABLE_ID);
    // Sets the score
    scoreManager.updateScore(solution);
    solution.setSolverStatus(solverStatus);
    return solution;
}
Also used : TimeTable(org.acme.schooltimetabling.domain.TimeTable) SolverStatus(org.optaplanner.core.api.solver.SolverStatus) GET(javax.ws.rs.GET)

Example 13 with TimeTable

use of org.acme.schooltimetabling.domain.TimeTable in project optaplanner-quickstarts by kiegroup.

the class TimeTableApp method generateDemoData.

public static TimeTable generateDemoData() {
    List<Timeslot> timeslotList = new ArrayList<>(10);
    timeslotList.add(new Timeslot(DayOfWeek.MONDAY, LocalTime.of(8, 30), LocalTime.of(9, 30)));
    timeslotList.add(new Timeslot(DayOfWeek.MONDAY, LocalTime.of(9, 30), LocalTime.of(10, 30)));
    timeslotList.add(new Timeslot(DayOfWeek.MONDAY, LocalTime.of(10, 30), LocalTime.of(11, 30)));
    timeslotList.add(new Timeslot(DayOfWeek.MONDAY, LocalTime.of(13, 30), LocalTime.of(14, 30)));
    timeslotList.add(new Timeslot(DayOfWeek.MONDAY, LocalTime.of(14, 30), LocalTime.of(15, 30)));
    timeslotList.add(new Timeslot(DayOfWeek.TUESDAY, LocalTime.of(8, 30), LocalTime.of(9, 30)));
    timeslotList.add(new Timeslot(DayOfWeek.TUESDAY, LocalTime.of(9, 30), LocalTime.of(10, 30)));
    timeslotList.add(new Timeslot(DayOfWeek.TUESDAY, LocalTime.of(10, 30), LocalTime.of(11, 30)));
    timeslotList.add(new Timeslot(DayOfWeek.TUESDAY, LocalTime.of(13, 30), LocalTime.of(14, 30)));
    timeslotList.add(new Timeslot(DayOfWeek.TUESDAY, LocalTime.of(14, 30), LocalTime.of(15, 30)));
    List<Room> roomList = new ArrayList<>(3);
    roomList.add(new Room("Room A"));
    roomList.add(new Room("Room B"));
    roomList.add(new Room("Room C"));
    List<Lesson> lessonList = new ArrayList<>();
    long id = 0;
    lessonList.add(new Lesson(id++, "Math", "A. Turing", "9th grade"));
    lessonList.add(new Lesson(id++, "Math", "A. Turing", "9th grade"));
    lessonList.add(new Lesson(id++, "Physics", "M. Curie", "9th grade"));
    lessonList.add(new Lesson(id++, "Chemistry", "M. Curie", "9th grade"));
    lessonList.add(new Lesson(id++, "Biology", "C. Darwin", "9th grade"));
    lessonList.add(new Lesson(id++, "History", "I. Jones", "9th grade"));
    lessonList.add(new Lesson(id++, "English", "I. Jones", "9th grade"));
    lessonList.add(new Lesson(id++, "English", "I. Jones", "9th grade"));
    lessonList.add(new Lesson(id++, "Spanish", "P. Cruz", "9th grade"));
    lessonList.add(new Lesson(id++, "Spanish", "P. Cruz", "9th grade"));
    lessonList.add(new Lesson(id++, "Math", "A. Turing", "10th grade"));
    lessonList.add(new Lesson(id++, "Math", "A. Turing", "10th grade"));
    lessonList.add(new Lesson(id++, "Math", "A. Turing", "10th grade"));
    lessonList.add(new Lesson(id++, "Physics", "M. Curie", "10th grade"));
    lessonList.add(new Lesson(id++, "Chemistry", "M. Curie", "10th grade"));
    lessonList.add(new Lesson(id++, "French", "M. Curie", "10th grade"));
    lessonList.add(new Lesson(id++, "Geography", "C. Darwin", "10th grade"));
    lessonList.add(new Lesson(id++, "History", "I. Jones", "10th grade"));
    lessonList.add(new Lesson(id++, "English", "P. Cruz", "10th grade"));
    lessonList.add(new Lesson(id++, "Spanish", "P. Cruz", "10th grade"));
    return new TimeTable(timeslotList, roomList, lessonList);
}
Also used : ArrayList(java.util.ArrayList) TimeTable(org.acme.schooltimetabling.domain.TimeTable) Timeslot(org.acme.schooltimetabling.domain.Timeslot) Room(org.acme.schooltimetabling.domain.Room) Lesson(org.acme.schooltimetabling.domain.Lesson)

Example 14 with TimeTable

use of org.acme.schooltimetabling.domain.TimeTable in project optaplanner-quickstarts by kiegroup.

the class TimeTableResourceTest method solveDemoDataUntilFeasible.

@Test
@Timeout(600_000)
public void solveDemoDataUntilFeasible() throws InterruptedException {
    timeTableResource.solve();
    TimeTable timeTable;
    do {
        // Use do-while to give the solver some time and avoid retrieving an early infeasible solution.
        // Quick polling (not a Test Thread Sleep anti-pattern)
        // Test is still fast on fast machines and doesn't randomly fail on slow machines.
        Thread.sleep(20L);
        timeTable = timeTableResource.getTimeTable();
    } while (timeTable.getSolverStatus() != SolverStatus.NOT_SOLVING || !timeTable.getScore().isFeasible());
    assertFalse(timeTable.getLessonList().isEmpty());
    for (Lesson lesson : timeTable.getLessonList()) {
        assertNotNull(lesson.getTimeslot());
        assertNotNull(lesson.getRoom());
    }
    assertTrue(timeTable.getScore().isFeasible());
}
Also used : TimeTable(org.acme.schooltimetabling.domain.TimeTable) Lesson(org.acme.schooltimetabling.domain.Lesson) Test(org.junit.jupiter.api.Test) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Timeout(org.junit.jupiter.api.Timeout)

Example 15 with TimeTable

use of org.acme.schooltimetabling.domain.TimeTable in project optaplanner-quickstarts by kiegroup.

the class TimeTableMessagingHandlerTest method solvingThrowsException.

@Test
@Timeout(TEST_TIMEOUT_SECONDS)
void solvingThrowsException() {
    long problemId = 10L;
    // OptaPlanner doesn't tolerate a null planningId.
    TimeTable timeTableWithIncorrectLesson = new TimeTable(Arrays.asList(new Timeslot(1L, DayOfWeek.MONDAY, LocalTime.NOON, LocalTime.NOON.plusMinutes(30))), Arrays.asList(new Room(1L, "room-A")), Arrays.asList(new Lesson(null, "Math", "A. Touring", "10th grade")));
    sendSolverRequest(new SolverRequest(problemId, timeTableWithIncorrectLesson));
    SolverResponse solverResponse = receiveSolverResponse(MESSAGE_RECEIVE_TIMEOUT_SECONDS);
    assertThat(SolverResponse.ResponseStatus.FAILURE == solverResponse.getResponseStatus());
    assertThat(problemId == solverResponse.getProblemId());
    assertThat(solverResponse.getErrorInfo().getExceptionClassName()).isEqualTo(IllegalArgumentException.class.getName());
    assertThat(solverResponse.getErrorInfo().getExceptionMessage()).startsWith("The planningId (null)");
}
Also used : SolverRequest(org.acme.schooltimetabling.message.SolverRequest) TimeTable(org.acme.schooltimetabling.domain.TimeTable) SolverResponse(org.acme.schooltimetabling.message.SolverResponse) Timeslot(org.acme.schooltimetabling.domain.Timeslot) Room(org.acme.schooltimetabling.domain.Room) Lesson(org.acme.schooltimetabling.domain.Lesson) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test) Timeout(org.junit.jupiter.api.Timeout)

Aggregations

TimeTable (org.acme.schooltimetabling.domain.TimeTable)15 Lesson (org.acme.schooltimetabling.domain.Lesson)9 Room (org.acme.schooltimetabling.domain.Room)5 Timeslot (org.acme.schooltimetabling.domain.Timeslot)5 SolverRequest (org.acme.schooltimetabling.message.SolverRequest)5 Test (org.junit.jupiter.api.Test)5 Timeout (org.junit.jupiter.api.Timeout)5 QuarkusTest (io.quarkus.test.junit.QuarkusTest)4 SolverResponse (org.acme.schooltimetabling.message.SolverResponse)4 ArrayList (java.util.ArrayList)2 Incoming (org.eclipse.microprofile.reactive.messaging.Incoming)2 SolverStatus (org.optaplanner.core.api.solver.SolverStatus)2 SolverConfig (org.optaplanner.core.config.solver.SolverConfig)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 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