Skip to content
Advertisement

Nullable PlanningVariable causes all null solution

I’ve a business case to assign resources(employees) to some work requirements. Here are three domain classes to describe the problem:

JavaScript

And a PlanningEntity and PlanningSolution class defines as follows:

JavaScript

The simplify the problem, I added only one Constraint which scores -1 * (requirement's amount) if no resources assigned to the requirement.

JavaScript

The problem is that assignments in all solved ResourceSchedule hold null resource field no matter input data, and the best score is always 0hard/0soft which obviously contradicts with the defined Constraint. Meanwhile, if I remove the nullable = true in @PlanningVariable, then everything seems work properly — there are minus score and RequirementAssignment with Resource information.

Advertisement

Answer

forEach(...) only matches on planning entities with non-null variables. The solution is to use forEachIncludingNullVars(...) instead, as stated in the documentation for nullable variables.

Advertisement