Adding new object by increasing stream cardinality conditionally #1428
Replies: 2 comments 5 replies
-
I think joining should work here... You could create a stream that contains all Sunday night shifts:
and then join that to your grouped shifts
Important note: This way, if there is no Sunday night shift entity for a group, this group will not be included in the result of the join, which is probably undesirable. There might be a way to work around this using Timefold's API, but I'm not sure (did not find anything like a left join. Maintainers might know more about that @triceo?). If feasible, you could ensure your data starts correctly (i.e. with last Sunday's shift pinned). Might not be the most beautiful solution. Sorry, its a bit sloppy and might contain syntax errors, just quickly jotted it down. But I suppose the concept should work. |
Beta Was this translation helpful? Give feedback.
-
We have a The need for more powerful joins has been coming up lately. We have an issue which includes a lot of our random thoughts on the topic - but so far, no major effort was invested. It may change. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello! I have a (maybe) complicated question.
I am attempting to build a constraint, for calculating minimum pause between shifts at least once a week.
I have ShiftAssignmentByAbr class that contains the PlanningVariable - Employee. It also contains information about the shift, day, week and etc...
I am currently using the groupBy building block to group the ShiftAssignment's by employee and week and it works great!
My problem is the following. The previous Sunday could contain a night shift. The ShiftAssignment that contains the previous Sunday would have the same Employee, but different Week. In order to make my calculation 100% correct, I would need to add this ShiftAssignment somehow to the constraint stream, if it exists. If it does not, it would be null.
Essentialy I want to go from:
TriConstraintStream<Employee, Week, List<ShiftAssignmentByAbr>
to
QuadConstraintStream<Employee, Week, List<ShiftAssignmentByAbr>, ShiftAssignmentByAbr>
where the 4th element is the last week's Sunday shift, if it exists.
I looked into using join, or concat, but I couldn't find a way to make it work with any of them.
The only I found to achieve my is to only group them by employee and toList(...) and make my own custom handler.
This solution would work, but it would be slow, inconvenient, and negate incremental score calculation.
Is it possible to achieve this through the Timefold API directly?
Any advice would be helpful!
Thank you and sorry for the long question!
Beta Was this translation helpful? Give feedback.
All reactions