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