Search code examples
optaplanner

OptaPlanner @PlanningPin, null entities and .fromUniquePair()


I need some clarification, maybe someone can help me about the pinned and null entities with .from(). I understand that I need to use .fromUnfiltered() to get them in the stream. But what about .fromUniquePair(), are entities propagated down the stream if they are null and pinned ? Similar question if I use .fromUnfiltered() with a .join(), will the join() take the null and pinned entities in the second class?

Thank you!


Solution

  • Pinning has no effect on Constraint Streams - both from() and join() will always include pinned entities. Let's therefore concentrate on the uninitizalized entities.

    The thing to understand about fromUniquePair(Something.class) is that it is a shorthand for the following:

    from(Something.class)
       .join(Something.class, ...) // Replace "..." with joiners to get unique pairs.
    

    Therefore, both the left and the right will retrieve only initialized entities. If you want unique pairs including uninitialized entities, you will have to give up the shorthand and use a nested stream:

    fromUnfiltered(Something.class)
        .join(fromUnfiltered(Something.class), ...) // Replace "..." with the same joiners as above.