我试图写一个规则来平衡负载,首先是一个单一合同。我最终希望能够平衡不平等的合同,例如兼职(PT)和全职(FT)。
有人这样做并且可以分享他们的DRL规则吗?我发现您在输入公式之前需要使用PT x FT的倒数。
我已经在Optaplanner文档中多次阅读了网球示例。我可以得到一个奇异的合约来平衡,但是希望它在我在布尔类中创建的布尔值IS_LOADBALANCED
上触发。我收到一个我不明白的错误。第一个代码元素有效,但是我希望第二个代码元素基于布尔值工作,因为我想保持*规则“最小和最大分配数”与NurseRoster一起使用。
rule "fairAssignmentCountPerEmployee"
when
accumulate(
$e : Employee()
and accumulate(
ShiftAssignment(employee == $e);
$assignment : count()
);
$result : loadBalance($assignment)
)
then
scoreHolder.addSoftConstraintMatch(kcontext, -(int)$result.getMeanDeviationSquaredSumRootMillis());
end
rule "fairAssignmentCountPerEmployee"
salience 1
when
$contractLine : BooleanContractLine(contractLineType == ContractLineType. IS_LOADBALANCED, enabled == true, $contract : contract)
accumulate(
$e : Employee(contract == $contract)
and accumulate(
ShiftAssignment(employee == $e);
$assignment : count()
);
$result : loadBalance($assignment)
)
then
//Just to see the contract type
System.out.println($contract);
scoreHolder.addSoftConstraintMatch(kcontext, -(int)$result.getMeanDeviationSquaredSumRootMillis());
end
Caused by: java.lang.NullPointerException
at org.drools.core.reteoo.FromNodeLeftTuple.getAccumulatedObjects(FromNodeLeftTuple.java:111)
at org.drools.core.common.AgendaItem.getObjectsDeep(AgendaItem.java:79)
at org.drools.core.reteoo.RuleTerminalNodeLeftTuple.getObjectsDeep(RuleTerminalNodeLeftTuple.java:359)
at org.optaplanner.core.api.score.holder.AbstractScoreHolder.extractJustificationList(AbstractScoreHolder.java:133)
at org.optaplanner.core.api.score.holder.AbstractScoreHolder.registerConstraintMatch(AbstractScoreHolder.java:104)
at org.optaplanner.core.api.score.buildin.hardsoft.HardSoftScoreHolder.addSoftConstraintMatch(HardSoftScoreHolder.java:177)
at org.optaplanner.examples.nurserostering.solver.Rule_fairAssignmentCountPerEmployee343111290.defaultConsequence(Rule_fairAssignmentCountPerEmployee343111290.java:21)
at org.optaplanner.examples.nurserostering.solver.Rule_fairAssignmentCountPerEmployee343111290DefaultConsequenceInvokerGenerated.evaluate(Unknown Source)
at org.optaplanner.examples.nurserostering.solver.Rule_fairAssignmentCountPerEmployee343111290DefaultConsequenceInvoker.evaluate(Unknown Source)
at org.drools.core.phreak.RuleExecutor.innerFireActivation(RuleExecutor.java:432)
在此期间,我使用以下方法解决了该问题。但是,我仍在寻求帮助以平衡不平等的合同。有人吗?
rule "Minimum and maximum number of assignments"
salience 1 // Do these rules first (optional, for performance)
when
$contractLine : MinMaxContractLine(contractLineType == ContractLineType.TOTAL_ASSIGNMENTS, enabled == true, $contract : contract
) && BooleanContractLine(contractLineType == ContractLineType. IS_LOADBALANCED, enabled == false, contract == $contract)
$employee : Employee(contract == $contract)
accumulate(
$assignment : ShiftAssignment(employee == $employee);
$total : count($assignment)
)
then
int totalInt = $total.intValue();
if ($contractLine.isMinimumEnabled() && totalInt < $contractLine.getMinimumValue()) {
scoreHolder.addSoftConstraintMatch(kcontext,
(totalInt - $contractLine.getMinimumValue()) * $contractLine.getMinimumWeight());
} else if ($contractLine.isMaximumEnabled() && totalInt > $contractLine.getMaximumValue()) {
scoreHolder.addSoftConstraintMatch(kcontext,
($contractLine.getMaximumValue() - totalInt) * $contractLine.getMaximumWeight());
} else {
// Workaround for https://issues.jboss.org/browse/PLANNER-761
scoreHolder.addSoftConstraintMatch(kcontext, 0);
}
end
rule "fairAssignmentCountPerTeam"
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.addHardConstraintMatch(kcontext, - (int) $total.getZeroDeviationSquaredSumRootMillis());
end