gpt4 book ai didi

java - 采用 DRL 文件来启用强制类次计数和连续/实时规划

转载 作者:太空宇宙 更新时间:2023-11-04 09:11:59 26 4
gpt4 key购买 nike

我正在寻找有关以下 DRL 文件的改进方法的任何建议,以强制执行一定数量的轮类。我当前的方法通过 int TotalInt 值来划分员工的 ShiftAssignment 计数总数。需要一个基于规划元素进展的乘数。这似乎可以很好地确保满足员工每两周所需的轮类时间。例如,员工 1 - x 必须每两周轮类 10 次,员工 x - 20 必须每两周轮类 9 次,等等。这在持续计划推进期间是正确的。不幸的是,这是 DRL 文件中的硬编码方法。我不知道如何通过 Java 类和方法来解决这个问题。非常感谢任何建议。

 rule "Minimum and maximum number of assignments"

salience 1

when
$contractLine : MinMaxContractLine(contractLineType == ContractLineType.TOTAL_ASSIGNMENTS, enabled == true, $contract : contract) && BooleanContractLine(contractLineType == ContractLineType. IS_LOADBALANCED, enabled == false,contract == $contract)&& BooleanContractLine(contractLineType == ContractLineType.IS_CASUAL, enabled == false,contract == $contract)

$employee : Employee(contract == $contract)

accumulate(
$assignment : ShiftAssignment(employee == $employee);
$total : count($assignment)

)
then
int totalInt = $total.intValue();

if ($contractLine.isMaximumEnabled() && totalInt > ($contractLine.getMaximumValue() ) && totalInt < ($contractLine.getMaximumValue()* 2 )){

scoreHolder.addSoftConstraintMatch(kcontext,
($contractLine.getMaximumValue() - totalInt) * $contractLine.getMaximumWeight());


}
else if ($contractLine.isMaximumEnabled() && totalInt > ($contractLine.getMaximumValue()* 2 ) && totalInt < ($contractLine.getMaximumValue()* 3 )){

scoreHolder.addSoftConstraintMatch(kcontext,
(($contractLine.getMaximumValue() *2 )- (totalInt)) * $contractLine.getMaximumWeight());



}


else if ($contractLine.isMaximumEnabled() && totalInt > ($contractLine.getMaximumValue()* 3 ) && totalInt < ($contractLine.getMaximumValue()* 4 )){

scoreHolder.addSoftConstraintMatch(kcontext,
(($contractLine.getMaximumValue() *3 )- (totalInt)) * $contractLine.getMaximumWeight());



}

else if ($contractLine.isMaximumEnabled() && totalInt > ($contractLine.getMaximumValue()* 4 ) && totalInt < ($contractLine.getMaximumValue()* 5 )){

scoreHolder.addSoftConstraintMatch(kcontext,
(($contractLine.getMaximumValue() *4 )- (totalInt)) * $contractLine.getMaximumWeight());


}

else if ($contractLine.isMaximumEnabled() && totalInt > ($contractLine.getMaximumValue()* 5 ) && totalInt < ($contractLine.getMaximumValue()* 6 )){

scoreHolder.addSoftConstraintMatch(kcontext,
(($contractLine.getMaximumValue() *5 )- (totalInt)) * $contractLine.getMaximumWeight());


}

else if ($contractLine.isMaximumEnabled() && totalInt > ($contractLine.getMaximumValue()* 6 ) && totalInt < ($contractLine.getMaximumValue()* 7 )){

scoreHolder.addSoftConstraintMatch(kcontext,
(($contractLine.getMaximumValue() *6 )- (totalInt)) * $contractLine.getMaximumWeight());


}
else if ($contractLine.isMaximumEnabled() && totalInt > ($contractLine.getMaximumValue()* 7 ) && totalInt < ($contractLine.getMaximumValue()* 8 )){

scoreHolder.addSoftConstraintMatch(kcontext,
(($contractLine.getMaximumValue() *7 )- (totalInt)) * $contractLine.getMaximumWeight());


}
else if ($contractLine.isMaximumEnabled() && totalInt > ($contractLine.getMaximumValue()* 8 ) && totalInt < ($contractLine.getMaximumValue()* 9 )){

scoreHolder.addSoftConstraintMatch(kcontext,
(($contractLine.getMaximumValue() *8 )- (totalInt)) * $contractLine.getMaximumWeight());


}
else if ($contractLine.isMaximumEnabled() && totalInt > ($contractLine.getMaximumValue()* 9 ) && totalInt < ($contractLine.getMaximumValue()* 10 )){

scoreHolder.addSoftConstraintMatch(kcontext,
(($contractLine.getMaximumValue() *9 )- (totalInt)) * $contractLine.getMaximumWeight());


}
else if ($contractLine.isMaximumEnabled() && totalInt > ($contractLine.getMaximumValue()* 10 ) && totalInt < ($contractLine.getMaximumValue()* 11 )){

scoreHolder.addSoftConstraintMatch(kcontext,
(($contractLine.getMaximumValue() * 10 )- (totalInt)) * $contractLine.getMaximumWeight());


}
else if ($contractLine.isMaximumEnabled() && totalInt > ($contractLine.getMaximumValue()* 11 ) && totalInt < ($contractLine.getMaximumValue()* 12 )){

scoreHolder.addSoftConstraintMatch(kcontext,
(($contractLine.getMaximumValue() * 11 )- (totalInt)) * $contractLine.getMaximumWeight());


}

