Reputation: 1073
I am trying to construct the domain model for an optimization use-case, using OptaPlanner. In my mind the following problem should be modeled using two @PlanningEntity
classes, but since the OptaPlanner documentation often argues that you usually only need one @PlanningEntity
class, I am wondering if I am modelling my problem incorrectly, or whether this is in fact a situation to have two @PlanningEntity
classes.
Consider a school timetabling problem like the example provided by OptaPlanner here, but imagine we are also planning and optimising which students attend a lesson. If these problems are independent, then this could be solved by writing two different solvers, and running the "student planner" solver first, and then the "schedule planner" solver. However, assume that these two are not independent. For example, constraints regarding the placement of students in certain lessons might interact with when these lessons take place (student X prefers lessons in the morning, student Y prefers lessons in the afternoon, and student Z cannot have two lessons directly in a row). So, when optimising, I would like the solver to be able to consider both the timeslot of lessons as well as the students attending a lesson.
My idea to model this would be to extend the TimeTable
class in the example with a second @PlanningEntity
modelling student to lesson assignments, and in the Lesson
class the studentGroup
field would be replaced with a list containing all the students assigned to that lesson, probably in the form of a shadow variable (though this is an implementation detail).
@PlanningEntity
classes ("Student to lesson assignment" as well as Lesson
) are appropriate? Or is there a way to model this problem using only a single @PlanningEntity
? I know that a @PlanningVariable
cannot be a list, so I assume a List<Student> students
planning variable is not possible.@PlanningEntityCollection
can only be a field on the @PlanningSolution
? Or is there a way to have the student assignments be a field on the Lesson
?Upvotes: 0
Views: 238
Reputation: 1029
Since you want to assign lessons to time and rooms and students to lessons, I think you truly need two @PlanningEntity
classes. As multiple students can attend multiple lessons, you can perhaps create a new StudentAssignment
@PlanningEntity
class with Lesson
as its @PlanningVariable
.
Yes, the @PlanningEntityCollection
can only be a field on the @PlanningSolution
class. What can be put inside the @PlanningEntity
class is the @ValueRangeProvider
that provides values for the @PlanningVariable
field.
Upvotes: 0