Skip to content

fix: clone the solution before sending it to the consumer#1583

Merged
triceo merged 5 commits into
TimefoldAI:mainfrom
zepfred:fix/consumer
May 19, 2025
Merged

fix: clone the solution before sending it to the consumer#1583
triceo merged 5 commits into
TimefoldAI:mainfrom
zepfred:fix/consumer

Conversation

@zepfred

@zepfred zepfred commented May 7, 2025

Copy link
Copy Markdown
Contributor

This PR addresses an issue where we return the same solution instance as the SolverScope to external consumers. Therefore, if changes are made to the solution, it may be possible that these changes will affect the solver phases, because the current best solution from the solver scope is restored at the end of each phase.

AbstractSolver::runPhases(SolverScope<Solution_> solverScope) {
            ...
            // If there is a next phase, it starts from the best solution, which might differ from the working solution.
            // If there isn't, no need to planning clone the best solution to the working solution.
            if (it.hasNext()) {
                solverScope.setWorkingSolutionFromBestSolution();
            }

It is worth noting that I have analyzed the use of SolverScope::getBestSolution and external actions. The solution is now cloned before being shared with these external consumers.

@sonarqubecloud

sonarqubecloud Bot commented May 7, 2025

Copy link
Copy Markdown

@triceo triceo left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We can still improve this a bit.

@triceo triceo merged commit 1dde0ab into TimefoldAI:main May 19, 2025
39 of 40 checks passed
@zepfred zepfred deleted the fix/consumer 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.

It's not safe to edit planning solution in best solution consumer

2 participants