timefold-solver icon indicating copy to clipboard operation
timefold-solver copied to clipboard

Shadow Variable listeners called alphabetically instead of in order of declaration

Open pieterdeschepper opened this issue 1 year ago • 0 comments

Describe the bug When you have more than 1 Shadowvariable listeners on a variable, they are called alphabetically based on the source variable name.

Expected behavior They are called in the order of declaration

Actual behavior Describe clearly and concisely what actually happened.

To Reproduce Taken from the food-packaging quickstart, this is the original

    @InverseRelationShadowVariable(sourceVariableName = "jobList")
    private Line line;
    @PreviousElementShadowVariable(sourceVariableName = "jobList")
    private Job previousJob;
   
    @ShadowVariable(variableListenerClass = StartDateTimeUpdatingVariableListener.class, sourceVariableName = "line")
    @ShadowVariable(variableListenerClass = StartDateTimeUpdatingVariableListener.class, sourceVariableName = "previousJob")
    private LocalDateTime startCleaningDateTime;

When you change it to e.g.

    @InverseRelationShadowVariable(sourceVariableName = "jobList")
    private Line technician;
    @PreviousElementShadowVariable(sourceVariableName = "jobList")
    private Job previousJob;
   
    @ShadowVariable(variableListenerClass = StartDateTimeUpdatingVariableListener.class, sourceVariableName = "technician")
    @ShadowVariable(variableListenerClass = StartDateTimeUpdatingVariableListener.class, sourceVariableName = "previousJob")
    private LocalDateTime startCleaningDateTime;

You will notice that the variable listener is called in another order (because technician comes alphabetically after `previousJob``

@ge0ffrey has an idea why it happens

Environment

Timefold Solver Version or Git ref:

Output of java -version:

Output of uname -a or ver:

Additional information

Related issue in quickstarts: https://github.com/TimefoldAI/timefold-quickstarts/issues/315

pieterdeschepper avatar Mar 04 '24 14:03 pieterdeschepper