-
Notifications
You must be signed in to change notification settings - Fork 165
chore: improve sorting operation #1900
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
base: main
Are you sure you want to change the base?
Conversation
1b647b1 to
6507949
Compare
|
@triceo The PR is ready for review and will rerun all previous model validations, just like we did when adding the sorting feature. |
|
There is an issue with the quickstart compilation job, and I will take a look. |
triceo
left a comment
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 am not excited about how sorting creates yet another completely separate path for some selectors, and another part for others.
ValueRangeManager needs to be the ultimate source of truth. Think of the future, where we are inevitably going to be asked to enable mutable value ranges on entities. (When variables change, so do value ranges.) This complexity simply cannot be managed, if value ranges are all over the place. This needs to be centralized.
This future is closer than you think; early next year I expect.
IMO we should start cutting off the paths that lead to these discrepancies. Deprecating, failing fast. Especially when we introduce new functionality, like here - with new functionality, there is no backwards compatibility. We can simply decide to make some things impossible. We can start to reduce the impossible cross-combinations of move selector configurations.
Also, you are far too attached to the ValueRange type. In the future, this type will not exist. Every ValueRange will just be a Collection. Make your future you's life easier, and stop treating the ValueRange interface as a building block for everything.
We only have a limited amount of time to spend on this, and there are good things in here. Let's discuss where we go from here.
core/src/main/java/ai/timefold/solver/core/api/domain/valuerange/ValueRange.java
Outdated
Show resolved
Hide resolved
core/src/main/java/ai/timefold/solver/core/impl/domain/valuerange/ValueRangeCache.java
Outdated
Show resolved
Hide resolved
...ava/ai/timefold/solver/core/impl/heuristic/selector/common/decorator/SelectionSetSorter.java
Outdated
Show resolved
Hide resolved
...a/ai/timefold/solver/core/impl/heuristic/selector/value/FromEntityPropertyValueSelector.java
Show resolved
Hide resolved
| * because the FilteringValueRangeSelector or the related Nearby selector does not respect the sort order | ||
| * provided by the child selectors. | ||
| */ | ||
| var canSortAtValueRangeLevel = entityValueRangeRecorderId == null && nearbySelectionConfig == null; |
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.
So... let's assume I have provided the nearby distance meter, and nothing else. (No selector configuration.) Does nearby use value ranges?
If not, then I wonder why we're really doing this. The idea of value ranges is that there would be one place where all of this happens, but if something as critical as nearby still ignores value ranges, then arguably the idea failed.
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.
So... let's assume I have provided the nearby distance meter, and nothing else. (No selector configuration.) Does nearby use value ranges?
I'm unsure if this is even possible. The point is, if there is a nearby configuration, then it means we will create nodes that ignore the sorting provided by the child selectors.
If not, then I wonder why we're really doing this. The idea of value ranges is that there would be one place where all of this happens, but if something as critical as nearby still ignores value ranges, then arguably the idea failed.
I see your point and will work on a solution. That means we will need to pass the sorter to the range filtering and nearby nodes.
...rc/main/java/ai/timefold/solver/core/impl/heuristic/selector/value/ValueSelectorFactory.java
Outdated
Show resolved
Hide resolved
The Vert.x exception is a red herring. Your real problem is here: |
core/src/main/java/ai/timefold/solver/core/impl/score/director/ValueRangeManager.java
Outdated
Show resolved
Hide resolved
core/src/main/java/ai/timefold/solver/core/impl/score/director/ValueRangeManager.java
Show resolved
Hide resolved
|
I'm thinking we're approaching this all wrong. We're building this hierarchy of selectors, decorating with additional behaviors. But value ranges shouldn't work like that. Value ranges are meant to be the root selector. When sorting is necessary, it should be applied to the root selector directly, not via some decorator later. The root iteration should already happen in the sorted order. How do values come into the value range selector? Who puts them there? That is where we need to start - and that source of data needs to be the value range manager. Which will already have everything sorted. And then we can start building all the other functionality on top of that - the filter decorator etc., all of that can be layered on top of what's already sorted. This is a large refactor, and maybe we don't want to do it right now. But this is the way to make sure that value range manager is the only source of truth for data. And consequently, it is the only way how we can safely produce value ranges which change with their entity variables. |
That's the current approach. The base method
Yes, that's correct. However, the range filtering and the nearby nodes ignore the root selector sort order because they use different structures to fetch the values: reachable values and the distance matrix.
I have a solution to maintain the |
|
@triceo I'll begin reviewing the necessary changes to the enterprise repository, and This change is needed because both |
306bb78 to
43f59de
Compare
|
triceo
left a comment
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.
Without running any benchmarks, I can already anticipate several places where performance will suffer compared to the previous solution. IMO all of them are fixable, and may also lead to significantly simpler code.



This PR enables sorting the value ranges at the
ValueRangeManagerlevel.The sorting feature is likely useful during the CH phase, and the new approach can address the sorting requirement for the existing CH configurations. However, the existing selector sorting nodes remain available, as they are required for range filtering or nearby selectors. Also, these corner cases may only make sense for the LS phases.