I have a optaplanner/Timefold solution which works. It provides a solution with a real time feedback during the day to the business. But request for changes get queued in ad hoc, so I need to clone the solution to test if any request has a feasibly solution, before submitting it further into the main solution. For this I clone the current best solution to use for the test as follows:
SolutionDescriptor solutionDescriptor = SolutionDescriptor.buildSolutionDescriptor(DistributionSolution.class, MoverEntity.class, LoaderEntity.class );
FieldAccessingSolutionCloner<DistributionSolution> distSolCloner = new FieldAccessingSolutionCloner<>(solutionDescriptor);
DistributionSolution clonedSolution = distSolCloner.cloneSolution(currentDistributionSolution);
But it seems fragile to hardcode the solution and entity classes, I could use the solverConfig.xml but thats another sort of hard coding, it can be moved to a factory etc. But I am looking for a more dynamic way of getting an initialized SolutionCloner. I looked at the TimeFoldProcesser.class as it seems to make exactly that using reflection, but not sure how to access it at run time ? Any idea on how to go around this ?
Be aware that SolutionDescriptor
is not public API; you are doing something you shouldn't have been doing in the first place.
I'm not entirely sure why you need to do any of this; if you want to check that any particular problem has a feasible solution, you should run the solver. Nothing prevents you from running multiple solvers at the same time - one for your actual problem, and another to test a hypothesis.
That said, Timefold Solver will introduce a feature very soon that will help you with this; we call it the Recommended Fit API and it is designed to give super-fast answers to your question: "where best can I put this new entity in my current solution?"
Wrt. "hardcoding entity and solution", I do not understand that part of the question at all. The configuration needs to be written somewhere - doesn't matter if it's in SolverConfig
or if it's in solverConfig.xml
; it has to be somewhere.
Wrt. TimefoldProcessor
- if you're using Quarkus, you're already using it; it is an implementation detail of our Quarkus support. If you're not using Quarkus, there is no way to use it.