我正在尝试向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的所有计划,并检查是否没有一个满足条件的规则。
我认为您只需要翻转关系运算符,因为您要在没有时间表的情况下对情况进行惩罚,以使班次适合时间表] ::
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