Changing the Data model of Time Table app

73 Views Asked by At

Introduction/Context:

I'm working on developing a Time-fold's app using Spring Boot. The goal is to create a timetable similar to the example provided in Time-fold's documentation. I've defined two enumerations, DomainandRoom-type, which represent the teaching domain of a teacher and the type of room respectively.

Entities:

this picture represents entities:

enter image description here

Enumeration:


public enum Domain {
    MATHEMATICS,
    SCIENCE,
    HISTORY,
    // Other teaching domains...
}


public enum RoomType {
    ART_ROOM,
    MUSIC_ROOM,
    COMPUTER_ROOM,
    CLASSROOM,
    // Other room types...
}

Question/Issue:

Now, I need to annotate these entities using Time-fold's annotations to achieve the desired functionality. Specifically, I want for a specified room assign lessons to teachers based on certain constraints, such as maximum lessons per day, teacher availability, etc. I want a solution like this on Monday, in Room x, with a maximum of lessons per day equal to 3, lesson 1 is assigned to teacher y, lesson 2 is assigned to teacher z, and lesson 3 is assigned to a teacher w

How can I annotate these entities to accomplish this?

1

There are 1 best solutions below

2
Dickson the developer On

I don't have much experience in timefold, however, I see from the documentation (Link below) that they have provided some examples using the same concept of 'lessons'.

https://timefold.ai/docs/timefold-solver/latest/quickstart/spring-boot/spring-boot-quickstart#_lesson

UPDATE

In this update, I have added some code to aid with the solution. (Note that I have ommited some code such as getters and setters)

public class Teacher {

    @PlanningId
    private Long id;

    private String name;

    // No-arg constructor required for Hibernate
    public Teacher() {
    }

    public Teacher(long id, String name) {
        this.id = id;
        this.name = name;
    }

    @Override
    public String toString() {
        return name;
    }

    // Getters and setters
}

public class Timeslot {

    @PlanningId
    private Long id;

    private DayOfWeek dayOfWeek;
    private LocalTime startTime;
    private LocalTime endTime;

    // No-arg constructor required for Hibernate
    public Timeslot() {
    }

    public Timeslot(long id, DayOfWeek dayOfWeek, LocalTime startTime, LocalTime endTime) {
        this.id = id;
        this.dayOfWeek = dayOfWeek;
        this.startTime = startTime;
        this.endTime = endTime;
    }

    public Timeslot(long id, DayOfWeek dayOfWeek, LocalTime startTime) {
        this(id, dayOfWeek, startTime, startTime.plusMinutes(50));
    }

    @Override
    public String toString() {
        return dayOfWeek + " " + startTime;
    }
// Getters and setters

}

public class Room {

    @PlanningId
    private Long id;

    private String name;

    // No-arg constructor required for Hibernate
    public Room() {
    }

    public Room(long id, String name) {
        this.id = id;
        this.name = name;
    }

    @Override
    public String toString() {
        return name;
    }

    // Getters and setters

    
}


@PlanningEntity
public class Lesson {

    @PlanningId
    private Long id;

    private String subject;

    @PlanningVariable(valueRangeProviderRefs = {"timeslotRange"})
    private Timeslot timeslot;

    @PlanningVariable(valueRangeProviderRefs = {"roomRange"})
    private Room room;

    @PlanningVariable(valueRangeProviderRefs = {"teacherRange"})
    private Teacher teacher;

    // No-arg constructor required for Timefold
    public Lesson() {
    }

    public Lesson(long id, String subject, Teacher teacher) {
        this.id = id;
        this.subject = subject;
        this.teacher = teacher;
    }

    public Lesson(long id, String subject, Teacher teacher, Timeslot timeslot, Room room) {
        this(id, subject, teacher);
        this.timeslot = timeslot;
        this.room = room;
    }

    @Override
    public String toString() {
        return subject + "(" + id + ")";
    }

    // Getters and setters

}