javaoptaplannertimefold

Planning entity with multiple planning variables will not try some scenarios forever


There are two planning variables A and B in one planning entity C. And there are some relationships between A and B: relationship1: when A is in scope (A1 ... A10), B must be in scope (B1 ... B3). relationship2: when A is in scope (A11 ... A15), B must be in scope (B4).

And now we use value range providers in C:

class C{
  @PlanningVariable private A a;

  @ValueRangeProvider private List<A> aScope; //A1 ... A15

  @PlanningVariable
  private B b;

  @ValueRangeProvider private List<B> bScope; // B1 ... B4
}

we use a hardConstraint constraintD to constrain the above relationships. But we found in Debug log: if there is a planning entity c, c.a == A1, c.b == B1: when timefold doing moving, it will try change c.a = A11, but c.b is still B1 so that it will break hard constraint D, so this move will not be accepted. Such and such, it will not try to change c from relationship1 to relationship2.

we try to use the unionMoveSelector, but it still not work on above scenario.

are there any suggestion about this problem?


Solution

  • The generic moves Timefold Solver offers are not aware of the fact that these two variables should be changed only together. Correct assignment is then unlikely.

    In this situation, I would recommend implementing a custom move that contains the logic for correctly assigning both variables.

    To achieve best results, the custom move should assign only values that don't break hard constraints.