Skip to content

feat(neighborhoods): add groupBy() support#2334

Merged
triceo merged 6 commits into
TimefoldAI:mainfrom
triceo:groupby
Jun 4, 2026
Merged

feat(neighborhoods): add groupBy() support#2334
triceo merged 6 commits into
TimefoldAI:mainfrom
triceo:groupby

Conversation

@triceo

@triceo triceo commented Jun 3, 2026

Copy link
Copy Markdown
Collaborator

No description provided.

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

Adds groupBy() capabilities to the Neighborhoods enumerating stream API (preview), including support for collectors, and wires SolutionView into grouping so predicates/mappers/collectors can access working-solution state consistently with other building blocks.

Changes:

  • Extends UniEnumeratingStream/BiEnumeratingStream preview APIs with groupBy(...) overloads (keys-only, collector-only, keys+collector) and implements them in the enumerating stream internals.
  • Introduces a preview collector API (*NeighborhoodsCollector*) plus NeighborhoodsCollectors.toList(...), and adapts these collectors to Bavet’s constraint collector machinery at node-build time (when SolutionView is available).
  • Adds/updates tests and docs, and exports the new preview collector package from the Java module.

Reviewed changes

Copilot reviewed 27 out of 29 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
model/test-model/src/main/java/ai/timefold/solver/model/testmodel/EmployeeScheduleOutputMetrics.java Minor formatting-only change.
model/test-model/src/main/java/ai/timefold/solver/model/testmodel/EmployeeScheduleInputMetrics.java Minor formatting-only change.
docs/src/modules/ROOT/pages/optimization-algorithms/neighborhoods.adoc Mentions groupBy as another building block supporting solutionView-aware functions.
core/src/test/java/ai/timefold/solver/core/preview/api/neighborhood/stream/enumerating/UniEnumeratingStreamTest.java Refactors helpers/names and adds groupBy(...)/collector test coverage.
core/src/test/java/ai/timefold/solver/core/preview/api/neighborhood/stream/enumerating/BiEnumeratingStreamTest.java New tests for groupBy(...) on bi-stream sources.
core/src/main/java/module-info.java Exports the new preview collector package.
core/src/main/java/ai/timefold/solver/core/preview/api/neighborhood/stream/enumerating/UniEnumeratingStream.java Adds groupBy(...) overloads to the preview uni-stream API.
core/src/main/java/ai/timefold/solver/core/preview/api/neighborhood/stream/enumerating/BiEnumeratingStream.java Adds groupBy(...) overloads to the preview bi-stream API.
core/src/main/java/ai/timefold/solver/core/preview/api/neighborhood/stream/collector/UniNeighborhoodsCollectorValueHandle.java New preview API for incremental per-value handles (uni).
core/src/main/java/ai/timefold/solver/core/preview/api/neighborhood/stream/collector/UniNeighborhoodsCollectorAccumulator.java New preview API for creating per-value handles using SolutionView (uni).
core/src/main/java/ai/timefold/solver/core/preview/api/neighborhood/stream/collector/UniNeighborhoodsCollector.java New preview API collector contract (uni).
core/src/main/java/ai/timefold/solver/core/preview/api/neighborhood/stream/collector/NeighborhoodsCollectors.java New factory for common neighborhoods collectors (toList).
core/src/main/java/ai/timefold/solver/core/preview/api/neighborhood/stream/collector/BiNeighborhoodsCollectorValueHandle.java New preview API for incremental per-value handles (bi).
core/src/main/java/ai/timefold/solver/core/preview/api/neighborhood/stream/collector/BiNeighborhoodsCollectorAccumulator.java New preview API for creating per-value handles using SolutionView (bi).
core/src/main/java/ai/timefold/solver/core/preview/api/neighborhood/stream/collector/BiNeighborhoodsCollector.java New preview API collector contract (bi).
core/src/main/java/ai/timefold/solver/core/impl/util/ConstantLambdaUtils.java Adds constant Neighborhoods*Mapper pickers for node sharing; removes unused constants.
core/src/main/java/ai/timefold/solver/core/impl/neighborhood/stream/enumerating/uni/UniGroupUniEnumeratingStream.java Switches grouping node construction to a SolutionView-aware constructor and marks distinctness.
core/src/main/java/ai/timefold/solver/core/impl/neighborhood/stream/enumerating/uni/UniGroupBiEnumeratingStream.java New uni-parent-to-bi-output grouping stream implementation.
core/src/main/java/ai/timefold/solver/core/impl/neighborhood/stream/enumerating/uni/AbstractUniEnumeratingStream.java Implements the new groupBy(...) API and routes distinct() through neighborhoods constant mappers.
core/src/main/java/ai/timefold/solver/core/impl/neighborhood/stream/enumerating/common/NeighborhoodsGroupNodeConstructorWithoutAccumulate.java New internal wrapper for non-accumulating group node constructors keyed for sharing.
core/src/main/java/ai/timefold/solver/core/impl/neighborhood/stream/enumerating/common/NeighborhoodsGroupNodeConstructorWithAccumulate.java New internal wrapper for accumulating group node constructors keyed for sharing.
core/src/main/java/ai/timefold/solver/core/impl/neighborhood/stream/enumerating/common/NeighborhoodsGroupNodeConstructor.java New internal factory tying mappers/collectors to Bavet group node constructors using SolutionView.
core/src/main/java/ai/timefold/solver/core/impl/neighborhood/stream/enumerating/common/AbstractNeighborhoodsGroupNodeConstructor.java New equality-keyed base implementation supporting node sharing.
core/src/main/java/ai/timefold/solver/core/impl/neighborhood/stream/enumerating/bi/BiGroupUniEnumeratingStream.java New bi-parent-to-uni-output grouping stream implementation.
core/src/main/java/ai/timefold/solver/core/impl/neighborhood/stream/enumerating/bi/BiGroupBiEnumeratingStream.java Updates grouping node construction to be SolutionView-aware and marks distinctness.
core/src/main/java/ai/timefold/solver/core/impl/neighborhood/stream/enumerating/bi/AbstractBiEnumeratingStream.java Implements the new groupBy(...) API and routes distinct() through neighborhoods constant mappers.
core/src/main/java/ai/timefold/solver/core/impl/neighborhood/stream/collector/ToListUniNeighborhoodsCollector.java Internal implementation of uni toList() collector.
core/src/main/java/ai/timefold/solver/core/impl/neighborhood/stream/collector/ToListBiNeighborhoodsCollector.java Internal implementation of bi toList(mapper) collector with SolutionView support.
core/src/main/java/ai/timefold/solver/core/impl/neighborhood/stream/collector/NeighborhoodsCollectorUtils.java Adapts neighborhoods collectors to Bavet constraint collectors at build time (with SolutionView).

Comment thread docs/src/modules/ROOT/pages/optimization-algorithms/neighborhoods.adoc 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

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

@triceo

triceo commented Jun 4, 2026

Copy link
Copy Markdown
Collaborator Author

Since I made significant changes (mostly adding new collectors), I'm re-requesting a review, @Christopher-Chianelli.

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

Copilot reviewed 32 out of 34 changed files in this pull request and generated 3 comments.

@sonarqubecloud

sonarqubecloud Bot commented Jun 4, 2026

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

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

See analysis details on SonarQube Cloud

@triceo triceo merged commit cddd6e0 into TimefoldAI:main Jun 4, 2026
21 of 22 checks passed
@triceo triceo deleted the groupby branch June 4, 2026 15:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants