为员工排班添加轮班之间最短工时的约束参数

问题描述 投票:0回答:1

我正在尝试修改员工调度快速入门中的约束以支持参数,但它似乎不起作用。

我将代码修改为这样,不知道为什么它不起作用。

Constraint atLeast10HoursBetweenTwoShifts(ConstraintFactory constraintFactory) {
return constraintFactory.forEach(Shift.class)
        .join(Shift.class, equal(Shift::getEmployee), lessThanOrEqual(Shift::getEnd, Shift::getStart))
        .join(ConstraintParameters.class)
        .filter((firstShift,
                secondShift, constraintParameters) -> {
             return Duration.between(firstShift.getEnd(), secondShift.getStart()).toHours() < constraintParameters.minRestHours();
        })
        .penalize(HardSoftBigDecimalScore.ONE_HARD,
                (firstShift, secondShift, constraintParameters) -> {
                    int breakLength = (int) Duration.between(firstShift.getEnd(), secondShift.getStart()).toMinutes();
                    return (constraintParameters.minRestHours() * 60) - breakLength;
                })
        .asConstraint("At least 10 hours between 2 shifts");
}

timefold
1个回答
0
投票

可能没有已知可连接的 ConstraintParameters 实例。

检查您的解决方案类是否具有用 @ProblemFactProperty 注释的 ConstraintParameters 字段。

© www.soinside.com 2019 - 2024. All rights reserved.