我正在解析来自ScoreDirector的数据以显示在GUI中,我想知道 getJustificationList()是如何工作的,以便我可以可靠地在字符串中显示数据。
以下是一些应用上下文:
rule "The max duration per day must be met"
when
$contract : Contract()
$day : Day()
$totalDuration : Integer() from accumulate(
ScheduleTime(
timeGrain != null,
timeGrain.day != null,
contract == $contract,
getDayOfYear() == $day.getDayOfYear(),
$scheduleTimeDuration : getGrainDuration()
),
sum($scheduleTimeDuration)
)
then
scoreHolder.penalize(kcontext, Math.abs($totalDuration - $contract.getRequiredGrainPerDay()));
end
当我执行这段代码
for (ConstraintMatch match : constraintMatchTotal.getConstraintMatchSet()) {
if (((HardMediumSoftScore) match.getScore()).getHardScore() != 0){
for (int i = 0; i < match.getJustificationList().size(); i ++){
System.out.println(
i+". " +
match.getJustificationList().get(i).getClass().getName() +
" => " +
match.getJustificationList().get(i).toString());
}
}
}
它表明:
0. java.lang.Integer => 0
1. domain.Day => 2019-Jun-01
2. domain.Contract => Contract for Bernadine Swift
0. java.lang.Integer => 0
1. domain.Day => 2019-May-26
2. domain.Contract => Contract for Charles Schwarzeneger
...
在上面的示例中,顺序似乎与在drools规则中向后创建变量的顺序相关。
是什么决定值在列表中的显示顺序?如何确定到达索引2时将是Contract对象而不是其他对象?
修改 这是使用的optaplanner版本: 7.21.0.Final