Skip to content

fix: call cascade listeners for unassigned values #1480

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Mar 28, 2025

Conversation

zepfred
Copy link
Contributor

@zepfred zepfred commented Mar 25, 2025

No description provided.

Copy link
Collaborator

@triceo triceo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will need refactoring.

Copy link
Collaborator

@triceo triceo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll run some benchmarks overnight.
This is likely to affect performance, I want to know by how much.

@triceo
Copy link
Collaborator

triceo commented Mar 27, 2025

There is a performance regression, which is unavoidable. The code now does more than it did before. Performance regressions are acceptable, if they fix incorrect behavior.

However, I made a whole bunch of changes to minimize the regression. There is a simple underlying principle to all of my changes: don't do things that don't need doing. Please review the changes and ask questions in case anything is unclear.

@triceo triceo force-pushed the fix/cascading-update branch from 58648f1 to 6d18ae5 Compare March 27, 2025 08:59
@triceo
Copy link
Collaborator

triceo commented Mar 27, 2025

I'll have the final benchmark results in a few hours.

Copy link
Collaborator

@triceo triceo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't able to measure any regression anymore that I could attribute to this PR. LGTM after the Sonar issues are fixed.

@triceo triceo requested a review from Copilot March 27, 2025 16:12
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes the cascade listener handling for unassigned values and adds several tests and improvements to support this behavior. Key changes include:

  • Added tests for LinkedIdentityHashSet, ElementAwareList, and cascading update behavior.
  • Updated TestdataSingleCascadingValue and MoveDirectorTest to verify that cascade updates are correctly invoked and undone.
  • Enhanced VariableListenerSupport and related notification classes to support cascade updates for unassigned values.

Reviewed Changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated no comments.

Show a summary per file
File Description
core/src/test/java/ai/timefold/solver/core/impl/util/LinkedIdentityHashSetTest.java New tests for the identity-based set implementation.
core/src/test/java/ai/timefold/solver/core/impl/util/ElementAwareListTest.java Added clear() test to ensure proper list resetting.
core/src/test/java/ai/timefold/solver/core/impl/testdata/domain/cascade/single_var/TestdataSingleCascadingValue.java Introduced null-check to reset cascade values when the entity is unassigned.
core/src/test/java/ai/timefold/solver/core/impl/testdata/domain/cascade/single_var/TestdataSingleCascadingEasyScoreCalculator.java New score calculator for cascading update testing.
core/src/test/java/ai/timefold/solver/core/impl/move/director/MoveDirectorTest.java Added a test to verify undo behavior of cascading updates.
core/src/main/java/ai/timefold/solver/core/impl/util/LinkedIdentityHashSet.java New implementation of a set using identity comparisons.
core/src/main/java/ai/timefold/solver/core/impl/util/ElementAwareList.java Updated iterator to return an empty iterator when appropriate and added clear() support.
core/src/main/java/ai/timefold/solver/core/impl/domain/variable/listener/support/VariableListenerSupport.java Enhanced to add cascade notifications for unassigned values and refactored related logic.
core/src/main/java/ai/timefold/solver/core/impl/domain/variable/listener/support/Notification.java Updated the list variable change notification creation to return a ListVariableChangedNotification.
core/src/main/java/ai/timefold/solver/core/impl/domain/variable/listener/support/ListVariableEvent.java Removed redundant record as part of the refactoring.
core/src/main/java/ai/timefold/solver/core/impl/domain/variable/listener/support/ListVariableChangedNotification.java Made public to ensure accessibility in cascade update contexts.
core/src/main/java/ai/timefold/solver/core/impl/domain/variable/listener/support/AbstractNotification.java Added getEntity() accessor to support notification logic.
Comments suppressed due to low confidence (2)

core/src/main/java/ai/timefold/solver/core/impl/domain/variable/listener/support/VariableListenerSupport.java:245

  • [nitpick] Consider renaming 'unassignedValueWithEmptyInverseEntitySet' to a more concise name (e.g., 'unassignedEmptyInverseSet') to improve readability in the cascade update logic.
unassignedValueWithEmptyInverseEntitySet.add(element);

core/src/main/java/ai/timefold/solver/core/impl/domain/variable/listener/support/VariableListenerSupport.java:320

  • [nitpick] Consider adding an inline comment explaining why the value is removed from the unassigned set here, to clarify its role in the cascade update process.
unassignedValueWithEmptyInverseEntitySet.remove(value);

Copy link

@triceo triceo merged commit 5447b0f into TimefoldAI:main Mar 28, 2025
33 of 34 checks passed
@zepfred zepfred deleted the fix/cascading-update branch May 20, 2025 17:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cascading update logic does not activate when an undo move is performed
2 participants