Search code examples
optaplanner

Optaplanner: Performant implementation to known on the anchor which is the last entity of its chain


Which is the performant implementation to known on the anchor which is the current last entity of its chain?

Right now I traverse all the chain up to the end to get it which is O(n) in terms of performance.

Is there a way to attach a VariableListener on the Anchor to be notified en every chain update?

NOTE: My entities have a reference to previous and next (the later implemented by a VariableListener on the entity)

Thanks.


Solution

  • Create a @CustomShadowVariable with the source set to:

    • the @PlanningVariable (for example Customer.previousStandstill) to be notified of every chain update
    • the @AnchorShadowVariable (for example Customer.vehicle) to be notified of every planning entity switching to another anchor