Search in sources :

Example 1 with Timeslot

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

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

Example 3 with Timeslot

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

the class TimeTableApp method printTimetable.

private static void printTimetable(TimeTable timeTable) {
    LOGGER.info("");
    List<Room> roomList = timeTable.getRoomList();
    List<Lesson> lessonList = timeTable.getLessonList();
    Map<Timeslot, Map<Room, List<Lesson>>> lessonMap = lessonList.stream().filter(lesson -> lesson.getTimeslot() != null && lesson.getRoom() != null).collect(Collectors.groupingBy(Lesson::getTimeslot, Collectors.groupingBy(Lesson::getRoom)));
    LOGGER.info("|            | " + roomList.stream().map(room -> String.format("%-10s", room.getName())).collect(Collectors.joining(" | ")) + " |");
    LOGGER.info("|" + "------------|".repeat(roomList.size() + 1));
    for (Timeslot timeslot : timeTable.getTimeslotList()) {
        List<List<Lesson>> cellList = roomList.stream().map(room -> {
            Map<Room, List<Lesson>> byRoomMap = lessonMap.get(timeslot);
            if (byRoomMap == null) {
                return Collections.<Lesson>emptyList();
            }
            List<Lesson> cellLessonList = byRoomMap.get(room);
            if (cellLessonList == null) {
                return Collections.<Lesson>emptyList();
            }
            return cellLessonList;
        }).collect(Collectors.toList());
        LOGGER.info("| " + String.format("%-10s", timeslot.getDayOfWeek().toString().substring(0, 3) + " " + timeslot.getStartTime()) + " | " + cellList.stream().map(cellLessonList -> String.format("%-10s", cellLessonList.stream().map(Lesson::getSubject).collect(Collectors.joining(", ")))).collect(Collectors.joining(" | ")) + " |");
        LOGGER.info("|            | " + cellList.stream().map(cellLessonList -> String.format("%-10s", cellLessonList.stream().map(Lesson::getTeacher).collect(Collectors.joining(", ")))).collect(Collectors.joining(" | ")) + " |");
        LOGGER.info("|            | " + cellList.stream().map(cellLessonList -> String.format("%-10s", cellLessonList.stream().map(Lesson::getStudentGroup).collect(Collectors.joining(", ")))).collect(Collectors.joining(" | ")) + " |");
        LOGGER.info("|" + "------------|".repeat(roomList.size() + 1));
    }
    List<Lesson> unassignedLessons = lessonList.stream().filter(lesson -> lesson.getTimeslot() == null || lesson.getRoom() == null).collect(Collectors.toList());
    if (!unassignedLessons.isEmpty()) {
        LOGGER.info("");
        LOGGER.info("Unassigned lessons");
        for (Lesson lesson : unassignedLessons) {
            LOGGER.info("  " + lesson.getSubject() + " - " + lesson.getTeacher() + " - " + lesson.getStudentGroup());
        }
    }
}
Also used : SolverConfig(org.optaplanner.core.config.solver.SolverConfig) Solver(org.optaplanner.core.api.solver.Solver) Logger(org.slf4j.Logger) TimeTableConstraintProvider(org.acme.schooltimetabling.solver.TimeTableConstraintProvider) LoggerFactory(org.slf4j.LoggerFactory) SolverFactory(org.optaplanner.core.api.solver.SolverFactory) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) TimeTable(org.acme.schooltimetabling.domain.TimeTable) List(java.util.List) Lesson(org.acme.schooltimetabling.domain.Lesson) DayOfWeek(java.time.DayOfWeek) Duration(java.time.Duration) Map(java.util.Map) LocalTime(java.time.LocalTime) Collections(java.util.Collections) Room(org.acme.schooltimetabling.domain.Room) Timeslot(org.acme.schooltimetabling.domain.Timeslot) ArrayList(java.util.ArrayList) List(java.util.List) Room(org.acme.schooltimetabling.domain.Room) Lesson(org.acme.schooltimetabling.domain.Lesson) Timeslot(org.acme.schooltimetabling.domain.Timeslot) Map(java.util.Map)

Example 4 with Timeslot

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

the class TimeslotResourceTest method getAll.

@Test
public void getAll() {
    List<Timeslot> timeslotList = given().when().get("/timeslots").then().statusCode(200).extract().body().jsonPath().getList(".", Timeslot.class);
    assertFalse(timeslotList.isEmpty());
    Timeslot firstTimeslot = timeslotList.get(0);
    assertEquals(DayOfWeek.MONDAY, firstTimeslot.getDayOfWeek());
    assertEquals(LocalTime.of(8, 30), firstTimeslot.getStartTime());
    assertEquals(LocalTime.of(9, 30), firstTimeslot.getEndTime());
}
Also used : Timeslot(org.acme.schooltimetabling.domain.Timeslot) Test(org.junit.jupiter.api.Test) QuarkusTest(io.quarkus.test.junit.QuarkusTest)

Example 5 with Timeslot

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

Aggregations

Timeslot (org.acme.schooltimetabling.domain.Timeslot)8 Lesson (org.acme.schooltimetabling.domain.Lesson)6 Room (org.acme.schooltimetabling.domain.Room)6 TimeTable (org.acme.schooltimetabling.domain.TimeTable)5 QuarkusTest (io.quarkus.test.junit.QuarkusTest)3 ArrayList (java.util.ArrayList)3 Test (org.junit.jupiter.api.Test)3 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 Transactional (javax.transaction.Transactional)1 SolverRequest (org.acme.schooltimetabling.message.SolverRequest)1 SolverResponse (org.acme.schooltimetabling.message.SolverResponse)1 TimeTableConstraintProvider (org.acme.schooltimetabling.solver.TimeTableConstraintProvider)1 Timeout (org.junit.jupiter.api.Timeout)1 Solver (org.optaplanner.core.api.solver.Solver)1