Skip to content

chore: Move streams basic variables allow value ranges on entities#1658

Closed
triceo wants to merge 22 commits into
TimefoldAI:mainfrom
triceo:ms-list
Closed

chore: Move streams basic variables allow value ranges on entities#1658
triceo wants to merge 22 commits into
TimefoldAI:mainfrom
triceo:ms-list

Conversation

@triceo

@triceo triceo commented Jun 23, 2025

Copy link
Copy Markdown
Collaborator

The filtering during picking is refactored, so that the filter gets access to solution
and therefore can decide whether or not a particular value is or is not part of a value range.
Moves that do not fit in the value range can now be filtered out,
regardless whether the value range comes from a solution or from an entity.

We also implement a cache for value ranges, and thread it through the solver.
This cache will only be invalidated on-demand in situations where relevant information changes,
leading to best possible performance.

Code pertaining to the previous implementation is removed,
as the previous implementation only supported value ranges on solution.

@triceo triceo changed the title chore: Move streams allow value ranges on entities chore: Move streams basic variables allow value ranges on entities Jun 24, 2025
@triceo triceo marked this pull request as ready for review June 24, 2025 10:22
@triceo triceo requested review from Copilot and zepfred June 24, 2025 10:22
@triceo triceo added this to the v1.24.0 milestone Jun 24, 2025
@triceo triceo self-assigned this Jun 24, 2025

This comment was marked as outdated.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 refactors the move streams API to support entity-based value ranges, implements a caching ValueRangeState for on-demand lookups, and migrates legacy generic stream code to the new maybeapi approach.

  • Move stream implementations are reorganized under maybeapi, with factories and sessions updated to use SolutionView and SolutionViewTriPredicate.
  • Introduce ValueRangeState to cache solution/entity value ranges and add isValueInRange methods in SolutionView and AbstractScoreDirector.
  • Remove legacy generic stream and dataset code, updating tests and domain models to align with the new API.

Reviewed Changes

Copilot reviewed 80 out of 80 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
core/src/main/java/ai/timefold/solver/core/preview/api/move/SolutionView.java Add isValueInRange overloads for solution/entity value-range checks.
core/src/main/java/ai/timefold/solver/core/impl/score/director/ValueRangeState.java New class to cache and lookup solution/entity value ranges efficiently.
core/src/main/java/ai/timefold/solver/core/impl/move/streams/maybeapi/stream/UniMoveStream.java Introduce default pick overload and switch to SolutionViewTriPredicate.
core/src/main/java/ai/timefold/solver/core/impl/move/streams/maybeapi/generic/ChangeMoveProvider.java Refactor change-move provider to pick null and filter via SolutionViewTriPredicate.
core/src/main/java/ai/timefold/solver/core/api/domain/valuerange/ValueRangeProvider.java Enhance Javadoc with determinism, null handling, and solver-change guidance.
Comments suppressed due to low confidence (2)

core/src/main/java/ai/timefold/solver/core/impl/domain/valuerange/descriptor/AbstractFromPropertyValueRangeDescriptor.java:158

  • [nitpick] This line is duplicated in the error message. Remove the redundant "Maybe remove that null element from the dataset." to avoid confusion.
                    Maybe remove that null element from the dataset.

core/src/main/java/ai/timefold/solver/core/preview/api/move/SolutionView.java:79

  • The @Nullable annotation is used here but not imported. Add import org.jspecify.annotations.Nullable; to avoid a compile error.
            @Nullable Value_ value) {

Comment on lines +13 to +16
// TODO Bring an API that works incrementally;
// The current implementation will scan the entire B stream for each A.
<B> BiMoveStream<Solution_, A, B> pick(UniDataStream<Solution_, B> uniDataStream,
SolutionViewTriPredicate<Solution_, A, B> filter);

Copilot AI Jun 30, 2025

Copy link

Choose a reason for hiding this comment

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

[nitpick] This TODO indicates that the current pick implementation performs a full scan for each element A, which can degrade performance. Consider designing an incremental or indexed approach to avoid N×M iteration.

Suggested change
// TODO Bring an API that works incrementally;
// The current implementation will scan the entire B stream for each A.
<B> BiMoveStream<Solution_, A, B> pick(UniDataStream<Solution_, B> uniDataStream,
SolutionViewTriPredicate<Solution_, A, B> filter);
// Updated to use an indexed approach for efficient lookups.
// This avoids scanning the entire B stream for each A.
<B> BiMoveStream<Solution_, A, B> pick(UniDataStream<Solution_, B> uniDataStream,
SolutionViewTriPredicate<Solution_, A, B> filter, Function<B, ?> indexKeyExtractor);

Copilot uses AI. Check for mistakes.
@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
41.8% Coverage on New Code (required ≥ 70%)

See analysis details on SonarQube Cloud

@triceo triceo removed this from the v1.24.0 milestone Jul 8, 2025
@triceo

triceo commented Jul 23, 2025

Copy link
Copy Markdown
Collaborator Author

Will be replaced shortly with a new version, updated to the latest code and significantly refactored for improved performance.

@triceo triceo closed this Jul 23, 2025
@triceo triceo deleted the ms-list branch July 23, 2025 12:33
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.

3 participants