Search in sources :

Example 1 with TimeTable

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

the class TimeTableMessagingHandlerTest method solve.

@Test
@Timeout(TEST_TIMEOUT_SECONDS)
void solve() {
    long problemId = 1L;
    TimeTable unsolvedTimeTable = createTestTimeTable();
    sendSolverRequest(new SolverRequest(problemId, unsolvedTimeTable));
    SolverResponse solverResponse = receiveSolverResponse(MESSAGE_RECEIVE_TIMEOUT_SECONDS);
    assertThat(SolverResponse.ResponseStatus.SUCCESS == solverResponse.getResponseStatus());
    assertThat(problemId == solverResponse.getProblemId());
    assertThat(solverResponse.getTimeTable().getLessonList()).hasSameSizeAs(unsolvedTimeTable.getLessonList());
    assertThat(solverResponse.getTimeTable().getScore().isFeasible()).isTrue();
}
Also used : SolverRequest(org.acme.schooltimetabling.message.SolverRequest) TimeTable(org.acme.schooltimetabling.domain.TimeTable) SolverResponse(org.acme.schooltimetabling.message.SolverResponse) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test) Timeout(org.junit.jupiter.api.Timeout)

Example 2 with TimeTable

use of org.acme.schooltimetabling.domain.TimeTable 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 3 with TimeTable

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

the class TimeTableResource method solve.

@POST
@Path("solve")
public void solve() throws JsonProcessingException {
    TimeTable timeTable = timeTableRepository.get();
    timeTable.setSolverStatus(SolverStatus.SOLVING_SCHEDULED);
    SolverRequest solverRequest = new SolverRequest(SINGLETON_TIME_TABLE_ID, timeTable);
    String solverRequestJson = objectMapper.writeValueAsString(solverRequest);
    solverRequestEmitter.send(solverRequestJson);
}
Also used : SolverRequest(org.acme.schooltimetabling.message.SolverRequest) TimeTable(org.acme.schooltimetabling.domain.TimeTable) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Example 4 with TimeTable

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

the class TimeTableResource method process.

@Incoming("solver_response")
@Acknowledgment(Acknowledgment.Strategy.POST_PROCESSING)
public void process(String solverResponseMessage) {
    SolverResponse solverResponse;
    try {
        solverResponse = objectMapper.readValue(solverResponseMessage, SolverResponse.class);
    } catch (JsonProcessingException ex) {
        throw new IllegalStateException("Unable to deserialize the solver response.", ex);
    }
    if (solverResponse.isSuccess()) {
        TimeTable timeTable = solverResponse.getTimeTable();
        timeTable.setSolverStatus(SolverStatus.NOT_SOLVING);
        timeTableRepository.update(timeTable);
    } else {
        timeTableRepository.get().setSolverStatus(SolverStatus.NOT_SOLVING);
        throw new IllegalStateException("Solving failed with exception class (" + solverResponse.getErrorInfo().getExceptionClassName() + ") and message (" + solverResponse.getErrorInfo().getExceptionMessage() + ").");
    }
}
Also used : SolverResponse(org.acme.schooltimetabling.message.SolverResponse) TimeTable(org.acme.schooltimetabling.domain.TimeTable) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Incoming(org.eclipse.microprofile.reactive.messaging.Incoming) Acknowledgment(org.eclipse.microprofile.reactive.messaging.Acknowledgment)

Example 5 with TimeTable

use of org.acme.schooltimetabling.domain.TimeTable 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)

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