在Drools DRL中检查对象数组没有值

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

我正在尝试向optaplanner商业中心的员工名册示例添加新规则。检查是否将轮班分配给员工的规则,从而降低了硬约束得分持有者。

package employeerostering.employeerostering;

rule "ShiftHoursWithinEmployeeSchedule"
    dialect "mvel"
    when
        $shiftAssignment : ShiftAssignment( $employee : employee != null, $shiftEndDateTime : shift.timeslot.endTime, $shiftStartDate : shift.timeslot.startTime)

        not Schedule ( day == $shiftEndDateTime.dayOfWeek.getValue() && (startTime > $shiftStartDateTime || endTime < $shiftEndDateTime) ) from $employee.schedules

    then
        scoreHolder.addHardConstraintMatch(kcontext, -1);
end

我是DRL的新手,我想修改第二条规则,以便它遍历$ employee的所有计划,并检查是否没有一个满足条件的规则。

drools optaplanner
1个回答
1
投票

我认为您只需要翻转关系运算符,因为您要在没有时间表的情况下对情况进行惩罚,以使班次适合时间表] ::

not Schedule ( day == $shiftEndDateTime.dayOfWeek.getValue() && (
        startTime < $shiftStartDateTime &&
        endTime > $shiftEndDateTime)
) from $employee.schedules

不确定Schedule.startTime的类型。如果是一天中的时间偏移量(例如8:00),则您可能无法将其与Timeslot.startTime进行比较,后者可能是绝对时间量(日期+时间)。

我建议在Timeslot中重用Schedule类型,而不是将时间表定义为日+时间。然后,您应该可以编写:

rule "ShiftHoursWithinEmployeeSchedule"
    dialect "mvel"
    when
        $shiftAssignment : ShiftAssignment( $employee : employee != null, $shiftEndDateTime : shift.timeslot.endTime, $shiftStartDate : shift.timeslot.startTime)

        not Schedule ( timeslot.startTime > $shiftStartDateTime && timeslot.endTime < $shiftEndDateTime ) from $employee.schedules

    then
        scoreHolder.addHardConstraintMatch(kcontext, -1);
end
© www.soinside.com 2019 - 2024. All rights reserved.