如何确定轮班中的女性员工人数

时间:2019-05-26 10:00:26

标签: drools optaplanner

我为员工轮班添加了自定义规则,其中我有4种轮班类型,而在一种类型的轮班中,必须确定女性员工的数量

我尝试在班次类别中添加一个字段,即requiredFemalesEmployees,该字段设置为1    //硬约束    规则“ OneFemaleInShiftA”

when    
$gender:Employee(gender=="F")
 $rfe:Shift(requiredFemalesEmployees==1)
 accumulate(
$a:ShiftAssignment(employee==$gender,$shift:shift.requiredFemalesEmployees),
 $total :count($a)
)

then
 if($total.intValue()!=1){
 scoreHolder.addHardConstraintMatch(kcontext, - 1);
 } 

结束

任何建议都会有很大帮助。

1 个答案:

答案 0 :(得分:0)

首先,您创建了一个名为$ rfe的变量,但未使用,在此行中: $ a:ShiftAssignment(employee == $ gender,$ shift: shift.requiredFemalesEmployees ),您要为$ shift分配什么?

这是我的示例:

rule "oneFemaleInShift"
    when    
        $gender:Employee(gender=="F")
        $rfe:Shift(requiredFemalesEmployees==1)
        Number(intValue!=1) from accumulate(
            $a:ShiftAssignment(employee==$gender, ¿¿$shift:shift.requiredFemalesEmployees??),
            count($a)
        )

    then
        scoreHolder.addHardConstraintMatch(kcontext, - 1);

我们需要域模型或Java POJO的源来了解它们之间的关系。

我认为这会对您有所帮助

rule "oneFemaleInShift"
    when    
        $femaleEmployee:Employee(gender=="F") //GET FEMALE POJOS
        $rfe:Shift(requiredFemalesEmployees==1) // GET SHIFT WHERE FEMALE IS REQUIRED
        Number(intValue > 0) from accumulate( //COUNT NUMBER OF FEMALE EMPLOYEES IN THAT SHIFT, PENALIZE SOLUTION WHERE THERE ARE LESS THAN 1
            $a:ShiftAssignment(employee==$femaleEmployee, shift==$rfe), 
            count($a)
        )
    then
        scoreHolder.addHardConstraintMatch(kcontext, - 1); // LOOK AT THE VALUE OF HARD SCORE, PROPORTION WITH OTHER HARD CONSTRAINT