sudo
sudo

Reputation: 316

What is the better way to model this (simple) Optaplanner use case?

I'm modeling a simple use case, but my initial idea apparently isn't easily implemented after all, for the beginner that I (still) am. My use case ...

I want to assign teachers to several school activities (of varying durations). Teachers have different working regimes (full-time, part-time, 1 day per week, ...). Every (model's) school activity has to be assigned to 1 teacher - I model "real-life" school activities needing 2 teachers as 2 school activities needing 1 teacher each. With this in mind, for performant score calculation reasons, I had in mind to keep a map of teachers with per teacher one duration (in minutes) containing the sum of all activities that teacher is assigned to. However, I'm puzzled as to where I would have to keep that map : I don't succeed in updating any "across-class" shadow variable. The documentation doesn't suggest that (what I call) "across-class" shadow variables are impossible (as it mentions the possibility of specifying the "entityClass" on p. 225 of the 8.0.0.Final User Guide).

So I wonder how this is to be modeled (or implemented, if shadow variables are to be used) ? Should I better not keep such a map, and just calculate all of a teacher's assigned school activity duration's sum at every new score calculation anyway ? This seems such a waste of performance if it can be calculated in a much simpler (addition/subtraction) way at the proper moment when assigning another teacher to an activity.

(I could add the class' declaration if it'd be necessary)

Upvotes: 0

Views: 61

Answers (1)

sudo
sudo

Reputation: 316

Me being the Optaplanner beginner, made a mistake from which I think other Optaplanner beginners could learn too. I found out why my shadow variables weren't updating...

The annotations in the code themselves weren't incorrect as such. What was incorrect, was the missing <entityClass> - element of the class that evolved into containing the shadow variable. Initially, that class was not a PlanningEntity (and wasn't included in the solver configuration's <entityClass> - element list). So it became a PlanningEntity when it got to contain the ShadowVariable.

So in my solver configuration, I had to add that second class as an extra <entityClass> - element !

Hope other newbies can learn from this :-)

Upvotes: 1

Related Questions