brewphone
brewphone

Reputation: 1366

Optaplanner, by default, will values in PlanningVariable range be repeated

As usual my PlanningSolution class has a list of PlanningEntity, the PlanningEntity class has a Integer PlanningVariable member variable. Now I have 2 elements in the PlanningEntity list, and the PlanningVariable's range can be either 1 or 2. For sure (1,2) and (2,1) are potential solutions, my question is, by default, will (1,1) and (2,2) be potential solutions as well? if they are not, how can I make (1,1) and (2,2) be potential solutions?

Upvotes: 0

Views: 85

Answers (1)

yurloc
yurloc

Reputation: 2358

Yes, OptaPlanner will use values from a value range repeatedly.

Notice that the requirement to use a value just once is a constraint that makes sense in some use cases but not in all of them. People that need this behavior can express such requirement as a hard constraint using Constraint Streams.

OptaPlanner works with no constraints out of the box so that it can explore the search space freely.

In your case you don't have to take any extra steps to allow repeating values. All of the following are solutions that OptaPlanner will eventually find:

  • (1, 1)
  • (1, 2)
  • (2, 1)
  • (2, 2)

Upvotes: 3

Related Questions