else if ($contractLine.isMaximumEnabled() && totalInt > ($contractLine.getMaximumValue()* 12 ) && totalInt < ($contractLine.getMaximumValue()* 13 )){

scoreHolder.addSoftConstraintMatch(kcontext,
(($contractLine.getMaximumValue() * 12 )- (totalInt)) * $contractLine.getMaximumWeight());


}
else if ($contractLine.isMaximumEnabled() && totalInt > ($contractLine.getMaximumValue()* 13 ) && totalInt < ($contractLine.getMaximumValue()* 14 )){

scoreHolder.addSoftConstraintMatch(kcontext,
(($contractLine.getMaximumValue() * 13 )- (totalInt)) * $contractLine.getMaximumWeight());


}
else if ($contractLine.isMaximumEnabled() && totalInt > ($contractLine.getMaximumValue()* 14 ) && totalInt < ($contractLine.getMaximumValue()* 15 )){

scoreHolder.addSoftConstraintMatch(kcontext,
(($contractLine.getMaximumValue() * 14 )- (totalInt)) * $contractLine.getMaximumWeight());


}
else if ($contractLine.isMaximumEnabled() && totalInt > ($contractLine.getMaximumValue()* 15 ) && totalInt < ($contractLine.getMaximumValue()* 16 )){

scoreHolder.addSoftConstraintMatch(kcontext,
(($contractLine.getMaximumValue() * 15 )- (totalInt)) * $contractLine.getMaximumWeight());


}
else if ($contractLine.isMaximumEnabled() && totalInt > ($contractLine.getMaximumValue()* 16 ) && totalInt < ($contractLine.getMaximumValue()* 17 )){

scoreHolder.addSoftConstraintMatch(kcontext,
(($contractLine.getMaximumValue() * 16 )- (totalInt)) * $contractLine.getMaximumWeight());


}
else if ($contractLine.isMaximumEnabled() && totalInt > ($contractLine.getMaximumValue()* 17 ) && totalInt < ($contractLine.getMaximumValue()* 18 )){

scoreHolder.addSoftConstraintMatch(kcontext,
(($contractLine.getMaximumValue() * 17 )- (totalInt)) * $contractLine.getMaximumWeight());



}
else if ($contractLine.isMaximumEnabled() && totalInt > ($contractLine.getMaximumValue()* 18 ) && totalInt < ($contractLine.getMaximumValue()* 19 )){

scoreHolder.addSoftConstraintMatch(kcontext,
(($contractLine.getMaximumValue() * 18 )- (totalInt)) * $contractLine.getMaximumWeight());


}
else if ($contractLine.isMaximumEnabled() && totalInt > ($contractLine.getMaximumValue()* 19 ) && totalInt < ($contractLine.getMaximumValue()* 20 )){

scoreHolder.addSoftConstraintMatch(kcontext,
(($contractLine.getMaximumValue() * 19 )- (totalInt)) * $contractLine.getMaximumWeight());


}
else if ($contractLine.isMaximumEnabled() && totalInt > ($contractLine.getMaximumValue()* 20 ) && totalInt < ($contractLine.getMaximumValue()* 21 )){

scoreHolder.addSoftConstraintMatch(kcontext,
(($contractLine.getMaximumValue() * 20 )- (totalInt)) * $contractLine.getMaximumWeight());


}
else if ($contractLine.isMaximumEnabled() && totalInt > ($contractLine.getMaximumValue()* 21 ) && totalInt < ($contractLine.getMaximumValue()* 22 )){

scoreHolder.addSoftConstraintMatch(kcontext,
(($contractLine.getMaximumValue() * 21 )- (totalInt)) * $contractLine.getMaximumWeight());


}
else if ($contractLine.isMaximumEnabled() && totalInt > ($contractLine.getMaximumValue()* 22 ) && totalInt < ($contractLine.getMaximumValue()* 23 )){

scoreHolder.addSoftConstraintMatch(kcontext,
(($contractLine.getMaximumValue() * 22 )- (totalInt)) * $contractLine.getMaximumWeight());


}
else if ($contractLine.isMaximumEnabled() && totalInt > ($contractLine.getMaximumValue()* 23 ) && totalInt < ($contractLine.getMaximumValue()* 24 )){

scoreHolder.addSoftConstraintMatch(kcontext,
(($contractLine.getMaximumValue() * 23 )- (totalInt)) * $contractLine.getMaximumWeight());


}
else if ($contractLine.isMaximumEnabled() && totalInt > ($contractLine.getMaximumValue()* 24 ) && totalInt < ($contractLine.getMaximumValue()* 25 )){

scoreHolder.addSoftConstraintMatch(kcontext,
(($contractLine.getMaximumValue() * 24 )- (totalInt)) * $contractLine.getMaximumWeight());


}
else if ($contractLine.isMaximumEnabled() && totalInt > ($contractLine.getMaximumValue()* 25 ) && totalInt < ($contractLine.getMaximumValue()* 26 )){

scoreHolder.addSoftConstraintMatch(kcontext,
(($contractLine.getMaximumValue() * 25 )- (totalInt)) * $contractLine.getMaximumWeight());


}
else if ($contractLine.isMaximumEnabled() && totalInt > ($contractLine.getMaximumValue()* 26 ) && totalInt < ($contractLine.getMaximumValue()* 27 )){

scoreHolder.addSoftConstraintMatch(kcontext,
(($contractLine.getMaximumValue() * 26 )- (totalInt)) * $contractLine.getMaximumWeight());


}

