javaquarkustimefold

Question on preventing hardcoding of constraint parameters


From the quickstarts, I was attempting to modify the hard-coded constraints in EmployeeSchedulingConstraintProvider, but was not successful in doing so.

Link to quickstart: https://github.com/TimefoldAI/timefold-quickstarts/blob/c18de9dfc3ae2ad38446312aeb1a21c61df326f7/java/employee-scheduling/src/main/java/org/acme/employeescheduling/solver/EmployeeSchedulingConstraintProvider.java#L66

For example, I attempted modifying the atLeast10HoursBetweenTwoShifts to accept other values e.g. 5.

Attempt 1: Injecting a Repository into the EmployeeSchedulingConstraintProvider, but it always returned null. It appears that I should not be mixing Quarkus and Timefold together.

Attempt 2: Adding an additional parameter List<ConstraintCriteria> constraints into the EmployeeSchedule class, which is used in solve() in EmployeeScheduleResource. However, attempts to extract the constraints out in the EmployeeSchedulingConstraintProvider was not successful.

Attempt 3: Tried to follow the guide in Timefold Docs, but I am unable to add @PlanningFactProperty and ConstraintPararameters to follow along the guide. I am not too sure if I am applying it correctly.

Cannot resolve symbol 'PlanningFactProperty'

Cannot resolve symbol 'ConstraintPararameters'

    <version.io.quarkus>3.14.2</version.io.quarkus>
    <version.ai.timefold.solver>1.13.0</version.ai.timefold.solver>

https://docs.timefold.ai/timefold-solver/latest/constraints-and-score/constraint-configuration#passingParametersToConstraints

Noticed this guide being posted, which is similar to this problem, but it appears to use a Deprecated method: Making my soft constraint tunable in Timefold

Would appreciate some pointers, or guidance on how to proceed further, on easily modifying the constraint parameters


Solution

  • Chris' comment already explains what's wrong here.

    You refer to an older question, mentioning that it uses a deprecated method. That is true. What you see in our documentation now, overriding constraint weights, replaces constraint configuration.

    Finally, our documentation also shows how to pass settings directly to constraints, avoiding any hard-coded values. Together, this should answer your question.