Skip to content

Instantly share code, notes, and snippets.

@ge0ffrey
Created August 9, 2016 12:27
Show Gist options
  • Save ge0ffrey/e7c9758f2c20b5b5703b6b4b6da3ed29 to your computer and use it in GitHub Desktop.
Save ge0ffrey/e7c9758f2c20b5b5703b6b4b6da3ed29 to your computer and use it in GitHub Desktop.
This rule:
// Identical shiftTypes during a weekend
rule "identicalShiftTypesDuringWeekend"
when
$contractLine : BooleanContractLine(contractLineType == ContractLineType.IDENTICAL_SHIFT_TYPES_DURING_WEEKEND,
enabled == true, $contract : contract)
$employee : Employee(contract == $contract, $weekendLength : weekendLength)
ShiftDate(dayOfWeek == DayOfWeek.SUNDAY, $sundayIndex : dayIndex)
$shiftType : ShiftType()
accumulate(
$assignment : ShiftAssignment(
weekend == true,
weekendSundayIndex == $sundayIndex,
employee == $employee,
shiftType == $shiftType);
$weekendAssignmentTotal : count($assignment);
$weekendAssignmentTotal > 0 and $weekendAssignmentTotal < $weekendLength
)
then
scoreHolder.addSoftConstraintMatch(kcontext,
($weekendAssignmentTotal.intValue() - $weekendLength) * $contractLine.getWeight());
end
throws
java.lang.IllegalStateException: There are errors in a score DRL:
Error Messages:
Message [id=1, level=ERROR, path=org/optaplanner/examples/nurserostering/solver/nurseRosteringScoreRules.drl, line=452, column=0
text=[ERR 102] Line 452:40 mismatched input 'and' in rule "identicalShiftTypesDuringWeekend"]
Message [id=2, level=ERROR, path=org/optaplanner/examples/nurserostering/solver/nurseRosteringScoreRules.drl, line=0, column=0
text=Parser returned a null Package]
---
More specfically, this line:
$weekendAssignmentTotal : Long(this > 0 && < $weekendLength) from accumulate(
...,
count($assignment)
)
has become
accumulate(
...;
$weekendAssignmentTotal : count($assignment);
$weekendAssignmentTotal > 0 and $weekendAssignmentTotal < $weekendLength
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment