timefold-solver
timefold-solver copied to clipboard
Feat: Improve error message when @PlanningListVariable is used alongside a @PlanningVariable on different classes
Is your feature request related to a problem? Please describe.
Currently, if you use a @PlanningVariable and a @PlanningListVariable on different classes, the following exception occurs:
java.lang.IllegalArgumentException: The config (QueuedValuePlacerConfig(ValueSelectorConfig(jobs), ListChangeMoveSelectorConfig(ValueSelectorConfig(null), null))) has no entityClass configured and because there are multiple in the entityClassSet ([class org.acme.foodpackaging.domain.Job, class org.acme.foodpackaging.domain.Line]), it cannot be deduced automatically.
at ai.timefold.solver.core.impl.AbstractFromConfigFactory.getTheOnlyEntityDescriptor(AbstractFromConfigFactory.java:67)
Describe the solution you'd like
Ideally, the error message should improve by telling the user that @PlanningListVariable cannot be used with @PlanningVariable currently:
java.lang.IllegalArgumentException: There exists a PlanningListVariable (...), so there can be no PlanningVariable (...). Maybe used a chained model?
Describe alternatives you've considered This issue will become stale once PlanningListVariable supports co-existing with other PlanningVariable(s)
Additional context https://stackoverflow.com/q/78102453/9698517
If the @PlanningVariable and @PlanningListVariable are defined on the same class, there is a better error message:
java.lang.UnsupportedOperationException: Combining basic variables ([Line.product variable]) with list variables (Line.jobs variable) on a single planning entity (org.acme.foodpackaging.domain.Line) is not supported.
@Christopher-Chianelli That's an important distinction. We are absolutely sure we do not support combining list variables and basic variables on the same entity.
But are we so sure we don't support it on two different entity classes? Because the original exception is just saying you need to configure the selector specifically for a particular entity, as there are two different entities. It's not saying that the combination is not supported.
I am pretty sure there are no tests for @PlanningVariable + @PlanningListVariable on different entities, so if it supported, it not tested. Additionally, that exception is from the default phase list/SoverConfig. Finally, the docs state
Planning list variable does not yet support ... coexistence with another list or basic planning variable.
The docs is ambiguous too - does "coexistence" mean "in the same solution" or "in the same entity class"? IMO this needs to be tested to know for sure.
If we can reconfigure the selector manually to two selectors, one for each entity, and it still blows up, then it's clear - we do not support this use case. (I think that this is the more likely outcome, I'm just not 100.0 % sure.)
Well, "Construction Heuristic phase with a list variable does not support moveSelectorConfigList configuration. Remove the moveSelectorConfigList ([UnionMoveSelectorConfig(null)]) from the config.", so it is impossible to configure the selector.