For example, to do the "Some employees are qualified to do either role, but others can only be a cashier, or a restocker." constraint in the article, it would be written like this:
def required_skill(constraint_factory: ConstraintFactory):
return (constraint_factory.for_each(Shift)
.filter(lambda shift: shift.required_skill not in shift.employee.skills)
.penalize(HardSoftScore.ONE_HARD)
.as_constraint("Missing required skill")
)
Some examples taken from Timefold quickstarts:- Employee scheduling (https://github.com/TimefoldAI/timefold-quickstarts/tree/stab...)
- Vehicle routing (https://github.com/TimefoldAI/timefold-quickstarts/tree/stab...)
- School timetabling (https://github.com/TimefoldAI/timefold-quickstarts/tree/stab...)