I'm trying to develop a small planning application with timefold.ai. As it grew, the Construction Phase takes more und more time. I embedded TimeFold into a Spring Boot application and I am using this code to run the solver async in background:
this.solverJob = solverManager.solveBuilder()
.withProblemId(currentSolution.getId())
.withProblemFinder(jobId -> currentSolution)
.withBestSolutionConsumer(solution -> {
this.currentSolution = solution;
} )
.withExceptionHandler((jobId, exception) -> {
log.error("Failed solving jobId ({}).", jobId, exception);
})
.run();
The BestSolutionConsumer
is only invoked after the construction phase has completed. Therefore, during the construction phase, which takes approximately 5-10 minutes for my current problem sizes, I am unable to provide progress updates to the user. Is it possible to access the currentSolution
while it is being initialized?
I also tried the solveAndListen
method of the SolverManger
, but it also only triggers the change event after the construction phase has finished.
We don't currently don't send out these CH update events by default for performance reasons: If your Construction Heuristic has 3000 steps (see the INFO log line "CH ended" to see how many steps it has), then any such step would send out an event and would need to planning clone the best solution, which would then happen 3000 times.
Sounds like you're only interested in the score, not the semi-initialized solution so far.
We could consider an RFE to be able to optionally requests these CH step update events. Potentially throttled. With or without the best solution?
But as your CH takes 5-10 minutes, I would argue you have a bigger priority: I would start by bringing that below 30 seconds by: