Search in sources :

Example 6 with Lesson

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

the class LessonResourceTest method getAll.

@Test
public void getAll() {
    List<Lesson> lessonList = given().when().get("/lessons").then().statusCode(200).extract().body().jsonPath().getList(".", Lesson.class);
    assertFalse(lessonList.isEmpty());
    Lesson firstLesson = lessonList.get(0);
    assertNotNull(firstLesson.getSubject());
    assertNotNull(firstLesson.getTeacher());
    assertNotNull(firstLesson.getStudentGroup());
}
Also used : Lesson(org.acme.schooltimetabling.domain.Lesson) Test(org.junit.jupiter.api.Test) QuarkusTest(io.quarkus.test.junit.QuarkusTest)

Example 7 with Lesson

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

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

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

the class DemoDataGenerator method generateDemoData.

@Transactional
public void generateDemoData(@Observes StartupEvent startupEvent) {
    if (demoData == DemoData.NONE) {
        return;
    }
    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)));
    if (demoData == DemoData.LARGE) {
        timeslotList.add(new Timeslot(DayOfWeek.WEDNESDAY, LocalTime.of(8, 30), LocalTime.of(9, 30)));
        timeslotList.add(new Timeslot(DayOfWeek.WEDNESDAY, LocalTime.of(9, 30), LocalTime.of(10, 30)));
        timeslotList.add(new Timeslot(DayOfWeek.WEDNESDAY, LocalTime.of(10, 30), LocalTime.of(11, 30)));
        timeslotList.add(new Timeslot(DayOfWeek.WEDNESDAY, LocalTime.of(13, 30), LocalTime.of(14, 30)));
        timeslotList.add(new Timeslot(DayOfWeek.WEDNESDAY, LocalTime.of(14, 30), LocalTime.of(15, 30)));
        timeslotList.add(new Timeslot(DayOfWeek.THURSDAY, LocalTime.of(8, 30), LocalTime.of(9, 30)));
        timeslotList.add(new Timeslot(DayOfWeek.THURSDAY, LocalTime.of(9, 30), LocalTime.of(10, 30)));
        timeslotList.add(new Timeslot(DayOfWeek.THURSDAY, LocalTime.of(10, 30), LocalTime.of(11, 30)));
        timeslotList.add(new Timeslot(DayOfWeek.THURSDAY, LocalTime.of(13, 30), LocalTime.of(14, 30)));
        timeslotList.add(new Timeslot(DayOfWeek.THURSDAY, LocalTime.of(14, 30), LocalTime.of(15, 30)));
        timeslotList.add(new Timeslot(DayOfWeek.FRIDAY, LocalTime.of(8, 30), LocalTime.of(9, 30)));
        timeslotList.add(new Timeslot(DayOfWeek.FRIDAY, LocalTime.of(9, 30), LocalTime.of(10, 30)));
        timeslotList.add(new Timeslot(DayOfWeek.FRIDAY, LocalTime.of(10, 30), LocalTime.of(11, 30)));
        timeslotList.add(new Timeslot(DayOfWeek.FRIDAY, LocalTime.of(13, 30), LocalTime.of(14, 30)));
        timeslotList.add(new Timeslot(DayOfWeek.FRIDAY, LocalTime.of(14, 30), LocalTime.of(15, 30)));
    }
    timeslotRepository.persist(timeslotList);
    List<Room> roomList = new ArrayList<>(3);
    roomList.add(new Room("Room A"));
    roomList.add(new Room("Room B"));
    roomList.add(new Room("Room C"));
    if (demoData == DemoData.LARGE) {
        roomList.add(new Room("Room D"));
        roomList.add(new Room("Room E"));
        roomList.add(new Room("Room F"));
    }
    roomRepository.persist(roomList);
    List<Lesson> lessonList = new ArrayList<>();
    lessonList.add(new Lesson("Math", "A. Turing", "9th grade"));
    lessonList.add(new Lesson("Math", "A. Turing", "9th grade"));
    lessonList.add(new Lesson("Physics", "M. Curie", "9th grade"));
    lessonList.add(new Lesson("Chemistry", "M. Curie", "9th grade"));
    lessonList.add(new Lesson("Biology", "C. Darwin", "9th grade"));
    lessonList.add(new Lesson("History", "I. Jones", "9th grade"));
    lessonList.add(new Lesson("English", "I. Jones", "9th grade"));
    lessonList.add(new Lesson("English", "I. Jones", "9th grade"));
    lessonList.add(new Lesson("Spanish", "P. Cruz", "9th grade"));
    lessonList.add(new Lesson("Spanish", "P. Cruz", "9th grade"));
    if (demoData == DemoData.LARGE) {
        lessonList.add(new Lesson("Math", "A. Turing", "9th grade"));
        lessonList.add(new Lesson("Math", "A. Turing", "9th grade"));
        lessonList.add(new Lesson("Math", "A. Turing", "9th grade"));
        lessonList.add(new Lesson("ICT", "A. Turing", "9th grade"));
        lessonList.add(new Lesson("Physics", "M. Curie", "9th grade"));
        lessonList.add(new Lesson("Geography", "C. Darwin", "9th grade"));
        lessonList.add(new Lesson("Geology", "C. Darwin", "9th grade"));
        lessonList.add(new Lesson("History", "I. Jones", "9th grade"));
        lessonList.add(new Lesson("English", "I. Jones", "9th grade"));
        lessonList.add(new Lesson("Drama", "I. Jones", "9th grade"));
        lessonList.add(new Lesson("Art", "S. Dali", "9th grade"));
        lessonList.add(new Lesson("Art", "S. Dali", "9th grade"));
        lessonList.add(new Lesson("Physical education", "C. Lewis", "9th grade"));
        lessonList.add(new Lesson("Physical education", "C. Lewis", "9th grade"));
        lessonList.add(new Lesson("Physical education", "C. Lewis", "9th grade"));
    }
    lessonList.add(new Lesson("Math", "A. Turing", "10th grade"));
    lessonList.add(new Lesson("Math", "A. Turing", "10th grade"));
    lessonList.add(new Lesson("Math", "A. Turing", "10th grade"));
    lessonList.add(new Lesson("Physics", "M. Curie", "10th grade"));
    lessonList.add(new Lesson("Chemistry", "M. Curie", "10th grade"));
    lessonList.add(new Lesson("French", "M. Curie", "10th grade"));
    lessonList.add(new Lesson("Geography", "C. Darwin", "10th grade"));
    lessonList.add(new Lesson("History", "I. Jones", "10th grade"));
    lessonList.add(new Lesson("English", "P. Cruz", "10th grade"));
    lessonList.add(new Lesson("Spanish", "P. Cruz", "10th grade"));
    if (demoData == DemoData.LARGE) {
        lessonList.add(new Lesson("Math", "A. Turing", "10th grade"));
        lessonList.add(new Lesson("Math", "A. Turing", "10th grade"));
        lessonList.add(new Lesson("ICT", "A. Turing", "10th grade"));
        lessonList.add(new Lesson("Physics", "M. Curie", "10th grade"));
        lessonList.add(new Lesson("Biology", "C. Darwin", "10th grade"));
        lessonList.add(new Lesson("Geology", "C. Darwin", "10th grade"));
        lessonList.add(new Lesson("History", "I. Jones", "10th grade"));
        lessonList.add(new Lesson("English", "P. Cruz", "10th grade"));
        lessonList.add(new Lesson("English", "P. Cruz", "10th grade"));
        lessonList.add(new Lesson("Drama", "I. Jones", "10th grade"));
        lessonList.add(new Lesson("Art", "S. Dali", "10th grade"));
        lessonList.add(new Lesson("Art", "S. Dali", "10th grade"));
        lessonList.add(new Lesson("Physical education", "C. Lewis", "10th grade"));
        lessonList.add(new Lesson("Physical education", "C. Lewis", "10th grade"));
        lessonList.add(new Lesson("Physical education", "C. Lewis", "10th grade"));
        lessonList.add(new Lesson("Math", "A. Turing", "11th grade"));
        lessonList.add(new Lesson("Math", "A. Turing", "11th grade"));
        lessonList.add(new Lesson("Math", "A. Turing", "11th grade"));
        lessonList.add(new Lesson("Math", "A. Turing", "11th grade"));
        lessonList.add(new Lesson("Math", "A. Turing", "11th grade"));
        lessonList.add(new Lesson("ICT", "A. Turing", "11th grade"));
        lessonList.add(new Lesson("Physics", "M. Curie", "11th grade"));
        lessonList.add(new Lesson("Chemistry", "M. Curie", "11th grade"));
        lessonList.add(new Lesson("French", "M. Curie", "11th grade"));
        lessonList.add(new Lesson("Physics", "M. Curie", "11th grade"));
        lessonList.add(new Lesson("Geography", "C. Darwin", "11th grade"));
        lessonList.add(new Lesson("Biology", "C. Darwin", "11th grade"));
        lessonList.add(new Lesson("Geology", "C. Darwin", "11th grade"));
        lessonList.add(new Lesson("History", "I. Jones", "11th grade"));
        lessonList.add(new Lesson("History", "I. Jones", "11th grade"));
        lessonList.add(new Lesson("English", "P. Cruz", "11th grade"));
        lessonList.add(new Lesson("English", "P. Cruz", "11th grade"));
        lessonList.add(new Lesson("English", "P. Cruz", "11th grade"));
        lessonList.add(new Lesson("Spanish", "P. Cruz", "11th grade"));
        lessonList.add(new Lesson("Drama", "P. Cruz", "11th grade"));
        lessonList.add(new Lesson("Art", "S. Dali", "11th grade"));
        lessonList.add(new Lesson("Art", "S. Dali", "11th grade"));
        lessonList.add(new Lesson("Physical education", "C. Lewis", "11th grade"));
        lessonList.add(new Lesson("Physical education", "C. Lewis", "11th grade"));
        lessonList.add(new Lesson("Physical education", "C. Lewis", "11th grade"));
        lessonList.add(new Lesson("Math", "A. Turing", "12th grade"));
        lessonList.add(new Lesson("Math", "A. Turing", "12th grade"));
        lessonList.add(new Lesson("Math", "A. Turing", "12th grade"));
        lessonList.add(new Lesson("Math", "A. Turing", "12th grade"));
        lessonList.add(new Lesson("Math", "A. Turing", "12th grade"));
        lessonList.add(new Lesson("ICT", "A. Turing", "12th grade"));
        lessonList.add(new Lesson("Physics", "M. Curie", "12th grade"));
        lessonList.add(new Lesson("Chemistry", "M. Curie", "12th grade"));
        lessonList.add(new Lesson("French", "M. Curie", "12th grade"));
        lessonList.add(new Lesson("Physics", "M. Curie", "12th grade"));
        lessonList.add(new Lesson("Geography", "C. Darwin", "12th grade"));
        lessonList.add(new Lesson("Biology", "C. Darwin", "12th grade"));
        lessonList.add(new Lesson("Geology", "C. Darwin", "12th grade"));
        lessonList.add(new Lesson("History", "I. Jones", "12th grade"));
        lessonList.add(new Lesson("History", "I. Jones", "12th grade"));
        lessonList.add(new Lesson("English", "P. Cruz", "12th grade"));
        lessonList.add(new Lesson("English", "P. Cruz", "12th grade"));
        lessonList.add(new Lesson("English", "P. Cruz", "12th grade"));
        lessonList.add(new Lesson("Spanish", "P. Cruz", "12th grade"));
        lessonList.add(new Lesson("Drama", "P. Cruz", "12th grade"));
        lessonList.add(new Lesson("Art", "S. Dali", "12th grade"));
        lessonList.add(new Lesson("Art", "S. Dali", "12th grade"));
        lessonList.add(new Lesson("Physical education", "C. Lewis", "12th grade"));
        lessonList.add(new Lesson("Physical education", "C. Lewis", "12th grade"));
        lessonList.add(new Lesson("Physical education", "C. Lewis", "12th grade"));
    }
    Lesson lesson = lessonList.get(0);
    lesson.setTimeslot(timeslotList.get(0));
    lesson.setRoom(roomList.get(0));
    lessonRepository.persist(lessonList);
}
Also used : ArrayList(java.util.ArrayList) Timeslot(org.acme.schooltimetabling.domain.Timeslot) Room(org.acme.schooltimetabling.domain.Room) Lesson(org.acme.schooltimetabling.domain.Lesson) Transactional(javax.transaction.Transactional)

Example 10 with Lesson

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

the class TimeTableResource method save.

@Transactional
protected void save(TimeTable timeTable) {
    for (Lesson lesson : timeTable.getLessonList()) {
        // TODO this is awfully naive: optimistic locking causes issues if called by the SolverManager
        Lesson attachedLesson = lessonRepository.findById(lesson.getId());
        attachedLesson.setTimeslot(lesson.getTimeslot());
        attachedLesson.setRoom(lesson.getRoom());
    }
}
Also used : Lesson(org.acme.schooltimetabling.domain.Lesson) Transactional(javax.transaction.Transactional)

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