是的,它可以。有几个例子实际上是这样做的。有几种方法可以设计/实现它。这是我更喜欢的一个:
@PlanningEntity class TaskAssignment {
Task task;
@PlanningVariable Employee employee;
public int getDuration() {
// Warning: If affinity's or task types would change during planning (except during real-time planning ProblemFactChange of course),
// we would need to do this through DRL or break incremental score calculation.
return employee.getAffinityTo(task.getType()).getDuration();
}
}
rule affinityBasedDuration
when
TaskAssignment(employee != null, $d : duration)
then
// addSoft(-$d)
end
你甚至可以传入参数:
when
$a : TaskAssignment($id : id)
$b : TaskAssignment($id < id, $d: calculateOverlap($a))
then
// addSoft(-$d)
end
@PlanningEntity class TaskAssignment {
...
public int calculateOverlap(TaskAssignment other) {
// calculate overlap with this.startTimestamp vs other.startTimestamp
// and this.endTimestamp vs other.endTimestamp
}
}