else if ($contractLine.isMaximumEnabled() && totalInt > ($contractLine.getMaximumValue()* 27 ) && totalInt < ($contractLine.getMaximumValue()* 28 )){

scoreHolder.addSoftConstraintMatch(kcontext,
(($contractLine.getMaximumValue() * 27 )- (totalInt)) * $contractLine.getMaximumWeight());


}

else if ($contractLine.isMaximumEnabled() && totalInt > ($contractLine.getMaximumValue()* 28 ) && totalInt < ($contractLine.getMaximumValue()* 29 )){

scoreHolder.addSoftConstraintMatch(kcontext,
(($contractLine.getMaximumValue() * 28 )- (totalInt)) * $contractLine.getMaximumWeight());


}

else {
// Workaround for https://issues.jboss.org/browse/PLANNER-761


scoreHolder.addSoftConstraintMatch(kcontext, 0);

}
end
rule "Minimum and maximum number of assignments with Casuals"
//salience
when
$contractLine : MinMaxContractLine(contractLineType == ContractLineType.TOTAL_ASSIGNMENTS, enabled == false, $contract : contract)&& BooleanContractLine(contractLineType == ContractLineType.IS_CASUAL, enabled == true, contract == $contract)
$employee : Employee(contract == $contract)
accumulate(
$assignment : ShiftAssignment(employee == $employee);
$total : count($assignment)
)
then
int totalInt = $total.intValue();

scoreHolder.addSoftConstraintMatch(kcontext,- totalInt);

end


/*rule "fairAssignmentCountPerEmployee"
salience 2
when //$contractLine : BooleanContractLine(contractLineType == ContractLineType. IS_LOADBALANCED, enabled == true, $contract : contract)


$e : Employee()

$result : loadBalance() from accumulate(

ShiftAssignment(employee == $e),
count()
);


then

scoreHolder.addSoftConstraintMatch(kcontext, -(int)$result.getMeanDeviationSquaredSumRootMillis());

end*/

rule "fairAssignmentCountPerEmployee"

when $contractLine : BooleanContractLine(contractLineType == ContractLineType. IS_LOADBALANCED, enabled == true, $contract : contract)

accumulate(
ShiftAssignment(employee != null, $e : employee, contract == $contract, $shift:shift);
$total : loadBalanceByCount($e)
)
then

scoreHolder.addSoftConstraintMatch(kcontext, - (int) $total.getZeroDeviationSquaredSumRootMillis());
end

最佳答案

你不能改变数学吗?看来您正在检查 totalInt 下降的时间间隔。您可以直接除以 $constractLine.getMaximumValue() 来获取系数,而不是检查 28 个场景。

例如

coefficient = Math.ceil(totalInt/$contractLine.getMaximumValue());
score = (coefficient * $contractLine.getMaximumvalue() - totalInt ) * coefficient;
scoreHolder.addSoftConstraintMatch(kcontext, score);

我没有检查所有边缘情况,但这应该达到与您使用 28 个间隔所做的相同的效果(并且具有更广泛的范围)。

关于java - 采用 DRL 文件来启用强制类次计数和连续/实时规划,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59572228/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com