Search code examples
optaplanner

Solution Cloning happening at steps that produce a "new best score" in a row


Something that recently caught my attention was a step being slower than others when a "new best score" is produced. This is definitely the solution cloning that is happening at every step that produces a "new best score".

So this is okay if the "new best score" steps are not in a row. If for example we have 50 steps in a row the solution cloning process will be executed 50 times. A smarter way would be to do the cloning process at the end of the sequence(only once).

Is this something that can be implemented easily or there is some other thing that would prevent it?

Another idea would be to do the cloning at every "new best score" step but only to clone the planning entity instances changed by the move selected as a step and append them to the best solution.


Solution

  • If you have 50 steps in a row, and the first 23 steps improve the best solution, do we need to do a planning clone during that step 23 of that working solution? Yes, we do, because there is no guarantee that any of the next 27 steps will improve the best score, so we don't want to loose the state of the solution at step 23. Not every step improves the best score, some go to a worse score (especially with Late Acceptance).

    That being said, in Construction Heuristics - we actually don't do intermediate planning clones because we can guarantee that the solution will only improve (more initialized variables is always better).

    In any case, the best way to make planning clones light is to design a model for which the planning entity class doesn't have any incoming references (except from the solution class of course)