Automatic solution cloning in Planner

For Planner 6.0.0.Beta1, implementing the Solution’s planning clone method is now optional. This means there’s less boilerplate code to write. Also, because the planning clone method notoriously hard to write from scratch (most people just copy pasted the examples to avoid mistakes), it’s now easier to get started with Planner too.

The out-of-the-box SolutionCloner works well for most use cases: it’s fast, yet still does a few sanity checks to detect errors.

Custom solution cloning

You can still choose to roll your own solution cloning. Now, it’s also documented what Planner expects you to do:

A planning clone of a Solution must fulfill these requirements:

  • The clone must represent the same planning problem. Usually it reuses the same instances of the problem facts and problem fact collections as the original.
  • The clone must use different, cloned instances of the entities and entity collections. Changes to the original Solution‘s entities must not effect its clone.

And there’s also warning, in case you’re using chained planning variables, for a common pitfall:
Cloning an entity with a chained variable is devious: a variable of an entity A might point to another entity B. If A is cloned, then it’s variable must point to the clone of B, not the original B.

But don’t worry about that: just use the default SolutionCloner, which will take care of all that for you.

Author

Comments are closed.