-
Notifications
You must be signed in to change notification settings - Fork 145
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will need refactoring.
...a/ai/timefold/solver/core/impl/domain/variable/listener/support/VariableListenerSupport.java
Outdated
Show resolved
Hide resolved
This reverts commit ac622ea.
There was a problem hiding this 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.
core/src/main/java/ai/timefold/solver/core/impl/util/IdentityHashSet.java
Outdated
Show resolved
Hide resolved
core/src/main/java/ai/timefold/solver/core/impl/util/IdentityHashSet.java
Outdated
Show resolved
Hide resolved
core/src/main/java/ai/timefold/solver/core/impl/util/IdentityHashSet.java
Outdated
Show resolved
Hide resolved
...a/ai/timefold/solver/core/impl/domain/variable/listener/support/VariableListenerSupport.java
Outdated
Show resolved
Hide resolved
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. |
58648f1
to
6d18ae5
Compare
6d18ae5
to
a5372e8
Compare
...a/ai/timefold/solver/core/impl/domain/variable/listener/support/VariableListenerSupport.java
Show resolved
Hide resolved
...a/ai/timefold/solver/core/impl/domain/variable/listener/support/VariableListenerSupport.java
Show resolved
Hide resolved
core/src/main/java/ai/timefold/solver/core/impl/util/LinkedIdentityHashSet.java
Show resolved
Hide resolved
core/src/main/java/ai/timefold/solver/core/impl/util/LinkedIdentityHashSet.java
Show resolved
Hide resolved
core/src/main/java/ai/timefold/solver/core/impl/util/LinkedIdentityHashSet.java
Show resolved
Hide resolved
core/src/main/java/ai/timefold/solver/core/impl/util/ElementAwareList.java
Show resolved
Hide resolved
...a/ai/timefold/solver/core/impl/domain/variable/listener/support/VariableListenerSupport.java
Show resolved
Hide resolved
...a/ai/timefold/solver/core/impl/domain/variable/listener/support/VariableListenerSupport.java
Show resolved
Hide resolved
...a/ai/timefold/solver/core/impl/domain/variable/listener/support/VariableListenerSupport.java
Show resolved
Hide resolved
I'll have the final benchmark results in a few hours. |
There was a problem hiding this 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.
There was a problem hiding this 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);
|
No description provided.