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();
}
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);
}
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);
}
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() + ").");
}
}
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));
}
Aggregations