Skip to content

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

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

Closed
jason076 opened this issue Apr 25, 2025 · 7 comments · Fixed by #1583
Closed

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

jason076 opened this issue Apr 25, 2025 · 7 comments · Fixed by #1583
Assignees
Milestone

Comments

@jason076
Copy link

Describe the bug
Best solution consumer of solver manager is fired before deep clone of the planning solution has been completed. This lead to problems if you need to post-process the data returned from timefold solver. I recognized it because timefold throws in some cases IllegalStateExecption with "Verify the consistency of your input problem for that bi-directional relationship." message if I manually change content of bi-directional data.

Expected behavior

  1. Planning Solution gets first deep cloned
  2. Best Solution consumer is triggered after deep clone is completed. So it is safe to manipulate the Solution passed to best solution consumer.

Actual behavior
Planning Solution consumer and deeclone running in different thread and are not synchronized. If you edit a planning solution in the solution consumer it can influence the running planning if the edit took place before deepclone happend.

To Reproduce

  1. Create a Planning with a PlanningEntity having a bi-directional relationship(invers Shadow Variable)
  2. Start solving with solver manger and add a best solution consumer
  3. In best solution consumer change one side of the bi directional relation ship
  4. Wait for the IllegalStateException. It happens only if bestSolutionConsumer thread is faster than the thread executing the planning

Environment

Timefold Solver Version or Git ref: 1.21.0

Output of java -version: Eclipse Temurin JDK 21.0.6+7-LTS

Output of uname -a or ver: 24.3.0 Darwin Kernel Version 24.3.0: Thu Jan 2 20:24:23 PST 2025; root:xnu-11215.81.4~3/RELEASE_ARM64_T6020 arm64

Additional information

Provide any and all other information which might be relevant to the issue.

@jason076 jason076 added the process/needs triage Requires initial assessment of validity, priority etc. label Apr 25, 2025
@triceo
Copy link
Contributor

triceo commented Apr 25, 2025

Hello @jason076, and thanks for reporting!

What you're saying makes sense - the solution needs to be cloned before the event is fired. In fact, it has been designed like this, and it's worked like this for years. Which makes me question if there could be something else going on as well.

Any chance you could provide a reproducer that we could run on our end?

@jason076
Copy link
Author

I will try to find some time to do it. What I already checked is that my deep cloning is working correct. So thats not the issue.

@jason076
Copy link
Author

I am still trying to replicate it. What I found until now is that is only happens on phase change between construction heuristic and local search, hence on the first found solution. If I start manipulating the solution after local search started everything is working fine.

@jason076
Copy link
Author

I finally could reproduce it. Just run gradle build and gradle run and it should throw the exception.
reproducer.zip

@triceo
Copy link
Contributor

triceo commented Apr 25, 2025

Thank you, @jason076!

@triceo triceo removed the process/needs triage Requires initial assessment of validity, priority etc. label Apr 25, 2025
@zepfred zepfred linked a pull request May 7, 2025 that will close this issue
@jason076
Copy link
Author

I saw that you have an open PR for the issue. Is there any estimation when the fix will be released? Will it take more than two weeks to be available in a new version? It's important for me to know, because if it will be released soon, I will create no workaround for it.

@triceo
Copy link
Contributor

triceo commented May 14, 2025

The next release is scheduled for June 10th.

@triceo triceo added this to the v1.23.0 milestone May 19, 2025
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 a pull request may close this issue.

3 participants