【发布时间】:2021-06-09 06:19:03
【问题描述】:
我正在尝试编写一个约束来检查整数数组 (binUsedArray) 的任何元素是否大于界限 (dailyMaxNb)。
rule "BinResourceConstraint"
when
BinResource($array : binUsedArray, $dailyMaxNb : dailyMaxNb)
$x : Integer() from $array
$x > $dailyMaxNb
then
scoreHolder.addHardConstraintMatch(kcontext, -1);
end
我阅读了 drools doc 5.1.8 并尝试编写类似这样的规则
rule "Iterate the numbers"
when
$xs : List()
$x : Integer() from $xs
then
$x matches and binds to each Integer in the collection
end
但出现了一些错误:
Caused by: java.lang.RuntimeException: [Message [id=1, kieBase=defaultKieBase, level=ERROR, path=com/cttq/aps/solver/taskScheduleConstraint.drl, line=78, column=0
text=[ERR 102] Line 78:11 mismatched input '>' in rule "BinResourceConstraint"], Message [id=2, kieBase=defaultKieBase, level=ERROR, path=com/cttq/aps/solver/taskScheduleConstraint.drl, line=0, column=0
text=Parser returned a null Package]]
===== 更新了 BinResource 类,binUsedArray 是一个大小为 30 的 int 数组,用于保留接下来 30 天使用的 bin 数量。
@PlanningEntity
public class BinResource {
private String index;
private String binType;
private String binArea;
private int dailyMaxNb;
@CustomShadowVariable(variableListenerRef = @PlanningVariableReference(entityClass = TaskAssignment.class, variableName = "modifiedProcessTimeInShift"))
private int[] binUsedArray;
【问题讨论】:
-
澄清一下 --
binUsedArray是int[]或Integer[]并且您想查看该数组中是否有任何值是> $dailyMaxNb? -
第二条规则适用于集合。数组不是 java.util.Collection,因此您不能对
int[]/Integer[]使用相同的工作流程是有道理的。 -
@RoddyoftheFrozenPeas binUsedArray 是 int[] 是的,我想检查这个数组中的每个值。
标签: drools optaplanner