Matching a general element-wise pattern using the consecutive sequences collector #1594
tomashauser
started this conversation in
General
Replies: 1 comment 10 replies
-
Hello @tomashauser!
We are.
This often works well, because we typically want to look at numbers of shifts in sequence. For detecting complex patterns which need to span breaks too, you currently have no other option than to go through the entire This operation will not be incremental and therefore not perform optimally, but that won't matter much for short chains. (Planning window for these problems typically isn't too long.) |
Beta Was this translation helpful? Give feedback.
10 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Let us consider an instance of Nurse Rostering problem with a
Shift
as a planning entity andEmployee
as a planning variable. It is not unusual to want the consecutive shifts to adhere to a specific pattern. For example, an employee may want to avoid a (NIGHT, DAY) pattern due to sleep schedule adjustment issues, or perhaps prefer (NIGHT, BREAK, DAY) for the same reason. To avoid fixating specifically on day patterns, we may simply give each shift a tag and penalize/reward an occurrence of specific consecutive subsequence of tags within an employee's schedule, possibly including breaks.In the incubator-kie-optaplanner project we may find a surprisingly awkward approach to this, using a dot product over the set of all shift assignments:
They also support a three-day-pattern in the same manner, they just use a third join.
When I saw that, I was glad we have the
ConsecutiveSequencesCollector
which presumably uses an efficient algorithm under the hood to provide the consecutive sequencues, and allows us to approach problems of this kind with a more general approach. My idea was following:however, when I tried to extract the actual items from the
ai.timefold.solver.core.api.score.stream.common.Sequence
, I realized it won't let me. Theseq.getItems()
only returns the items before the first break, and then, there are onlyai.timefold.solver.core.api.score.stream.common.Break
s which only expose the last item of the previous break and the first item of the next break. This is not enough information to extract the number of occurences of the pattern.Then I resorted to simply going through the list of all shifts for each employee, yielding an awful
O(n log(n))
constraint due to the need to also sort the array:There has to be a better way of doing this. Am I missing something? Why are you not exposing the whole sequences? Is it because the underlying algorithms wouldn't be as fast? Thank you for any insights.
Beta Was this translation helpful? Give feedback.
All reactions