I am solving an employee rostering problem with optaplanner. Currently I'm rewriting my rules written in DRL to Constraint Streams.
I have constraints, where the user can define, if he wants the rule as a hard or a soft constraint.
In DRL in the then
part I had access to my roster object and with this I could find out if I have to add a hardConstraintMatch
or a softConstraintMatch
.
How can I achieve that with Constraint Streams?
Here an example:
Constraint holiday(ConstraintFactory constraintFactory) {
return constraintFactory.forEach(Shift.class)
.join(
Absence.class,
Joiners.equal(Shift::getEmployee, Absence::getEmployee),
Joiners.greaterThanOrEqual(Shift::getDate, Absence::getStartDate),
Joiners.lessThanOrEqual(Shift::getDate, Absence::getEndDate)
).penalize(
"holiday",
// Here I would need something like roster.getRules().get("holiday").getType()
// to define dynamically if I have to add ONE_HARD or ONE_SOFT
HardMediumSoftLongScore.ONE_HARD,
(shift,absence) -> {
Roster roster = shift.getRoster();
return roster.getRules().get("holiday").getPenaltyValue();
}
);
}
Has someone an idea how to achieve that?