Search code examples
optaplanner

Optaplanner, ChangeProblem vs restart solver


Changing an Optaplanner problem mid flight, requires the use of the ProblemChange for the solver to queue the change real time and correct the solution. But is the behaviour much different than stopping the solver, saving and changing the BestSolution and restart the solver with the modified solution - Assuming the that the workingsolution is not far better than the last Bestsolution ?

The reason for the question is wheter its better to keep the solution in memory as I know new real time changes will occur, to be able to handle them fast. But on the other hand, they dont happen very often, so saving a solution and restart it after a change would make a more simple solution.


Solution

  • The current implementation of both OptaPlanner and Timefold actually restarts the solver on every problem change. ProblemChange may still be a little bit more efficient than just restarting the solver on your own, but the difference will likely be negligible.

    I would still recommend using ProblemChange though, because nothing is set in stone. Some day in the future, we may actually implement fully incremental ProblemChange, and you'll get free performance. Help the solver help you by providing your commands with a bit of extra semantics.